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

Commit

Permalink
GameComponent cleanup, cleanup of previous merge
Browse files Browse the repository at this point in the history
  • Loading branch information
flibitijibibo committed Apr 6, 2014
1 parent 37ba458 commit be42238
Show file tree
Hide file tree
Showing 8 changed files with 156 additions and 148 deletions.
226 changes: 120 additions & 106 deletions MonoGame.Framework/GameComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,118 +13,132 @@

namespace Microsoft.Xna.Framework
{
public class GameComponent : IGameComponent, IUpdateable, IComparable<GameComponent>, IDisposable
{
#region Public Properties
public class GameComponent : IGameComponent, IUpdateable, IComparable<GameComponent>, IDisposable
{
#region Public Properties

public Game Game
{
get;
private set;
}

public bool Enabled
{
get
{
return _enabled;
}
set
{
if (_enabled != value)
{
_enabled = value;
if (this.EnabledChanged != null)
{
this.EnabledChanged(this, EventArgs.Empty);
}
OnEnabledChanged(this, null);
}
}
}

public int UpdateOrder
{
get
{
return _updateOrder;
}
set
{
if (_updateOrder != value)
{
_updateOrder = value;
if (this.UpdateOrderChanged != null)
{
this.UpdateOrderChanged(this, EventArgs.Empty);
}
OnUpdateOrderChanged(this, null);
}
}
}

#endregion

#region Private Variables

bool _enabled = true;
int _updateOrder;

#endregion

#region Events

public event EventHandler<EventArgs> EnabledChanged;
public event EventHandler<EventArgs> UpdateOrderChanged;

#endregion

#region Public Constructors

public GameComponent(Game game)
{
this.Game = game;
}

#endregion

#region Deconstructor

~GameComponent()
{
Dispose(false);
}

#endregion

#region Public Dispose Method

/// <summary>
/// Shuts down the component.
/// </summary>
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

#endregion

#region Public Virtual Methods

public virtual void Initialize() {}

public virtual void Update(GameTime gameTime) {}

public Game Game { get; private set; }
#endregion

#region Protected Virtual Methods

public bool Enabled
{
get { return _enabled; }
set
{
if (_enabled != value)
{
_enabled = value;
if (this.EnabledChanged != null)
this.EnabledChanged(this, EventArgs.Empty);
OnEnabledChanged(this, null);
}
}
}
protected virtual void OnUpdateOrderChanged(object sender, EventArgs args) {}

public int UpdateOrder
{
get { return _updateOrder; }
set
{
if (_updateOrder != value)
{
_updateOrder = value;
if (this.UpdateOrderChanged != null)
this.UpdateOrderChanged(this, EventArgs.Empty);
OnUpdateOrderChanged(this, null);
}
}
}
protected virtual void OnEnabledChanged(object sender, EventArgs args) {}

#endregion
/// <summary>
/// Shuts down the component.
/// </summary>
protected virtual void Dispose(bool disposing) {}

#region Private Variables
#endregion

bool _enabled = true;
int _updateOrder;
#region IComparable<GameComponent> Members

#endregion
// TODO: Should be removed, as it is not part of XNA 4.0
public int CompareTo(GameComponent other)
{
return other.UpdateOrder - this.UpdateOrder;
}

#region Events

public event EventHandler<EventArgs> EnabledChanged;
public event EventHandler<EventArgs> UpdateOrderChanged;

#endregion

#region Public Constructors

public GameComponent(Game game)
{
this.Game = game;
}

#endregion

#region Deconstructor

~GameComponent()
{
Dispose(false);
}

#endregion

#region Public Dispose Method

/// <summary>
/// Shuts down the component.
/// </summary>
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

#endregion

#region Public Virtual Methods

public virtual void Initialize() { }

public virtual void Update(GameTime gameTime) { }

#endregion

#region Protected Virtual Methods

protected virtual void OnUpdateOrderChanged(object sender, EventArgs args) { }

protected virtual void OnEnabledChanged(object sender, EventArgs args) { }

/// <summary>
/// Shuts down the component.
/// </summary>
protected virtual void Dispose(bool disposing) { }

#endregion

#region IComparable<GameComponent> Members

// TODO: Should be removed, as it is not part of XNA 4.0
public int CompareTo(GameComponent other)
{
return other.UpdateOrder - this.UpdateOrder;
}

#endregion
}
#endregion
}
}
1 change: 0 additions & 1 deletion MonoGame.Framework/GameComponentCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,3 @@ private void OnComponentRemoved(GameComponentCollectionEventArgs eventArgs)
#endregion
}
}

