MezzanineEngine 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
worldobject.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 _worldobject_h
41 #define _worldobject_h
42 
43 #include "enumerations.h"
44 #include "transformableobject.h"
45 #include "attachable.h"
46 #include "Physics/physicsenumerations.h"
47 
48 namespace Mezzanine
49 {
50  class World;
51  class WorldProxy;
52  namespace Physics
53  {
54  class Collision;
55  }
56  ///////////////////////////////////////////////////////////////////////////////
57  /// @brief This is the base class from which classes that are insertable into the physical world.
58  /// @details
59  ///////////////////////////////////////
61  {
62  public:
63  /// @brief Basic container type for WorldProxy storage by this class.
64  typedef std::vector< WorldProxy* > ProxyContainer;
65  /// @brief Iterator type for WorldProxy instances stored by this class.
66  typedef ProxyContainer::iterator ProxyIterator;
67  /// @brief Const Iterator type for WorldProxy instances stored by this class.
68  typedef ProxyContainer::const_iterator ConstProxyIterator;
69  /// @brief Basic container type for the current collisions applied to this object.
70  typedef std::set< Physics::Collision* > CollisionContainer;
71  /// @brief Iterator type for the current collisions applied to this object.
72  typedef CollisionContainer::iterator CollisionIterator;
73  /// @brief Const Iterator type for the current collisions applied to this object.
74  typedef CollisionContainer::const_iterator ConstCollisionIterator;
75  protected:
76  /// @internal
77  /// @brief This member stores all existing collision events referencing this object.
79  /// @internal
80  /// @brief The name of the object.
82  /// @internal
83  /// @brief This is the world this object belongs to and will be inserted in/removed from.
85  public:
86  /// @brief Blank constructor.
87  /// @param TheWorld A pointer to the world this object belongs to.
88  WorldObject(World* TheWorld);
89  /// @brief Class constructor.
90  /// @param Name The name to be given to this object.
91  /// @param TheWorld A pointer to the world this object belongs to.
92  WorldObject(const String& Name, World* TheWorld);
93  /// @brief Class destructor.
94  virtual ~WorldObject();
95 
96  ///////////////////////////////////////////////////////////////////////////////
97  // Utility and Configuration
98 
99  /// @brief Gets the type of the object instance
100  /// @return Returns the type of the object instance
101  virtual Mezzanine::WorldObjectType GetType() const = 0;
102  /// @brief Gets the name of this object.
103  /// @return Returns a string containing the name of this object.
104  virtual const String& GetName() const;
105  /// @brief Gets the world this object currently belongs to.
106  /// @return Returns a pointer to the world that owns this object.
107  virtual World* GetWorld() const;
108 
109  /// @brief Gets whether or not this object is currently in the world.
110  /// @return Returns a bool indicating if this object has been added to the world.
111  virtual Boolean IsInWorld() const = 0;
112 
113  /// @brief Checks of the object is static.
114  /// @return Returns true if the object is static, false otherwise.
115  virtual Boolean IsStatic() const = 0;
116  /// @brief Checks of the object is kinematic.
117  /// @return Returns true if the object is kinematic, false otherwise.
118  virtual Boolean IsKinematic() const = 0;
119 
120  /// @brief Populates a container with all of the WorldProxies being used by this WorldObject.
121  /// @param Proxies The container of proxies to be populated.
122  virtual void GetProxies(ProxyContainer& Proxies) = 0;
123  /// @brief Populates a container with all the WorldProxies being used by this WorldObject specified in a provided mask.
124  /// @param Types The bitmask specifing the types of world proxies to populate the container with.
125  /// @param Proxies The container of proxies to be populated.
126  virtual void GetProxies(const UInt32 Types, ProxyContainer& Proxies) = 0;
127 
128  ///////////////////////////////////////////////////////////////////////////////
129  // Working with the World
130 
131  /// @brief Adds the object to the World.
132  virtual void AddToWorld() = 0;
133  /// @brief Removes the object from the World.
134  virtual void RemoveFromWorld() = 0;
135 
136  ///////////////////////////////////////////////////////////////////////////////
137  // Serialization
138 
139  /// @brief Convert this class to an XML::Node ready for serialization.
140  /// @param ParentNode The point in the XML hierarchy that all this renderable should be appended to.
141  virtual void ProtoSerialize(XML::Node& ParentNode) const;
142  /// @brief Convert the properties of this class to an XML::Node ready for serialization.
143  /// @param SelfRoot The root node containing all the serialized data for this instance.
144  virtual void ProtoSerializeProperties(XML::Node& SelfRoot) const;
145  /// @brief Convert the proxies of this class to an XML::Node ready for serialization.
146  /// @param SelfRoot The root node containing all the serialized data for this instance.
147  virtual void ProtoSerializeProxies(XML::Node& SelfRoot) const = 0;
148 
149  /// @brief Take the data stored in an XML Node and overwrite this object with it.
150  /// @param SelfRoot An XML::Node containing the data to populate this class with.
151  virtual void ProtoDeSerialize(const XML::Node& SelfRoot);
152  /// @brief Take the data stored in an XML Node and overwrite the properties of this object with it.
153  /// @param SelfRoot An XML::Node containing the data to populate this class with.
154  virtual void ProtoDeSerializeProperties(const XML::Node& SelfRoot);
155  /// @brief Take the data stored in an XML Node and overwrite the proxies of this object with it.
156  /// @param SelfRoot An XML::Node containing the data to populate this class with.
157  virtual void ProtoDeSerializeProxies(const XML::Node& SelfRoot) = 0;
158 
159  /// @brief Gets the most derived serializable name of this WorldObject.
160  /// @note When creating a new WorldObject class verify this method has a valid return for it in order for serialization to work properly.
161  /// @return Returns the name of the XML tag from the most derived class of "this".
162  virtual String GetDerivedSerializableName() const;
163  /// @brief Get the name of the the XML tag the proxy class will leave behind as its instances are serialized.
164  /// @return A string containing the name of this class.
165  static String GetSerializableName();
166 
167  ///////////////////////////////////////////////////////////////////////////////
168  // Internal Methods
169 
170  /// @internal
171  /// @brief Utility function for altering or checking the World Object every frame.
172  virtual void _Update() = 0;
173  /// @internal
174  /// @brief Notifies that a proxy belonging to this WorldObject is being forcibly destroyed, and it needs to update.
175  /// @note Forced destruction should only happen if a subsystem is being shutdown at a time when the WorldObject is still operational.
176  /// @param ToBeDestroyed The WorldProxy that is marked for destruction.
177  virtual void _NotifyProxyDestroyed(WorldProxy* ToBeDestroyed) = 0;
178  /// @internal
179  /// @brief Notifies this World Object of a collision that is occuring with it.
180  /// @param Col A pointer to the collision pertaining to this World Object.
181  /// @param State The state of the collision pertaining to this World Object.
182  virtual void _NotifyCollisionState(Physics::Collision* Col, const Physics::CollisionState State);
183  };//WorldObject
184 }//Mezzanine
185 
186 #endif