2012-08-09 09:45:04 +00:00
|
|
|
#region Using Statements
|
2011-10-31 05:36:24 +00:00
|
|
|
using System;
|
2012-09-01 15:09:10 +00:00
|
|
|
using System.Collections.Generic;
|
2011-10-31 05:36:24 +00:00
|
|
|
using ANX.Framework.Content;
|
|
|
|
using ANX.Framework.Graphics;
|
|
|
|
using ANX.Framework.NonXNA;
|
2012-08-29 12:46:08 +00:00
|
|
|
using ANX.Framework.NonXNA.Development;
|
2012-09-01 15:09:10 +00:00
|
|
|
using ANX.Framework.NonXNA.PlatformSystem;
|
2011-10-31 05:36:24 +00:00
|
|
|
|
|
|
|
#endregion // Using Statements
|
|
|
|
|
2012-08-09 09:45:04 +00:00
|
|
|
// This file is part of the ANX.Framework created by the
|
|
|
|
// "ANX.Framework developer group" and released under the Ms-PL license.
|
|
|
|
// For details see: http://anxframework.codeplex.com/license
|
2011-10-31 05:36:24 +00:00
|
|
|
|
|
|
|
namespace ANX.Framework
|
|
|
|
{
|
2012-09-01 11:20:05 +00:00
|
|
|
[PercentageComplete(60)]
|
2012-08-29 12:46:08 +00:00
|
|
|
[TestState(TestStateAttribute.TestState.Untested)]
|
2012-08-29 13:14:00 +00:00
|
|
|
[Developer("Glatzemann")]
|
2012-08-25 17:27:45 +00:00
|
|
|
public class Game : IDisposable
|
2012-09-01 11:20:05 +00:00
|
|
|
{
|
|
|
|
#region Private Members
|
|
|
|
private IGraphicsDeviceManager graphicsDeviceManager;
|
2012-08-25 17:27:45 +00:00
|
|
|
private IGraphicsDeviceService graphicsDeviceService;
|
|
|
|
private GameServiceContainer gameServices;
|
2012-09-01 11:20:05 +00:00
|
|
|
|
|
|
|
private bool firstUpdateDone;
|
|
|
|
private bool firstDrawDone;
|
|
|
|
private bool drawingSlow;
|
|
|
|
private bool inRun;
|
|
|
|
|
2012-08-25 17:27:45 +00:00
|
|
|
private GameHost host;
|
|
|
|
private bool ShouldExit;
|
|
|
|
|
2012-09-01 11:20:05 +00:00
|
|
|
private GameTimer gameTimer;
|
|
|
|
private TimeSpan gameTimeAccu;
|
2012-08-25 17:27:45 +00:00
|
|
|
private GameTime gameTime;
|
|
|
|
private TimeSpan totalGameTime;
|
2012-09-01 11:20:05 +00:00
|
|
|
private long updatesSinceRunningSlowly1;
|
|
|
|
private long updatesSinceRunningSlowly2;
|
|
|
|
private bool suppressDraw;
|
2012-08-25 17:27:45 +00:00
|
|
|
|
|
|
|
private GameTime gameUpdateTime;
|
|
|
|
|
|
|
|
private ContentManager content;
|
|
|
|
|
2012-08-29 12:32:14 +00:00
|
|
|
private List<IGameComponent> drawableGameComponents;
|
|
|
|
|
2012-09-01 11:20:05 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region Events
|
|
|
|
public event EventHandler<EventArgs> Activated;
|
2012-08-25 17:27:45 +00:00
|
|
|
public event EventHandler<EventArgs> Deactivated;
|
|
|
|
public event EventHandler<EventArgs> Disposed;
|
|
|
|
public event EventHandler<EventArgs> Exiting;
|
|
|
|
|
2012-09-01 11:20:05 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
public Game()
|
2012-08-25 17:27:45 +00:00
|
|
|
{
|
|
|
|
Logger.Info("created a new Game-Class");
|
|
|
|
|
|
|
|
this.gameServices = new GameServiceContainer();
|
|
|
|
this.gameTime = new GameTime();
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
AddInSystemFactory.Instance.Initialize();
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
Logger.Error("Error while initializing AddInSystem: " + ex);
|
|
|
|
throw new AddInLoadingException("Error while initializing AddInSystem.", ex);
|
|
|
|
}
|
|
|
|
|
|
|
|
AddSystemCreator<IInputSystemCreator>();
|
|
|
|
AddSystemCreator<ISoundSystemCreator>();
|
|
|
|
AddSystemCreator<IRenderSystemCreator>();
|
|
|
|
|
|
|
|
CreateGameHost();
|
|
|
|
|
|
|
|
Logger.Info("creating ContentManager");
|
|
|
|
this.content = new ContentManager(this.gameServices);
|
|
|
|
|
|
|
|
Logger.Info("creating GameTimer");
|
2012-09-01 11:20:05 +00:00
|
|
|
this.gameTimer = new GameTimer();
|
|
|
|
this.IsFixedTimeStep = true;
|
2012-08-25 17:27:45 +00:00
|
|
|
this.gameUpdateTime = new GameTime();
|
2012-09-01 11:20:05 +00:00
|
|
|
this.InactiveSleepTime = TimeSpan.FromMilliseconds(20.0);
|
|
|
|
this.TargetElapsedTime = TimeSpan.FromTicks(TimeSpan.TicksPerSecond / 60L); // default is 1/60s
|
2012-08-25 17:27:45 +00:00
|
|
|
|
2012-08-29 12:32:14 +00:00
|
|
|
//TODO: implement draw- and update-order handling of GameComponents
|
2012-09-06 09:58:13 +00:00
|
|
|
this.Components = new GameComponentCollection();
|
|
|
|
this.Components.ComponentAdded += components_ComponentAdded;
|
|
|
|
this.Components.ComponentRemoved += components_ComponentRemoved;
|
2012-08-29 12:32:14 +00:00
|
|
|
this.drawableGameComponents = new List<IGameComponent>();
|
|
|
|
|
2012-08-25 17:27:45 +00:00
|
|
|
Logger.Info("finished initializing new Game class");
|
2012-09-01 11:20:05 +00:00
|
|
|
|
|
|
|
this.IsActive = true;
|
2012-08-25 17:27:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
~Game()
|
|
|
|
{
|
2012-09-06 09:58:13 +00:00
|
|
|
this.Components.ComponentAdded -= components_ComponentAdded;
|
|
|
|
this.Components.ComponentRemoved -= components_ComponentRemoved;
|
2012-08-29 12:32:14 +00:00
|
|
|
|
2012-08-30 12:05:40 +00:00
|
|
|
Dispose(false);
|
2012-08-25 17:27:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#region CreateGameHost
|
|
|
|
private void CreateGameHost()
|
|
|
|
{
|
|
|
|
Logger.Info("creating GameHost");
|
2012-09-18 05:53:08 +00:00
|
|
|
host = PlatformSystem.Instance.CreateGameHost(this);
|
2012-08-30 12:05:40 +00:00
|
|
|
|
|
|
|
host.Activated += HostActivated;
|
|
|
|
host.Deactivated += HostDeactivated;
|
|
|
|
host.Suspend += HostSuspend;
|
|
|
|
host.Resume += HostResume;
|
|
|
|
host.Idle += HostIdle;
|
|
|
|
host.Exiting += HostExiting;
|
2012-08-25 17:27:45 +00:00
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region AddSystemCreator
|
|
|
|
private T AddSystemCreator<T>() where T : class, ICreator
|
|
|
|
{
|
|
|
|
T creator = AddInSystemFactory.Instance.GetDefaultCreator<T>();
|
|
|
|
if (creator != null)
|
|
|
|
this.gameServices.AddService(typeof(T), creator);
|
2012-08-25 21:22:30 +00:00
|
|
|
|
2012-08-25 17:27:45 +00:00
|
|
|
return creator;
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
protected virtual void Initialize()
|
|
|
|
{
|
|
|
|
//TODO: implement
|
|
|
|
|
|
|
|
this.LoadContent();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected virtual void Update(GameTime gameTime)
|
|
|
|
{
|
2012-09-06 09:58:13 +00:00
|
|
|
foreach (IUpdateable updateable in this.Components)
|
2012-08-29 12:32:14 +00:00
|
|
|
{
|
|
|
|
if (updateable.Enabled)
|
|
|
|
{
|
|
|
|
updateable.Update(gameTime);
|
|
|
|
}
|
|
|
|
}
|
2012-08-25 17:27:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected virtual void Draw(GameTime gameTime)
|
|
|
|
{
|
2012-08-29 12:32:14 +00:00
|
|
|
foreach (IDrawable drawable in this.drawableGameComponents)
|
|
|
|
{
|
|
|
|
if (drawable.Visible)
|
|
|
|
{
|
|
|
|
drawable.Draw(gameTime);
|
|
|
|
}
|
|
|
|
}
|
2012-08-25 17:27:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected virtual void LoadContent()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
protected virtual void UnloadContent()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
protected virtual void BeginRun()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
protected virtual void EndRun()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public void RunOneFrame()
|
|
|
|
{
|
|
|
|
throw new NotImplementedException();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SuppressDraw()
|
|
|
|
{
|
2012-09-01 11:20:05 +00:00
|
|
|
this.suppressDraw = true;
|
2012-08-25 17:27:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void ResetElapsedTime()
|
|
|
|
{
|
|
|
|
throw new NotImplementedException();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected virtual bool BeginDraw()
|
|
|
|
{
|
|
|
|
if ((this.graphicsDeviceManager != null) && !this.graphicsDeviceManager.BeginDraw())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
//Logger.BeginLogEvent(LoggingEvent.Draw, "");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected virtual void EndDraw()
|
|
|
|
{
|
|
|
|
if (this.graphicsDeviceManager != null)
|
|
|
|
{
|
|
|
|
this.graphicsDeviceManager.EndDraw();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Exit()
|
|
|
|
{
|
|
|
|
this.ShouldExit = true;
|
|
|
|
this.host.Exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Run()
|
|
|
|
{
|
|
|
|
this.RunGame();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Tick()
|
|
|
|
{
|
2012-08-29 12:11:03 +00:00
|
|
|
if (this.ShouldExit)
|
2012-09-01 11:20:05 +00:00
|
|
|
{
|
2012-08-29 12:11:03 +00:00
|
|
|
return;
|
2012-09-01 11:20:05 +00:00
|
|
|
}
|
2012-08-29 12:11:03 +00:00
|
|
|
|
2012-09-01 11:20:05 +00:00
|
|
|
// Throttle speed when the game is not active
|
|
|
|
if (!this.IsActive)
|
|
|
|
{
|
|
|
|
ThreadHelper.Sleep(InactiveSleepTime);
|
|
|
|
}
|
2012-08-09 09:45:04 +00:00
|
|
|
|
2012-09-01 11:20:05 +00:00
|
|
|
gameTimer.Update();
|
2012-08-25 17:27:45 +00:00
|
|
|
|
2012-09-01 11:20:05 +00:00
|
|
|
bool skipDraw = IsFixedTimeStep ? DoFixedTimeStep(gameTimer.Elapsed) : DoTimeStep(gameTimer.Elapsed);
|
|
|
|
this.suppressDraw = false;
|
|
|
|
if (skipDraw == false)
|
|
|
|
{
|
|
|
|
DrawFrame();
|
|
|
|
}
|
2012-08-25 17:27:45 +00:00
|
|
|
|
2012-09-01 11:20:05 +00:00
|
|
|
}
|
2012-08-25 17:27:45 +00:00
|
|
|
|
2012-09-01 11:20:05 +00:00
|
|
|
private bool DoFixedTimeStep(TimeSpan time)
|
|
|
|
{
|
|
|
|
bool skipDraw = false;
|
2012-08-25 17:27:45 +00:00
|
|
|
|
2012-09-01 11:20:05 +00:00
|
|
|
if (Math.Abs(time.Ticks - this.TargetElapsedTime.Ticks) < this.TargetElapsedTime.Ticks >> 6)
|
|
|
|
{
|
|
|
|
time = this.TargetElapsedTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.gameTimeAccu += time;
|
|
|
|
long updateCount = this.gameTimeAccu.Ticks / this.TargetElapsedTime.Ticks;
|
|
|
|
|
|
|
|
if (updateCount <= 0)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (updateCount > 1)
|
|
|
|
{
|
|
|
|
this.updatesSinceRunningSlowly2 = this.updatesSinceRunningSlowly1;
|
|
|
|
this.updatesSinceRunningSlowly1 = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.updatesSinceRunningSlowly1++;
|
|
|
|
this.updatesSinceRunningSlowly2++;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.drawingSlow = (this.updatesSinceRunningSlowly2 < 20);
|
|
|
|
|
|
|
|
while (updateCount > 0)
|
|
|
|
{
|
|
|
|
if (this.ShouldExit)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
updateCount -= 1L;
|
|
|
|
|
|
|
|
this.gameTime.ElapsedGameTime = this.TargetElapsedTime;
|
|
|
|
this.gameTime.TotalGameTime = this.totalGameTime;
|
|
|
|
this.gameTime.IsRunningSlowly = this.drawingSlow;
|
|
|
|
this.Update(this.gameTime);
|
|
|
|
skipDraw &= this.suppressDraw;
|
|
|
|
this.suppressDraw = false;
|
2012-08-25 17:27:45 +00:00
|
|
|
|
2012-09-01 11:20:05 +00:00
|
|
|
this.gameTimeAccu -= this.TargetElapsedTime;
|
|
|
|
this.totalGameTime += this.TargetElapsedTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
return skipDraw;
|
|
|
|
}
|
|
|
|
|
|
|
|
private bool DoTimeStep(TimeSpan time)
|
|
|
|
{
|
|
|
|
this.gameTime.ElapsedGameTime = time;
|
|
|
|
this.gameTime.TotalGameTime = this.totalGameTime;
|
|
|
|
this.gameTime.IsRunningSlowly = false;
|
|
|
|
|
|
|
|
this.Update(this.gameTime);
|
|
|
|
|
|
|
|
this.totalGameTime += time;
|
|
|
|
|
|
|
|
return suppressDraw;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void RunGame()
|
2012-08-25 17:27:45 +00:00
|
|
|
{
|
|
|
|
this.graphicsDeviceManager = this.Services.GetService(typeof(IGraphicsDeviceManager)) as IGraphicsDeviceManager;
|
|
|
|
if (this.graphicsDeviceManager != null)
|
|
|
|
this.graphicsDeviceManager.CreateDevice();
|
2012-08-30 12:05:40 +00:00
|
|
|
|
2012-08-25 17:27:45 +00:00
|
|
|
this.Initialize();
|
|
|
|
this.inRun = true;
|
|
|
|
this.BeginRun();
|
|
|
|
this.gameTime.ElapsedGameTime = TimeSpan.Zero;
|
|
|
|
this.gameTime.TotalGameTime = this.totalGameTime;
|
|
|
|
this.gameTime.IsRunningSlowly = false;
|
|
|
|
this.Update(this.gameTime);
|
2012-09-01 11:20:05 +00:00
|
|
|
this.firstUpdateDone = true;
|
2012-08-25 17:27:45 +00:00
|
|
|
this.host.Run();
|
|
|
|
this.EndRun();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void DrawFrame()
|
|
|
|
{
|
2012-09-01 11:20:05 +00:00
|
|
|
if (!this.ShouldExit)
|
|
|
|
{
|
|
|
|
if (this.firstUpdateDone)
|
|
|
|
{
|
|
|
|
if (!this.Window.IsMinimized)
|
|
|
|
{
|
|
|
|
if (this.BeginDraw())
|
|
|
|
{
|
|
|
|
this.Draw(this.gameTime);
|
|
|
|
this.EndDraw();
|
|
|
|
|
|
|
|
if (!this.firstDrawDone)
|
|
|
|
{
|
|
|
|
this.firstDrawDone = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-08-25 17:27:45 +00:00
|
|
|
}
|
|
|
|
|
2012-09-01 11:20:05 +00:00
|
|
|
#region Public Properties
|
|
|
|
public GameServiceContainer Services
|
2012-08-25 17:27:45 +00:00
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return this.gameServices;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public ContentManager Content
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return this.content;
|
|
|
|
}
|
|
|
|
set
|
|
|
|
{
|
|
|
|
this.content = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public GraphicsDevice GraphicsDevice
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
//TODO: GraphicsDevice property is heavily used. Maybe it is better to hook an event to the services container and
|
|
|
|
// cache the reference to the GraphicsDeviceService to prevent accessing the dictionary of the services container
|
|
|
|
|
|
|
|
IGraphicsDeviceService graphicsDeviceService = this.graphicsDeviceService;
|
|
|
|
if (graphicsDeviceService == null)
|
|
|
|
{
|
|
|
|
graphicsDeviceService = this.Services.GetService(typeof(IGraphicsDeviceService)) as IGraphicsDeviceService;
|
|
|
|
|
|
|
|
//TODO: exception if null
|
|
|
|
}
|
2012-09-01 11:20:05 +00:00
|
|
|
|
2012-08-25 17:27:45 +00:00
|
|
|
return graphicsDeviceService.GraphicsDevice;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public GameWindow Window
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
2012-09-01 11:20:05 +00:00
|
|
|
return (host != null) ? host.Window : null;
|
2012-08-25 17:27:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool IsFixedTimeStep
|
|
|
|
{
|
2012-09-01 11:20:05 +00:00
|
|
|
get;
|
|
|
|
set;
|
2012-08-25 17:27:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public TimeSpan TargetElapsedTime
|
|
|
|
{
|
2012-09-01 11:20:05 +00:00
|
|
|
get;
|
|
|
|
set;
|
2012-08-25 17:27:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public TimeSpan InactiveSleepTime
|
|
|
|
{
|
|
|
|
get;
|
|
|
|
set;
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool IsActive
|
|
|
|
{
|
2012-09-01 11:20:05 +00:00
|
|
|
get;
|
|
|
|
internal set;
|
|
|
|
}
|
2012-08-25 17:27:45 +00:00
|
|
|
|
|
|
|
public bool IsMouseVisible
|
|
|
|
{
|
|
|
|
get;
|
|
|
|
set;
|
|
|
|
}
|
|
|
|
|
|
|
|
public LaunchParameters LaunchParameters
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
throw new NotImplementedException();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-29 12:32:14 +00:00
|
|
|
public GameComponentCollection Components
|
|
|
|
{
|
|
|
|
get;
|
|
|
|
private set;
|
|
|
|
}
|
2012-08-25 17:27:45 +00:00
|
|
|
|
2012-09-01 11:20:05 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
internal bool IsActiveIgnoringGuide
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
throw new NotImplementedException();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-25 17:27:45 +00:00
|
|
|
public void Dispose()
|
|
|
|
{
|
2012-08-30 12:05:40 +00:00
|
|
|
Dispose(true);
|
|
|
|
GC.SuppressFinalize(this);
|
2012-08-25 17:27:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected virtual void Dispose(bool disposing)
|
|
|
|
{
|
2012-08-30 12:05:40 +00:00
|
|
|
if (disposing)
|
|
|
|
{
|
|
|
|
IDisposable disposable;
|
2012-09-06 09:58:13 +00:00
|
|
|
var array = new IGameComponent[Components.Count];
|
|
|
|
Components.CopyTo(array, 0);
|
2012-08-30 12:05:40 +00:00
|
|
|
for (int i = 0; i < array.Length; i++)
|
|
|
|
{
|
|
|
|
disposable = (IDisposable)array[i];
|
|
|
|
if (disposable != null)
|
|
|
|
disposable.Dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
disposable = (IDisposable)graphicsDeviceManager;
|
|
|
|
if (disposable != null)
|
|
|
|
disposable.Dispose();
|
|
|
|
|
|
|
|
if (Disposed != null)
|
|
|
|
Disposed(this, EventArgs.Empty);
|
|
|
|
}
|
2012-08-25 17:27:45 +00:00
|
|
|
}
|
|
|
|
|
2012-09-01 11:20:05 +00:00
|
|
|
protected virtual bool ShowMissingRequirementMessage(Exception exception)
|
|
|
|
{
|
|
|
|
throw new NotImplementedException();
|
|
|
|
}
|
|
|
|
|
|
|
|
#region Event Handling
|
|
|
|
protected virtual void OnActivated(Object sender, EventArgs args)
|
2012-08-25 17:27:45 +00:00
|
|
|
{
|
2012-09-01 11:20:05 +00:00
|
|
|
RaiseIfNotNull(this.Activated, sender, args);
|
2012-08-25 17:27:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected virtual void OnDeactivated(Object sender, EventArgs args)
|
|
|
|
{
|
2012-09-01 11:20:05 +00:00
|
|
|
RaiseIfNotNull(this.Deactivated, sender, args);
|
2012-08-25 17:27:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected virtual void OnExiting(Object sender, EventArgs args)
|
|
|
|
{
|
2012-09-01 11:20:05 +00:00
|
|
|
RaiseIfNotNull(this.Exiting, sender, args);
|
2012-08-25 17:27:45 +00:00
|
|
|
}
|
|
|
|
|
2012-09-01 11:20:05 +00:00
|
|
|
private void RaiseIfNotNull(EventHandler<EventArgs> eventDelegate, Object sender, EventArgs args)
|
|
|
|
{
|
|
|
|
if (eventDelegate != null)
|
|
|
|
{
|
|
|
|
eventDelegate(sender, args);
|
|
|
|
}
|
|
|
|
}
|
2012-08-29 12:32:14 +00:00
|
|
|
|
|
|
|
private void components_ComponentRemoved(object sender, GameComponentCollectionEventArgs e)
|
|
|
|
{
|
|
|
|
if (e.GameComponent is IDrawable)
|
|
|
|
{
|
|
|
|
drawableGameComponents.Remove(e.GameComponent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void components_ComponentAdded(object sender, GameComponentCollectionEventArgs e)
|
|
|
|
{
|
|
|
|
if (e.GameComponent is IDrawable)
|
|
|
|
{
|
|
|
|
drawableGameComponents.Add(e.GameComponent);
|
|
|
|
}
|
2012-08-29 12:33:35 +00:00
|
|
|
|
|
|
|
e.GameComponent.Initialize();
|
2012-08-29 12:32:14 +00:00
|
|
|
}
|
|
|
|
|
2012-09-01 11:20:05 +00:00
|
|
|
private void HostActivated(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if (!IsActive)
|
|
|
|
{
|
|
|
|
this.IsActive = true;
|
|
|
|
this.OnActivated(this, EventArgs.Empty);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void HostDeactivated(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if (IsActive)
|
|
|
|
{
|
|
|
|
this.IsActive = false;
|
|
|
|
this.OnDeactivated(this, EventArgs.Empty);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void HostExiting(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
ShouldExit = true;
|
|
|
|
|
|
|
|
//TODO: implement
|
|
|
|
//this.OnExiting(this, EventArgs.Empty);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void HostIdle(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
this.Tick();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void HostResume(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
//TODO: implement
|
|
|
|
//this.clock.Resume();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void HostSuspend(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
//TODO: implement
|
|
|
|
//this.clock.Suspend();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
2011-10-31 05:36:24 +00:00
|
|
|
}
|