Spinning Topp Logo BlackTopp Studios
inc
areaeffectmanager.h
1 // © Copyright 2010 - 2016 BlackTopp Studios Inc.
2 /* This file is part of The Mezzanine Engine.
3 
4  The Mezzanine Engine is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  The Mezzanine Engine is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with The Mezzanine Engine. If not, see <http://www.gnu.org/licenses/>.
16 */
17 /* The original authors have included a copy of the license specified above in the
18  'Docs' folder. See 'gpl.txt'
19 */
20 /* We welcome the use of the Mezzanine engine to anyone, including companies who wish to
21  Build professional software and charge for their product.
22 
23  However there are some practical restrictions, so if your project involves
24  any of the following you should contact us and we will try to work something
25  out:
26  - DRM or Copy Protection of any kind(except Copyrights)
27  - Software Patents You Do Not Wish to Freely License
28  - Any Kind of Linking to Non-GPL licensed Works
29  - Are Currently In Violation of Another Copyright Holder's GPL License
30  - If You want to change our code and not add a few hundred MB of stuff to
31  your distribution
32 
33  These and other limitations could cause serious legal problems if you ignore
34  them, so it is best to simply contact us or the Free Software Foundation, if
35  you have any questions.
36 
37  Joseph Toppi - toppij@gmail.com
38  John Blackwood - makoenergy02@gmail.com
39 */
40 #ifndef _areaeffectmanager_h
41 #define _areaeffectmanager_h
42 
43 #include "worldmanager.h"
44 #include "worldmanagerfactory.h"
45 #ifndef SWIG
46  #include "Threading/workunit.h"
47 #endif
48 
49 namespace Mezzanine
50 {
51  class AreaEffect;
52  class AreaEffectFactory;
53  class AreaEffectManager;
54 
55  class FieldOfForce;
56  class GravityField;
57  class GravityWell;
58 
59  namespace Physics {
60  class CollisionShape;
61  }
62 
63  ///////////////////////////////////////////////////////////////////////////////
64  /// @brief This is a Mezzanine::Threading::iWorkUnit for the updating of AreaEffects.
65  /// @details
66  ///////////////////////////////////////
68  {
69  protected:
70  /// @internal
71  /// @brief A pointer to the manager this work unit is processing.
73  /// @internal
74  /// @brief Protected copy constructor. THIS IS NOT ALLOWED.
75  /// @param Other The other work unit being copied from. WHICH WILL NEVER HAPPEN.
77  /// @internal
78  /// @brief Protected assignment operator. THIS IS NOT ALLOWED.
79  /// @param Other The other work unit being copied from. WHICH WILL NEVER HAPPEN.
80  AreaEffectUpdateWorkUnit& operator=(const AreaEffectUpdateWorkUnit& Other);
81  public:
82  /// @brief Class constructor.
83  /// @param Target The AreaEffectManager this work unit will process during the frame.
85  /// @brief Class destructor.
86  virtual ~AreaEffectUpdateWorkUnit();
87 
88  ///////////////////////////////////////////////////////////////////////////////
89  // Utility
90 
91  /// @brief This does any required update of the Graphical Scene graph and REnders one frame
92  /// @param CurrentThreadStorage The storage class for all resources owned by this work unit during it's execution.
93  virtual void DoWork(Threading::DefaultThreadSpecificStorage::Type& CurrentThreadStorage);
94  };//AreaEffectUpdateWorkUnit
95 
96  ///////////////////////////////////////////////////////////////////////////////
97  /// @class AreaEffectManager
98  /// @headerfile areaeffectmanager.h
99  /// @brief A manager responsible for the storage and management of all areaeffects in use.
100  /// @details More or less Management point for a container of areaeffects to help keep them sorted.
101  ///////////////////////////////////////
103  {
104  public:
105  /// @brief Basic container type for AreaEffectFactory storage by this class.
106  typedef std::map<String,AreaEffectFactory*> FactoryMap;
107  /// @brief Iterator type for AreaEffectFactory instances stored by this class.
108  typedef FactoryMap::iterator FactoryIterator;
109  /// @brief Const Iterator type for AreaEffectFactory instances stored by this class.
110  typedef FactoryMap::const_iterator ConstFactoryIterator;
111  /// @brief Basic container type for AreaEffect storage by this class.
112  typedef std::vector<AreaEffect*> AreaEffectContainer;
113  /// @brief Iterator type for AreaEffect instances stored by this class.
114  typedef AreaEffectContainer::iterator AreaEffectIterator;
115  /// @brief Const Iterator type for AreaEffect instances stored by this class.
116  typedef AreaEffectContainer::const_iterator ConstAreaEffectIterator;
117 
118  /// @brief A String containing the name of this manager implementation.
120  /// @brief A ManagerType enum value used to describe the type of interface/functionality this manager provides.
122  protected:
123  friend class AreaEffectUpdateWorkUnit;
124 
125  /// @internal
126  /// @brief A map containing all registered AreaEffect type factories.
128  /// @internal
129  /// @brief Container storing all AreaEffects belonging to this manager.
130  AreaEffectContainer AreaEffects;
131 
132  /// @internal
133  /// @brief The work unit that updates all the actors stored by this manager.
135  /// @internal
136  /// @brief Can be used for thread safe logging and other thread specific resources.
138  public:
139  /// @brief Class constructor.
140  /// @param Creator The parent world that is creating the manager.
141  AreaEffectManager(World* Creator);
142  /// @brief XML constructor.
143  /// @param Creator The parent world that is creating the manager.
144  /// @param XMLNode The node of the xml document to construct from.
145  AreaEffectManager(World* Creator, const XML::Node& XMLNode);
146  /// @brief Class destructor.
147  virtual ~AreaEffectManager();
148 
149  ///////////////////////////////////////////////////////////////////////////////
150  // Prefab AreaEffect Type Creation
151 
152  /// @brief Creates a new FieldOfForce.
153  /// @param Name The name to be given to the new FieldOfForce.
154  /// @param AddToWorld Wether or not the new AreaEffect should be added to the world after it has been created.
155  /// @return Returns a pointer to the created AreaEffect.
156  FieldOfForce* CreateFieldOfForce(const String& Name, const Boole AddToWorld = true);
157  /// @brief Creates a new FieldOfForce.
158  /// @param Name The name to be given to the new FieldOfForce.
159  /// @param AEShape A pointer to the Collision shape that will be applied to the new FieldOfForce.
160  /// @param AddToWorld Wether or not the new AreaEffect should be added to the world after it has been created.
161  /// @return Returns a pointer to the created AreaEffect.
162  FieldOfForce* CreateFieldOfForce(const String& Name, Physics::CollisionShape* AEShape, const Boole AddToWorld = true);
163  /// @brief Creates a new FieldOfForce.
164  /// @param SelfRoot An XML::Node containing the data to populate this class with.
165  /// @return Returns a pointer to the created AreaEffect.
166  FieldOfForce* CreateFieldOfForce(const XML::Node& SelfRoot);
167  /// @brief Creates a new GravityField.
168  /// @param Name The name to be given to the new GravityField.
169  /// @param AddToWorld Wether or not the new AreaEffect should be added to the world after it has been created.
170  /// @return Returns a pointer to the created AreaEffect.
171  GravityField* CreateGravityField(const String& Name, const Boole AddToWorld = true);
172  /// @brief Creates a new GravityField.
173  /// @param Name The name to be given to the new GravityField.
174  /// @param AEShape A pointer to the Collision shape that will be applied to the new GravityField.
175  /// @param AddToWorld Wether or not the new AreaEffect should be added to the world after it has been created.
176  /// @return Returns a pointer to the created AreaEffect.
177  GravityField* CreateGravityField(const String& Name, Physics::CollisionShape* AEShape, const Boole AddToWorld = true);
178  /// @brief Creates a new GravityField.
179  /// @param SelfRoot An XML::Node containing the data to populate this class with.
180  /// @return Returns a pointer to the created AreaEffect.
181  GravityField* CreateGravityField(const XML::Node& SelfRoot);
182  /// @brief Creates a new GravityWell.
183  /// @param Name The name to be given to the new GravityWell.
184  /// @param AddToWorld Wether or not the new AreaEffect should be added to the world after it has been created.
185  /// @return Returns a pointer to the created AreaEffect.
186  GravityWell* CreateGravityWell(const String& Name, const Boole AddToWorld = true);
187  /// @brief Creates a new GravityWell.
188  /// @param Name The name to be given to the new GravityWell.
189  /// @param AEShape A pointer to the Collision shape that will be applied to the new GravityWell.
190  /// @param AddToWorld Wether or not the new AreaEffect should be added to the world after it has been created.
191  /// @return Returns a pointer to the created AreaEffect.
192  GravityWell* CreateGravityWell(const String& Name, Physics::CollisionShape* AEShape, const Boole AddToWorld = true);
193  /// @brief Creates a new GravityWell.
194  /// @param SelfRoot An XML::Node containing the data to populate this class with.
195  /// @return Returns a pointer to the created AreaEffect.
196  GravityWell* CreateGravityWell(const XML::Node& SelfRoot);
197 
198  ///////////////////////////////////////////////////////////////////////////////
199  // AreaEffect Management
200 
201  /// @brief Creates a new AreaEffect.
202  /// @param TypeName A string containing the name of the type of AreaEffect to be constructed.
203  /// @param InstanceName A string containing the name to be given to the created AreaEffect.
204  /// @param Params A container of additional parameters to be used for the construction of the new AreaEffect.
205  /// @param AddToWorld Wether or not the new AreaEffect should be added to the world after it has been created.
206  /// @return Returns a pointer to the created AreaEffect.
207  AreaEffect* CreateAreaEffect(const String& TypeName, const String& InstanceName, const NameValuePairMap& Params, const Boole AddToWorld = true);
208  /// @brief Creates a new AreaEffect class from an XML node.
209  /// @remarks This is mostly useful for deserialization.
210  /// @return Returns a pointer to the created AreaEffect.
211  AreaEffect* CreateAreaEffect(const XML::Node& SelfRoot);
212 
213  /// @brief Gets an AreaEffect by Index.
214  /// @param Index The index of the areaeffect you wish to retrieve.
215  /// @return Returns a pointer to the areaeffect at the specified index.
216  virtual AreaEffect* GetAreaEffect(const Whole Index) const;
217  /// @brief Gets an AreaEffect by Name.
218  /// @param Name The name of the areaeffect you wish to retrieve.
219  /// @return Returns a pointer to the areaeffect of the specified name.
220  virtual AreaEffect* GetAreaEffect(const String& Name) const;
221  /// @brief Gets the number of actors stored in this manager.
222  /// @return Returns a whole representing the current areaeffect count.
223  virtual Whole GetNumAreaEffects() const;
224  /// @brief Destroys an areaeffect at the specified index.
225  /// @param Index The index at which to destroy the areaeffect.
226  virtual void DestroyAreaEffect(const Whole Index);
227  /// @brief Destroys an areaeffect.
228  /// @param ToBeDestroyed The areaeffect to be destroyed.
229  virtual void DestroyAreaEffect(AreaEffect* ToBeDestroyed);
230  /// @brief Destroys all actors currently within this manager.
231  virtual void DestroyAllAreaEffects();
232 
233  #ifndef SWIG
234  /// @brief Gets an iterator to the first AreaEffect in this manager.
235  /// @return Returns an iterator to the first AreaEffect being stored by this manager.
236  AreaEffectIterator BeginAreaEffect();
237  /// @brief Gets an iterator to one passed the last AreaEffect in this manager.
238  /// @return Returns an iterator to one passed the last AreaEffect being stored by this manager.
239  AreaEffectIterator EndAreaEffect();
240  /// @brief Gets a const iterator to the first AreaEffect in this manager.
241  /// @return Returns a const iterator to the first AreaEffect being stored by this manager.
242  ConstAreaEffectIterator BeginAreaEffect() const;
243  /// @brief Gets a const iterator to one passed the last AreaEffect in this manager.
244  /// @return Returns a const iterator to one passed the last AreaEffect being stored by this manager.
245  ConstAreaEffectIterator EndAreaEffect() const;
246  #endif
247 
248  ///////////////////////////////////////////////////////////////////////////////
249  // AreaEffectFactory Management
250 
251  /// @brief Adds/registers a AreaEffect factory with this manager, allowing it to be constructed through this API.
252  /// @param ToBeAdded The AreaEffect factory to be added.
253  virtual void AddAreaEffectFactory(AreaEffectFactory* ToBeAdded);
254  /// @brief Removes a AreaEffect factory from this manager.
255  /// @param ToBeRemoved A pointer to the AreaEffect factory that is to be removed.
256  virtual void RemoveAreaEffectFactory(AreaEffectFactory* ToBeRemoved);
257  /// @brief Removes a AreaEffect factory from this manager.
258  /// @param ImplName The name of the AreaEffect implementation created by the factory to be removed.
259  virtual void RemoveAreaEffectFactory(const String& ImplName);
260  /// @brief Removes and destroys a AreaEffect factory in this manager.
261  /// @param ToBeDestroyed A pointer to the AreaEffect factory that is to be removed and destroyed.
262  virtual void DestroyAreaEffectFactory(AreaEffectFactory* ToBeDestroyed);
263  /// @brief Removes and destroys a AreaEffect factory in this manager.
264  /// @param ImplName The name of the AreaEffect implementation created by the factory to be removed and destroyed.
265  virtual void DestroyAreaEffectFactory(const String& ImplName);
266  /// @brief Destroys all AreaEffect factories in this manager.
267  /// @warning The destruction of AreaEffect factories should only be done after all the AreaEffects have been destroyed, otherwise this will cause an exception.
268  virtual void DestroyAllAreaEffectFactories();
269 
270  ///////////////////////////////////////////////////////////////////////////////
271  // Utility
272 
273  /// @copydoc WorldManager::Pause(const UInt32)
274  virtual void Pause(const UInt32 PL);
275 
276  /// @brief Does all of the necessary configuration to prepare for the start of the main loop.
277  virtual void MainLoopInitialize();
278  /// @copydoc WorldManager::Initialize()
279  virtual void Initialize();
280  /// @copydoc ManagerBase::Deinitialize()
281  virtual void Deinitialize();
282 
283  /// @brief Gets the work unit responsible for updating area effects stored by this manager.
284  /// @return Returns a pointer to the AreaEffectUpdateWorkUnit used by this manager.
285  AreaEffectUpdateWorkUnit* GetAreaEffectUpdateWork();
286 
287  ///////////////////////////////////////////////////////////////////////////////
288  // Type Identifier Methods
289 
290  /// @copydoc ManagerBase::GetInterfaceType()
291  virtual ManagerType GetInterfaceType() const;
292  /// @copydoc ManagerBase::GetImplementationTypeName()
293  virtual String GetImplementationTypeName() const;
294  };//AreaEffectManager
295 
296  ///////////////////////////////////////////////////////////////////////////////
297  /// @class DefaultAreaEffectManagerFactory
298  /// @brief A factory responsible for the creation and destruction of the default areaeffectmanager.
299  ///////////////////////////////////////
301  {
302  public:
303  /// @brief Class constructor.
305  /// @brief Class destructor.
307 
308  /// @copydoc ManagerFactory::GetManagerImplName()
309  String GetManagerImplName() const;
310  /// @copydoc ManagerFactory::GetManagerType() const
312 
313  /// @copydoc WorldManagerFactory::CreateManager(World*, const NameValuePairList&)
314  WorldManager* CreateManager(World* Creator, const NameValuePairList& Params);
315  /// @copydoc WorldManagerFactory::CreateManager(World*, const XML::Node&)
316  WorldManager* CreateManager(World* Creator, const XML::Node& XMLNode);
317  /// @copydoc WorldManagerFactory::DestroyManager(WorldManager*)
318  void DestroyManager(WorldManager* ToBeDestroyed);
319  };//DefaultAreaEffectManagerFactory
320 }//Mezzanine
321 
322 #endif
This is the base class for all collision shapes.
AreaEffectContainer::iterator AreaEffectIterator
Iterator type for AreaEffect instances stored by this class.
bool Boole
Generally acts a single bit, true or false.
Definition: datatypes.h:173
Default implementation of WorkUnit. This represents on piece of work through time.
Definition: workunit.h:160
A manager responsible for the storage and management of all areaeffects in use.
void DestroyManager(WorldManager *ToBeDestroyed)
Destroys a Manager created by this factory.
ManagerType
A listing of Manager Types.
Definition: managerbase.h:65
This is a gravity well implementation of the AreaEffect class.
Definition: gravitywell.h:53
This is a Mezzanine::Threading::iWorkUnit for the updating of AreaEffects.
This is an implementation of the AreaEffect class that alters gravity in a region.
Definition: gravityfield.h:52
A thread specific collection of double-buffered and algorithm specific resources. ...
This class is used to define area's in the world that have unique effects.
Definition: areaeffect.h:65
This is field that applies force in a direction, and doesn't tamper with gravity. ...
Definition: fieldofforce.h:56
A light-weight handle for manipulating nodes in DOM tree.
Definition: node.h:89
FactoryMap::const_iterator ConstFactoryIterator
Const Iterator type for AreaEffectFactory instances stored by this class.
Threading::DefaultThreadSpecificStorage::Type * ThreadResources
Can be used for thread safe logging and other thread specific resources.
uint32_t UInt32
An 32-bit unsigned integer.
Definition: datatypes.h:126
A factory responsible for the creation and destruction of the default areaeffectmanager.
String GetManagerImplName() const
Gets the name of the manager that is created by this factory.
static const ManagerBase::ManagerType InterfaceType
A ManagerType enum value used to describe the type of interface/functionality this manager provides...
A base factory type for the creation of AreaEffect objects.
Definition: areaeffect.h:249
std::list< NameValuePair > NameValuePairList
This is a datatype mostly used for describing settings or parameters that can't be declared in advanc...
Definition: datatypes.h:206
FactoryMap::iterator FactoryIterator
Iterator type for AreaEffectFactory instances stored by this class.
This is the base class for all managers that belong to a single world instance.
Definition: worldmanager.h:55
#define MEZZ_LIB
Some platforms require special decorations to denote what is exported/imported in a share library...
FactoryMap AreaEffectFactories
A map containing all registered AreaEffect type factories.
WorldManager * CreateManager(World *Creator, const NameValuePairList &Params)
Creates a manager of the type represented by this factory.
virtual ~DefaultAreaEffectManagerFactory()
Class destructor.
ManagerBase::ManagerType GetManagerType() const
Gets the type of manager that is created by this factory.
The bulk of the engine components go in this namspace.
Definition: actor.cpp:56
unsigned long Whole
Whole is an unsigned integer, it will be at least 32bits in size.
Definition: datatypes.h:151
AreaEffectUpdateWorkUnit * AreaEffectUpdateWork
The work unit that updates all the actors stored by this manager.
This class represents a world for objects to interact within.
Definition: world.h:74
std::vector< AreaEffect * > AreaEffectContainer
Basic container type for AreaEffect storage by this class.
This is a base class for factories that construct managers used by the World class.
AreaEffectManager * TargetManager
A pointer to the manager this work unit is processing.
static const String ImplementationName
A String containing the name of this manager implementation.
std::map< String, String > NameValuePairMap
This is a datatype mostly used for describing settings or parameters that can't be declared in advanc...
Definition: datatypes.h:209
std::string String
A datatype used to a series of characters.
Definition: datatypes.h:159
std::map< String, AreaEffectFactory * > FactoryMap
Basic container type for AreaEffectFactory storage by this class.
AreaEffectContainer AreaEffects
Container storing all AreaEffects belonging to this manager.
This file has the definition of the workunit.
AreaEffectContainer::const_iterator ConstAreaEffectIterator
Const Iterator type for AreaEffect instances stored by this class.