15 changes: 3 additions & 12 deletions MonoGame.Framework/GameComponentCollectionEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,19 @@ public class GameComponentCollectionEventArgs : EventArgs

public IGameComponent GameComponent
{
get
{
return _gameComponent;
}
get;
private set;
}

#endregion

#region Private Variables

private IGameComponent _gameComponent;

#endregion

#region Public Constructors

public GameComponentCollectionEventArgs(IGameComponent gameComponent)
{
_gameComponent = gameComponent;
GameComponent = gameComponent;
}

#endregion
}
}

25 changes: 11 additions & 14 deletions MonoGame.Framework/GamePlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
#endregion

#region Using Statements
using System;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Input.Touch;
using System;
#endregion

namespace Microsoft.Xna.Framework
Expand Down Expand Up @@ -75,8 +75,6 @@ public GameWindow Window
{
return _window;
}


protected set
{
if (_window == null)
Expand Down Expand Up @@ -160,7 +158,7 @@ protected GamePlatform(Game game)

/// <summary>
/// Gives derived classes an opportunity to do work before any
/// components are initialized. Note that the base implementation sets
/// components are initialized. Note that the base implementation sets
/// IsActive to true, so derived classes should either call the base
/// implementation or set IsActive to true by their own means.
/// </summary>
Expand All @@ -179,7 +177,7 @@ public virtual void BeforeInitialize()

/// <summary>
/// Gives derived classes an opportunity to do work just before the
/// run loop is begun. Implementations may also return false to prevent
/// run loop is begun. Implementations may also return false to prevent
/// the run loop from starting.
/// </summary>
/// <returns></returns>
Expand Down Expand Up @@ -207,7 +205,7 @@ public virtual bool BeforeRun()

/// <summary>
/// Gives derived classes an opportunity to do work just before Update
/// is called for all IUpdatable components. Returning false from this
/// is called for all IUpdatable components. Returning false from this
/// method will result in this round of Update calls being skipped.
/// </summary>
/// <param name="gameTime"></param>
Expand All @@ -216,7 +214,7 @@ public virtual bool BeforeRun()

/// <summary>
/// Gives derived classes an opportunity to do work just before Draw
/// is called for all IDrawable components. Returning false from this
/// is called for all IDrawable components. Returning false from this
/// method will result in this round of Draw calls being skipped.
/// </summary>
/// <param name="gameTime"></param>
Expand Down Expand Up @@ -270,9 +268,9 @@ bool willBeFullScreen
/// The new height of the game's client window.
/// </param>
public abstract void EndScreenDeviceChange(
string screenDeviceName,
int clientWidth,
int clientHeight
string screenDeviceName,
int clientWidth,
int clientHeight
);

/// <summary>
Expand All @@ -283,7 +281,7 @@ int clientHeight

/// <summary>
/// MSDN: Use this method if your game is recovering from a slow-running state, and
/// ElapsedGameTime is too large to be useful. Frame timing is generally handled
/// ElapsedGameTime is too large to be useful. Frame timing is generally handled
/// by the Game class, but some platforms still handle it elsewhere. Once all
/// platforms rely on the Game class's functionality, this method and any overrides
/// should be removed.
Expand All @@ -292,14 +290,14 @@ int clientHeight

protected virtual void OnIsMouseVisibleChanged() {}

public virtual void Present() { }
public virtual void Present() {}

#endregion

#region Protected Methods

/// <summary>
/// Raises the AsyncRunLoopEnded event. This method must be called by
/// Raises the AsyncRunLoopEnded event. This method must be called by
/// derived classes when the asynchronous run loop they start has
/// stopped running.
/// </summary>
Expand Down Expand Up @@ -373,4 +371,3 @@ protected virtual void Dispose(bool disposing)
#endregion
}
}

7 changes: 4 additions & 3 deletions MonoGame.Framework/GameTime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ public TimeSpan TotalGameTime
set;
}

public TimeSpan ElapsedGameTime {
public TimeSpan ElapsedGameTime
{
get;
set;
}

public bool IsRunningSlowly {
public bool IsRunningSlowly
{
get;
set;
}
Expand Down Expand Up @@ -61,4 +63,3 @@ public GameTime(TimeSpan totalRealTime, TimeSpan elapsedRealTime, bool isRunning
#endregion
}
}

Loading

0 comments on commit be42238

Please sign in to comment.