FIFE  2008.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
animation.h
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 *
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 
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 #include "util/resource/resource_ptr.h"
41 
42 namespace FIFE {
43 
44  class Image;
45 
54  class Animation : public ResourceClass {
55  public:
58  explicit Animation();
59 
62  ~Animation();
63 
70  void addFrame(ResourcePtr image, unsigned int duration);
71 
78  int getFrameIndex(unsigned int timestamp);
79 
82  Image* getFrame(int index);
83 
86  Image* getFrameByTimestamp(unsigned int timestamp);
87 
91  int getFrameDuration(int index) const;
92 
95  unsigned int getNumFrames() const;
96 
103  void setActionFrame(int num) { m_action_frame = num; }
104 
108  int getActionFrame() const { return m_action_frame; }
109 
117  void setDirection(unsigned int direction);
118 
123  unsigned int getDirection() const { return m_direction; }
124 
127  unsigned int getDuration() const { return m_animation_endtime; }
128 
129  private:
132  struct FrameInfo {
133  unsigned int index;
134  unsigned int duration;
135  ResourcePtr image;
136  };
137 
140  bool isValidIndex(int index) const;
141 
142  // Map of timestamp + associated frame
143  std::map<unsigned int, FrameInfo> m_framemap;
144  // vector of frames for fast indexed access
145  std::vector<FrameInfo> m_frames;
146  // Action frame of the Animation.
147  int m_action_frame;
148  // time when animation ends (zero based)
149  int m_animation_endtime;
150  // Direction for this animation
151  unsigned int m_direction;
152 
153  };
154 }
155 
156 #endif
157 /* vim: set noexpandtab: set shiftwidth=2: set tabstop=2: */