Dealing with SceneLoader load times
by Jacob Lynch · in Torque X 2D · 10/15/2010 (2:40 am) · 29 replies
We are getting to the point in our game development where we are loading a couple scenes that each contain a couple hundred objects (with associated components, materials, animations, etc). This leads to a loading time of a minute or two, which is a long time to stare at a loading screen. Does anyone have any tips on how to reduce loading time? I'd appreciate it!
Thanks!
Thanks!
About the author
#22
That's great! I will have a go at implementing this. I'll try not overlap content blocks too, the last thing I want is Duncan whining at me ;-)
Cheers
10/20/2010 (8:59 am)
@JohnThat's great! I will have a go at implementing this. I'll try not overlap content blocks too, the last thing I want is Duncan whining at me ;-)
Cheers
#23
[whine]I advise against overlapping content blocks because in some particular instances it can lead to your game crashing - in john's case, however, that won't happen because all the overlapping content is already loaded and never unloaded.[/whine]
10/20/2010 (12:28 pm)
Yeah you wouldn't want me whining at you - few people can bear it for very long ;-)[whine]I advise against overlapping content blocks because in some particular instances it can lead to your game crashing - in john's case, however, that won't happen because all the overlapping content is already loaded and never unloaded.[/whine]
#24
Sometimes a good whine is needed!!
What happens with multiple scenes? Will there be a risk of the game crashing? Or does that depened on what content is being unloaded?
Oh and what are the variables _commonContent and _allContent declared as?
Cheers
10/20/2010 (12:45 pm)
ha ha!Sometimes a good whine is needed!!
What happens with multiple scenes? Will there be a risk of the game crashing? Or does that depened on what content is being unloaded?
Oh and what are the variables _commonContent and _allContent declared as?
Cheers
#25
Multiple scenes in themselves are abolutely fine. It's only when you have overlapping content blocks that there can be issues. And only if you are unloading content blocks.
Essentially what can happen is that you unload a content block which in turn unloads all it's loaded content, while at the same time your game is still referencing that piece of content... oops!
The content loader is intelligent and only loads one instance of each resource, but if you unload a content block it will still take all it's resources with it (this is the way the xna resource manager works - all or nothing). If your game happens to be referencing one of those resources it will crash. This is generally an issue anyway of course - you don't want to unload content yr game is still using! Overlapping content blocks can just make this situation more likely if you aren't careful about the loading/unloading of their content.
Generally it will be fine, but it *can* catch you out so I typically advise against it, because you might waste a day wondering wtf is going on before you realise. Plus it's more efficient not to overlap content blocks anyway if you are overlapping a ton of content :)
10/20/2010 (6:34 pm)
They will be declared as ContentBlock.Multiple scenes in themselves are abolutely fine. It's only when you have overlapping content blocks that there can be issues. And only if you are unloading content blocks.
Essentially what can happen is that you unload a content block which in turn unloads all it's loaded content, while at the same time your game is still referencing that piece of content... oops!
The content loader is intelligent and only loads one instance of each resource, but if you unload a content block it will still take all it's resources with it (this is the way the xna resource manager works - all or nothing). If your game happens to be referencing one of those resources it will crash. This is generally an issue anyway of course - you don't want to unload content yr game is still using! Overlapping content blocks can just make this situation more likely if you aren't careful about the loading/unloading of their content.
Generally it will be fine, but it *can* catch you out so I typically advise against it, because you might waste a day wondering wtf is going on before you realise. Plus it's more efficient not to overlap content blocks anyway if you are overlapping a ton of content :)
#26
-or- Can you go ahead and call that and if you load up a scene it will just finish loading whatever isn't loaded yet?
10/21/2010 (5:42 pm)
So do you have to wait for the content to get loaded if doing as John has with:_commonContent.AsyncLoadImmediately(_AsyncCallbackLoadCommon, null);
-or- Can you go ahead and call that and if you load up a scene it will just finish loading whatever isn't loaded yet?
#27
10/21/2010 (7:51 pm)
You should let it load before you try and use stuff that it's loading. It loads the content using a separate hardware thread so that your game can keep on running - if you try to access stuff that is in the middle of loading it would almost certainly crash your game.
#28
10/22/2010 (12:36 am)
That is exactly why I wait until all my common content has loaded before trying to load any level. You don't want to find yourself in a position where things can randomly break due to threading. If you are asynchronously loading something, add some way to block your game from loading anything else until it is done.
#29
10/22/2010 (1:40 pm)
Yep, async loading will allow you to do something else while stuff is loading (like showing an animated loading screen or your game's splash screens at startup), but you shouldn't try to use any of the stuff that is loading until it's all finished.
Torque Owner John Norman
Suckerfree Games
public bool LoadedCommonContent { get; private set; } protected override void BeginRun() { base.BeginRun(); ... _commonContent = new ContentBlock(); _commonContent.AddFolder<Texture2D>(@"data/images/characters/human_knight/", true); _commonContent.AddFolder<Texture2D>(@"data/images/characters/human_peasant_female/", true); _commonContent.AddFolder<Texture2D>(@"data/images/characters/human_peasant_male/", true); _commonContent.AddFolder<Texture2D>(@"data/images/characters/kobold_spawn/", true); _commonContent.AddFolder<Texture2D>(@"data/images/hud/", true); _commonContent.AddFolder<Texture2D>(@"data/images/objects/", true); _commonContent.AddFolder<Texture2D>(@"data/images/text/", true); _commonContent.AsyncLoadImmediately(_AsyncCallbackLoadCommon, null); _allContent = new ContentBlock(); _allContent.AddFolder<Texture2D>(@"data/images/", true); _allContent.AllowLoading(); ... } protected void _AsyncCallbackLoadCommon(IAsyncResult ar) { AsyncContentBlockResult result = ar as AsyncContentBlockResult; if (result == null) return; // If we completed loading, finish with loading our scene. if (result.IsCompleted) { LoadedCommonContent = true; } }I tell it to load my common assets in the background. When the loading is finished, it sets Game.Instance.LoadedCommonContent to true. When I load my first level, I delay until LoadedCommonContent has been set to true, then I load the actual level._commonContent is my content block with all my common content. _allContent is a content block with all my content. By calling _allContent.AllowLoading(), it lets Torque X load all the rest of my content normally (on demand.) This works well for my game. You may have to fine tune it for yours. Also, if you overlap content blocks like I do (_allContent has files that _commonContent has), Duncan will whine at you, so I recommend you don't do that. :)
EDIT: Also, always use forward slashes in your path names. That is all.