Spinning Topp Logo BlackTopp Studios
inc
debrismanager.h
Go to the documentation of this file.
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 _debrismanager_h
41 #define _debrismanager_h
42 
43 /// @file
44 /// @brief This file contains the declaration for the manager that manages debris objects in a world.
45 
46 #include "worldmanager.h"
47 #include "worldmanagerfactory.h"
48 #ifndef SWIG
49  #include "Threading/workunit.h"
50 #endif
51 
52 namespace Mezzanine
53 {
54  class Debris;
55  class DebrisFactory;
56  class DebrisManager;
57 
58  class RigidDebris;
59  class SoftDebris;
60 
61  namespace Physics {
62  class CollisionShape;
63  }
64  namespace Graphics {
65  class Mesh;
66  }
67  ///////////////////////////////////////////////////////////////////////////////
68  /// @brief This is a Mezzanine::Threading::iWorkUnit for the updating of Debris.
69  /// @details
70  ///////////////////////////////////////
72  {
73  protected:
74  /// @internal
75  /// @brief A pointer to the manager this work unit is processing.
77  /// @internal
78  /// @brief Protected copy constructor. THIS IS NOT ALLOWED.
79  /// @param Other The other work unit being copied from. WHICH WILL NEVER HAPPEN.
81  /// @internal
82  /// @brief Protected assignment operator. THIS IS NOT ALLOWED.
83  /// @param Other The other work unit being copied from. WHICH WILL NEVER HAPPEN.
84  DebrisUpdateWorkUnit& operator=(const DebrisUpdateWorkUnit& Other);
85  public:
86  /// @brief Class constructor.
87  /// @param Target The DebrisManager this work unit will process during the frame.
89  /// @brief Class destructor.
90  virtual ~DebrisUpdateWorkUnit();
91 
92  ///////////////////////////////////////////////////////////////////////////////
93  // Utility
94 
95  /// @brief This does any required update of the Debris stored by it's manager.
96  /// @param CurrentThreadStorage The storage class for all resources owned by this work unit during it's execution.
97  virtual void DoWork(Threading::DefaultThreadSpecificStorage::Type& CurrentThreadStorage);
98  };//DebrisUpdateWorkUnit
99 
100  ///////////////////////////////////////////////////////////////////////////////
101  /// @brief A manager responsible for the storage and management of all Debris that exist in a world.
102  /// @details More or less Management point for a container of Debris to help keep them sorted.
103  ///////////////////////////////////////
105  {
106  public:
107  /// @brief Basic container type for DebrisFactory storage by this class.
108  typedef std::map<String,DebrisFactory*> FactoryMap;
109  /// @brief Iterator type for DebrisFactory instances stored by this class.
110  typedef FactoryMap::iterator FactoryIterator;
111  /// @brief Const Iterator type for DebrisFactory instances stored by this class.
112  typedef FactoryMap::const_iterator ConstFactoryIterator;
113  /// @brief Basic container type for Debris storage by this class.
114  typedef std::vector< Debris* > DebrisContainer;
115  /// @brief Iterator type for Debris instances stored by this class.
116  typedef DebrisContainer::iterator DebrisIterator;
117  /// @brief Const Iterator type for Debris instances stored by this class.
118  typedef DebrisContainer::const_iterator ConstDebrisIterator;
119 
120  /// @brief A String containing the name of this manager implementation.
122  /// @brief A ManagerType enum value used to describe the type of interface/functionality this manager provides.
124  protected:
125  friend class DebrisUpdateWorkUnit;
126 
127  /// @internal
128  /// @brief A map containing all registered Debris type factories.
129  FactoryMap DebrisFactories;
130  /// @internal
131  /// @brief Container storing all Debris belonging to this manager.
132  DebrisContainer Debriss;
133 
134  /// @internal
135  /// @brief The work unit that updates all the Debris stored by this manager.
137  /// @internal
138  /// @brief Can be used for thread safe logging and other thread specific resources.
140  public:
141  /// @brief Class constructor.
142  /// @param Creator The parent world that is creating the manager.
143  DebrisManager(World* Creator);
144  /// @brief XML constructor.
145  /// @param Creator The parent world that is creating the manager.
146  /// @param XMLNode The node of the xml document to construct from.
147  DebrisManager(World* Creator, const XML::Node& XMLNode);
148  /// @brief Class destructor.
149  virtual ~DebrisManager();
150 
151  ///////////////////////////////////////////////////////////////////////////////
152  // Prefab Debris Type Creation
153 
154  /// @brief Creates a new RigidDebris.
155  /// @param Name The name to be given to the new RigidDebris.
156  /// @param Mass The mass of the debris object.
157  /// @param AddToWorld Wether or not the new Debris should be added to the world after it has been created.
158  /// @return Returns a pointer to the created Debris.
159  RigidDebris* CreateRigidDebris(const String& Name, const Real Mass, const Boole AddToWorld = true);
160  /// @brief Creates a new RigidDebris.
161  /// @param Name The name to be given to the new RigidDebris.
162  /// @param Mass The mass of the debris object.
163  /// @param DebMesh A pointer to the Graphics mesh that will be applied to the new RigidDebris.
164  /// @param DebShape A pointer to the Collision shape that will be applied to the new RigidDebris.
165  /// @param AddToWorld Wether or not the new Debris should be added to the world after it has been created.
166  /// @return Returns a pointer to the created Debris.
167  RigidDebris* CreateRigidDebris(const String& Name, const Real Mass, Graphics::Mesh* DebMesh, Physics::CollisionShape* DebShape, const Boole AddToWorld = true);
168  /// @brief Creates a new RigidDebris.
169  /// @param SelfRoot An XML::Node containing the data to populate this class with.
170  /// @return Returns a pointer to the created Debris.
171  RigidDebris* CreateRigidDebris(const XML::Node& SelfRoot);
172  /// @brief Creates a new SoftDebris.
173  /// @param Name The name to be given to the new SoftDebris.
174  /// @param Mass The mass of the debris object.
175  /// @param AddToWorld Wether or not the new Debris should be added to the world after it has been created.
176  /// @return Returns a pointer to the created Debris.
177  SoftDebris* CreateSoftDebris(const String& Name, const Real Mass, const Boole AddToWorld = true);
178  /// @brief Creates a new SoftDebris.
179  /// @param SelfRoot An XML::Node containing the data to populate this class with.
180  /// @return Returns a pointer to the created Debris.
181  SoftDebris* CreateSoftDebris(const XML::Node& SelfRoot);
182 
183  ///////////////////////////////////////////////////////////////////////////////
184  // Debris Management
185 
186  /// @brief Creates a new Debris.
187  /// @param TypeName A string containing the name of the type of Debris to be constructed.
188  /// @param InstanceName A string containing the name to be given to the created Debris.
189  /// @param Params A container of additional parameters to be used for the construction of the new Debris.
190  /// @param AddToWorld Wether or not the new Debris should be added to the world after it has been created.
191  /// @return Returns a pointer to the created Debris.
192  Debris* CreateDebris(const String& TypeName, const String& InstanceName, const NameValuePairMap& Params, const Boole AddToWorld = true);
193  /// @brief Creates a new Debris class from an XML node.
194  /// @remarks This is mostly useful for deserialization.
195  /// @return Returns a pointer to the created Debris.
196  Debris* CreateDebris(const XML::Node& SelfRoot);
197 
198  /// @brief Gets an Debris by Index.
199  /// @param Index The index of the Debris you wish to retrieve.
200  /// @return Returns a pointer to the Debris at the specified index.
201  virtual Debris* GetDebris(const Whole Index) const;
202  /// @brief Gets an Debris by Name.
203  /// @param Name The name of the Debris you wish to retrieve.
204  /// @return Returns a pointer to the Debris of the specified name.
205  virtual Debris* GetDebris(const String& Name) const;
206  /// @brief Gets the number of Debriss stored in this manager.
207  /// @return Returns a whole representing the current Debris count.
208  virtual Whole GetNumDebris() const;
209  /// @brief Destroys an Debris at the specified index.
210  /// @param Index The index at which to destroy the Debris.
211  virtual void DestroyDebris(const Whole Index);
212  /// @brief Destroys an Debris.
213  /// @param ToBeDestroyed The Debris to be destroyed.
214  virtual void DestroyDebris(Debris* ToBeDestroyed);
215  /// @brief Destroys all Debriss currently within this manager.
216  virtual void DestroyAllDebris();
217 
218  #ifndef SWIG
219  /// @brief Gets an iterator to the first Debris in this manager.
220  /// @return Returns an iterator to the first Debris being stored by this manager.
221  DebrisIterator BeginDebris();
222  /// @brief Gets an iterator to one passed the last Debris in this manager.
223  /// @return Returns an iterator to one passed the last Debris being stored by this manager.
224  DebrisIterator EndDebris();
225  /// @brief Gets a const iterator to the first Debris in this manager.
226  /// @return Returns a const iterator to the first Debris being stored by this manager.
227  ConstDebrisIterator BeginDebris() const;
228  /// @brief Gets a const iterator to one passed the last Debris in this manager.
229  /// @return Returns a const iterator to one passed the last Debris being stored by this manager.
230  ConstDebrisIterator EndDebris() const;
231  #endif
232 
233  ///////////////////////////////////////////////////////////////////////////////
234  // DebrisFactory Management
235 
236  /// @brief Adds/registers a Debris factory with this manager, allowing it to be constructed through this API.
237  /// @param ToBeAdded The Debris factory to be added.
238  virtual void AddDebrisFactory(DebrisFactory* ToBeAdded);
239  /// @brief Removes a Debris factory from this manager.
240  /// @param ToBeRemoved A pointer to the Debris factory that is to be removed.
241  virtual void RemoveDebrisFactory(DebrisFactory* ToBeRemoved);
242  /// @brief Removes a Debris factory from this manager.
243  /// @param ImplName The name of the Debris implementation created by the factory to be removed.
244  virtual void RemoveDebrisFactory(const String& ImplName);
245  /// @brief Removes and destroys a Debris factory in this manager.
246  /// @param ToBeDestroyed A pointer to the Debris factory that is to be removed and destroyed.
247  virtual void DestroyDebrisFactory(DebrisFactory* ToBeDestroyed);
248  /// @brief Removes and destroys a Debris factory in this manager.
249  /// @param ImplName The name of the Debris implementation created by the factory to be removed and destroyed.
250  virtual void DestroyDebrisFactory(const String& ImplName);
251  /// @brief Destroys all Debris factories in this manager.
252  /// @warning The destruction of Debris factories should only be done after all the Debris have been destroyed, otherwise this will cause an exception.
253  virtual void DestroyAllDebrisFactories();
254 
255  ///////////////////////////////////////////////////////////////////////////////
256  // Utility
257 
258  /// @copydoc WorldManager::Pause(const UInt32)
259  virtual void Pause(const UInt32 PL);
260 
261  /// @copydoc WorldManager::Initialize()
262  virtual void Initialize();
263  /// @copydoc ManagerBase::Deinitialize()
264  virtual void Deinitialize();
265 
266  /// @brief Gets the work unit responsible for updating Debriss stored by this manager.
267  /// @return Returns a pointer to the ActorUpdateWorkUnit used by this manager.
268  DebrisUpdateWorkUnit* GetDebrisUpdateWork();
269 
270  ///////////////////////////////////////////////////////////////////////////////
271  // Type Identifier Methods
272 
273  /// @copydoc ManagerBase::GetInterfaceType()
274  virtual ManagerType GetInterfaceType() const;
275  /// @copydoc ManagerBase::GetImplementationTypeName()
276  virtual String GetImplementationTypeName() const;
277  };//DebrisManager
278 
279  ///////////////////////////////////////////////////////////////////////////////
280  /// @class DefaultDebrisManagerFactory
281  /// @brief A factory responsible for the creation and destruction of the default DebrisManager.
282  ///////////////////////////////////////
284  {
285  public:
286  /// @brief Class constructor.
288  /// @brief Class destructor.
290 
291  /// @copydoc ManagerFactory::GetManagerImplName()
292  String GetManagerImplName() const;
293  /// @copydoc ManagerFactory::GetManagerType() const
295 
296  /// @copydoc WorldManagerFactory::CreateManager(World*, const NameValuePairList&)
297  WorldManager* CreateManager(World* Creator, const NameValuePairList& Params);
298  /// @copydoc WorldManagerFactory::CreateManager(World*, const XML::Node&)
299  WorldManager* CreateManager(World* Creator, const XML::Node& XMLNode);
300  /// @copydoc WorldManagerFactory::DestroyManager(WorldManager*)
301  void DestroyManager(WorldManager* ToBeDestroyed);
302  };//DefaultDebrisManagerFactory
303 }//Mezzanine
304 
305 #endif
DebrisManager * TargetManager
A pointer to the manager this work unit is processing.
Definition: debrismanager.h:76
This is the base class for all collision shapes.
A factory responsible for the creation and destruction of the default DebrisManager.
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 deformable debris.
Definition: softdebris.h:62
ManagerType
A listing of Manager Types.
Definition: managerbase.h:65
DebrisContainer::iterator DebrisIterator
Iterator type for Debris instances stored by this class.
virtual ~DefaultDebrisManagerFactory()
Class destructor.
This class is used to check and modify the properties of a graphics mesh.
Definition: mesh.h:63
A base factory type for the creation of Debris objects.
Definition: debris.h:95
A non-deformable debris.
Definition: rigiddebris.h:64
FactoryMap::const_iterator ConstFactoryIterator
Const Iterator type for DebrisFactory instances stored by this class.
std::vector< Debris * > DebrisContainer
Basic container type for Debris storage by this class.
float Real
A Datatype used to represent a real floating point number.
Definition: datatypes.h:141
A thread specific collection of double-buffered and algorithm specific resources. ...
A manager responsible for the storage and management of all Debris that exist in a world...
A light-weight handle for manipulating nodes in DOM tree.
Definition: node.h:89
A simple world object without a large structure ideal for representing loose small objects...
Definition: debris.h:54
DebrisContainer Debriss
Container storing all Debris belonging to this manager.
uint32_t UInt32
An 32-bit unsigned integer.
Definition: datatypes.h:126
String GetManagerImplName() const
Gets the name of the manager that is created by this factory.
FactoryMap::iterator FactoryIterator
Iterator type for DebrisFactory instances stored by this class.
ManagerBase::ManagerType GetManagerType() const
Gets the type of manager that is created by this factory.
DebrisUpdateWorkUnit * DebrisUpdateWork
The work unit that updates all the Debris stored by this manager.
FactoryMap DebrisFactories
A map containing all registered Debris type factories.
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
This is the base class for all managers that belong to a single world instance.
Definition: worldmanager.h:55
This is a Mezzanine::Threading::iWorkUnit for the updating of Debris.
Definition: debrismanager.h:71
std::map< String, DebrisFactory * > FactoryMap
Basic container type for DebrisFactory storage by this class.
Threading::DefaultThreadSpecificStorage::Type * ThreadResources
Can be used for thread safe logging and other thread specific resources.
#define MEZZ_LIB
Some platforms require special decorations to denote what is exported/imported in a share library...
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
This class represents a world for objects to interact within.
Definition: world.h:74
This is a base class for factories that construct managers used by the World class.
static const String ImplementationName
A String containing the name of this manager implementation.
DefaultDebrisManagerFactory()
Class constructor.
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
void DestroyManager(WorldManager *ToBeDestroyed)
Destroys a Manager created by this factory.
DebrisContainer::const_iterator ConstDebrisIterator
Const Iterator type for Debris instances stored by this class.
WorldManager * CreateManager(World *Creator, const NameValuePairList &Params)
Creates a manager of the type represented by this factory.
std::string String
A datatype used to a series of characters.
Definition: datatypes.h:159
This file has the definition of the workunit.
static const ManagerBase::ManagerType InterfaceType
A ManagerType enum value used to describe the type of interface/functionality this manager provides...