Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I created my own Menu System that is event driven.

In order to have a loading screen and multithreaded loading to work, I devised this sort of implementation:

//Let's check if the game is done loading.
if (_game != null) 
{
    _gameLoaded = _game.DoneLoading;
}

//This means the game is loading still, 
//therefore the loading screen should be active.
if (!_gameLoaded && _gameActive) 
{
    _gameScreenList[2].UpdateMenu();
}

//The loading screen was selected.
if (_gameScreenList[2].CurrentState == GameScreen.State.Shown && !_gameActive) 
{
     Components.Add(_game = new ParadoxGame(this));
     _game.Initialize(); //Initializes the Game so that the loading can begin.
     _gameActive = true;
}

In the XNA Game Component that contains the actual game, in the LoadContent method I simply created a new Thread that calls another method ThreadLoad that has all the actual loading.

I also have a boolean variable called DoneLoading in the XNA Game Component that is set to true at the end of the ThreadLoad.

I am wondering if this is a poor implementation.

share|improve this question
3  
Instead of polling the game to see if it's done, why not have it just fire an event when the loading thread finishes? –  LKIM Jul 24 '12 at 19:52
1  
I am not sure how it is supposed to be done in XNA, but using a boolean flag in a multithreaded application = shooting yourself in a foot. Also (_game != null) is rather a parameter validation then a condition to check if the game has finished loading. –  oleksii Jul 24 '12 at 19:53
    
@LKIM If I use an event, regarding the Update and Draw methods of the ParadoxGame Component, how would I make sure the objects aren't use when they are not loaded? @ oleksii I am not checking if the game has finished loading, but I am checking the state of the load boolean variable. –  Rob Jul 24 '12 at 20:04
    
In your event handler you set a boolean _gaveLoaded = true. Then everywhere else, you just need to poll that value instead of continually asking the game. –  LKIM Jul 24 '12 at 20:14
    
@LKIM Tell me if this implementation is good: pastebin.com/TKak3XHK –  Rob Jul 24 '12 at 21:29
add comment

migrated from stackoverflow.com Jul 24 '12 at 23:41

This question came from our site for professional and enthusiast programmers.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.