GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/resources/animation/animation.cpp Lines: 16 38 42.1 %
Date: 2021-03-17 Branches: 0 10 0.0 %

Line Branch Exec Source
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
24
#include "resources/animation/animation.h"
25
26
#include "utils/foreach.h"
27
28
#include "debug.h"
29
30
Animation::Animation() noexcept2 :
31
    MemoryCounter(),
32
    mFrames(),
33
    mName("animation"),
34
    mDuration(0)
35
{
36
}
37
38
1298
Animation::Animation(const std::string &name) noexcept2 :
39
    MemoryCounter(),
40
    mFrames(),
41
    mName(name),
42
3894
    mDuration(0)
43
{
44
1298
}
45
46
21529
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
86116
        = { image, delay, offsetX, offsetY, rand, FrameType::ANIMATION, "" };
52
21529
    mFrames.push_back(frame);
53
21529
    mDuration += delay;
54
21529
}
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
2
void Animation::addLabel(const std::string &name) noexcept2
68
{
69
6
    const Frame frame = { nullptr, 0, 0, 0, 100, FrameType::LABEL, name };
70
2
    mFrames.push_back(frame);
71
2
}
72
73
4
void Animation::addGoto(const std::string &name, const int rand) noexcept2
74
{
75
12
    const Frame frame = { nullptr, 0, 0, 0, rand, FrameType::GOTO, name };
76
4
    mFrames.push_back(frame);
77
4
}
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
85
void Animation::setLastFrameDelay(const int delay) noexcept2
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
98
int Animation::calcMemoryLocal() const
99
{
100
    int sz = sizeof(Animation);
101
    FOR_EACH (FramesCIter, it, mFrames)
102
    {
103
        const Frame &frame = *it;
104
        sz += static_cast<int>(sizeof(Frame) +
105
            frame.nextAction.capacity());
106
    }
107
    return sz;
108
}