FIFE  6e1afdbeda11afe9ac53e6023a4be96ef88f1dc6
animation.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2017 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/resource/resource.h"
33 
34 #include "image.h"
35 
36 // 3rd party library includes
37 
38 // FIFE includes
39 // These includes are split up in two parts, separated by one empty line
40 // First block: files included from the FIFE root src directory
41 // Second block: files included from the same folder
42 
43 namespace FIFE {
44 
53  class Animation : public IResource {
54  public:
57  Animation(IResourceLoader* loader = 0);
58  Animation(const std::string& name, IResourceLoader* loader = 0);
59 
62  ~Animation();
63 
64  virtual size_t getSize();
65 
66  virtual void load();
67  virtual void free();
68 
69  void invalidate();
70 
77  void addFrame(ImagePtr image, uint32_t duration);
78 
85  int32_t getFrameIndex(uint32_t timestamp);
86 
89  ImagePtr getFrame(int32_t index);
90 
94 
97  std::vector<ImagePtr> getFrames();
98 
102  int32_t getFrameDuration(int32_t index) const;
103 
106  uint32_t getFrameCount() const;
107 
114  void setActionFrame(int32_t num) { m_action_frame = num; }
115 
119  int32_t getActionFrame() const { return m_action_frame; }
120 
128  void setDirection(uint32_t direction);
129 
134  uint32_t getDirection() const { return m_direction; }
135 
139 
140  private:
143  struct FrameInfo {
147  };
148 
149  std::string createUniqueAnimationName();
150 
153  bool isValidIndex(int32_t index) const;
154 
155  // Map of timestamp + associated frame
156  std::map<uint32_t, FrameInfo> m_framemap;
157  // vector of frames for fast indexed access
158  std::vector<FrameInfo> m_frames;
159  // Action frame of the Animation.
160  int32_t m_action_frame;
161  // time when animation ends (zero based)
163  // Direction for this animation
165 
166  };
167 
169 
170 }
171 
172 #endif
int32_t getFrameDuration(int32_t index) const
Gets the frame duration for given (indexed) frame.
Definition: animation.cpp:171
std::vector< ImagePtr > getFrames()
Gets all frame images.
Definition: animation.cpp:163
void setDirection(uint32_t direction)
Animation direction tells how this animation is associated with movement when played starting from fr...
Definition: animation.cpp:182
uint32_t getDuration() const
Gets the total duration for the whole animation.
Definition: animation.h:138
int32_t m_animation_endtime
Definition: animation.h:162
Animation.
Definition: animation.h:53
Animation(IResourceLoader *loader=0)
Constructor.
Definition: animation.cpp:40
void setActionFrame(int32_t num)
Sets the action frame.
Definition: animation.h:114
Contains information about one animation frame (duration + frame index + frame pointer) ...
Definition: animation.h:143
uint32_t m_direction
Definition: animation.h:164
int32_t getActionFrame() const
Gets the action frame.
Definition: animation.h:119
ImagePtr getFrameByTimestamp(uint32_t timestamp)
Gets the frame image that matches the given timestamp.
Definition: animation.cpp:150
std::vector< FrameInfo > m_frames
Definition: animation.h:158
virtual void load()
Definition: animation.cpp:63
std::string createUniqueAnimationName()
Definition: animation.cpp:90
void invalidate()
Definition: animation.cpp:81
uint32_t getFrameCount() const
Get the number of frames.
Definition: animation.cpp:178
int32_t getFrameIndex(uint32_t timestamp)
Get the frame index that matches given timestamp.
Definition: animation.cpp:124
virtual void free()
Definition: animation.cpp:73
std::map< uint32_t, FrameInfo > m_framemap
Definition: animation.h:156
ImagePtr getFrame(int32_t index)
Gets the frame iamge that matches the given index.
Definition: animation.cpp:139
void addFrame(ImagePtr image, uint32_t duration)
Adds new frame into animation Frames must be added starting from first frame.
Definition: animation.cpp:104
SharedPtr< Animation > AnimationPtr
Definition: animation.h:168
~Animation()
Destructor.
Definition: animation.cpp:54
int32_t m_action_frame
Definition: animation.h:160
bool isValidIndex(int32_t index) const
Checks for animation frame index overflows.
Definition: animation.cpp:134
unsigned int uint32_t
Definition: core.h:40
virtual size_t getSize()
Definition: animation.cpp:59
uint32_t getDirection() const
Gets the animation direction.
Definition: animation.h:134