ManaPlus
Public Member Functions | Protected Types | Protected Attributes
Action Class Reference

#include <action.h>

Inheritance diagram for Action:
MemoryCounter

Public Member Functions

 Action (const std::string &name)
 
 ~Action ()
 
void setAnimation (const SpriteDirection::Type direction, Animation *const animation)
 
const AnimationgetAnimation (SpriteDirection::Type direction) const
 
unsigned getNumber () const
 
void setNumber (const unsigned n)
 
void setLastFrameDelay (const int delay)
 
int calcMemoryLocal () const
 
int calcMemoryChilds (const int level) const
 
std::string getCounterName () const
 
- Public Member Functions inherited from MemoryCounter
 MemoryCounter ()
 
virtual ~MemoryCounter ()
 
int calcMemory (const int level) const
 

Protected Types

typedef std::map< SpriteDirection::Type, Animation * > Animations
 
typedef Animations::iterator AnimationIter
 
typedef Animations::const_iterator AnimationCIter
 

Protected Attributes

Animations mAnimations
 
std::string mCounterName
 
unsigned mNumber
 

Detailed Description

An action consists of several animations, one for each direction.

Definition at line 40 of file action.h.

Member Typedef Documentation

◆ AnimationCIter

typedef Animations::const_iterator Action::AnimationCIter
protected

Definition at line 73 of file action.h.

◆ AnimationIter

typedef Animations::iterator Action::AnimationIter
protected

Definition at line 72 of file action.h.

◆ Animations

typedef std::map<SpriteDirection::Type, Animation*> Action::Animations
protected

Definition at line 71 of file action.h.

Constructor & Destructor Documentation

◆ Action()

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

Definition at line 33 of file action.cpp.

33  :
34  MemoryCounter(),
35  mAnimations(),
36  mCounterName(name),
37  mNumber(100)
38 {
39 }
unsigned mNumber
Definition: action.h:77
std::string mCounterName
Definition: action.h:76
Animations mAnimations
Definition: action.h:75

Referenced by calcMemoryLocal().

◆ ~Action()

Action::~Action ( )

Definition at line 41 of file action.cpp.

42 {
44 }
void delete_all(Container &c)
Definition: dtor.h:56

References delete_all(), and mAnimations.

Member Function Documentation

◆ calcMemoryChilds()

int Action::calcMemoryChilds ( const int  level) const
virtual

Reimplemented from MemoryCounter.

Definition at line 96 of file action.cpp.

97 {
98  int sz = 0;
100  {
101  sz += sizeof(SpriteDirection::Type);
102  const Animation *const animation = (*it).second;
103  sz += animation->calcMemory(level + 1);
104  }
105  return sz;
106 }
Animations::const_iterator AnimationCIter
Definition: action.h:73
int calcMemory(const int level) const
#define FOR_EACH(type, iter, array)
Definition: foreach.h:25

References MemoryCounter::calcMemory(), FOR_EACH, and mAnimations.

◆ calcMemoryLocal()

int Action::calcMemoryLocal ( ) const
virtual

Reimplemented from MemoryCounter.

Definition at line 91 of file action.cpp.

92 {
93  return sizeof(Action);
94 }
Action(const std::string &name)
Definition: action.cpp:33

References Action().

◆ getAnimation()

const Animation * Action::getAnimation ( SpriteDirection::Type  direction) const

Definition at line 46 of file action.cpp.

48 {
49  Animations::const_iterator i = mAnimations.find(direction);
50 
51  if (i == mAnimations.end())
52  {
53  if (direction == SpriteDirection::UPLEFT
54  || direction == SpriteDirection::UPRIGHT)
55  {
56  direction = SpriteDirection::UP;
57  }
58  else if (direction == SpriteDirection::DOWNLEFT
59  || direction == SpriteDirection::DOWNRIGHT)
60  {
61  direction = SpriteDirection::DOWN;
62  }
63  i = mAnimations.find(direction);
64 
65  // When the given direction is not available, return the first one.
66  // (either DEFAULT, or more usually DOWN).
67  if (i == mAnimations.end())
68  i = mAnimations.begin();
69  }
70 
71  return (i == mAnimations.end()) ? nullptr : i->second;
72 }
#define nullptr
Definition: localconsts.h:45

References SpriteDirection::DOWN, SpriteDirection::DOWNLEFT, SpriteDirection::DOWNRIGHT, nullptr, SpriteDirection::UP, SpriteDirection::UPLEFT, and SpriteDirection::UPRIGHT.

◆ getCounterName()

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

Reimplemented from MemoryCounter.

Definition at line 67 of file action.h.

68  { return mCounterName; }

References mCounterName.

◆ getNumber()

unsigned Action::getNumber ( ) const
inline

Definition at line 55 of file action.h.

56  { return mNumber; }

References mNumber.

◆ setAnimation()

void Action::setAnimation ( const SpriteDirection::Type  direction,
Animation *const  animation 
)

Definition at line 74 of file action.cpp.

76 {
77  mAnimations[direction] = animation;
78 }

Referenced by SpriteDef::loadAnimation().

◆ setLastFrameDelay()

void Action::setLastFrameDelay ( const int  delay)

Definition at line 80 of file action.cpp.

81 {
83  {
84  Animation *const animation = (*it).second;
85  if (animation == nullptr)
86  continue;
87  animation->setLastFrameDelay(delay);
88  }
89 }
Animations::iterator AnimationIter
Definition: action.h:72
void setLastFrameDelay(const int delay)
Definition: animation.cpp:85

References FOR_EACH, and Animation::setLastFrameDelay().

◆ setNumber()

void Action::setNumber ( const unsigned  n)
inline

Definition at line 58 of file action.h.

59  { mNumber = n; }

References mNumber.

Referenced by SpriteDef::loadAction().

Field Documentation

◆ mAnimations

Animations Action::mAnimations
protected

Definition at line 75 of file action.h.

Referenced by calcMemoryChilds(), and ~Action().

◆ mCounterName

std::string Action::mCounterName
protected

Definition at line 76 of file action.h.

Referenced by getCounterName().

◆ mNumber

unsigned Action::mNumber
protected

Definition at line 77 of file action.h.

Referenced by getNumber(), and setNumber().


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