Skip to content
This repository has been archived by the owner on Mar 30, 2019. It is now read-only.

Commit

Permalink
[Toolkit.Game] Separate Game/GameSystem.LoadContent from Initialize, …
Browse files Browse the repository at this point in the history
…in scenarios where Initialize method is overriden, the base.Initialize should not start to load content until all game systems are initialized
  • Loading branch information
Alexandre Mutel committed Feb 5, 2013
1 parent 1a64773 commit a1e5d65
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
23 changes: 9 additions & 14 deletions Source/Toolkit/SharpDX.Toolkit.Game/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ public class Game : Component
private int nextLastUpdateCountIndex;
private bool drawRunningSlowly;
private bool forceElapsedTimeToZero;
private bool isInitialzing;
private bool contentLoaded = false;

private readonly TimerTick timer;
Expand Down Expand Up @@ -316,6 +315,9 @@ internal void InitializeBeforeRun()
// Initialize this instance and all game systems
Initialize();

// Load the content of the game
LoadContent();

IsRunning = true;

BeginRun();
Expand Down Expand Up @@ -616,26 +618,13 @@ protected virtual void Initialize()
pendingGameSystems[0].Initialize();
pendingGameSystems.RemoveAt(0);
}

// Load the content of the game
isInitialzing = true;
LoadContent();
isInitialzing = false;
}

/// <summary>
/// Loads the content.
/// </summary>
protected virtual void LoadContent()
{
// When initializing, we don't need to call explicitly the LoadContent for each GameSystem
// as they were already called by the GameSystem.Initialize method
// Otherwise, in case of a GraphicsDevice reset, we need to call GameSystem.LoadContent
if (isInitialzing)
{
return;
}

lock (contentableGameSystems)
{
foreach (var contentable in contentableGameSystems)
Expand Down Expand Up @@ -874,6 +863,12 @@ private void GameSystems_ItemAdded(object sender, ObservableCollectionEventArgs<
contentableGameSystems.Add(contentableSystem);
}
}

if (IsRunning)
{
// Load the content of the system if the game is already running
contentableSystem.LoadContent();
}
}

// Add an updateable system to the separate list
Expand Down
2 changes: 0 additions & 2 deletions Source/Toolkit/SharpDX.Toolkit.Game/GameSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,6 @@ public virtual void Initialize()

// Gets the graphics device service
graphicsDeviceService = (IGraphicsDeviceService)registry.GetService(typeof(IGraphicsDeviceService));

((IContentable)this).LoadContent();
}

#endregion
Expand Down

0 comments on commit a1e5d65

Please sign in to comment.