_________ __                 __
        /   _____//  |_____________ _/  |______     ____  __ __  ______
        \_____  \\   __\_  __ \__  \\   __\__  \   / ___\|  |  \/  ___/
        /        \|  |  |  | \// __ \|  |  / __ \_/ /_/  >  |  /\___ \
       /_______  /|__|  |__|  (____  /__| (____  /\___  /|____//____  >
               \/                  \/          \//_____/            \/
    ______________________                           ______________________
                          T H E   W A R   B E G I N S
                   Stratagus - A free fantasy real time strategy game engine

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
particle.h
Go to the documentation of this file.
1 // _________ __ __
2 // / _____// |_____________ _/ |______ ____ __ __ ______
3 // \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/
4 // / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ |
5 // /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
6 // \/ \/ \//_____/ \/
7 // ______________________ ______________________
8 // T H E W A R B E G I N S
9 // Stratagus - A free fantasy real time strategy game engine
10 //
12 //
13 // (c) Copyright 2007-2008 by Jimmy Salmon and Francois Beerten
14 //
15 // This program is free software; you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation; only version 2 of the License.
18 //
19 // This program is distributed in the hope that it will be useful,
20 // but WITHOUT ANY WARRANTY; without even the implied warranty of
21 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 // GNU General Public License for more details.
23 //
24 // You should have received a copy of the GNU General Public License
25 // along with this program; if not, write to the Free Software
26 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
27 // 02111-1307, USA.
28 
29 #ifndef __PARTICLE_H__
30 #define __PARTICLE_H__
31 
33 
34 #include <vector>
35 
36 class CGraphic;
37 class CViewport;
38 
39 
40 struct CPosition {
41  CPosition(float x, float y) : x(x), y(y) {}
42  float x;
43  float y;
44 };
45 
47 {
48  CGraphic *g;
49  int ticksPerFrame;
50  int currentFrame;
51  int currTicks;
52 public:
53  GraphicAnimation(CGraphic *g, int ticksPerFrame);
55 
61  void draw(int x, int y);
62 
67  void update(int ticks);
68 
69  bool isFinished();
70  bool isVisible(const CViewport &vp, const CPosition &pos);
72 };
73 
74 
75 
76 // Base particle class
77 class CParticle
78 {
79 public:
80  CParticle(CPosition position, int drawlevel = 0) :
81  pos(position), destroyed(false), drawLevel(drawlevel)
82  {}
83  virtual ~CParticle() {}
84 
85  virtual bool isVisible(const CViewport &vp) const = 0;
86  virtual void draw() = 0;
87  virtual void update(int) = 0;
88 
89  inline void destroy() { destroyed = true; }
90  inline bool isDestroyed() { return destroyed; }
91 
92  virtual CParticle *clone() = 0;
93 
94  int getDrawLevel() const { return drawLevel; }
95  void setDrawLevel(int value) { drawLevel = value; }
96 
97 protected:
99  bool destroyed;
101 };
102 
103 
104 class StaticParticle : public CParticle
105 {
106 public:
107  StaticParticle(CPosition position, GraphicAnimation *flame, int drawlevel = 0);
108  virtual ~StaticParticle();
109 
110  virtual bool isVisible(const CViewport &vp) const;
111  virtual void draw();
112  virtual void update(int ticks);
113  virtual CParticle *clone();
114 
115 protected:
117 };
118 
119 
120 // Chunk particle
121 class CChunkParticle : public CParticle
122 {
123 public:
126  int minVelocity = 0, int maxVelocity = 400,
127  int minTrajectoryAngle = 77, int maxTTL = 0, int drawlevel = 0);
128  virtual ~CChunkParticle();
129 
130  virtual bool isVisible(const CViewport &vp) const;
131  virtual void draw();
132  virtual void update(int ticks);
133  virtual CParticle *clone();
134  int getSmokeDrawLevel() const { return smokeDrawLevel; }
135  int getDestroyDrawLevel() const { return destroyDrawLevel; }
136  void setSmokeDrawLevel(int value) { smokeDrawLevel = value; }
137  void setDestroyDrawLevel(int value) { destroyDrawLevel = value; }
138 
139 protected:
143  int maxTTL;
145  int lifetime;
146  int age;
150  float height;
156 
157  struct {
158  float x;
159  float y;
160  } direction;
161 };
162 
163 
164 // Smoke particle
165 class CSmokeParticle : public CParticle
166 {
167 public:
168  CSmokeParticle(CPosition position, GraphicAnimation *animation, float speedx = 0, float speedy = -22.0f, int drawlevel = 0);
169  virtual ~CSmokeParticle();
170 
171  virtual bool isVisible(const CViewport &vp) const;
172  virtual void draw();
173  virtual void update(int ticks);
174  virtual CParticle *clone();
175 
176 protected:
178  struct {
179  float x;
180  float y;
181  } speedVector;
182 };
183 
185 {
186 public:
187  CRadialParticle(CPosition position, GraphicAnimation *animation, int maxSpeed, int drawlevel = 0);
188  virtual ~CRadialParticle();
189 
190  virtual bool isVisible(const CViewport &vp) const;
191  virtual void draw();
192  virtual void update(int ticks);
193  virtual CParticle *clone();
194 
195 protected:
197  float direction;
198  int speed;
199  int maxSpeed;
200 };
201 
202 
204 {
205 public:
208 
209  static void init();
210  static void exit();
211 
212  void prepareToDraw(const CViewport &vp, std::vector<CParticle *> &table);
213  void endDraw();
214 
215  void update();
216 
217  void add(CParticle *particle);
218  void clear();
219 
220  CPosition getScreenPos(const CPosition &pos) const;
221 
222  inline void setLowDetail(bool detail) { lowDetail = detail; }
223  inline bool getLowDetail() const { return lowDetail; }
224 
225 private:
226  std::vector<CParticle *> particles;
227  std::vector<CParticle *> new_particles;
228  const CViewport *vp;
229  unsigned long lastTicks;
230  bool lowDetail;
231 };
232 
234 
236 
237 #endif // !__PARTICLE_H__
virtual bool isVisible(const CViewport &vp) const
Definition: smokeparticle.cpp:54
bool destroyed
Definition: particle.h:99
StaticParticle(CPosition position, GraphicAnimation *flame, int drawlevel=0)
Definition: staticparticle.cpp:36
float x
Definition: particle.h:158
GraphicAnimation * destroyAnimation
Definition: particle.h:155
void add(CParticle *particle)
Definition: particlemanager.cpp:121
virtual void draw()
Definition: smokeparticle.cpp:59
int age
Definition: particle.h:146
~GraphicAnimation()
Definition: particle.h:54
virtual void update(int ticks)
Definition: staticparticle.cpp:59
GraphicAnimation * puff
Definition: particle.h:177
int drawLevel
Definition: particle.h:100
int initialVelocity
Definition: particle.h:141
void clear()
Definition: particlemanager.cpp:61
CRadialParticle(CPosition position, GraphicAnimation *animation, int maxSpeed, int drawlevel=0)
Definition: radialparticle.cpp:37
int smokeDrawLevel
Definition: particle.h:151
float trajectoryAngle
Definition: particle.h:142
void prepareToDraw(const CViewport &vp, std::vector< CParticle * > &table)
Definition: particlemanager.cpp:80
virtual ~CSmokeParticle()
Definition: smokeparticle.cpp:49
int minTrajectoryAngle
Definition: particle.h:149
virtual CParticle * clone()
Definition: chunkparticle.cpp:152
void endDraw()
Definition: particlemanager.cpp:94
virtual void draw()
Definition: staticparticle.cpp:53
int maxTTL
Definition: particle.h:143
float y
Definition: particle.h:180
GraphicAnimation * debrisAnimation
Definition: particle.h:153
void update()
Definition: particlemanager.cpp:99
virtual bool isVisible(const CViewport &vp) const
Definition: radialparticle.cpp:55
void setDestroyDrawLevel(int value)
Definition: particle.h:137
float x
Definition: particle.h:179
virtual void update(int ticks)
Definition: smokeparticle.cpp:65
Definition: particle.h:184
int getDrawLevel() const
Definition: particle.h:94
GraphicAnimation * animation
Definition: particle.h:196
Definition: video.h:64
Definition: viewport.h:63
CParticle(CPosition position, int drawlevel=0)
Definition: particle.h:80
int getSmokeDrawLevel() const
Definition: particle.h:134
CParticleManager()
Definition: particlemanager.cpp:43
float y
Definition: particle.h:43
GraphicAnimation * clone()
Definition: graphicanimation.cpp:99
virtual bool isVisible(const CViewport &vp) const
Definition: staticparticle.cpp:48
int destroyDrawLevel
Definition: particle.h:152
virtual CParticle * clone()
Definition: radialparticle.cpp:77
int speed
Definition: particle.h:198
void update(int ticks)
Definition: graphicanimation.cpp:55
static void init()
Definition: particlemanager.cpp:52
CChunkParticle(CPosition position, GraphicAnimation *smokeAnimation, GraphicAnimation *debrisAnimation, GraphicAnimation *destroyAnimation, int minVelocity=0, int maxVelocity=400, int minTrajectoryAngle=77, int maxTTL=0, int drawlevel=0)
Definition: chunkparticle.cpp:47
virtual CParticle * clone()
Definition: staticparticle.cpp:67
bool getLowDetail() const
Definition: particle.h:223
float direction
Definition: particle.h:197
virtual void draw()
Definition: radialparticle.cpp:60
GraphicAnimation * smokeAnimation
Definition: particle.h:154
Definition: particle.h:40
virtual CParticle * clone()=0
void draw(int x, int y)
Definition: graphicanimation.cpp:48
Definition: particle.h:165
bool isVisible(const CViewport &vp, const CPosition &pos)
Definition: graphicanimation.cpp:69
Definition: particle.h:121
virtual ~CParticle()
Definition: particle.h:83
int maxVelocity
Definition: particle.h:148
Definition: particle.h:203
float height
Definition: particle.h:150
bool isDestroyed()
Definition: particle.h:90
struct CChunkParticle::@17 direction
virtual CParticle * clone()
Definition: smokeparticle.cpp:78
float y
Definition: particle.h:159
CPosition pos
Definition: particle.h:98
static void exit()
Definition: particlemanager.cpp:56
virtual void update(int ticks)
Definition: chunkparticle.cpp:108
GraphicAnimation(CGraphic *g, int ticksPerFrame)
Definition: graphicanimation.cpp:41
virtual void update(int)=0
void setLowDetail(bool detail)
Definition: particle.h:222
virtual ~CChunkParticle()
Definition: chunkparticle.cpp:72
virtual ~CRadialParticle()
Definition: radialparticle.cpp:50
virtual void update(int ticks)
Definition: radialparticle.cpp:66
virtual ~StaticParticle()
Definition: staticparticle.cpp:43
struct CSmokeParticle::@18 speedVector
int nextSmokeTicks
Definition: particle.h:144
int maxSpeed
Definition: particle.h:199
int minVelocity
Definition: particle.h:147
Definition: particle.h:46
bool isFinished()
Definition: graphicanimation.cpp:64
~CParticleManager()
Definition: particlemanager.cpp:48
CSmokeParticle(CPosition position, GraphicAnimation *animation, float speedx=0, float speedy=-22.0f, int drawlevel=0)
Definition: smokeparticle.cpp:38
virtual void draw()=0
virtual void draw()
Definition: chunkparticle.cpp:90
virtual bool isVisible(const CViewport &vp) const =0
Definition: particle.h:77
CPosition initialPos
Definition: particle.h:140
int lifetime
Definition: particle.h:145
void destroy()
Definition: particle.h:89
void setDrawLevel(int value)
Definition: particle.h:95
Definition: particle.h:104
virtual bool isVisible(const CViewport &vp) const
Definition: chunkparticle.cpp:85
GraphicAnimation * animation
Definition: particle.h:116
CParticleManager ParticleManager
Definition: particlemanager.cpp:40
CPosition(float x, float y)
Definition: particle.h:41
int getDestroyDrawLevel() const
Definition: particle.h:135
void setSmokeDrawLevel(int value)
Definition: particle.h:136
float x
Definition: particle.h:42
CPosition getScreenPos(const CPosition &pos) const
Definition: particlemanager.cpp:126
(C) Copyright 1998-2012 by The Stratagus Project under the GNU General Public License.
All trademarks and copyrights on this page are owned by their respective owners.