TriEngine  v0.0.16
General-purpose engine in C#/OpenGL
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events
TriDevs.TriEngine.StateManagement.GameState Class Reference

Base GameState class that all other game states derive from, defines basic GameState behaviour. More...

Inheritance diagram for TriDevs.TriEngine.StateManagement.GameState:
[legend]
Collaboration diagram for TriDevs.TriEngine.StateManagement.GameState:
[legend]

Public Member Functions

virtual void Update ()
 Updates the object. More...
 
virtual void Draw ()
 Draw the object to screen. More...
 
virtual void Load ()
 Loads resources associated with this game component. More...
 
virtual void Unload ()
 Unloads resources that were loaded in the Load method. More...
 
virtual void Pause ()
 Pauses the game state, preventing update calls from running. More...
 
virtual void Unpause ()
 Unpauses the game state, enabling update calls again. More...
 
IGameComponent AddComponent (IGameComponent component)
 Adds a game component to this game state. More...
 
void RemoveComponent (IGameComponent component)
 Removes the specified component from this game state. More...
 
void RemoveAllComponents ()
 Removes all components from the game state. More...
 
void RemoveAllComponents (Type type)
 Removes all components of the specified type from the game state. More...
 
void RemoveAllComponents (Predicate< IGameComponent > predicate)
 Removes all components that match the supplied predicate function. More...
 
bool HasComponent (IGameComponent component)
 Returns whether this game state contains the specified IGameComponent. More...
 
bool HasComponent (Type type)
 Returns whether this game state contains a specific type of component. More...
 
bool HasComponent (Func< IGameComponent, bool > func)
 Returns whether this game state contains a component that matches the supplied predicate. More...
 
IEnumerable< IGameComponentGetAllComponents ()
 Returns a read-only collection of all components in this game state. More...
 
IGameComponent GetComponent (Type type)
 Returns the specified component type if it exists in this game state. More...
 
IEnumerable< IGameComponentGetAllComponents (Type type)
 Returns all components of the specified type. More...
 
IGameComponent GetComponent (Func< IGameComponent, bool > func)
 Returns the first component that matches the supplied predicate function. More...
 
IEnumerable< IGameComponentGetAllComponents (Func< IGameComponent, bool > func)
 Returns all components that matches the supplied predicate function. More...
 

Protected Member Functions

 GameState ()
 

Protected Attributes

readonly List< IGameComponentComponents
 List of components currently added to this GameState. More...
 

Properties

bool Paused [get, set]
 
- Properties inherited from TriDevs.TriEngine.StateManagement.IGameState
bool Paused [get, set]
 Gets or sets a value indicating whether this game state is currently paused. More...
 

Detailed Description

Base GameState class that all other game states derive from, defines basic GameState behaviour.

Constructor & Destructor Documentation

TriDevs.TriEngine.StateManagement.GameState.GameState ( )
protected
45  {
46  Components = new List<IGameComponent>();
47  }

Member Function Documentation

IGameComponent TriDevs.TriEngine.StateManagement.GameState.AddComponent ( IGameComponent  component)

Adds a game component to this game state.

Parameters
componentThe component to add.
Returns
The component that was added.

Implements TriDevs.TriEngine.StateManagement.IGameState.

81  {
82  if (HasComponent(component))
83  throw new InvalidOperationException("Cannot add the same component more than once.");
84 
85  Components.Add(component);
86  component.Enable();
87  return component; // var comp = someState.AddComponent(new SomeComponent());
88  }

Here is the call graph for this function:

virtual void TriDevs.TriEngine.StateManagement.GameState.Draw ( )
virtual

Draw the object to screen.

Implements TriDevs.TriEngine.Interfaces.IDrawable.

55  {
56  foreach (var component in Components.OfType<IDrawableGameComponent>())
57  component.Draw();
58  }

Here is the call graph for this function:

Here is the caller graph for this function:

IEnumerable<IGameComponent> TriDevs.TriEngine.StateManagement.GameState.GetAllComponents ( )

Returns a read-only collection of all components in this game state.

Returns
Read-only collection of components.

Implements TriDevs.TriEngine.StateManagement.IGameState.

137  {
138  return Components.AsReadOnly();
139  }
IEnumerable<IGameComponent> TriDevs.TriEngine.StateManagement.GameState.GetAllComponents ( Type  type)

Returns all components of the specified type.

Parameters
typeThe type of game component requested.
Returns
A collection of all components of matching type.

Implements TriDevs.TriEngine.StateManagement.IGameState.

147  {
148  return Components.FindAll(c => c.GetType() == type);
149  }
IEnumerable<IGameComponent> TriDevs.TriEngine.StateManagement.GameState.GetAllComponents ( Func< IGameComponent, bool >  func)

Returns all components that matches the supplied predicate function.

Parameters
funcThe predicate function.
Returns
Collection of all matching components, empty collection if no matches were found.

Implements TriDevs.TriEngine.StateManagement.IGameState.

