Spinning Topp Logo BlackTopp Studios
inc
actormanager.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 actormanager_h
41 #define actormanager_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 Actor;
52  class ActorFactory;
53  class ActorManager;
54 
55  ///////////////////////////////////////////////////////////////////////////////
56  /// @brief This is a Mezzanine::Threading::iWorkUnit for the updating of actors.
57  /// @details
58  ///////////////////////////////////////
60  {
61  protected:
62  /// @internal
63  /// @brief A pointer to the manager this work unit is processing.
65  /// @internal
66  /// @brief Protected copy constructor. THIS IS NOT ALLOWED.
67  /// @param Other The other work unit being copied from. WHICH WILL NEVER HAPPEN.
69  /// @internal
70  /// @brief Protected assignment operator. THIS IS NOT ALLOWED.
71  /// @param Other The other work unit being copied from. WHICH WILL NEVER HAPPEN.
72  ActorUpdateWorkUnit& operator=(const ActorUpdateWorkUnit& Other);
73  public:
74  /// @brief Class constructor.
75  /// @param Target The ActorManager this work unit will process during the frame.
77  /// @brief Class destructor.
78  virtual ~ActorUpdateWorkUnit();
79 
80  ///////////////////////////////////////////////////////////////////////////////
81  // Utility
82 
83  /// @brief This does any required update of the Actors stored by it's manager.
84  /// @param CurrentThreadStorage The storage class for all resources owned by this work unit during it's execution.
85  virtual void DoWork(Threading::DefaultThreadSpecificStorage::Type& CurrentThreadStorage);
86  };//ActorUpdateWorkUnit
87 
88  ///////////////////////////////////////////////////////////////////////////////
89  /// @class ActorManager
90  /// @headerfile actormanager.h
91  /// @brief A manager responsible for the storage and management of all actors that exist in a world.
92  /// @details More or less Management point for a container of actors to help keep them sorted.
93  ///////////////////////////////////////
95  {
96  public:
97  /// @brief Basic container type for ActorFactory storage by this class.
98  typedef std::map<String,ActorFactory*> FactoryMap;
99  /// @brief Iterator type for ActorFactory instances stored by this class.
100  typedef FactoryMap::iterator FactoryIterator;
101  /// @brief Const Iterator type for ActorFactory instances stored by this class.
102  typedef FactoryMap::const_iterator ConstFactoryIterator;
103  /// @brief Basic container type for @ref Actor storage by this class.
104  typedef std::vector<Actor*> ActorContainer;
105  /// @brief Iterator type for @ref Actor instances stored by this class.
106  typedef ActorContainer::iterator ActorIterator;
107  /// @brief Const Iterator type for @ref Actor instances stored by this class.
108  typedef ActorContainer::const_iterator ConstActorIterator;
109 
110  /// @brief A String containing the name of this manager implementation.
112  /// @brief A ManagerType enum value used to describe the type of interface/functionality this manager provides.
114  protected:
115  friend class ActorUpdateWorkUnit;
116 
117  /// @internal
118  /// @brief A map containing all registered Actor type factories.
119  FactoryMap ActorFactories;
120  /// @internal
121  /// @brief Container storing all Actors belonging to this manager.
122  ActorContainer Actors;
123 
124  /// @internal
125  /// @brief The work unit that updates all the actors stored by this manager.
127  /// @internal
128  /// @brief Can be used for thread safe logging and other thread specific resources.
130  public:
131  /// @brief Class constructor.
132  /// @param Creator The parent world that is creating the manager.
133  ActorManager(World* Creator);
134  /// @brief XML constructor.
135  /// @param Creator The parent world that is creating the manager.
136  /// @param XMLNode The node of the xml document to construct from.
137  ActorManager(World* Creator, const XML::Node& XMLNode);
138  /// @brief Class destructor.
139  virtual ~ActorManager();
140 
141  ///////////////////////////////////////////////////////////////////////////////
142  // Prefab Actor Type Creation
143 
144  ///////////////////////////////////////////////////////////////////////////////
145  // Actor Management
146 
147  /// @brief Creates a new Actor.
148  /// @param TypeName A string containing the name of the type of Actor to be constructed.
149  /// @param InstanceName A string containing the name to be given to the created Actor.
150  /// @param Params A container of additional parameters to be used for the construction of the new Actor.
151  /// @return Returns a pointer to the created Actor.
152  Actor* CreateActor(const String& TypeName, const String& InstanceName, const NameValuePairMap& Params);
153  /// @brief Creates a new Actor class from an XML node.
154  /// @remarks This is mostly useful for deserialization.
155  /// @return Returns a pointer to the created Actor.
156  Actor* CreateActor(const XML::Node& SelfRoot);
157 
158  /// @brief Gets an Actor by Index.
159  /// @param Index The index of the Actor you wish to retrieve.
160  /// @return Returns a pointer to the Actor at the specified index.
161  virtual Actor* GetActor(const Whole Index) const;
162  /// @brief Gets an Actor by Name.
163  /// @param Name The name of the Actor you wish to retrieve.
164  /// @return Returns a pointer to the Actor of the specified name.
165  virtual Actor* GetActor(const String& Name) const;
166  /// @brief Gets the number of Actors stored in this manager.
167  /// @return Returns a whole representing the current Actor count.
168  virtual Whole GetNumActors() const;
169  /// @brief Destroys an Actor at the specified index.
170  /// @param Index The index at which to destroy the Actor.
171  virtual void DestroyActor(const Whole Index);
172  /// @brief Destroys an Actor.
173  /// @param ToBeDestroyed The Actor to be destroyed.
174  virtual void DestroyActor(Actor* ToBeDestroyed);
175  /// @brief Destroys all Actors currently within this manager.
176  virtual void DestroyAllActors();
177 
178  #ifndef SWIG
179  /// @brief Gets an iterator to the first Actor in this manager.
180  /// @return Returns an iterator to the first Actor being stored by this manager.
181  ActorIterator BeginActor();
182  /// @brief Gets an iterator to one passed the last Actor in this manager.
183  /// @return Returns an iterator to one passed the last Actor being stored by this manager.
184  ActorIterator EndActor();
185  /// @brief Gets a const iterator to the first Actor in this manager.
186  /// @return Returns a const iterator to the first Actor being stored by this manager.
187  ConstActorIterator BeginActor() const;
188  /// @brief Gets a const iterator to one passed the last Actor in this manager.
189  /// @return Returns a const iterator to one passed the last Actor being stored by this manager.
190  ConstActorIterator EndActor() const;
191  #endif
192 
193  ///////////////////////////////////////////////////////////////////////////////
194  // ActorFactory Management
195 
196  /// @brief Adds/registers a Actor factory with this manager, allowing it to be constructed through this API.
197  /// @param ToBeAdded The Actor factory to be added.
198  virtual void AddActorFactory(ActorFactory* ToBeAdded);
199  /// @brief Removes a Actor factory from this manager.
200  /// @param ToBeRemoved A pointer to the Actor factory that is to be removed.
201  virtual void RemoveActorFactory(ActorFactory* ToBeRemoved);
202  /// @brief Removes a Actor factory from this manager.
203  /// @param ImplName The name of the Actor implementation created by the factory to be removed.
204  virtual void RemoveActorFactory(const String& ImplName);
205  /// @brief Removes and destroys a Actor factory in this manager.
206  /// @param ToBeDestroyed A pointer to the Actor factory that is to be removed and destroyed.
207  virtual void DestroyActorFactory(ActorFactory* ToBeDestroyed);
208  /// @brief Removes and destroys a Actor factory in this manager.
209  /// @param ImplName The name of the Actor implementation created by the factory to be removed and destroyed.
210  virtual void DestroyActorFactory(const String& ImplName);
211  /// @brief Destroys all Actor factories in this manager.
212  /// @warning The destruction of Actor factories should only be done after all the Actor have been destroyed, otherwise this will cause an exception.
213  virtual void DestroyAllActorFactories();
214 
215  ///////////////////////////////////////////////////////////////////////////////
216  // Utility
217 
218  /// @copydoc WorldManager::Pause(const UInt32)
219  virtual void Pause(const UInt32 PL);
220 
221  /// @copydoc WorldManager::Initialize()
222  virtual void Initialize();
223  /// @copydoc ManagerBase::Deinitialize()
224  virtual void Deinitialize();
225 
226  /// @brief Gets the work unit responsible for updating actors stored by this manager.
227  /// @return Returns a pointer to the ActorUpdateWorkUnit used by this manager.
228  ActorUpdateWorkUnit* GetActorUpdateWork();
229 
230  ///////////////////////////////////////////////////////////////////////////////
231  // Type Identifier Methods
232 
233  /// @copydoc ManagerBase::GetInterfaceType()
234  virtual ManagerType GetInterfaceType() const;
235  /// @copydoc ManagerBase::GetImplementationTypeName()
236  virtual String GetImplementationTypeName() const;
237  };//ActorManager
238 
239  ///////////////////////////////////////////////////////////////////////////////
240  /// @class DefaultActorManagerFactory
241  /// @brief A factory responsible for the creation and destruction of the default actormanager.
242  ///////////////////////////////////////
244  {
245  public:
246  /// @brief Class constructor.
248  /// @brief Class destructor.
249  virtual ~DefaultActorManagerFactory();
250 
251  /// @copydoc ManagerFactory::GetManagerImplName()
252  String GetManagerImplName() const;
253  /// @copydoc ManagerFactory::GetManagerType() const
255 
256  /// @copydoc WorldManagerFactory::CreateManager(World*, const NameValuePairList&)
257  WorldManager* CreateManager(World* Creator, const NameValuePairList& Params);
258  /// @copydoc WorldManagerFactory::CreateManager(World*, const XML::Node&)
259  WorldManager* CreateManager(World* Creator, const XML::Node& XMLNode);
260  /// @copydoc WorldManagerFactory::DestroyManager(WorldManager*)
261  void DestroyManager(WorldManager* ToBeDestroyed);
262  };//DefaultActorManagerFactory
263 }//Mezzanine
264 
265 #endif
This is the base class from which all the actors inherit.
Definition: actor.h:57
WorldManager * CreateManager(World *Creator, const NameValuePairList &Params)
Creates a manager of the type represented by this factory.
Default implementation of WorkUnit. This represents on piece of work through time.
Definition: workunit.h:160
ManagerType
A listing of Manager Types.
Definition: managerbase.h:65
ActorContainer::const_iterator ConstActorIterator
Const Iterator type for Actor instances stored by this class.
Definition: actormanager.h:108
static const ManagerBase::ManagerType InterfaceType
A ManagerType enum value used to describe the type of interface/functionality this manager provides...
Definition: actormanager.h:113
A base factory type for the creation of Actor objects.
Definition: actor.h:71
FactoryMap ActorFactories
A map containing all registered Actor type factories.
Definition: actormanager.h:119
String GetManagerImplName() const
Gets the name of the manager that is created by this factory.
FactoryMap::iterator FactoryIterator
Iterator type for ActorFactory instances stored by this class.
Definition: actormanager.h:100
std::vector< Actor * > ActorContainer
Basic container type for Actor storage by this class.
Definition: actormanager.h:104
std::map< String, ActorFactory * > FactoryMap
Basic container type for ActorFactory storage by this class.
Definition: actormanager.h:98
A thread specific collection of double-buffered and algorithm specific resources. ...
ActorContainer Actors
Container storing all Actors belonging to this manager.
Definition: actormanager.h:122
ActorContainer::iterator ActorIterator
Iterator type for Actor instances stored by this class.
Definition: actormanager.h:106
A light-weight handle for manipulating nodes in DOM tree.
Definition: node.h:89
uint32_t UInt32
An 32-bit unsigned integer.
Definition: datatypes.h:126
ManagerBase::ManagerType GetManagerType() const
Gets the type of manager that is created by this factory.
virtual ~DefaultActorManagerFactory()
Class destructor.
DefaultActorManagerFactory()
Class constructor.
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
ActorUpdateWorkUnit * ActorUpdateWork
The work unit that updates all the actors stored by this manager.
Definition: actormanager.h:126
A factory responsible for the creation and destruction of the default actormanager.
Definition: actormanager.h:243
This is a Mezzanine::Threading::iWorkUnit for the updating of actors.
Definition: actormanager.h:59
FactoryMap::const_iterator ConstFactoryIterator
Const Iterator type for ActorFactory instances stored by this class.
Definition: actormanager.h:102
#define MEZZ_LIB
Some platforms require special decorations to denote what is exported/imported in a share library...
static const String ImplementationName
A String containing the name of this manager implementation.
Definition: actormanager.h:111
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::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
Threading::DefaultThreadSpecificStorage::Type * ThreadResources
Can be used for thread safe logging and other thread specific resources.
Definition: actormanager.h:129
std::string String
A datatype used to a series of characters.
Definition: datatypes.h:159
ActorManager * TargetManager
A pointer to the manager this work unit is processing.
Definition: actormanager.h:64
void DestroyManager(WorldManager *ToBeDestroyed)
Destroys a Manager created by this factory.
A manager responsible for the storage and management of all actors that exist in a world...
Definition: actormanager.h:94
This file has the definition of the workunit.