FIFE  be64c707dea6b3250bd4355bf5c825d25920087d
FIFE::Animation Class Reference

Animation. More...

#include <animation.h>

+ Inheritance diagram for FIFE::Animation:
+ Collaboration diagram for FIFE::Animation:

Classes

struct  FrameInfo
 Contains information about one animation frame (duration + frame index + frame pointer) More...
 

Public Member Functions

 Animation (IResourceLoader *loader=0)
 Constructor. More...
 
 Animation (const std::string &name, IResourceLoader *loader=0)
 
 ~Animation ()
 Destructor. More...
 
virtual size_t getSize ()
 
virtual void load ()
 
virtual void free ()
 
void invalidate ()
 
void addFrame (ImagePtr image, uint32_t duration)
 Adds new frame into animation Frames must be added starting from first frame. More...
 
int32_t getFrameIndex (uint32_t timestamp)
 Get the frame index that matches given timestamp. More...
 
ImagePtr getFrame (int32_t index)
 Gets the frame iamge that matches the given index. More...
 
ImagePtr getFrameByTimestamp (uint32_t timestamp)
 Gets the frame image that matches the given timestamp. More...
 
std::vector< ImagePtrgetFrames ()
 Gets all frame images. More...
 
int32_t getFrameDuration (int32_t index) const
 Gets the frame duration for given (indexed) frame. More...
 
uint32_t getFrameCount () const
 Get the number of frames. More...
 
void setActionFrame (int32_t num)
 Sets the action frame. More...
 
int32_t getActionFrame () const
 Gets the action frame. More...
 
void setDirection (uint32_t direction)
 Animation direction tells how this animation is associated with movement when played starting from frame 0 E.g. More...
 
uint32_t getDirection () const
 Gets the animation direction. More...
 
uint32_t getDuration () const
 Gets the total duration for the whole animation. More...
 
- Public Member Functions inherited from FIFE::IResource
 IResource (const std::string &name, IResourceLoader *loader=0)
 
virtual ~IResource ()
 
virtual const std::string & getName ()
 
ResourceHandle getHandle ()
 
virtual ResourceState getState ()
 
virtual void setState (const ResourceState &state)
 

Private Member Functions

std::string createUniqueAnimationName ()
 
bool isValidIndex (int32_t index) const
 Checks for animation frame index overflows. More...
 

Private Attributes

std::map< uint32_t, FrameInfom_framemap
 
std::vector< FrameInfom_frames
 
int32_t m_action_frame
 
int32_t m_animation_endtime
 
uint32_t m_direction
 

Additional Inherited Members

- Public Types inherited from FIFE::IResource
enum  ResourceState { RES_INVALID = 0, RES_NOT_LOADED, RES_LOADED }
 
- Protected Attributes inherited from FIFE::IResource
std::string m_name
 
IResourceLoaderm_loader
 
ResourceState m_state
 

Detailed Description

Animation.

A container of Images describing an animation. Animation itself does not take care of animating the images. Instead it contains images having associated timestamps. It is the responsibility of the animation user to query frames based on current timestamp and show returned images on screen.

Definition at line 53 of file animation.h.

Constructor & Destructor Documentation

◆ Animation() [1/2]

FIFE::Animation::Animation ( IResourceLoader loader = 0)

Constructor.

Definition at line 40 of file animation.cpp.

◆ Animation() [2/2]

FIFE::Animation::Animation ( const std::string &  name,
IResourceLoader loader = 0 
)

Definition at line 47 of file animation.cpp.

◆ ~Animation()

FIFE::Animation::~Animation ( )

Destructor.

Decreases the reference count of all referred images.

Definition at line 54 of file animation.cpp.

Member Function Documentation

◆ addFrame()

void FIFE::Animation::addFrame ( ImagePtr  image,
uint32_t  duration 
)

Adds new frame into animation Frames must be added starting from first frame.

Increases the reference count of the given image.

Parameters
imagePointer to Image. Does not transfer the ownership
durationDuration for given frame in the animation

Definition at line 104 of file animation.cpp.

References FIFE::Animation::FrameInfo::duration, FIFE::Animation::FrameInfo::image, FIFE::Animation::FrameInfo::index, m_animation_endtime, m_framemap, and m_frames.

Referenced by FIFE::ObjectLoader::load(), and FIFE::AnimationLoader::loadAnimation().

+ Here is the caller graph for this function:

◆ createUniqueAnimationName()

std::string FIFE::Animation::createUniqueAnimationName ( )
private

Definition at line 90 of file animation.cpp.

◆ free()

void FIFE::Animation::free ( )
virtual

Implements FIFE::IResource.

Definition at line 73 of file animation.cpp.

References m_frames, FIFE::IResource::m_state, and FIFE::IResource::RES_NOT_LOADED.

Referenced by invalidate().

+ Here is the caller graph for this function:

◆ getActionFrame()

int32_t FIFE::Animation::getActionFrame ( ) const
inline

Gets the action frame.

See also
setActionFrame

Definition at line 119 of file animation.h.

References m_action_frame, and setDirection().

Referenced by FIFE::LayerCache::updateVisual().

+ Here is the caller graph for this function:

◆ getDirection()

uint32_t FIFE::Animation::getDirection ( ) const
inline

Gets the animation direction.

See also
setDirection
Returns
direction for this animation

Definition at line 134 of file animation.h.

