GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/particle/particlevector.cpp Lines: 11 44 25.0 %
Date: 2017-11-29 Branches: 1 32 3.1 %

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/particle.h"
24
#include "particle/particlevector.h"
25
26
#include "debug.h"
27
28
204
ParticleVector::ParticleVector(ParticleContainer *const parent,
29
204
                               const bool delParent) :
30
    ParticleContainer(parent, delParent),
31
408
    mIndexedElements()
32
204
{}
33
34
408
ParticleVector::~ParticleVector()
35
204
{}
36
37
void ParticleVector::setLocally(const int index, Particle *const particle)
38
{
39
    if (index < 0)
40
        return;
41
42
    delLocally(index);
43
44
    if (mIndexedElements.size() <= CAST_SIZE(index))
45
        mIndexedElements.resize(index + 1, nullptr);
46
47
    if (particle != nullptr)
48
        particle->disableAutoDelete();
49
    mIndexedElements[index] = particle;
50
}
51
52
void ParticleVector::delLocally(const int index)
53
{
54
    if (index < 0)
55
        return;
56
57
    if (mIndexedElements.size() <= CAST_SIZE(index))
58
        return;
59
60
    Particle *const p = mIndexedElements[index];
61
    if (p != nullptr)
62
    {
63
        mIndexedElements[index] = nullptr;
64
        p->kill();
65
    }
66
}
67
68
408
void ParticleVector::clearLocally()
69
{
70
408
    for (unsigned int i = 0;
71
816
         i < CAST_U32(mIndexedElements.size());
72
         i++)
73
    {
74
        delLocally(i);
75
    }
76
408
}
77
78
void ParticleVector::moveTo(const float x, const float y)
79
{
80
    ParticleContainer::moveTo(x, y);
81
82
    for (STD_VECTOR<Particle *>::iterator it = mIndexedElements.begin();
83
         it != mIndexedElements.end(); ++it)
84
    {
85
        Particle *const p = *it;
86
        if (p != nullptr)
87
        {
88
            p->moveTo(x, y);
89
90
            if (p->isExtinct())
91
            {
92
                p->kill();
93
                *it = nullptr;
94
            }
95
        }
96
    }
97
}
98
99
size_t ParticleVector::usedSize() const
100
{
101
    size_t cnt = 0;
102
    for (STD_VECTOR<Particle *>::const_iterator it = mIndexedElements.begin();
103
         it != mIndexedElements.end(); ++it)
104
    {
105
        if (*it != nullptr)
106
            cnt ++;
107
    }
108
    return cnt;
109
4
}