GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/resources/animation/animation.cpp Lines: 17 40 42.5 %
Date: 2017-11-29 Branches: 0 8 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-2017  The ManaPlus Developers
6
 *
7
 *  This file is part of The ManaPlus Client.
8
 *
9
 *  This program is free software; you can redistribute it and/or modify
10
 *  it under the terms of the GNU General Public License as published by
11
 *  the Free Software Foundation; either version 2 of the License, or
12
 *  any later version.
13
 *
14
 *  This program is distributed in the hope that it will be useful,
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 *  GNU General Public License for more details.
18
 *
19
 *  You should have received a copy of the GNU General Public License
20
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 */
22
23
#include "resources/animation/animation.h"
24
25
#include "utils/foreach.h"
26
27
#include "debug.h"
28
29
Animation::Animation() noexcept2 :
30
    MemoryCounter(),
31
    mFrames(),
32
    mName("animation"),
33
    mDuration(0)
34
{
35
}
36
37
2320
Animation::Animation(const std::string &name) noexcept2 :
38
    MemoryCounter(),
39
    mFrames(),
40
    mName(name),
41
6960
    mDuration(0)
42
{
43
2320
}
44
45
38458
void Animation::addFrame(Image *const image, const int delay,
46
                         const int offsetX, const int offsetY,
47
                         const int rand) noexcept2
48
{
49
38458
    Frame frame
50
153832
        = { image, delay, offsetX, offsetY, rand, FrameType::ANIMATION, "" };
51
38458
    mFrames.push_back(frame);
52
38458
    mDuration += delay;
53
38458
}
54
55
void Animation::addTerminator(const int rand) noexcept2
56
{
57
    addFrame(nullptr, 0, 0, 0, rand);
58
}
59
60
void Animation::addJump(const std::string &name, const int rand) noexcept2
61
{
62
    const Frame frame = { nullptr, 0, 0, 0, rand, FrameType::JUMP, name };
63
    mFrames.push_back(frame);
64
}
65
66
4
void Animation::addLabel(const std::string &name) noexcept2
67
{
68
12
    const Frame frame = { nullptr, 0, 0, 0, 100, FrameType::LABEL, name };
69
4
    mFrames.push_back(frame);
70
4
}
71
72
8
void Animation::addGoto(const std::string &name, const int rand) noexcept2
73
{
74
24
    const Frame frame = { nullptr, 0, 0, 0, rand, FrameType::GOTO, name };
75
8
    mFrames.push_back(frame);
76
8
}
77
78
void Animation::addPause(const int delay, const int rand) noexcept2
79
{
80
    const Frame frame = { nullptr, delay, 0, 0, rand, FrameType::PAUSE, "" };
81
    mFrames.push_back(frame);
82
}
83
84
void Animation::setLastFrameDelay(const int delay) noexcept2
85
{
86
    for (FramesRevIter it = mFrames.rbegin(), it_end = mFrames.rend();
87
         it != it_end; ++ it)
88
    {
89
        if ((*it).type == FrameType::ANIMATION && ((*it).image != nullptr))
90
        {
91
            (*it).delay = delay;
92
            break;
93
        }
94
    }
95
}
96
97
int Animation::calcMemoryLocal() const
98
{
99
    int sz = sizeof(Animation);
100
    FOR_EACH (FramesCIter, it, mFrames)
101
    {
102
        const Frame &frame = *it;
103
        sz += static_cast<int>(sizeof(Frame) +
104
            frame.nextAction.capacity());
105
    }
106
    return sz;
107
}