157  {
158  return Components.Where(func);
159  }
IGameComponent TriDevs.TriEngine.StateManagement.GameState.GetComponent ( Type  type)

Returns the specified component type if it exists in this game state.

Parameters
typeThe component type to get.
Returns
The component object, or null if it's not added to this game state.

Implements TriDevs.TriEngine.StateManagement.IGameState.

142  {
143  return Components.FirstOrDefault(c => c.GetType() == type);
144  }
IGameComponent TriDevs.TriEngine.StateManagement.GameState.GetComponent ( Func< IGameComponent, bool >  func)

Returns the first component that matches the supplied predicate function.

Parameters
funcThe predicate function.
Returns
Component that matches the predicate, null if no matches were found.

Implements TriDevs.TriEngine.StateManagement.IGameState.

152  {
153  return Components.FirstOrDefault(func);
154  }
bool TriDevs.TriEngine.StateManagement.GameState.HasComponent ( IGameComponent  component)

Returns whether this game state contains the specified IGameComponent.

Parameters
componentThe component to check for.
Returns
True if the component has been added to this game state, false otherwise.

Implements TriDevs.TriEngine.StateManagement.IGameState.

122  {
123  return Components.Contains(component);
124  }
bool TriDevs.TriEngine.StateManagement.GameState.HasComponent ( Type  type)

Returns whether this game state contains a specific type of component.

Parameters
typeThe type to check for.
Returns
True if the type of component has been added to this game state, false otherwise.

Implements TriDevs.TriEngine.StateManagement.IGameState.

127  {
128  return Components.Any(c => c.GetType() == type);
129  }
bool TriDevs.TriEngine.StateManagement.GameState.HasComponent ( Func< IGameComponent, bool >  func)

Returns whether this game state contains a component that matches the supplied predicate.

Parameters
funcPredicate function to use for search.
Returns
True if the game state contains a matching component, false otherwise.

Implements TriDevs.TriEngine.StateManagement.IGameState.

132  {
133  return Components.Any(func);
134  }
virtual void TriDevs.TriEngine.StateManagement.GameState.Load ( )
virtual

Loads resources associated with this game component.

Implements TriDevs.TriEngine.StateManagement.IGameState.

61  {
62 
63  }
virtual void TriDevs.TriEngine.StateManagement.GameState.Pause ( )
virtual

Pauses the game state, preventing update calls from running.

Implements TriDevs.TriEngine.StateManagement.IGameState.

71  {
72  Paused = true;
73  }
void TriDevs.TriEngine.StateManagement.GameState.RemoveAllComponents ( )

Removes all components from the game state.

Implements TriDevs.TriEngine.StateManagement.IGameState.

101  {
102  Components.ForEach(c => c.Disable());
103  Components.Clear();
104  }
void TriDevs.TriEngine.StateManagement.GameState.RemoveAllComponents ( Type  type)

Removes all components of the specified type from the game state.

Parameters
typeThe type of component to remove.

Implements TriDevs.TriEngine.StateManagement.IGameState.

107  {
108  RemoveAllComponents(c => c.GetType() == type);
109  }
void TriDevs.TriEngine.StateManagement.GameState.RemoveAllComponents ( Predicate< IGameComponent predicate)

Removes all components that match the supplied predicate function.

Parameters
predicateThe predicate function.

Implements TriDevs.TriEngine.StateManagement.IGameState.

112  {
113  var removed = Components.FindAll(predicate);
114  if (removed.Count < 1)
115  return;
116 
117  Components.RemoveAll(predicate);
118  removed.ForEach(c => c.Disable());
119  }
void TriDevs.TriEngine.StateManagement.GameState.RemoveComponent ( IGameComponent  component)

Removes the specified component from this game state.

Parameters
component

Implements TriDevs.TriEngine.StateManagement.IGameState.

91  {
92  var match = Components.FirstOrDefault(c => c == component);
93  if (match == null)
94  return;
95 
96  Components.Remove(match);
97  match.Disable();
98  }

Here is the call graph for this function:

virtual void TriDevs.TriEngine.StateManagement.GameState.Unload ( )
virtual

Unloads resources that were loaded in the Load method.

Implements TriDevs.TriEngine.StateManagement.IGameState.

66  {
67 
68  }
virtual void TriDevs.TriEngine.StateManagement.GameState.Unpause ( )
virtual

Unpauses the game state, enabling update calls again.

Implements TriDevs.TriEngine.StateManagement.IGameState.

76  {
77  Paused = false;
78  }
virtual void TriDevs.TriEngine.StateManagement.GameState.Update ( )
virtual

Updates the object.

Implements TriDevs.TriEngine.Interfaces.IUpdatable.

50  {
51  Components.ForEach(c => c.Update());
52  }

Member Data Documentation

readonly List<IGameComponent> TriDevs.TriEngine.StateManagement.GameState.Components
protected

List of components currently added to this GameState.

Property Documentation

bool TriDevs.TriEngine.StateManagement.GameState.Paused
getset

The documentation for this class was generated from the following file: