forked from MonoGame/MonoGame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GameComponent.cs
92 lines (76 loc) · 2.36 KB
/
GameComponent.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// MonoGame - Copyright (C) The MonoGame Team
// This file is subject to the terms and conditions defined in
// file 'LICENSE.txt', which is part of this source code package.
using System;
namespace Microsoft.Xna.Framework
{
public class GameComponent : IGameComponent, IUpdateable, IComparable<GameComponent>, IDisposable
{
bool _enabled = true;
int _updateOrder;
public Game Game { get; private set; }
public bool Enabled
{
get { return _enabled; }
set
{
if (_enabled != value)
{
_enabled = value;
OnEnabledChanged(this, EventArgs.Empty);
}
}
}
public int UpdateOrder
{
get { return _updateOrder; }
set
{
if (_updateOrder != value)
{
_updateOrder = value;
OnUpdateOrderChanged(this, EventArgs.Empty);
}
}
}
public event EventHandler<EventArgs> EnabledChanged;
public event EventHandler<EventArgs> UpdateOrderChanged;
public GameComponent(Game game)
{
this.Game = game;
}
~GameComponent()
{
Dispose(false);
}
public virtual void Initialize() { }
public virtual void Update(GameTime gameTime) { }
protected virtual void OnUpdateOrderChanged(object sender, EventArgs args)
{
EventHelpers.Raise(sender, UpdateOrderChanged, args);
}
protected virtual void OnEnabledChanged(object sender, EventArgs args)
{
EventHelpers.Raise(sender, EnabledChanged, args);
}
/// <summary>
/// Shuts down the component.
/// </summary>
protected virtual void Dispose(bool disposing) { }
/// <summary>
/// Shuts down the component.
/// </summary>
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
#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
}
}