comparison engine/core/view/visual.h @ 356:ab41334e8a57

Added or1andov's code with a few adjustments to fix instance transparencies fixed[t:378] Added layer transparency support Added layer transparency to map editor
author prock@33b003aa-7bff-0310-803a-e67f0ece8222
date Thu, 24 Sep 2009 18:24:47 +0000
parents 90005975cdbb
children 8fa2f3aa0cbd
comparison
equal deleted inserted replaced
355:8b125ec749d7 356:ab41334e8a57
36 namespace FIFE { 36 namespace FIFE {
37 class Object; 37 class Object;
38 class Instance; 38 class Instance;
39 class Action; 39 class Action;
40 class Image; 40 class Image;
41 41
42 /** Base class for all 2 dimensional visual classes 42 /** Base class for all 2 dimensional visual classes
43 * Visual classes are extensions to visualize the stuff in model (e.g. instances) 43 * Visual classes are extensions to visualize the stuff in model (e.g. instances)
44 * The reason why its separated is to keep model view-agnostic, so that we could 44 * The reason why its separated is to keep model view-agnostic, so that we could
45 * have e.g. 3d, 2d and character based visualizations to the same data 45 * have e.g. 3d, 2d and character based visualizations to the same data
46 */ 46 */
47 class Visual2DGfx: public AbstractVisual { 47 class Visual2DGfx: public AbstractVisual {
48 public: 48 public:
49 /** Destructor 49 /** Destructor
50 */ 50 */
51 virtual ~Visual2DGfx(); 51 virtual ~Visual2DGfx();
52 52
53 /** Sets transparency value for object to be visualized 53 /** Sets transparency value for object to be visualized
54 * @param stackposition new stack position 54 * @param stackposition new stack position
55 */ 55 */
56 void setTransparency(uint8_t transparency) { m_transparency = transparency; } 56 void setTransparency(uint8_t transparency) { m_transparency = transparency; }
57 57
58 /** Gets current transparency value (0-255) 58 /** Gets current transparency value (0-255)
59 * @return current transparency value 59 * @return current transparency value
60 */ 60 */
61 unsigned int getTransparency() { return m_transparency; } 61 unsigned int getTransparency() { return m_transparency; }
62 62
63 /** Sets visibility value for object to be visualized 63 /** Sets visibility value for object to be visualized
64 * @param visible is object visible or not 64 * @param visible is object visible or not
65 */ 65 */
66 void setVisible(bool visible) { m_visible = visible; } 66 void setVisible(bool visible) { m_visible = visible; }
67 67
68 /** Is instance visible or not 68 /** Is instance visible or not
69 * @return is instance visible or not 69 * @return is instance visible or not
70 */ 70 */
71 unsigned int isVisible() { return m_visible; } 71 unsigned int isVisible() { return m_visible; }
72 72
73 protected: 73 protected:
74 /** Constructor 74 /** Constructor
75 */ 75 */
76 Visual2DGfx(); 76 Visual2DGfx();
77 77
78 uint8_t m_transparency; 78 uint8_t m_transparency;
79 uint8_t m_visible; 79 uint8_t m_visible;
80 80
81 }; 81 };
82 82
83 /** Object visual contains data that is needed for visualizing objects 83 /** Object visual contains data that is needed for visualizing objects
84 */ 84 */
85 class ObjectVisual: public Visual2DGfx { 85 class ObjectVisual: public Visual2DGfx {
86 public: 86 public:
87 /** Constructs and assigns it to the passed item 87 /** Constructs and assigns it to the passed item
88 */ 88 */
89 static ObjectVisual* create(Object* object); 89 static ObjectVisual* create(Object* object);
90 90
91 /** Destructor 91 /** Destructor
92 */ 92 */
93 virtual ~ObjectVisual(); 93 virtual ~ObjectVisual();
94 94
95 /** Adds new static image with given angle (degrees) 95 /** Adds new static image with given angle (degrees)
96 * Static images are used in case there are no actions active in the instance 96 * Static images are used in case there are no actions active in the instance
97 * There can be several static images for different angles, that are used in 97 * There can be several static images for different angles, that are used in
98 * case view / layer is rotated 98 * case view / layer is rotated
99 * In case there are no exact matches for current view angles, closest one is used 99 * In case there are no exact matches for current view angles, closest one is used
100 * @param angle angle for image. 0 degrees starts from right and turns counter-clockwise 100 * @param angle angle for image. 0 degrees starts from right and turns counter-clockwise
101 * (normal math notation) 101 * (normal math notation)
102 @param image_index index of image to use for given degress 102 @param image_index index of image to use for given degress
103 */ 103 */
104 void addStaticImage(unsigned int angle, int image_index); 104 void addStaticImage(unsigned int angle, int image_index);
105 105
106 /** Returns closest matching static image for given angle 106 /** Returns closest matching static image for given angle
107 * @return id for static image 107 * @return id for static image
108 */ 108 */
109 int getStaticImageIndexByAngle(int angle); 109 int getStaticImageIndexByAngle(int angle);
110 110
111 /** Returns closest matching image angle for given angle 111 /** Returns closest matching image angle for given angle
112 * @return closest matching angle 112 * @return closest matching angle
113 */ 113 */
114 int getClosestMatchingAngle(int angle); 114 int getClosestMatchingAngle(int angle);
115 115
116 /** Returns list of available static image angles for this object 116 /** Returns list of available static image angles for this object
117 */ 117 */
118 void getStaticImageAngles(std::vector<int>& angles); 118 void getStaticImageAngles(std::vector<int>& angles);
119 119
120 private: 120 private:
121 /** Constructor 121 /** Constructor
122 */ 122 */
123 ObjectVisual(); 123 ObjectVisual();
124 124
125 type_angle2id m_angle2img; 125 type_angle2id m_angle2img;
126 }; 126 };
127 127
128 /** InstanceVisualCacheItem caches values calculated by view 128 /** InstanceVisualCacheItem caches values calculated by view
129 * values are camera specific 129 * values are camera specific
130 * Class should be used by engine itself only 130 * Class should be used by engine itself only
131 */ 131 */
132 class InstanceVisualCacheItem { 132 class InstanceVisualCacheItem {
133 public: 133 public:
134 InstanceVisualCacheItem(); 134 InstanceVisualCacheItem();
135 135
136 /** Returns closest matching static image for given angle 136 /** Returns closest matching static image for given angle
137 * @return id for static image 137 * @return id for static image
138 * @see ObjectVisual::getStaticImageIndexByAngle 138 * @see ObjectVisual::getStaticImageIndexByAngle
139 */ 139 */
140 int getStaticImageIndexByAngle(unsigned int angle, Instance* instance); 140 int getStaticImageIndexByAngle(unsigned int angle, Instance* instance);
141 141
142 // point where instance was drawn during the previous render 142 // point where instance was drawn during the previous render
143 ScreenPoint screenpoint; 143 ScreenPoint screenpoint;
144 144
145 // dimensions of this visual during the previous render 145 // dimensions of this visual during the previous render
146 Rect dimensions; 146 Rect dimensions;
147 147
148 // image used during previous render 148 // image used during previous render
149 Image* image; 149 Image* image;
150 150
151 // current facing angle 151 // current facing angle
152 int facing_angle; 152 int facing_angle;
153 private: 153 private:
154 int m_cached_static_img_id; 154 int m_cached_static_img_id;
155 int m_cached_static_img_angle; 155 int m_cached_static_img_angle;
156 }; 156 };
160 class InstanceVisual: public Visual2DGfx { 160 class InstanceVisual: public Visual2DGfx {
161 public: 161 public:
162 /** Constructs and assigns it to the passed item 162 /** Constructs and assigns it to the passed item
163 */ 163 */
164 static InstanceVisual* create(Instance* instance); 164 static InstanceVisual* create(Instance* instance);
165 165
166 /** Destructor 166 /** Destructor
167 */ 167 */
168 virtual ~InstanceVisual(); 168 virtual ~InstanceVisual();
169 169
170 /** Sets stack position of the instance 170 /** Sets stack position of the instance
171 * Stack position is used to define the order in which instances residing 171 * Stack position is used to define the order in which instances residing
172 * in the same location are drawn 172 * in the same location are drawn
173 * @param stackposition new stack position 173 * @param stackposition new stack position
174 */ 174 */
175 void setStackPosition(int stackposition) { m_stackposition = stackposition; } 175 void setStackPosition(int stackposition) { m_stackposition = stackposition; }
176 176
177 /** Gets current stack position of instance 177 /** Gets current stack position of instance
178 * @return current stack position 178 * @return current stack position
179 */ 179 */
180 int getStackPosition() { return m_stackposition; } 180 int getStackPosition() { return m_stackposition; }
181 181
182 /** Get camera specific cache item for the visual 182 /** Get camera specific cache item for the visual
183 * @return cache item 183 * @return cache item
184 */ 184 */
185 inline InstanceVisualCacheItem& getCacheItem(Camera* cam) { return m_cache[cam]; } 185 inline InstanceVisualCacheItem& getCacheItem(Camera* cam) { return m_cache[cam]; }
186 186
187 private: 187 private:
188 /** Constructor 188 /** Constructor
189 */ 189 */
190 InstanceVisual(); 190 InstanceVisual();
191 int m_stackposition; 191 int m_stackposition;
192 // there is separate cache item for each camera 192 // there is separate cache item for each camera
193 std::map<Camera*, InstanceVisualCacheItem> m_cache; 193 std::map<Camera*, InstanceVisualCacheItem> m_cache;
194 }; 194 };
195 195
196 /** Action visual contains data that is needed to visualize different actions on screen 196 /** Action visual contains data that is needed to visualize different actions on screen
197 */ 197 */
198 class ActionVisual: public Visual2DGfx { 198 class ActionVisual: public Visual2DGfx {
199 public: 199 public:
200 /** Constructs and assigns it to the passed item 200 /** Constructs and assigns it to the passed item
201 */ 201 */
202 static ActionVisual* create(Action* action); 202 static ActionVisual* create(Action* action);
203 203
204 /** Destructor 204 /** Destructor
205 */ 205 */
206 virtual ~ActionVisual(); 206 virtual ~ActionVisual();
207 207
208 /** Adds new animation with given angle (degrees) 208 /** Adds new animation with given angle (degrees)
209 */ 209 */
210 void addAnimation(unsigned int angle, int animation_index); 210 void addAnimation(unsigned int angle, int animation_index);
211 211
212 /** Gets index to animation closest to given angle 212 /** Gets index to animation closest to given angle
213 * @return animation index, -1 if no animations available 213 * @return animation index, -1 if no animations available
214 */ 214 */
215 int getAnimationIndexByAngle(int angle); 215 int getAnimationIndexByAngle(int angle);
216 216
217 private: 217 private:
218 /** Constructor 218 /** Constructor
219 */ 219 */
220 ActionVisual(); 220 ActionVisual();
221 221
222 // animations associated with this action (handles to pool) 222 // animations associated with this action (handles to pool)
223 // mapping = direction -> animation 223 // mapping = direction -> animation
224 type_angle2id m_animations; 224 type_angle2id m_animations;
225 }; 225 };
226 226
227 } 227 }
228 #endif 228 #endif