Felix Bytow Posted January 8, 2014 Share Posted January 8, 2014 I came across a little problem with Map:Load on a big map with lots of dependencies (entities, sounds, textures, ...). Though it works fine and everything it has one problem: While loading the engine does not care for the event loop, causing the operating system to mark the process as not responding. If you know what's going on, this is no problem. But it may be confusing to later customers that might become nervous that the game just crashed. Even if you know why the game freezes during the loading of the map you cannot exactly be sure if it is still loading or if it crashed. I found in the documentation that there is an overload of Map:Load allowing to provide a hook that is called for each loaded instance: http://www.leadwerks.com/werkspace/page/documentation/_/command-reference/map/mapload-r510 Here my problem is: there is no example on how to use this method from LUA (as for now I only got the Indie version as a backer). I tried doing something like Map:Load("path to map", "onEntitiyLoaded"); But I am not sure on how to give self to that function so it can call e.g. self.World:Update() and stuff... also what I tried just made the game crash.... So there are 2 solutions I can think of: Doing the load in an extra thread which signals when it's done, so the main thread can just run the main loop and maybe show some art or a progress bar or what not. Or the load should be reentrant, so you can do the main loop and on each iteration you go on loading a bit more of the map. Quote Link to comment Share on other sites More sharing options...
Rick Posted January 8, 2014 Share Posted January 8, 2014 I believe that function needs to be global (just function onEntityLoaded(entity) end). However, I think this is called after the map is loaded and just passes all loaded entities in it, which would still provide a pause. Give it a try though to test it. A cheap way to do this would be to draw to the screen first a texture that says you are loading. Your draw code doesn't have to always be in the main loop so you can do this before loading a map. I do believe you will still end up with the "not working" thing though. Quote Link to comment Share on other sites More sharing options...
bandrewk Posted January 8, 2014 Share Posted January 8, 2014 Good idea Felix. I just tried it, even if it has no real purpose, it still looks kinda good to display all entities loaded Quote Link to comment Share on other sites More sharing options...
Felix Bytow Posted January 8, 2014 Author Share Posted January 8, 2014 Though the "display a simple image up front and then load everything" would be a quick fix it is not quite satisfying. The player usually won't care for the loaded entities, that is true, but he might like an animated loading screen more than a static one. With the loading placed in another thread one could display an arbitrary complex loading screen, starting from playing an ogv, displaying an image with music, or showing somethign like a status bar. Even some spinning tribals might suffice to show the user "hey, there is still something going on".... ATM I am not sure how far Lua supports multi threading but I will do some research in that direction. 1 Quote Link to comment Share on other sites More sharing options...
Felix Bytow Posted January 11, 2014 Author Share Posted January 11, 2014 So the Thread class of Leadwerks says the following: "This class is not available in Lua." However Lua itself supports something called coroutines. These are used for multithreading and as it seems would allow what I want to achieve. I'll try to create a proof of concept and if it works post some code here. Quote Link to comment Share on other sites More sharing options...
Rick Posted January 11, 2014 Share Posted January 11, 2014 I would be curious to see if that works, but I don't think coroutines are real threads. It just simulates them. Quote Link to comment Share on other sites More sharing options...
Felix Bytow Posted January 12, 2014 Author Share Posted January 12, 2014 Rick, sadly you are right. Coroutines do no preemptive multi tasking. A coroutine runs until it calls yield. Only then another coroutine or the main routine may gain control :/ so my coroutine test ran, but it had the same effect as using no coroutine at all. I also tested the Map:Load(mapfile, hook) overload again. The hook is called after most of the files have been loaded so is is of no use here :/ Quote Link to comment Share on other sites More sharing options...
DudeAwesome Posted January 14, 2014 Share Posted January 14, 2014 But it may be confusing to later customers that might become nervous that the game just crashed. Even if you know why the game freezes during the loading of the map you cannot exactly be sure if it is still loading or if it crashed. I would just use threads later when LE3 with c++ support is available. c++ is close to hardware. thats not a good choice to use lua for that IMO Quote It doesn´t work... why? mhmmm It works... why? Link to comment Share on other sites More sharing options...
Felix Bytow Posted January 14, 2014 Author Share Posted January 14, 2014 It is not like I had a choice * cough * (still waiting for the full version) Still the Map:Load function could have been implemented in a way that doesn't make your app look like it crashed ;-) Quote Link to comment Share on other sites More sharing options...
DudeAwesome Posted January 14, 2014 Share Posted January 14, 2014 well for the time until c++ support is available: in Half Life 2 there was no loading screen also. just a note "LOADING" and the game was stuck until map was loaded loading screen is just a fancy part of the game. you can implement it later. or do it like HL2 btw: I would seperated the whole GUI/Game Logic stuff in threads. It should be no reason to use just one for everything so that the game is waiting and wasting cpu time by drawing something like Ammo/Health text/textures on the screen when the ticks should needed somewhere else. Sure its harder to handle more than 1 thread because you may produce data races or tearing effects but its still a kind of performance optimizing when your code is executed asynchron in that case. Quote It doesn´t work... why? mhmmm It works... why? Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.