~ubuntu-branches/ubuntu/trusty/manaplus/trusty-proposed

« back to all changes in this revision

Viewing changes to src/particle/particlecontainer.h

  • Committer: Package Import Robot
  • Author(s): Patrick Matthäi
  • Date: 2013-09-17 10:35:51 UTC
  • mfrom: (1.1.10)
  • Revision ID: package-import@ubuntu.com-20130917103551-az7p3nz9jgxwqjfn
Tags: 1.3.9.15-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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-2013  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
#ifndef PARTICLE_PARTICLECONTAINER_H
 
24
#define PARTICLE_PARTICLECONTAINER_H
 
25
 
 
26
#include <list>
 
27
#include <vector>
 
28
 
 
29
#include "localconsts.h"
 
30
 
 
31
class Particle;
 
32
 
 
33
/**
 
34
 * Set of particle effects.  May be stacked with other ParticleContainers.  All
 
35
 * operations herein affect such stacked containers, unless the operations end
 
36
 * in `Locally'.
 
37
 */
 
38
class ParticleContainer
 
39
{
 
40
public:
 
41
    /**
 
42
     * Constructs a new particle container and assumes responsibility for
 
43
     * its parent (for all operations defined herein, except when ending in `Locally')
 
44
     *
 
45
     * delParent means that the destructor should also free the parent.
 
46
     */
 
47
    explicit ParticleContainer(ParticleContainer *const parent = nullptr,
 
48
                               const bool delParent = true);
 
49
 
 
50
    A_DELETE_COPY(ParticleContainer)
 
51
 
 
52
    virtual ~ParticleContainer();
 
53
 
 
54
    /**
 
55
     * Kills and removes all particle effects
 
56
     */
 
57
    void clear();
 
58
 
 
59
    /**
 
60
     * Kills and removes all particle effects (only in this container)
 
61
     */
 
62
    virtual void clearLocally()
 
63
    { }
 
64
 
 
65
    /**
 
66
     * Sets the positions of all elements
 
67
     */
 
68
    virtual void moveTo(const float x, const float y);
 
69
 
 
70
protected:
 
71
    ParticleContainer *mNext;           /**< Contained container, if any */
 
72
    bool mDelParent;                    /**< Delete mNext in destructor */
 
73
};
 
74
 
 
75
/**
 
76
 * Linked list of particle effects.
 
77
 */
 
78
class ParticleList final : public ParticleContainer
 
79
{
 
80
public:
 
81
    explicit ParticleList(ParticleContainer *const parent = nullptr,
 
82
                          const bool delParent = true);
 
83
 
 
84
    A_DELETE_COPY(ParticleList)
 
85
 
 
86
    virtual ~ParticleList();
 
87
 
 
88
    /**
 
89
     * Takes control of and adds a particle
 
90
     */
 
91
    void addLocally(Particle *const particle);
 
92
 
 
93
    /**
 
94
     * `kills' and removes a particle
 
95
     */
 
96
    void removeLocally(const Particle *const particle);
 
97
 
 
98
    virtual void clearLocally() override;
 
99
 
 
100
    virtual void moveTo(const float x, const float y) override;
 
101
 
 
102
protected:
 
103
    std::list<Particle *> mElements;    /**< Contained particle effects */
 
104
};
 
105
 
 
106
/**
 
107
 * Particle container with indexing facilities
 
108
 */
 
109
class ParticleVector final : public ParticleContainer
 
110
{
 
111
public:
 
112
    explicit ParticleVector(ParticleContainer *const parent = nullptr,
 
113
                            const bool delParent = true);
 
114
 
 
115
    A_DELETE_COPY(ParticleVector)
 
116
 
 
117
    virtual ~ParticleVector();
 
118
 
 
119
    /**
 
120
     * Sets a particle at a specified index.  Kills the previous particle
 
121
     * there, if needed.
 
122
     */
 
123
    virtual void setLocally(const int index, Particle *const particle);
 
124
 
 
125
    /**
 
126
     * Removes a particle at a specified index
 
127
     */
 
128
    virtual void delLocally(const int index);
 
129
 
 
130
    virtual void clearLocally() override;
 
131
 
 
132
    virtual void moveTo(const float x, const float y) override;
 
133
 
 
134
protected:
 
135
    std::vector<Particle *> mIndexedElements;
 
136
};
 
137
 
 
138
#endif  // PARTICLE_PARTICLECONTAINER_H