Mercurial > fife-parpg
comparison engine/core/video/animation.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_VIDEO_ANIMATION_H | |
23 #define FIFE_VIDEO_ANIMATION_H | |
24 | |
25 // Standard C++ library includes | |
26 #include <cassert> | |
27 #include <map> | |
28 #include <vector> | |
29 | |
30 // Platform specific includes | |
31 #include "util/base/fife_stdint.h" | |
32 | |
33 // 3rd party library includes | |
34 | |
35 // FIFE includes | |
36 // These includes are split up in two parts, separated by one empty line | |
37 // First block: files included from the FIFE root src directory | |
38 // Second block: files included from the same folder | |
39 #include "util/base/resourceclass.h" | |
40 | |
41 namespace FIFE { | |
42 | |
43 class Image; | |
44 | |
45 /** Animation. | |
46 * | |
47 * A container of Images describing an animation. Animation itself does | |
48 * not take care of animating the images. Instead it contains images | |
49 * having associated timestamps. It is the responsibility of the | |
50 * animation user to query frames based on current timestamp and show | |
51 * returned images on screen. | |
52 */ | |
53 class Animation : public ResourceClass { | |
54 public: | |
55 /** Constructor. | |
56 */ | |
57 explicit Animation(); | |
58 | |
59 /** Destructor. Decreases the reference count of all referred images. | |
60 */ | |
61 ~Animation(); | |
62 | |
63 //TODO: fill in these stubs! Note, m_location is not properly initialized. | |
64 virtual const ResourceLocation& getResourceLocation() { return m_location; } | |
65 | |
66 virtual void setResourceLocation(const ResourceLocation& location) { } | |
67 virtual void setResourceFile(const std::string& filename) { } | |
68 | |
69 /** Adds new frame into animation | |
70 * Frames must be added starting from first frame. Increases the reference | |
71 * count of the given image. | |
72 * @param image Pointer to Image. Does not transfer the ownership | |
73 * @param duration Duration for given frame in the animation | |
74 */ | |
75 void addFrame(Image* image, unsigned int duration); | |
76 | |
77 /** Get the frame index that matches given timestamp. In case there is no exact match, | |
78 * correct frame is calculated. E.g. if there are frames for timestamps 50 and 100 | |
79 * and frame for 75 is asked, frame associated with value 50 is given back. | |
80 * In case the timestamp is past the sequence, negative value is returned | |
81 * @see addFrame | |
82 */ | |
83 int getFrameIndex(unsigned int timestamp); | |
84 | |
85 /** Gets the frame that matches the given index. If no matches found, returns NULL | |
86 */ | |
87 Image* getFrame(int index); | |
88 | |
89 /** Gets the frame that matches the given timestamp. | |
90 */ | |
91 Image* getFrameByTimestamp(unsigned int timestamp); | |
92 | |
93 /** Gets the frame duration for given (indexed) frame. Returns negative value in case | |
94 * of incorrect index | |
95 */ | |
96 int getFrameDuration(int index); | |
97 | |
98 /** Get the number of frames | |
99 */ | |
100 unsigned int getNumFrames() const; | |
101 | |
102 /** Sets the action frame. Action frame is the frame when the related | |
103 * action actually happens. E.g. in case of punch animation, action frame is | |
104 * the frame when punch hits the target. In case there is no associated | |
105 * action frame, value is negative | |
106 * @param num index of the action frame. | |
107 */ | |
108 void setActionFrame(int num) { m_action_frame = num; } | |
109 | |
110 /** Gets the action frame. | |
111 * @see setActionFrame | |
112 */ | |
113 int getActionFrame() { return m_action_frame; } | |
114 | |
115 /** Animation direction tells how this animation is associated | |
116 * with movement when played starting from frame 0 | |
117 * E.g. in walking animation there should be direction assigned so | |
118 * that engine can choose the correct animation when characters are | |
119 * moved around the map area | |
120 * @param direction direction to set | |
121 */ | |
122 void setDirection(unsigned int direction); | |
123 | |
124 /** Gets the animation direction | |
125 * @see setDirection | |
126 * @return direction for this animation | |
127 */ | |
128 unsigned int getDirection() { return m_direction; } | |
129 | |
130 /** Gets the total duration for the whole animation | |
131 */ | |
132 int getDuration() { return m_animation_endtime; } | |
133 | |
134 private: | |
135 /** Contains information about one animation frame (duration + frame index + frame pointer) | |
136 */ | |
137 struct FrameInfo { | |
138 unsigned int index; | |
139 unsigned int duration; | |
140 Image* img; | |
141 }; | |
142 | |
143 ResourceLocation m_location; | |
144 | |
145 /** Checks for animation frame index overflows | |
146 */ | |
147 bool isValidIndex(int index); | |
148 | |
149 // Map of timestamp + associated frame | |
150 std::map<unsigned int, FrameInfo> m_framemap; | |
151 // vector of frames for fast indexed access | |
152 std::vector<FrameInfo> m_frames; | |
153 // Action frame of the Animation. | |
154 int m_action_frame; | |
155 // time when animation ends (zero based) | |
156 int m_animation_endtime; | |
157 // Direction for this animation | |
158 unsigned int m_direction; | |
159 | |
160 }; | |
161 } | |
162 | |
163 #endif | |
164 /* vim: set noexpandtab: set shiftwidth=2: set tabstop=2: */ |