animation.h

00001 /***************************************************************************
00002  *   Copyright (C) 2005-2008 by the FIFE team                              *
00003  *   http://www.fifengine.de                                               *
00004  *   This file is part of FIFE.                                            *
00005  *                                                                         *
00006  *   FIFE is free software; you can redistribute it and/or                 *
00007  *   modify it under the terms of the GNU Lesser General Public            *
00008  *   License as published by the Free Software Foundation; either          *
00009  *   version 2.1 of the License, or (at your option) any later version.    *
00010  *                                                                         *
00011  *   This library is distributed in the hope that it will be useful,       *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00014  *   Lesser General Public License for more details.                       *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Lesser General Public      *
00017  *   License along with this library; if not, write to the                 *
00018  *   Free Software Foundation, Inc.,                                       *
00019  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
00020  ***************************************************************************/
00021 
00022 #ifndef FIFE_VIDEO_ANIMATION_H
00023 #define FIFE_VIDEO_ANIMATION_H
00024 
00025 // Standard C++ library includes
00026 #include <cassert>
00027 #include <map>
00028 #include <vector>
00029 
00030 // Platform specific includes
00031 #include "util/base/fife_stdint.h"
00032 
00033 // 3rd party library includes
00034 
00035 // FIFE includes
00036 // These includes are split up in two parts, separated by one empty line
00037 // First block: files included from the FIFE root src directory
00038 // Second block: files included from the same folder
00039 #include "util/base/resourceclass.h"
00040 #include "util/resource/resource_ptr.h"
00041 
00042 namespace FIFE {
00043 
00044     class Image;
00045 
00054     class Animation : public ResourceClass {
00055     public:
00058         explicit Animation();
00059 
00062         ~Animation();
00063 
00070         void addFrame(ResourcePtr image, unsigned int duration);
00071 
00078         int getFrameIndex(unsigned int timestamp);
00079 
00082         Image* getFrame(int index);
00083 
00086         Image* getFrameByTimestamp(unsigned int timestamp);
00087 
00091         int getFrameDuration(int index) const;
00092 
00095         unsigned int getNumFrames() const;
00096 
00103         void setActionFrame(int num) { m_action_frame = num; }
00104 
00108         int getActionFrame() const { return m_action_frame; }
00109 
00117         void setDirection(unsigned int direction);
00118 
00123         unsigned int getDirection() const { return m_direction; }
00124 
00127         unsigned int getDuration() const { return m_animation_endtime; }
00128 
00129     private:
00132         struct FrameInfo {
00133             unsigned int index;
00134             unsigned int duration;
00135             ResourcePtr image;
00136         };
00137 
00140         bool isValidIndex(int index) const;
00141 
00142         // Map of timestamp + associated frame
00143         std::map<unsigned int, FrameInfo> m_framemap;
00144         // vector of frames for fast indexed access
00145         std::vector<FrameInfo> m_frames;
00146         // Action frame of the Animation.
00147         int m_action_frame;
00148         // time when animation ends (zero based)
00149         int m_animation_endtime;
00150         // Direction for this animation
00151         unsigned int m_direction;
00152 
00153     };
00154 }
00155 
00156 #endif
00157 /* vim: set noexpandtab: set shiftwidth=2: set tabstop=2: */