ManaPlus
Public Types | Public Member Functions | Protected Attributes | Friends
Animation Class Reference

#include <animation.h>

Inheritance diagram for Animation:
MemoryCounter

Public Types

typedef std::vector< FrameFrames
 
typedef Frames::iterator FramesIter
 
typedef Frames::const_iterator FramesCIter
 
typedef Frames::reverse_iterator FramesRevIter
 

Public Member Functions

 Animation ()
 
 Animation (const std::string &name)
 
void addFrame (Image *const image, const int delay, const int offsetX, const int offsetY, const int rand)
 
void addTerminator (const int rand)
 
size_t getLength () const
 
void addJump (const std::string &name, const int rand)
 
void addLabel (const std::string &name)
 
void addGoto (const std::string &name, const int rand)
 
void addPause (const int delay, const int rand)
 
void setLastFrameDelay (const int delay)
 
int calcMemoryLocal () const
 
std::string getCounterName () const
 
- Public Member Functions inherited from MemoryCounter
 MemoryCounter ()
 
virtual ~MemoryCounter ()
 
int calcMemory (const int level) const
 
virtual int calcMemoryChilds (const int level) const
 

Protected Attributes

Frames mFrames
 
std::string mName
 
int mDuration
 

Friends

class AnimatedSprite
 
class ParticleEmitter
 
class SimpleAnimation
 

Detailed Description

An animation consists of several frames, each with their own delay and offset.

Definition at line 41 of file animation.h.

Member Typedef Documentation

◆ Frames

typedef std::vector<Frame> Animation::Frames

Definition at line 83 of file animation.h.

◆ FramesCIter

typedef Frames::const_iterator Animation::FramesCIter

Definition at line 85 of file animation.h.

◆ FramesIter

typedef Frames::iterator Animation::FramesIter

Definition at line 84 of file animation.h.

◆ FramesRevIter

typedef Frames::reverse_iterator Animation::FramesRevIter

Definition at line 86 of file animation.h.

Constructor & Destructor Documentation

◆ Animation() [1/2]

Animation::Animation ( )

Definition at line 30 of file animation.cpp.

30  :
31  MemoryCounter(),
32  mFrames(),
33  mName("animation"),
34  mDuration(0)
35 {
36 }
std::string mName
Definition: animation.h:100
Frames mFrames
Definition: animation.h:99
int mDuration
Definition: animation.h:101

Referenced by calcMemoryLocal().

◆ Animation() [2/2]

Animation::Animation ( const std::string &  name)
explicit

Definition at line 38 of file animation.cpp.

38  :
39  MemoryCounter(),
40  mFrames(),
41  mName(name),
42  mDuration(0)
43 {
44 }

Member Function Documentation

◆ addFrame()

void Animation::addFrame ( Image *const  image,
const int  delay,
const int  offsetX,
const int  offsetY,
const int  rand 
)

Appends a new animation at the end of the sequence.

Definition at line 46 of file animation.cpp.

49 {
50  Frame frame
51  = { image, delay, offsetX, offsetY, rand, FrameType::ANIMATION, "" };
52  mFrames.push_back(frame);
53  mDuration += delay;
54 }
@ ANIMATION
Definition: frametype.h:33
Definition: frame.h:39

References FrameType::ANIMATION.

Referenced by SpriteDef::addSequence(), SimpleAnimation::initializeAnimation(), SpriteDef::loadAnimation(), ParticleEmitter::ParticleEmitter(), ProgressIndicator::ProgressIndicator(), and MapReader::readTileset().

◆ addGoto()

void Animation::addGoto ( const std::string &  name,
const int  rand 
)

Definition at line 73 of file animation.cpp.

74 {
75  const Frame frame = { nullptr, 0, 0, 0, rand, FrameType::GOTO, name };
76  mFrames.push_back(frame);
77 }

References FrameType::GOTO.

Referenced by SpriteDef::loadAnimation().

◆ addJump()

void Animation::addJump ( const std::string &  name,
const int  rand 
)

Definition at line 61 of file animation.cpp.

