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 #include "util/base/fifeclass.h"
00033 #include "util/base/sharedptr.h"
00034 
00035 #include "image.h"
00036 
00037 // 3rd party library includes
00038 
00039 // FIFE includes
00040 // These includes are split up in two parts, separated by one empty line
00041 // First block: files included from the FIFE root src directory
00042 // Second block: files included from the same folder
00043 
00044 namespace FIFE {
00045 
00046     class Image;
00047 
00056     class Animation : public FifeClass {
00057     public:
00060         explicit Animation();
00061 
00064         ~Animation();
00065 
00072         void addFrame(ImagePtr image, uint32_t duration);
00073 
00080         int32_t getFrameIndex(uint32_t timestamp);
00081 
00084         ImagePtr getFrame(int32_t index);
00085 
00088         ImagePtr getFrameByTimestamp(uint32_t timestamp);
00089 
00093         int32_t getFrameDuration(int32_t index) const;
00094 
00097         uint32_t getFrameCount() const;
00098 
00105         void setActionFrame(int32_t num) { m_action_frame = num; }
00106 
00110         int32_t getActionFrame() const { return m_action_frame; }
00111 
00119         void setDirection(uint32_t direction);
00120 
00125         uint32_t getDirection() const { return m_direction; }
00126 
00129         uint32_t getDuration() const { return m_animation_endtime; }
00130 
00131     private:
00134         struct FrameInfo {
00135             uint32_t index;
00136             uint32_t duration;
00137             ImagePtr image;
00138         };
00139 
00142         bool isValidIndex(int32_t index) const;
00143 
00144         // Map of timestamp + associated frame
00145         std::map<uint32_t, FrameInfo> m_framemap;
00146         // vector of frames for fast indexed access
00147         std::vector<FrameInfo> m_frames;
00148         // Action frame of the Animation.
00149         int32_t m_action_frame;
00150         // time when animation ends (zero based)
00151         int32_t m_animation_endtime;
00152         // Direction for this animation
00153         uint32_t m_direction;
00154 
00155     };
00156 
00157     typedef SharedPtr<Animation> AnimationPtr;
00158 
00159 }
00160 
00161 #endif
00162 /* vim: set noexpandtab: set shiftwidth=2: set tabstop=2: */