NLS Engine  v0.1
The Next Logical Step in game engine design.
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Defines
Entity.h
Go to the documentation of this file.
00001 
00013 #pragma once
00014 
00015 // Standard Includes
00016 #include <memory>
00017 #include <set>
00018 
00019 // Library Includes
00020 #include <d3dx9math.h>
00021 #include <boost/any.hpp>
00022 
00023 // Local Includes
00024 #include "QuatMath.h"
00025 #include "PropertyMap.h"
00026 #include "Entity_fwd.h"
00027 
00028 // Forward Declarations
00029 class ComponentInterface;
00030 
00031 // Typedefs
00032 typedef std::shared_ptr<std::string> MutableStringSPTR;
00033 
00034 
00035 class Entity {
00036   friend class ComponentInterface;
00037   friend class EntityList;
00038   
00039 public:
00040   static EntitySPTR Factory(const std::string& = "", const int& = -1);
00041   static void FactoryAtAddress(void*);
00042   static void FactoryAtAddress(void*, const std::string&);
00043   static void FactoryAtAddress(void*, const std::string&, const int&);
00044   ~Entity();
00045   
00046   void SetParent(EntitySPTR newParent);
00047   EntitySPTR GetParent(void) const;
00048   
00049   int GetId() const;
00050 
00054   D3DXVECTOR3 GetWorldPosition(void) const;
00055   
00056   void SetWorldPosition(float, float, float);
00057 
00061   D3DXQUATERNION GetWorldRotation(void) const;
00062   
00066   float GetWorldScale(void) const;
00067   
00071   void SetRotation(D3DXQUATERNION);
00072   
00076   void SetRotation(float, float, float);
00077   
00081   void ChangePosition(D3DXVECTOR3);
00082   
00086   void ChangeRotation(D3DXQUATERNION);
00087   
00091   void ChangeRotation(float, float, float);
00092   
00096   void ChangeScale(float);
00097   
00098   void SetName(const std::string& name);
00099   
00100   std::string GetName();
00101   
00102   MutableStringSPTR GetNameSPTR();
00103   
00104 protected: // Friend access
00105   void RegisterComponent(ComponentInterface*);
00106   void UnregisterComponent(ComponentInterface*);
00107   
00108   bool NotifyEntityRemoval(EntitySPTR);
00109   
00110 private:
00111   Entity(const std::string& = "", const int& = -1);
00112   
00113   void ClearComponents();
00114   
00115 public:
00116   D3DXVECTOR3 location; 
00117   D3DXQUATERNION rotation; 
00118   float scale; 
00119   int id;
00120   int priority;
00121   PropertyMap properties;
00122 private:
00123   MutableStringSPTR name;
00124   
00125   mutable Threading::ReadWriteMutex parentMutex;
00126   EntitySPTR parent; 
00127   
00128   mutable Threading::ReadWriteMutex componentsMutex;
00129   std::set<ComponentInterface*> components; 
00130 };