MezzanineEngine 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
debrismanager.h
Go to the documentation of this file.
1 // © Copyright 2010 - 2014 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 "managerfactory.h"
48 #include "Threading/workunit.h"
49 
50 namespace Mezzanine
51 {
52  class Debris;
53  class DebrisFactory;
54  class DebrisManager;
55 
56  class RigidDebris;
57  class SoftDebris;
58  ///////////////////////////////////////////////////////////////////////////////
59  /// @brief This is a Mezzanine::Threading::iWorkUnit for the updating of Debris.
60  /// @details
61  ///////////////////////////////////////
63  {
64  protected:
65  /// @internal
66  /// @brief A pointer to the manager this work unit is processing.
68  /// @internal
69  /// @brief Protected copy constructor. THIS IS NOT ALLOWED.
70  /// @param Other The other work unit being copied from. WHICH WILL NEVER HAPPEN.
72  /// @internal
73  /// @brief Protected assignment operator. THIS IS NOT ALLOWED.
74  /// @param Other The other work unit being copied from. WHICH WILL NEVER HAPPEN.
75  DebrisUpdateWorkUnit& operator=(const DebrisUpdateWorkUnit& Other);
76  public:
77  /// @brief Class constructor.
78  /// @param Target The DebrisManager this work unit will process during the frame.
80  /// @brief Class destructor.
81  virtual ~DebrisUpdateWorkUnit();
82 
83  ///////////////////////////////////////////////////////////////////////////////
84  // Utility
85 
86  /// @brief This does any required update of the Debris stored by it's manager.
87  /// @param CurrentThreadStorage The storage class for all resources owned by this work unit during it's execution.
88  virtual void DoWork(Threading::DefaultThreadSpecificStorage::Type& CurrentThreadStorage);
89  };//DebrisUpdateWorkUnit
90 
91  ///////////////////////////////////////////////////////////////////////////////
92  /// @brief A manager responsible for the storage and management of all Debris that exist in a world.
93  /// @details More or less Management point for a container of Debris to help keep them sorted.
94  ///////////////////////////////////////
96  {
97  public:
98  /// @brief Basic container type for DebrisFactory storage by this class.
99  typedef std::map<String,DebrisFactory*> FactoryMap;
100  /// @brief Iterator type for DebrisFactory instances stored by this class.
101  typedef FactoryMap::iterator FactoryIterator;
102  /// @brief Const Iterator type for DebrisFactory instances stored by this class.
103  typedef FactoryMap::const_iterator ConstFactoryIterator;
104  /// @brief Basic container type for Debris storage by this class.
105  typedef std::vector< Debris* > DebrisContainer;
106  /// @brief Iterator type for Debris instances stored by this class.
107  typedef DebrisContainer::iterator DebrisIterator;
108  /// @brief Const Iterator type for Debris instances stored by this class.
109  typedef DebrisContainer::const_iterator ConstDebrisIterator;
110  protected:
111  friend class DebrisUpdateWorkUnit;
112 
113  /// @internal
114  /// @brief A map containing all registered Debris type factories.
116  /// @internal
117  /// @brief Container storing all Debris belonging to this manager.
119 
120  /// @internal
121  /// @brief The work unit that updates all the Debris stored by this manager.
123  /// @internal
124  /// @brief Can be used for thread safe logging and other thread specific resources.
126  public:
127  /// @brief Class constructor.
128  DebrisManager();
129  /// @brief XML constructor.
130  /// @param XMLNode The node of the xml document to construct from.
131  DebrisManager(XML::Node& XMLNode);
132  /// @brief Class destructor.
133  virtual ~DebrisManager();
134 
135  ///////////////////////////////////////////////////////////////////////////////
136  // Prefab Debris Type Creation
137 
138  /// @brief Creates a new RigidDebris.
139  /// @param Name The name to be given to the new RigidDebris.
140  /// @param Mass The mass of the debris object.
141  /// @return Returns a pointer to the created Debris.
142  RigidDebris* CreateRigidDebris(const String& Name, const Real Mass);
143  /// @brief Creates a new RigidDebris.
144  /// @param SelfRoot An XML::Node containing the data to populate this class with.
145  /// @return Returns a pointer to the created Debris.
146  RigidDebris* CreateRigidDebris(const XML::Node& SelfRoot);
147  /// @brief Creates a new SoftDebris.
148  /// @param Name The name to be given to the new SoftDebris.
149  /// @param Mass The mass of the debris object.
150  /// @return Returns a pointer to the created Debris.
151  SoftDebris* CreateSoftDebris(const String& Name, const Real Mass);
152  /// @brief Creates a new SoftDebris.
153  /// @param SelfRoot An XML::Node containing the data to populate this class with.
154  /// @return Returns a pointer to the created Debris.
155  SoftDebris* CreateSoftDebris(const XML::Node& SelfRoot);
156 
157  ///////////////////////////////////////////////////////////////////////////////
158  // Debris Management
159 
160  /// @brief Creates a new Debris.
161  /// @param TypeName A string containing the name of the type of Debris to be constructed.
162  /// @param InstanceName A string containing the name to be given to the created Debris.
163  /// @param Params A container of additional parameters to be used for the construction of the new Debris.
164  /// @return Returns a pointer to the created Debris.
165  Debris* CreateDebris(const String& TypeName, const String& InstanceName, const NameValuePairMap& Params);
166  /// @brief Creates a new Debris class from an XML node.
167  /// @remarks This is mostly useful for deserialization.
168  /// @return Returns a pointer to the created Debris.
169  Debris* CreateDebris(const XML::Node& SelfRoot);
170 
171  /// @brief Gets an Debris by Index.
172  /// @param Index The index of the Debris you wish to retrieve.
173  /// @return Returns a pointer to the Debris at the specified index.
174  virtual Debris* GetDebris(const Whole Index) const;
175  /// @brief Gets an Debris by Name.
176  /// @param Name The name of the Debris you wish to retrieve.
177  /// @return Returns a pointer to the Debris of the specified name.
178  virtual Debris* GetDebris(const String& Name) const;
179  /// @brief Gets the number of Debriss stored in this manager.
180  /// @return Returns a whole representing the current Debris count.
181  virtual Whole GetNumDebris() const;
182  /// @brief Destroys an Debris at the specified index.
183  /// @param Index The index at which to destroy the Debris.
184  virtual void DestroyDebris(const Whole Index);
185  /// @brief Destroys an Debris.
186  /// @param ToBeDestroyed The Debris to be destroyed.
187  virtual void DestroyDebris(Debris* ToBeDestroyed);
188  /// @brief Destroys all Debriss currently within this manager.
189  virtual void DestroyAllDebris();
190 
191  ///////////////////////////////////////////////////////////////////////////////
192  // DebrisFactory Management
193 
194  /// @brief Adds/registers a Debris factory with this manager, allowing it to be constructed through this API.
195  /// @param ToBeAdded The Debris factory to be added.
196  virtual void AddDebrisFactory(DebrisFactory* ToBeAdded);
197  /// @brief Removes a Debris factory from this manager.
198  /// @param ToBeRemoved A pointer to the Debris factory that is to be removed.
199  virtual void RemoveDebrisFactory(DebrisFactory* ToBeRemoved);
200  /// @brief Removes a Debris factory from this manager.
201  /// @param ImplName The name of the Debris implementation created by the factory to be removed.
202  virtual void RemoveDebrisFactory(const String& ImplName);
203  /// @brief Removes and destroys a Debris factory in this manager.
204  /// @param ToBeDestroyed A pointer to the Debris factory that is to be removed and destroyed.
205  virtual void DestroyDebrisFactory(DebrisFactory* ToBeDestroyed);
206  /// @brief Removes and destroys a Debris factory in this manager.
207  /// @param ImplName The name of the Debris implementation created by the factory to be removed and destroyed.
208  virtual void DestroyDebrisFactory(const String& ImplName);
209  /// @brief Destroys all Debris factories in this manager.
210  /// @warning The destruction of Debris factories should only be done after all the Debris have been destroyed, otherwise this will cause an exception.
211  virtual void DestroyAllDebrisFactories();
212 
213  ///////////////////////////////////////////////////////////////////////////////
214  // Utility
215 
216  /// @copydoc WorldManager::Pause(const UInt32)
217  virtual void Pause(const UInt32 PL);
218 
219  /// @copydoc WorldManager::Initialize()
220  virtual void Initialize();
221  /// @copydoc ManagerBase::Deinitialize()
222  virtual void Deinitialize();
223 
224  /// @brief Gets the work unit responsible for updating Debriss stored by this manager.
225  /// @return Returns a pointer to the ActorUpdateWorkUnit used by this manager.
226  DebrisUpdateWorkUnit* GetDebrisUpdateWork();
227 
228  ///////////////////////////////////////////////////////////////////////////////
229  // Type Identifier Methods
230 
231  /// @copydoc ManagerBase::GetInterfaceType()
232  virtual ManagerType GetInterfaceType() const;
233  /// @copydoc ManagerBase::GetImplementationTypeName()
234  virtual String GetImplementationTypeName() const;
235  };//DebrisManager
236 
237  ///////////////////////////////////////////////////////////////////////////////
238  /// @brief A factory responsible for the creation and destruction of the default DebrisManager.
239  ///////////////////////////////////////
241  {
242  public:
243  /// @brief Class constructor.
245  /// @brief Class destructor.
247 
248  /// @copydoc ManagerFactory::GetManagerTypeName()
249  String GetManagerTypeName() const;
250 
251  /// @copydoc ManagerFactory::CreateManager(NameValuePairList&)
253  /// @copydoc ManagerFactory::CreateManager(XML::Node&)
255  /// @copydoc ManagerFactory::DestroyManager(ManagerBase*)
256  void DestroyManager(ManagerBase* ToBeDestroyed);
257  };//DefaultDebrisManagerFactory
258 }//Mezzanine
259 
260 #endif