References m_direction.

Referenced by FIFE::ObjectLoader::load().

+ Here is the caller graph for this function:

◆ getDuration()

uint32_t FIFE::Animation::getDuration ( ) const
inline

◆ getFrame()

ImagePtr FIFE::Animation::getFrame ( int32_t  index)

Gets the frame iamge that matches the given index.

If no matches found, returns an invalid ImagePtr

Definition at line 139 of file animation.cpp.

References FIFE::IResource::getState(), isValidIndex(), FIFE::Image::load(), m_frames, and FIFE::IResource::RES_NOT_LOADED.

Referenced by fcn::AnimationIcon::AnimationIcon(), fcn::AnimationIcon::logic(), fcn::AnimationIcon::setAnimation(), and fcn::AnimationIcon::stop().

+ Here is the caller graph for this function:

◆ getFrameByTimestamp()

ImagePtr FIFE::Animation::getFrameByTimestamp ( uint32_t  timestamp)

◆ getFrameCount()

uint32_t FIFE::Animation::getFrameCount ( ) const

Get the number of frames.

Definition at line 178 of file animation.cpp.

References m_frames.

Referenced by fcn::AnimationIcon::AnimationIcon(), FIFE::AnimationLoader::loadAnimation(), fcn::AnimationIcon::setAnimation(), fcn::AnimationIcon::stop(), and FIFE::LayerCache::updateVisual().

+ Here is the caller graph for this function:

◆ getFrameDuration()

int32_t FIFE::Animation::getFrameDuration ( int32_t  index) const

Gets the frame duration for given (indexed) frame.

Returns negative value in case of incorrect index

Definition at line 171 of file animation.cpp.

References isValidIndex(), and m_frames.

◆ getFrameIndex()

int32_t FIFE::Animation::getFrameIndex ( uint32_t  timestamp)

Get the frame index that matches given timestamp.

In case there is no exact match, correct frame is calculated. E.g. if there are frames for timestamps 50 and 100 and frame for 75 is asked, frame associated with value 50 is given back. In case the timestamp is past the sequence, negative value is returned

See also
addFrame

Definition at line 124 of file animation.cpp.

References m_animation_endtime, and m_framemap.

Referenced by fcn::AnimationIcon::logic(), and FIFE::LayerCache::updateVisual().

+ Here is the caller graph for this function:

◆ getFrames()

std::vector< ImagePtr > FIFE::Animation::getFrames ( )

Gets all frame images.

Definition at line 163 of file animation.cpp.

References m_frames.

Referenced by FIFE::ResourceAnimationLoader::load().

+ Here is the caller graph for this function:

◆ getSize()

size_t FIFE::Animation::getSize ( )
virtual

Implements FIFE::IResource.

Definition at line 59 of file animation.cpp.

◆ invalidate()

void FIFE::Animation::invalidate ( )

Definition at line 81 of file animation.cpp.

References free(), m_action_frame, m_animation_endtime, m_direction, m_framemap, and m_frames.

◆ isValidIndex()

bool FIFE::Animation::isValidIndex ( int32_t  index) const
private

Checks for animation frame index overflows.

Definition at line 134 of file animation.cpp.

References m_frames.

Referenced by getFrame(), and getFrameDuration().

+ Here is the caller graph for this function:

◆ load()

void FIFE::Animation::load ( )
virtual

◆ setActionFrame()

void FIFE::Animation::setActionFrame ( int32_t  num)
inline

Sets the action frame.

Action frame is the frame when the related action actually happens. E.g. in case of punch animation, action frame is the frame when punch hits the target. In case there is no associated action frame, value is negative

Parameters
numindex of the action frame.

Definition at line 114 of file animation.h.

References m_action_frame.

Referenced by FIFE::ObjectLoader::load(), and FIFE::AnimationLoader::loadAnimation().

+ Here is the caller graph for this function:

◆ setDirection()

void FIFE::Animation::setDirection ( uint32_t  direction)

Animation direction tells how this animation is associated with movement when played starting from frame 0 E.g.

in walking animation there should be direction assigned so that engine can choose the correct animation when characters are moved around the map area

Parameters
directiondirection to set

Definition at line 182 of file animation.cpp.

References m_direction.

Referenced by getActionFrame(), and FIFE::AnimationLoader::loadAnimation().

+ Here is the caller graph for this function:

Member Data Documentation

◆ m_action_frame

int32_t FIFE::Animation::m_action_frame
private

Definition at line 160 of file animation.h.

Referenced by getActionFrame(), invalidate(), and setActionFrame().

◆ m_animation_endtime

int32_t FIFE::Animation::m_animation_endtime
private

Definition at line 162 of file animation.h.

Referenced by addFrame(), getDuration(), getFrameByTimestamp(), getFrameIndex(), and invalidate().

◆ m_direction

uint32_t FIFE::Animation::m_direction
private

Definition at line 164 of file animation.h.

Referenced by getDirection(), invalidate(), and setDirection().

◆ m_framemap

std::map<uint32_t, FrameInfo> FIFE::Animation::m_framemap
private

Definition at line 156 of file animation.h.

Referenced by addFrame(), getFrameByTimestamp(), getFrameIndex(), and invalidate().

◆ m_frames

std::vector<FrameInfo> FIFE::Animation::m_frames
private

The documentation for this class was generated from the following files: