GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/particle/particlelist.cpp Lines: 12 37 32.4 %
Date: 2021-03-17 Branches: 1 12 8.3 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2008-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 "particle/particlelist.h"
25
26
#include "utils/foreach.h"
27
28
#include "particle/particle.h"
29
30
#include "debug.h"
31
32
typedef std::list<Particle *>::iterator ParticleListIter;
33
typedef std::list<Particle *>::const_iterator ParticleListCIter;
34
35
103
ParticleList::ParticleList(ParticleContainer *const parent,
36
103
                           const bool delParent) :
37
    ParticleContainer(parent, delParent),
38
    mElements(),
39
206
    mSize(0U)
40
103
{}
41
42
206
ParticleList::~ParticleList()
43
{
44
103
}
45
46
void ParticleList::addLocally(Particle *const particle)
47
{
48
    if (particle != nullptr)
49
    {
50
        mElements.push_back(particle);
51
        mSize ++;
52
    }
53
}
54
55
void ParticleList::removeLocally(const Particle *const particle)
56
{
57
    for (std::list<Particle *>::iterator it = mElements.begin();
58
         it != mElements.end(); )
59
    {
60
        Particle *const p = *it;
61
        if (p == particle)
62
        {
63
            p->kill();
64
            p->prepareToDie();
65
            it = mElements.erase(it);
66
            mSize --;
67
        }
68
        else
69
        {
70
            ++it;
71
        }
72
    }
73
}
74
75
206
void ParticleList::clearLocally()
76
{
77
1030
    FOR_EACH (ParticleListCIter, it, mElements)
78
    {
79
        (*it)->kill();
80
        (*it)->prepareToDie();
81
    }
82
83
412
    mElements.clear();
84
206
    mSize = 0U;
85
206
}
86
87
void ParticleList::moveTo(const float x, const float y)
88
{
89
    ParticleContainer::moveTo(x, y);
90
91
    for (std::list<Particle *>::iterator it = mElements.begin();
92
         it != mElements.end(); )
93
    {
94
        Particle *const p = *it;
95
        p->moveTo(x, y);
96
        if (p->isExtinct())
97
        {
98
            p->kill();
99
            it = mElements.erase(it);
100
            mSize --;
101
        }
102
        else
103
        {
104
            ++it;
105
        }
106
    }
107
2
}