00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #if !defined(_XRB_ENGINE2_ENTITY_HPP_)
00012 #define _XRB_ENGINE2_ENTITY_HPP_
00013
00014 #include "xrb.hpp"
00015
00016 #include "xrb_engine2_enums.hpp"
00017 #include "xrb_engine2_object.hpp"
00018 #include "xrb_engine2_types.hpp"
00019
00020 namespace Xrb
00021 {
00022
00023 class Serializer;
00024
00025 namespace Engine2
00026 {
00027
00028 class Compound;
00029 class Object;
00030 class ObjectLayer;
00031 class PhysicsHandler;
00032 class QuadTree;
00033 class Sprite;
00034 class World;
00035
00036 class Entity
00037 {
00038 public:
00039
00040 Entity ()
00041 :
00042 m_wrapped_offset(FloatVector2::ms_zero)
00043 {
00044 ResetWorldIndex();
00045 m_owner_object = NULL;
00046 }
00047 virtual ~Entity ()
00048 {
00049 ASSERT1(m_owner_object == NULL);
00050 }
00051
00052
00053
00054
00055
00056
00057 virtual void Write (Serializer &serializer) const = 0;
00058
00059
00060
00061
00062 virtual void HandleObjectLayerContainment (bool component_x, bool component_y) = 0;
00063
00064
00065
00066
00067
00068
00069 inline EntityWorldIndex WorldIndex () const { return m_world_index; }
00070 inline bool IsInWorld () const { return m_world_index != ENTITY_IS_NOT_IN_WORLD; }
00071 inline FloatVector2 const &WrappedOffset () const { return m_wrapped_offset; }
00072 inline FloatVector2 UnwrappedTranslation () const { return Translation() + m_wrapped_offset; }
00073
00074 inline Object *OwnerObject () const { return m_owner_object; }
00075
00076
00077 Sprite *OwnerSprite () const;
00078
00079
00080 Compound *OwnerCompound () const;
00081
00082
00083
00084
00085
00086
00087 inline void SetWorldIndex (EntityWorldIndex world_index) { m_world_index = world_index; }
00088 void SetWrappedOffset (FloatVector2 const &wrapped_offset);
00089
00090
00091
00092
00093
00094
00095 void AccumulateWrappedOffset (FloatVector2 const &wrapped_offset_delta);
00096
00097 void RemoveFromWorld ();
00098
00099
00100 void AddBackIntoWorld ();
00101
00102
00103 inline void ResetWorldIndex () { m_world_index = ENTITY_IS_NOT_IN_WORLD; }
00104
00105 void ReAddToQuadTree (QuadTreeType quad_tree_type);
00106
00107
00108
00109
00110
00111 void ScheduleForDeletion (Float time_delay);
00112 void ScheduleForRemovalFromWorld (Float time_delay);
00113
00114
00115
00116
00117
00118 inline ObjectType GetObjectType () const { ASSERT3(m_owner_object != NULL); return m_owner_object->GetObjectType(); }
00119 inline Float Radius (QuadTreeType quad_tree_type) const { ASSERT3(m_owner_object != NULL); return m_owner_object->Radius(quad_tree_type); }
00120 inline Float RadiusSquared (QuadTreeType quad_tree_type) const { ASSERT3(m_owner_object != NULL); return m_owner_object->RadiusSquared(quad_tree_type); }
00121 inline Float VisibleRadius () const { ASSERT3(m_owner_object != NULL); return m_owner_object->VisibleRadius(); }
00122 inline Float VisibleRadiusSquared () const { ASSERT3(m_owner_object != NULL); return m_owner_object->VisibleRadiusSquared(); }
00123 inline Float PhysicalRadius () const { ASSERT3(m_owner_object != NULL); return m_owner_object->PhysicalRadius(); }
00124 inline Float PhysicalRadiusSquared () const { ASSERT3(m_owner_object != NULL); return m_owner_object->PhysicalRadiusSquared(); }
00125 inline ObjectLayer *GetObjectLayer () const { ASSERT3(m_owner_object != NULL); return m_owner_object->GetObjectLayer(); }
00126 inline bool HasOwnerQuadTree (QuadTreeType quad_tree_type) const { ASSERT3(m_owner_object != NULL); return m_owner_object->HasOwnerQuadTree(quad_tree_type); }
00127 inline QuadTree *OwnerQuadTree (QuadTreeType quad_tree_type) const { ASSERT3(m_owner_object != NULL); return m_owner_object->OwnerQuadTree(quad_tree_type); }
00128
00129 inline FloatVector2 const &Translation () const { ASSERT3(m_owner_object != NULL); return m_owner_object->Translation(); }
00130 inline FloatVector2 const &ScaleFactors () const { ASSERT3(m_owner_object != NULL); return m_owner_object->ScaleFactors(); }
00131 inline Float ScaleFactor () const { ASSERT3(m_owner_object != NULL); return m_owner_object->ScaleFactor(); }
00132 inline Float Angle () const { ASSERT3(m_owner_object != NULL); return m_owner_object->Angle(); }
00133 inline FloatMatrix2 const &Transformation () const { ASSERT3(m_owner_object != NULL); return m_owner_object->Transformation(); }
00134 inline FloatMatrix2 TransformationInverse () const { ASSERT3(m_owner_object != NULL); return m_owner_object->TransformationInverse(); }
00135 inline Float Determinant () const { ASSERT3(m_owner_object != NULL); return m_owner_object->Determinant(); }
00136 inline void SetTranslation (FloatVector2 const &translation) { ASSERT3(m_owner_object != NULL); m_owner_object->SetTranslation(translation); ReAddToQuadTree(QTT_VISIBILITY); ReAddToQuadTree(QTT_PHYSICS_HANDLER); }
00137 inline void SetScaleFactors (FloatVector2 const &scale_factors) { ASSERT3(m_owner_object != NULL); m_owner_object->SetScaleFactors(scale_factors); ReAddToQuadTree(QTT_VISIBILITY); ReAddToQuadTree(QTT_PHYSICS_HANDLER); }
00138 inline void SetScaleFactor (Float scale_factor) { ASSERT3(m_owner_object != NULL); m_owner_object->SetScaleFactor(scale_factor); ReAddToQuadTree(QTT_VISIBILITY); ReAddToQuadTree(QTT_PHYSICS_HANDLER); }
00139 inline void SetAngle (Float const angle) { ASSERT3(m_owner_object != NULL); m_owner_object->SetAngle(angle); }
00140 inline void Translate (FloatVector2 const &translation) { ASSERT3(m_owner_object != NULL); m_owner_object->Translate(translation); ReAddToQuadTree(QTT_VISIBILITY); ReAddToQuadTree(QTT_PHYSICS_HANDLER); }
00141 inline void Scale (FloatVector2 const &scale_factors) { ASSERT3(m_owner_object != NULL); m_owner_object->Scale(scale_factors); ReAddToQuadTree(QTT_VISIBILITY); ReAddToQuadTree(QTT_PHYSICS_HANDLER); }
00142 inline void Scale (Float scale_factor) { ASSERT3(m_owner_object != NULL); m_owner_object->Scale(scale_factor); ReAddToQuadTree(QTT_VISIBILITY); ReAddToQuadTree(QTT_PHYSICS_HANDLER); }
00143 inline void Rotate (Float const angle) { ASSERT3(m_owner_object != NULL); m_owner_object->Rotate(angle); }
00144 inline void ResetTranslation () { ASSERT3(m_owner_object != NULL); m_owner_object->ResetTranslation(); ReAddToQuadTree(QTT_VISIBILITY); ReAddToQuadTree(QTT_PHYSICS_HANDLER); }
00145 inline void ResetScale () { ASSERT3(m_owner_object != NULL); m_owner_object->ResetScale(); ReAddToQuadTree(QTT_VISIBILITY); ReAddToQuadTree(QTT_PHYSICS_HANDLER); }
00146 inline void ResetAngle () { ASSERT3(m_owner_object != NULL); m_owner_object->ResetAngle(); }
00147
00148 protected:
00149
00150
00151
00152
00153
00154
00155 virtual void HandleNewOwnerObject () = 0;
00156
00157 virtual void CloneProperties (Entity const *entity) = 0;
00158
00159 private:
00160
00161 void ReadClassSpecific (Serializer &serializer);
00162 void WriteClassSpecific (Serializer &serializer) const;
00163
00164 void HandleChangedRadius (Float old_radius, Float new_radius);
00165
00166 EntityWorldIndex m_world_index;
00167
00168 FloatVector2 m_wrapped_offset;
00169 Object *m_owner_object;
00170
00171 friend class Object;
00172 };
00173
00174 }
00175
00176 }
00177
00178 #endif // !defined(_XRB_ENGINE2_ENTITY_HPP_)