Mercurial > fife-parpg
comparison engine/core/view/visual.h @ 0:4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
author | mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Sun, 29 Jun 2008 18:44:17 +0000 |
parents | |
children | 90005975cdbb |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4a0efb7baf70 |
---|---|
1 /*************************************************************************** | |
2 * Copyright (C) 2005-2008 by the FIFE team * | |
3 * http://www.fifengine.de * | |
4 * This file is part of FIFE. * | |
5 * * | |
6 * FIFE is free software; you can redistribute it and/or modify * | |
7 * it under the terms of the GNU General Public License as published by * | |
8 * the Free Software Foundation; either version 2 of the License, or * | |
9 * (at your option) any later version. * | |
10 * * | |
11 * This program is distributed in the hope that it will be useful, * | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of * | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | |
14 * GNU General Public License for more details. * | |
15 * * | |
16 * You should have received a copy of the GNU General Public License * | |
17 * along with this program; if not, write to the * | |
18 * Free Software Foundation, Inc., * | |
19 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * | |
20 ***************************************************************************/ | |
21 | |
22 #ifndef FIFE_VIEW_VISUAL_H | |
23 #define FIFE_VIEW_VISUAL_H | |
24 | |
25 // Standard C++ library includes | |
26 | |
27 // 3rd party library includes | |
28 | |
29 // FIFE includes | |
30 // These includes are split up in two parts, separated by one empty line | |
31 // First block: files included from the FIFE root src directory | |
32 // Second block: files included from the same folder | |
33 #include "model/metamodel/abstractvisual.h" | |
34 #include "view/camera.h" | |
35 | |
36 namespace FIFE { | |
37 class Object; | |
38 class Instance; | |
39 class Action; | |
40 class Image; | |
41 | |
42 /** Base class for all 2 dimensional visual classes | |
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 | |
45 * have e.g. 3d, 2d and character based visualizations to the same data | |
46 */ | |
47 class Visual2DGfx: public AbstractVisual { | |
48 public: | |
49 /** Destructor | |
50 */ | |
51 virtual ~Visual2DGfx(); | |
52 | |
53 /** Sets transparency value for object to be visualized | |
54 * @param stackposition new stack position | |
55 */ | |
56 void setTransparency(uint8_t transparency) { m_transparency = transparency; } | |
57 | |
58 /** Gets current transparency value (0-255) | |
59 * @return current transparency value | |
60 */ | |
61 unsigned int getTransparency() { return m_transparency; } | |
62 | |
63 /** Sets visibility value for object to be visualized | |
64 * @param visible is object visible or not | |
65 */ | |
66 void setVisible(bool visible) { m_visible = visible; } | |
67 | |
68 /** Is instance visible or not | |
69 * @return is instance visible or not | |
70 */ | |
71 unsigned int isVisible() { return m_visible; } | |
72 | |
73 protected: | |
74 /** Constructor | |
75 */ | |
76 Visual2DGfx(); | |
77 | |
78 uint8_t m_transparency; | |
79 uint8_t m_visible; | |
80 | |
81 }; | |
82 | |
83 /** Object visual contains data that is needed for visualizing objects | |
84 */ | |
85 class ObjectVisual: public Visual2DGfx { | |
86 public: | |
87 /** Constructs and assigns it to the passed item | |
88 */ | |
89 static ObjectVisual* create(Object* object); | |
90 | |
91 /** Destructor | |
92 */ | |
93 virtual ~ObjectVisual(); | |
94 | |
95 /** Adds new static image with given angle (degrees) | |
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 | |
98 * case view / layer is rotated | |
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 | |
101 * (normal math notation) | |
102 @param image_index index of image to use for given degress | |
103 */ | |
104 void addStaticImage(unsigned int angle, int image_index); | |
105 | |
106 /** Returns closest matching static image for given angle | |
107 * @return id for static image | |
108 */ | |
109 int getStaticImageIndexByAngle(int angle); | |
110 | |
111 /** Returns closest matching image angle for given angle | |
112 * @return closest matching angle | |
113 */ | |
114 int getClosestMatchingAngle(int angle); | |
115 | |
116 /** Returns list of available static image angles for this object | |
117 */ | |
118 void getStaticImageAngles(std::vector<int>& angles); | |
119 | |
120 private: | |
121 /** Constructor | |
122 */ | |
123 ObjectVisual(); | |
124 | |
125 type_angle2id m_angle2img; | |
126 }; | |
127 | |
128 /** InstanceVisualCacheItem caches values calculated by view | |
129 * values are camera specific | |
130 * Class should be used by engine itself only | |
131 */ | |
132 class InstanceVisualCacheItem { | |
133 public: | |
134 InstanceVisualCacheItem(); | |
135 | |
136 /** Returns closest matching static image for given angle | |
137 * @return id for static image | |
138 * @see ObjectVisual::getStaticImageIndexByAngle | |
139 */ | |
140 int getStaticImageIndexByAngle(unsigned int angle, Instance* instance); | |
141 | |
142 // point where instance was drawn during the previous render | |
143 ScreenPoint screenpoint; | |
144 | |
145 // dimensions of this visual during the previous render | |
146 Rect dimensions; | |
147 | |
148 // image used during previous render | |
149 Image* image; | |
150 | |
151 // current facing angle | |
152 int facing_angle; | |
153 private: | |
154 int m_cached_static_img_id; | |
155 int m_cached_static_img_angle; | |
156 }; | |
157 | |
158 /** Instance visual contains data that is needed to visualize the instance on screen | |
159 */ | |
160 class InstanceVisual: public Visual2DGfx { | |
161 public: | |
162 /** Constructs and assigns it to the passed item | |
163 */ | |
164 static InstanceVisual* create(Instance* instance); | |
165 | |
166 /** Destructor | |
167 */ | |
168 virtual ~InstanceVisual(); | |
169 | |
170 /** Sets stack position of the instance | |
171 * Stack position is used to define the order in which instances residing | |
172 * in the same location are drawn | |
173 * @param stackposition new stack position | |
174 */ | |
175 void setStackPosition(int stackposition) { m_stackposition = stackposition; } | |
176 | |
177 /** Gets current stack position of instance | |
178 * @return current stack position | |
179 */ | |
180 int getStackPosition() { return m_stackposition; } | |
181 | |
182 /** Get camera specific cache item for the visual | |
183 * @return cache item | |
184 */ | |
185 inline InstanceVisualCacheItem& getCacheItem(Camera* cam) { return m_cache[cam]; } | |
186 | |
187 private: | |
188 /** Constructor | |
189 */ | |
190 InstanceVisual(); | |
191 int m_stackposition; | |
192 // there is separate cache item for each camera | |
193 std::map<Camera*, InstanceVisualCacheItem> m_cache; | |
194 }; | |
195 | |
196 /** Action visual contains data that is needed to visualize different actions on screen | |
197 */ | |
198 class ActionVisual: public Visual2DGfx { | |
199 public: | |
200 /** Constructs and assigns it to the passed item | |
201 */ | |
202 static ActionVisual* create(Action* action); | |
203 | |
204 /** Destructor | |
205 */ | |
206 virtual ~ActionVisual(); | |
207 | |
208 /** Adds new animation with given angle (degrees) | |
209 */ | |
210 void addAnimation(unsigned int angle, int animation_index); | |
211 | |
212 /** Gets index to animation closest to given angle | |
213 * @return animation index, -1 if no animations available | |
214 */ | |
215 int getAnimationIndexByAngle(int angle); | |
216 | |
217 private: | |
218 /** Constructor | |
219 */ | |
220 ActionVisual(); | |
221 | |
222 // animations associated with this action (handles to pool) | |
223 // mapping = direction -> animation | |
224 type_angle2id m_animations; | |
225 }; | |
226 | |
227 } | |
228 #endif |