GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/particle/particlelist.cpp Lines: 12 37 32.4 %
Date: 2017-11-29 Branches: 1 10 10.0 %

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