FIFE
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
animation.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2013 by the FIFE team *
3  * http://www.fifengine.net *
4  * This file is part of FIFE. *
5  * *
6  * FIFE is free software; you can redistribute it and/or *
7  * modify it under the terms of the GNU Lesser General Public *
8  * License as published by the Free Software Foundation; either *
9  * version 2.1 of the License, or (at your option) any later version. *
10  * *
11  * This library 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 GNU *
14  * Lesser General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU Lesser General Public *
17  * License along with this library; if not, write to the *
18  * Free Software Foundation, Inc., *
19  * 51 Franklin Street, 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 #include "util/base/fifeclass.h"
33 #include "util/base/sharedptr.h"
34 
35 #include "image.h"
36 
37 // 3rd party library includes
38 
39 // FIFE includes
40 // These includes are split up in two parts, separated by one empty line
41 // First block: files included from the FIFE root src directory
42 // Second block: files included from the same folder
43 
44 namespace FIFE {
45 
46  class Image;
47 
56  class Animation : public FifeClass {
57  public:
60  explicit Animation();
61 
64  ~Animation();
65 
72  void addFrame(ImagePtr image, uint32_t duration);
73 
80  int32_t getFrameIndex(uint32_t timestamp);
81 
84  ImagePtr getFrame(int32_t index);
85 
89 
93  int32_t getFrameDuration(int32_t index) const;
94 
97  uint32_t getFrameCount() const;
98 
105  void setActionFrame(int32_t num) { m_action_frame = num; }
106 
110  int32_t getActionFrame() const { return m_action_frame; }
111 
119  void setDirection(uint32_t direction);
120 
125  uint32_t getDirection() const { return m_direction; }
126 
130 
131  private:
134  struct FrameInfo {
138  };
139 
142  bool isValidIndex(int32_t index) const;
143 
144  // Map of timestamp + associated frame
145  std::map<uint32_t, FrameInfo> m_framemap;
146  // vector of frames for fast indexed access
147  std::vector<FrameInfo> m_frames;
148  // Action frame of the Animation.
149  int32_t m_action_frame;
150  // time when animation ends (zero based)
152  // Direction for this animation
154 
155  };
156 
158 
159 }
160 
161 #endif
162 /* vim: set noexpandtab: set shiftwidth=2: set tabstop=2: */
Animation()
Constructor.
Definition: animation.cpp:41
int32_t getFrameDuration(int32_t index) const
Gets the frame duration for given (indexed) frame.
Definition: animation.cpp:112
void setDirection(uint32_t direction)
Animation direction tells how this animation is associated with movement when played starting from fr...
Definition: animation.cpp:124
uint32_t getDuration() const
Gets the total duration for the whole animation.
Definition: animation.h:129
int32_t m_animation_endtime
Definition: animation.h:151
Base class for all fife classes Used e.g.
Definition: fifeclass.h:42
Animation.
Definition: animation.h:56
void setActionFrame(int32_t num)
Sets the action frame.
Definition: animation.h:105
Contains information about one animation frame (duration + frame index + frame pointer) ...
Definition: animation.h:134
uint32_t m_direction
Definition: animation.h:153
int32_t getActionFrame() const
Gets the action frame.
Definition: animation.h:110
ImagePtr getFrameByTimestamp(uint32_t timestamp)
Gets the frame image that matches the given timestamp.
Definition: animation.cpp:99
std::vector< FrameInfo > m_frames
Definition: animation.h:147
uint32_t getFrameCount() const
Get the number of frames.
Definition: animation.cpp:120
int32_t getFrameIndex(uint32_t timestamp)
Get the frame index that matches given timestamp.
Definition: animation.cpp:72
std::map< uint32_t, FrameInfo > m_framemap
Definition: animation.h:145
ImagePtr getFrame(int32_t index)
Gets the frame iamge that matches the given index.
Definition: animation.cpp:87
void addFrame(ImagePtr image, uint32_t duration)
Adds new frame into animation Frames must be added starting from first frame.
Definition: animation.cpp:52
SharedPtr< Animation > AnimationPtr
Definition: animation.h:157
~Animation()
Destructor.
Definition: animation.cpp:47
int32_t m_action_frame
Definition: animation.h:149
bool isValidIndex(int32_t index) const
Checks for animation frame index overflows.
Definition: animation.cpp:82
unsigned int uint32_t
Definition: core.h:40
uint32_t getDirection() const
Gets the animation direction.
Definition: animation.h:125