62 {
63  const Frame frame = { nullptr, 0, 0, 0, rand, FrameType::JUMP, name };
64  mFrames.push_back(frame);
65 }

References FrameType::JUMP.

Referenced by SpriteDef::loadAnimation().

◆ addLabel()

void Animation::addLabel ( const std::string &  name)

Definition at line 67 of file animation.cpp.

68 {
69  const Frame frame = { nullptr, 0, 0, 0, 100, FrameType::LABEL, name };
70  mFrames.push_back(frame);
71 }

References FrameType::LABEL.

Referenced by SpriteDef::loadAnimation().

◆ addPause()

void Animation::addPause ( const int  delay,
const int  rand 
)

Definition at line 79 of file animation.cpp.

80 {
81  const Frame frame = { nullptr, delay, 0, 0, rand, FrameType::PAUSE, "" };
82  mFrames.push_back(frame);
83 }

References FrameType::PAUSE.

Referenced by SpriteDef::loadAnimation().

◆ addTerminator()

void Animation::addTerminator ( const int  rand)

Appends an animation terminator that states that the animation should not loop.

Definition at line 56 of file animation.cpp.

57 {
58  addFrame(nullptr, 0, 0, 0, rand);
59 }
void addFrame(Image *const image, const int delay, const int offsetX, const int offsetY, const int rand)
Definition: animation.cpp:46

Referenced by SimpleAnimation::initializeAnimation(), SpriteDef::loadAnimation(), and ParticleEmitter::ParticleEmitter().

◆ calcMemoryLocal()

int Animation::calcMemoryLocal ( ) const
virtual

Reimplemented from MemoryCounter.

Definition at line 98 of file animation.cpp.

99 {
100  int sz = sizeof(Animation);
102  {
103  const Frame &frame = *it;
104  sz += static_cast<int>(sizeof(Frame) +
105  frame.nextAction.capacity());
106  }
107  return sz;
108 }
Frames::const_iterator FramesCIter
Definition: animation.h:85
#define FOR_EACH(type, iter, array)
Definition: foreach.h:25
std::string nextAction
Definition: frame.h:48

References Animation(), FOR_EACH, mFrames, and Frame::nextAction.

◆ getCounterName()

std::string Animation::getCounterName ( ) const
inlinevirtual

Reimplemented from MemoryCounter.

Definition at line 95 of file animation.h.

96  { return mName; }

References mName.

◆ getLength()

size_t Animation::getLength ( ) const
inline

Returns the length of this animation in frames.

Definition at line 70 of file animation.h.

71  { return mFrames.size(); }

References mFrames.

Referenced by AnimatedSprite::getFrameCount(), SimpleAnimation::getLength(), AnimatedSprite::play(), MapReader::readTileset(), SimpleAnimation::setFrame(), and SimpleAnimation::update().

◆ setLastFrameDelay()

void Animation::setLastFrameDelay ( const int  delay)

Definition at line 85 of file animation.cpp.

86 {
87  for (FramesRevIter it = mFrames.rbegin(), it_end = mFrames.rend();
88  it != it_end; ++ it)
89  {
90  if ((*it).type == FrameType::ANIMATION && ((*it).image != nullptr))
91  {
92  (*it).delay = delay;
93  break;
94  }
95  }
96 }
Frames::reverse_iterator FramesRevIter
Definition: animation.h:86

References FrameType::ANIMATION.

Referenced by Action::setLastFrameDelay().

Friends And Related Function Documentation

◆ AnimatedSprite

friend class AnimatedSprite
friend

Definition at line 43 of file animation.h.

◆ ParticleEmitter

friend class ParticleEmitter
friend

Definition at line 44 of file animation.h.

◆ SimpleAnimation

friend class SimpleAnimation
friend

Definition at line 45 of file animation.h.

Field Documentation

◆ mDuration

int Animation::mDuration
protected

Definition at line 101 of file animation.h.

◆ mFrames

Frames Animation::mFrames
protected

◆ mName

std::string Animation::mName
protected

Definition at line 100 of file animation.h.

Referenced by getCounterName().


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