Jump to content

Map:Load with progress


Felix Bytow
 Share

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

  • Upvote 1
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 :/

Link to comment
Share on other sites

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

It doesn´t work... why? mhmmm It works... why?

Link to comment
Share on other sites

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

 

4643603808_066e67ab10.jpg

 

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.

It doesn´t work... why? mhmmm It works... why?

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...