Spinning Topp Logo BlackTopp Studios
inc
world.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 
41 #ifndef _world_h
42 #define _world_h
43 
44 #include "worldmanager.h"
45 
46 namespace Mezzanine
47 {
48  class ActorManager;
49  class AreaEffectManager;
50  class DebrisManager;
51  class TerrainManager;
52  class WorldManager;
53  class WorldManagerFactory;
54  namespace Audio
55  {
56  class SoundScapeManager;
57  }
58  namespace Graphics
59  {
60  class SceneManager;
61  }
62  namespace Physics
63  {
64  class PhysicsManager;
65  class ManagerConstructionInfo;
66  }
67  ///////////////////////////////////////////////////////////////////////////////
68  /// @class World
69  /// @headerfile world.h
70  /// @brief This class represents a world for objects to interact within.
71  /// @details Objects can be inserted and removed from worlds in order to simulate them. Multiple worlds can
72  /// exist but objects can only belong to one world at a time.
73  ///////////////////////////////////////
75  {
76  public:
77  /// @brief Basic container type for factories that construct known manager types.
78  typedef std::map<String,WorldManagerFactory*> ManagerFactoryMap;
79  /// @brief Iterator type for manager factories stored by this class.
80  typedef ManagerFactoryMap::iterator ManagerFactoryIterator;
81  /// @brief Const Iterator type for manager factories stored by this class.
82  typedef ManagerFactoryMap::const_iterator ConstManagerFactoryIterator;
83  /// @brief Basic container type for @ref WorldManager storage by this class.
84  typedef std::vector< WorldManager* > WorldManagerContainer;
85  /// @brief Iterator type for @ref WorldManager instances stored by this class.
86  typedef WorldManagerContainer::iterator WorldManagerIterator;
87  /// @brief Const Iterator type for @ref WorldManager instances stored by this class.
88  typedef WorldManagerContainer::const_iterator ConstWorldManagerIterator;
89  protected:
90  /// @internal
91  /// @brief A global container for registered factories for WorldManagers.
92  static ManagerFactoryMap ManagerFactories;
93  /// @internal
94  /// @brief A container storing all the managers belonging to this world.
95  WorldManagerContainer WorldManagers;
96  /// @internal
97  /// @brief Unique string identifier for world.
99 
100  /// @internal
101  /// @brief Helper function used to assist construction.
102  void Construct(const Physics::ManagerConstructionInfo& PhysicsInfo, const String& SceneType, const WorldManagerContainer& ManagerToBeAdded);
103 
104  /// @internal
105  /// @brief Checks if all managers currently stored in this World have been initialized.
106  /// @return Returns true if all stored managers have been initialized, false otherwise.
107  Boole VerifyManagerInitializations();
108  public:
109  /// @brief Class constructor.
110  /// @param WorldName String name of the world.
111  World(const String& WorldName);
112  /// @brief Pre-made manager constructor.
113  /// @param WorldName String name of the world.
114  /// @param Managers A container of pre-made managers to be used by this world.
115  World(const String& WorldName, const WorldManagerContainer& Managers);
116  /// @brief Descriptive constructor.
117  /// @param WorldName String name of the world.
118  /// @param PhysicsInfo A ManagerConstructionInfo struct with data on how to configure the physics for this world.
119  /// @param SceneType A string containing the name of the underlying scene type for this world.
120  World(const String& WorldName, const Physics::ManagerConstructionInfo& PhysicsInfo, const String& SceneType);
121  /// @brief Descriptive pre-made manager constructor.
122  /// @param WorldName String name of the world.
123  /// @param Managers A container of pre-made managers to be used by this world.
124  /// @param PhysicsInfo A ManagerConstructionInfo struct with data on how to configure the physics for this world.
125  /// @param SceneType A string containing the name of the underlying scene type for this world.
126  World(const String& WorldName, const WorldManagerContainer& Managers, const Physics::ManagerConstructionInfo& PhysicsInfo, const String& SceneType);
127  /// @brief XML constructor.
128  /// @param SelfNode The node that represents the data to populate this world with.
129  World(const XML::Node& SelfNode);
130  /// @brief class destructor.
131  virtual ~World();
132 
133  ///////////////////////////////////////////////////////////////////////////////
134  // Utility
135 
136  /// @brief Gets the name of this world.
137  /// @return Returns a string containing the name used to identify this world.
138  const String& GetName() const;
139  /// @brief Pauses all animations, particles, and object movement throughout the world.
140  /// @param Pause Pauses the world if true, unpauses if false.
141  void PauseWorld(const Boole Pause);
142 
143  /// @brief Clears the world of all objects.
144  /// @remarks This will delete all world objects and supporting objects (such as constraints) and any metadata related to them.
145  /// This method is designed to clear the slate for the world back to zero and be ready for re-use without having to destroy and
146  /// recreate the world and setting custom configurations in the world.
147  void Clear();
148 
149  ///////////////////////////////////////////////////////////////////////////////
150  // Initialization
151 
152  /// @brief Initializes all managers in this world and performs all the necessary hooks to enable this world.
153  void Initialize();
154  /// @brief Deinitializes all managers in this world and unhooks all of it's systems, disabling this world.
155  void Deinitialize();
156 
157  /// @brief Initialize any default managers and any added after construction. This should be called before the Entresol enters it's main loop.
158  void PreMainLoopInit();
159 
160  ///////////////////////////////////////////////////////////////////////////////
161  // Upper Management
162 
163  /// @brief Creates a new manager.
164  /// @param ManagerImplName The name of the manager implementation to create.
165  /// @param Params A list of name-value pairs for the params that are to be used when creating the manager.
166  /// @param AddToWorld Whether or not to add the created manager to the World after creation.
167  /// @return Returns a pointer to the created manager.
168  WorldManager* CreateManager(const String& ManagerImplName, const NameValuePairList& Params, Boole AddToWorld = true);
169  /// @brief Creates a new manager.
170  /// @param ManagerImplName The name of the manager implementation to create.
171  /// @param XMLNode An XML node containing all construction and initialization info for the manager to be created.
172  /// @param AddToWorld Whether or not to add the created manager to the World after creation.
173  /// @return Returns a pointer to the created manager.
174  WorldManager* CreateManager(const String& ManagerImplName, const XML::Node& XMLNode, Boole AddToWorld = true);
175  /// @brief Destroys a manager.
176  /// @warning Some managers may depend on other managers for a part of their functionality. Use individual destruction of managers carefully.
177  /// @param ToBeDestroyed The manager to be destroyed.
178  void DestroyManager(WorldManager* ToBeDestroyed);
179  /// @brief Destroys all managers currently in the World.
180  /// @warning Do not call this in anything that is run during the main loop. If you do you will have a bad time.
181  void DestroyAllManagers();
182 
183  /// @brief This adds a manager, in the correct order, to the list that the world calls on.
184  /// @param ManagerToAdd The pointer to the manager to be added.
185  /// @return Returns true if the manager was successfully added, false if the manager or it's type was non-unique.
186  Boole AddManager(WorldManager* ManagerToAdd);
187  /// @brief This is will find the manager of a given type.
188  /// @param ManagerToGet The type ID of the manager to get. Use ManagerBase::ManagerType enum values for this.
189  /// @return This returns a pointer to a WorldManager, or a NULL pointer if no matching manager exists.
190  WorldManager* GetManager(const Whole ManagerToGet);
191  /// @brief This removes a manager by finding the matching pointer.
192  /// @param ToBeRemoved A pointer to the manager to be removed.
193  void RemoveManager(WorldManager* ToBeRemoved);
194  /// @brief This removes a manager of a specific type from the list
195  /// @param ToBeRemoved The type ID of the manager to get. Use ManagerBase::ManagerType enum values for this.
196  void RemoveManager(const Whole ToBeRemoved);
197  /// @brief This removes all managers from the manager list.
198  void RemoveAllManagers();
199 
200  /// @brief This gets the list of managers in the world.
201  /// @return This returns a pointer to a vector containing the managers in this world.
202  WorldManagerContainer& GetWorldManagers();
203 
204  ///////////////////////////////////////////////////////////////////////////////
205  // Factories Management
206 
207  /// @brief Adds/registers a manager factory for use with World instances.
208  /// @param ToBeAdded The manager factory to be added.
209  static void AddManagerFactory(WorldManagerFactory* ToBeAdded);
210  /// @brief Removes a manager factory from the container of registered factories.
211  /// @param ToBeRemoved A pointer to the manager factory that is to be removed.
212  static void RemoveManagerFactory(WorldManagerFactory* ToBeRemoved);
213  /// @brief Removes a manager factory from the container of registered factories.
214  /// @param ImplName The name of the manager implementation created by the factory to be removed.
215  static void RemoveManagerFactory(const String& ImplName);
216  /// @brief Removes and destroys a manager factory in the container of registered factories.
217  /// @param ToBeRemoved A pointer to the manager factory that is to be removed and destroyed.
218  static void DestroyManagerFactory(WorldManagerFactory* ToBeRemoved);
219  /// @brief Removes and destroys a manager factory in the container of registered factories.
220  /// @param ImplName The name of the manager implementation created by the factory to be removed and destroyed.
221  static void DestroyManagerFactory(const String& ImplName);
222  /// @brief Destroys all registered manager factories.
223  /// @warning The destruction of manager factories should only be done after the corresponding managers have been destroyed, otherwise this will cause an exception.
224  static void DestroyAllManagerFactories();
225  /// @brief Adds all the default manager factories provided by the engine.
226  static void AddAllEngineDefaultManagerFactories();
227 
228  ///////////////////////////////////////////////////////////////////////////////
229  // Serialization
230 
231  /// @brief Convert this class to an XML::Node ready for serialization.
232  /// @param ParentNode The point in the XML hierarchy that this World should be appended to.
233  virtual void ProtoSerialize(XML::Node& ParentNode) const;
234  /// @brief Convert the properties of this class to an XML::Node ready for serialization.
235  /// @param SelfRoot The root node containing all the serialized data for this instance.
236  virtual void ProtoSerializeProperties(XML::Node& SelfRoot) const;
237 
238  /// @brief Take the data stored in an XML Node and overwrite this object with it.
239  /// @param SelfRoot An XML::Node containing the data to populate this class with.
240  virtual void ProtoDeSerialize(const XML::Node& SelfRoot);
241  /// @brief Take the data stored in an XML Node and overwrite the properties of this object with it.
242  /// @param SelfRoot An XML::Node containing the data to populate this class with.
243  virtual void ProtoDeSerializeProperties(const XML::Node& SelfRoot);
244 
245  /// @brief Gets the most derived serializable name of this World.
246  /// @note When creating a new World class verify this method has a valid return for it in order for serialization to work properly.
247  /// @return Returns the name of the XML tag from the most derived class of "this".
248  virtual String GetDerivedSerializableName() const;
249  /// @brief Get the name of the the XML tag the World class will leave behind as its instances are serialized.
250  /// @return A string containing the name of this class.
251  static String GetSerializableName();
252  };//World
253 }//Mezzanine
254 
255 #endif
static ManagerFactoryMap ManagerFactories
A global container for registered factories for WorldManagers.
Definition: world.h:92
WorldManagerContainer::const_iterator ConstWorldManagerIterator
Const Iterator type for WorldManager instances stored by this class.
Definition: world.h:88
bool Boole
Generally acts a single bit, true or false.
Definition: datatypes.h:173
WorldManagerContainer WorldManagers
A container storing all the managers belonging to this world.
Definition: world.h:95
ManagerFactoryMap::const_iterator ConstManagerFactoryIterator
Const Iterator type for manager factories stored by this class.
Definition: world.h:82
WorldManagerContainer::iterator WorldManagerIterator
Iterator type for WorldManager instances stored by this class.
Definition: world.h:86
String Name
Unique string identifier for world.
Definition: world.h:98
std::map< String, WorldManagerFactory * > ManagerFactoryMap
Basic container type for factories that construct known manager types.
Definition: world.h:78
ManagerFactoryMap::iterator ManagerFactoryIterator
Iterator type for manager factories stored by this class.
Definition: world.h:80
A light-weight handle for manipulating nodes in DOM tree.
Definition: node.h:89
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
#define MEZZ_LIB
Some platforms require special decorations to denote what is exported/imported in a share library...
std::vector< WorldManager * > WorldManagerContainer
Basic container type for WorldManager storage by this class.
Definition: world.h:84
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.
std::string String
A datatype used to a series of characters.
Definition: datatypes.h:159
This is the base manager class for audio being played in a 3D environment.
This is a helper class storing information needed for the construction of a PhysicsManager.