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