00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef _BASEVISUAL_
00019 #define _BASEVISUAL_
00020
00021 #include <string>
00022
00023 #include "util/AbstractStreamedObject.h"
00024 #include "util/Attribute.h"
00025 #include "util/Vector2.h"
00026
00027 #define DEFAULT_VISUAL_CONSTRUCTOR(class_name, initialization_list) \
00028 class_name##(const std::string & type) \
00029 :BaseVisual(type) initialization_list \
00030 {\
00031 }
00032
00033 class AbstractRenderer;
00034 class GameEntity;
00035
00036 class BaseVisual : public AbstractStreamedObject
00037 {
00038 private:
00039 std::string m_type;
00040 GameEntity* m_pOwner;
00041 Vector2 m_position;
00042 float m_fRotation;
00043 float m_fScale;
00044 bool m_bRelativeXForm;
00045 public:
00046 BaseVisual(const std::string& type)
00047 :m_type(type), m_pOwner(0), m_fRotation(0.0f), m_fScale(1.0f), m_bRelativeXForm(true)
00048 {
00049 }
00050
00051 BaseVisual(const std::string & type, GameEntity* pOwner, const Vector2 & position, const float fRotation, const float fScale, bool bRelativeXForm)
00052 :m_type(type), m_pOwner(pOwner), m_position(position), m_fRotation(fRotation), m_bRelativeXForm(bRelativeXForm)
00053 {
00054 }
00055
00056 virtual ~BaseVisual() { }
00057
00058 void SetPosition(const Vector2 & position) { m_position = position; }
00059 const Vector2 & GetPosition() const { return m_position; }
00060
00061 void SetRotation(const float fRotation) { m_fRotation = fRotation; }
00062 float GetRotation() const { return m_fRotation; }
00063
00064 void SetScale(const float fScale) { m_fScale = fScale; }
00065 float GetScale() const { return m_fScale; }
00066
00067 GameEntity * GetOwner() const { return m_pOwner; }
00068 void SetOwner(GameEntity * pOwner) { m_pOwner = pOwner; }
00069
00070 bool IsRelativeXForm() const { return m_bRelativeXForm; }
00071 void SetRelativeXForm(bool bRelative) { m_bRelativeXForm = bRelative; }
00072
00073 const std::string & GetType() const { return m_type; }
00074
00075 Vector2 GetAbsolutePosition() const;
00076 float GetAbsoluteRotation() const;
00077
00078 virtual void RenderVisual(AbstractRenderer * pRenderer, const int nDelta) = 0;
00079
00080 virtual bool FromAttribute(const Attribute * pRoot);
00081 virtual void ToStream(std::ostream& stream) const;
00082 virtual void FromStream(std::istream& stream);
00083 };
00084
00085 #endif