MezzanineEngine 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
areaeffectmanager.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 _areaeffectmanager_h
41 #define _areaeffectmanager_h
42 
43 #include "worldmanager.h"
44 #include "managerfactory.h"
45 #include "Threading/workunit.h"
46 
47 namespace Mezzanine
48 {
49  class AreaEffect;
50  class AreaEffectFactory;
51  class AreaEffectManager;
52 
53  class FieldOfForce;
54  class GravityField;
55  class GravityWell;
56 
57  ///////////////////////////////////////////////////////////////////////////////
58  /// @brief This is a Mezzanine::Threading::iWorkUnit for the updating of AreaEffects.
59  /// @details
60  ///////////////////////////////////////
62  {
63  protected:
64  /// @internal
65  /// @brief A pointer to the manager this work unit is processing.
67  /// @internal
68  /// @brief Protected copy constructor. THIS IS NOT ALLOWED.
69  /// @param Other The other work unit being copied from. WHICH WILL NEVER HAPPEN.
71  /// @internal
72  /// @brief Protected assignment operator. THIS IS NOT ALLOWED.
73  /// @param Other The other work unit being copied from. WHICH WILL NEVER HAPPEN.
74  AreaEffectUpdateWorkUnit& operator=(const AreaEffectUpdateWorkUnit& Other);
75  public:
76  /// @brief Class constructor.
77  /// @param Target The AreaEffectManager this work unit will process during the frame.
79  /// @brief Class destructor.
80  virtual ~AreaEffectUpdateWorkUnit();
81 
82  ///////////////////////////////////////////////////////////////////////////////
83  // Utility
84 
85  /// @brief This does any required update of the Graphical Scene graph and REnders one frame
86  /// @param CurrentThreadStorage The storage class for all resources owned by this work unit during it's execution.
87  virtual void DoWork(Threading::DefaultThreadSpecificStorage::Type& CurrentThreadStorage);
88  };//AreaEffectUpdateWorkUnit
89 
90  ///////////////////////////////////////////////////////////////////////////////
91  /// @class AreaEffectManager
92  /// @headerfile areaeffectmanager.h
93  /// @brief A manager responsible for the storage and management of all areaeffects in use.
94  /// @details More or less Management point for a container of areaeffects to help keep them sorted.
95  ///////////////////////////////////////
97  {
98  public:
99  /// @brief Basic container type for AreaEffectFactory storage by this class.
100  typedef std::map<String,AreaEffectFactory*> FactoryMap;
101  /// @brief Iterator type for AreaEffectFactory instances stored by this class.
102  typedef FactoryMap::iterator FactoryIterator;
103  /// @brief Const Iterator type for AreaEffectFactory instances stored by this class.
104  typedef FactoryMap::const_iterator ConstFactoryIterator;
105  /// @brief Basic container type for AreaEffect storage by this class.
106  typedef std::vector<AreaEffect*> AreaEffectContainer;
107  /// @brief Iterator type for AreaEffect instances stored by this class.
108  typedef AreaEffectContainer::iterator AreaEffectIterator;
109  /// @brief Const Iterator type for AreaEffect instances stored by this class.
110  typedef AreaEffectContainer::const_iterator ConstAreaEffectIterator;
111  protected:
112  friend class AreaEffectUpdateWorkUnit;
113 
114  /// @internal
115  /// @brief A map containing all registered AreaEffect type factories.
117  /// @internal
118  /// @brief Container storing all AreaEffects belonging to this manager.
120 
121  /// @internal
122  /// @brief The work unit that updates all the actors stored by this manager.
124  /// @internal
125  /// @brief Can be used for thread safe logging and other thread specific resources.
127  public:
128  /// @brief Class constructor.
130  /// @brief XML constructor.
131  /// @param XMLNode The node of the xml document to construct from.
132  AreaEffectManager(XML::Node& XMLNode);
133  /// @brief Class destructor.
134  virtual ~AreaEffectManager();
135 
136  ///////////////////////////////////////////////////////////////////////////////
137  // Prefab AreaEffect Type Creation
138 
139  /// @brief Creates a new FieldOfForce.
140  /// @param Name The name to be given to the new FieldOfForce.
141  /// @return Returns a pointer to the created AreaEffect.
142  FieldOfForce* CreateFieldOfForce(const String& Name);
143  /// @brief Creates a new FieldOfForce.
144  /// @param SelfRoot An XML::Node containing the data to populate this class with.
145  /// @return Returns a pointer to the created AreaEffect.
146  FieldOfForce* CreateFieldOfForce(const XML::Node& SelfRoot);
147  /// @brief Creates a new GravityField.
148  /// @param Name The name to be given to the new GravityField.
149  /// @return Returns a pointer to the created AreaEffect.
150  GravityField* CreateGravityField(const String& Name);
151  /// @brief Creates a new GravityField.
152  /// @param SelfRoot An XML::Node containing the data to populate this class with.
153  /// @return Returns a pointer to the created AreaEffect.
154  GravityField* CreateGravityField(const XML::Node& SelfRoot);
155  /// @brief Creates a new GravityWell.
156  /// @param Name The name to be given to the new GravityWell.
157  /// @return Returns a pointer to the created AreaEffect.
158  GravityWell* CreateGravityWell(const String& Name);
159  /// @brief Creates a new GravityWell.
160  /// @param SelfRoot An XML::Node containing the data to populate this class with.
161  /// @return Returns a pointer to the created AreaEffect.
162  GravityWell* CreateGravityWell(const XML::Node& SelfRoot);
163 
164  ///////////////////////////////////////////////////////////////////////////////
165  // AreaEffect Management
166 
167  /// @brief Creates a new AreaEffect.
168  /// @param TypeName A string containing the name of the type of AreaEffect to be constructed.
169  /// @param InstanceName A string containing the name to be given to the created AreaEffect.
170  /// @param Params A container of additional parameters to be used for the construction of the new AreaEffect.
171  /// @return Returns a pointer to the created AreaEffect.
172  AreaEffect* CreateAreaEffect(const String& TypeName, const String& InstanceName, const NameValuePairMap& Params);
173  /// @brief Creates a new AreaEffect class from an XML node.
174  /// @remarks This is mostly useful for deserialization.
175  /// @return Returns a pointer to the created AreaEffect.
176  AreaEffect* CreateAreaEffect(const XML::Node& SelfRoot);
177 
178  /// @brief Gets an AreaEffect by Index.
179  /// @param Index The index of the areaeffect you wish to retrieve.
180  /// @return Returns a pointer to the areaeffect at the specified index.
181  virtual AreaEffect* GetAreaEffect(const Whole Index) const;
182  /// @brief Gets an AreaEffect by Name.
183  /// @param Name The name of the areaeffect you wish to retrieve.
184  /// @return Returns a pointer to the areaeffect of the specified name.
185  virtual AreaEffect* GetAreaEffect(const String& Name) const;
186  /// @brief Gets the number of actors stored in this manager.
187  /// @return Returns a whole representing the current areaeffect count.
188  virtual Whole GetNumAreaEffects() const;
189  /// @brief Destroys an areaeffect at the specified index.
190  /// @param Index The index at which to destroy the areaeffect.
191  virtual void DestroyAreaEffect(const Whole Index);
192  /// @brief Destroys an areaeffect.
193  /// @param ToBeDestroyed The areaeffect to be destroyed.
194  virtual void DestroyAreaEffect(AreaEffect* ToBeDestroyed);
195  /// @brief Destroys all actors currently within this manager.
196  virtual void DestroyAllAreaEffects();
197 
198  ///////////////////////////////////////////////////////////////////////////////
199  // AreaEffectFactory Management
200 
201  /// @brief Adds/registers a AreaEffect factory with this manager, allowing it to be constructed through this API.
202  /// @param ToBeAdded The AreaEffect factory to be added.
203  virtual void AddAreaEffectFactory(AreaEffectFactory* ToBeAdded);
204  /// @brief Removes a AreaEffect factory from this manager.
205  /// @param ToBeRemoved A pointer to the AreaEffect factory that is to be removed.
206  virtual void RemoveAreaEffectFactory(AreaEffectFactory* ToBeRemoved);
207  /// @brief Removes a AreaEffect factory from this manager.
208  /// @param ImplName The name of the AreaEffect implementation created by the factory to be removed.
209  virtual void RemoveAreaEffectFactory(const String& ImplName);
210  /// @brief Removes and destroys a AreaEffect factory in this manager.
211  /// @param ToBeDestroyed A pointer to the AreaEffect factory that is to be removed and destroyed.
212  virtual void DestroyAreaEffectFactory(AreaEffectFactory* ToBeDestroyed);
213  /// @brief Removes and destroys a AreaEffect factory in this manager.
214  /// @param ImplName The name of the AreaEffect implementation created by the factory to be removed and destroyed.
215  virtual void DestroyAreaEffectFactory(const String& ImplName);
216  /// @brief Destroys all AreaEffect factories in this manager.
217  /// @warning The destruction of AreaEffect factories should only be done after all the AreaEffects have been destroyed, otherwise this will cause an exception.
218  virtual void DestroyAllAreaEffectFactories();
219 
220  ///////////////////////////////////////////////////////////////////////////////
221  // Utility
222 
223  /// @copydoc WorldManager::Pause(const UInt32)
224  virtual void Pause(const UInt32 PL);
225 
226  /// @brief Does all of the necessary configuration to prepare for the start of the main loop.
227  virtual void MainLoopInitialize();
228  /// @copydoc WorldManager::Initialize()
229  virtual void Initialize();
230  /// @copydoc ManagerBase::Deinitialize()
231  virtual void Deinitialize();
232 
233  /// @brief Gets the work unit responsible for updating area effects stored by this manager.
234  /// @return Returns a pointer to the AreaEffectUpdateWorkUnit used by this manager.
235  AreaEffectUpdateWorkUnit* GetAreaEffectUpdateWork();
236 
237  ///////////////////////////////////////////////////////////////////////////////
238  // Type Identifier Methods
239 
240  /// @copydoc ManagerBase::GetInterfaceType()
241  virtual ManagerType GetInterfaceType() const;
242  /// @copydoc ManagerBase::GetImplementationTypeName()
243  virtual String GetImplementationTypeName() const;
244  };//AreaEffectManager
245 
246  ///////////////////////////////////////////////////////////////////////////////
247  /// @class DefaultAreaEffectManagerFactory
248  /// @headerfile areaeffectmanager.h
249  /// @brief A factory responsible for the creation and destruction of the default areaeffectmanager.
250  ///////////////////////////////////////
252  {
253  public:
254  /// @brief Class constructor.
256  /// @brief Class destructor.
258 
259  /// @copydoc ManagerFactory::GetManagerTypeName()
260  String GetManagerTypeName() const;
261 
262  /// @copydoc ManagerFactory::CreateManager(NameValuePairList&)
264  /// @copydoc ManagerFactory::CreateManager(XML::Node&)
266  /// @copydoc ManagerFactory::DestroyManager(ManagerBase*)
267  void DestroyManager(ManagerBase* ToBeDestroyed);
268  };//DefaultAreaEffectManagerFactory
269 }//Mezzanine
270 
271 #endif