ManaPlus
animation.cpp
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2004-2009 The Mana World Development Team
4  * Copyright (C) 2009-2010 The Mana Developers
5  * Copyright (C) 2011-2019 The ManaPlus Developers
6  * Copyright (C) 2019-2021 Andrei Karas
7  *
8  * This file is part of The ManaPlus Client.
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
25 
26 #include "utils/foreach.h"
27 
28 #include "debug.h"
29 
31  MemoryCounter(),
32  mFrames(),
33  mName("animation"),
34  mDuration(0)
35 {
36 }
37 
38 Animation::Animation(const std::string &name) noexcept2 :
39  MemoryCounter(),
40  mFrames(),
41  mName(name),
42  mDuration(0)
43 {
44 }
45 
46 void Animation::addFrame(Image *const image, const int delay,
47  const int offsetX, const int offsetY,
48  const int rand) noexcept2
49 {
50  Frame frame
51  = { image, delay, offsetX, offsetY, rand, FrameType::ANIMATION, "" };
52  mFrames.push_back(frame);
53  mDuration += delay;
54 }
55 
56 void Animation::addTerminator(const int rand) noexcept2
57 {
58  addFrame(nullptr, 0, 0, 0, rand);
59 }
60 
61 void Animation::addJump(const std::string &name, const int rand) noexcept2
62 {
63  const Frame frame = { nullptr, 0, 0, 0, rand, FrameType::JUMP, name };
64  mFrames.push_back(frame);
65 }
66 
67 void Animation::addLabel(const std::string &name) noexcept2
68 {
69  const Frame frame = { nullptr, 0, 0, 0, 100, FrameType::LABEL, name };
70  mFrames.push_back(frame);
71 }
72 
73 void Animation::addGoto(const std::string &name, const int rand) noexcept2
74 {
75  const Frame frame = { nullptr, 0, 0, 0, rand, FrameType::GOTO, name };
76  mFrames.push_back(frame);
77 }
78 
79 void Animation::addPause(const int delay, const int rand) noexcept2
80 {
81  const Frame frame = { nullptr, delay, 0, 0, rand, FrameType::PAUSE, "" };
82  mFrames.push_back(frame);
83 }
84 
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 }
97 
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::reverse_iterator FramesRevIter
Definition: animation.h:86
void addLabel(const std::string &name)
Definition: animation.cpp:67
void addGoto(const std::string &name, const int rand)
Definition: animation.cpp:73
void addJump(const std::string &name, const int rand)
Definition: animation.cpp:61
Frames mFrames
Definition: animation.h:99
void addTerminator(const int rand)
Definition: animation.cpp:56
void addFrame(Image *const image, const int delay, const int offsetX, const int offsetY, const int rand)
Definition: animation.cpp:46
int calcMemoryLocal() const
Definition: animation.cpp:98
Frames::const_iterator FramesCIter
Definition: animation.h:85
void setLastFrameDelay(const int delay)
Definition: animation.cpp:85
void addPause(const int delay, const int rand)
Definition: animation.cpp:79
#define FOR_EACH(type, iter, array)
Definition: foreach.h:25
#define noexcept2
Definition: localconsts.h:50
@ ANIMATION
Definition: frametype.h:33
Definition: frame.h:39
std::string nextAction
Definition: frame.h:48