Colobot
particle.h
Go to the documentation of this file.
1 /*
2  * This file is part of the Colobot: Gold Edition source code
3  * Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
4  * http://epsitec.ch; http://colobot.info; http://github.com/colobot
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see http://gnu.org/licenses
18  */
19 
25 #pragma once
26 
27 
28 #include "graphics/engine/engine.h"
29 
30 #include "object/interface/trace_drawing_object.h"
31 
32 #include "sound/sound_type.h"
33 
34 
35 class CRobotMain;
36 class CObject;
37 class CSoundInterface;
38 
39 
40 // Graphics module namespace
41 namespace Gfx
42 {
43 
44 const short MAXPARTICULE = 500;
45 const short MAXPARTITYPE = 6;
46 const short MAXTRACK = 100;
47 const short MAXTRACKLEN = 10;
48 const short MAXPARTIFOG = 100;
49 const short MAXWHEELTRACE = 1000;
50 
51 const short SH_WORLD = 0; // particle in the world in the interface
52 const short SH_FRONT = 1; // particle in the world on the interface
53 const short SH_INTERFACE = 2; // particle in the interface
54 const short SH_MAX = 3;
55 
56 // type == 0 -> triangles
57 // type == 1 -> effect00 (black background)
58 // type == 2 -> effect01 (black background)
59 // type == 3 -> effect02 (black background)
60 // type == 4 -> text (white background)
61 
62 
64 {
65  PARTIEXPLOT = 1,
67  PARTIMOTOR = 3,
68  PARTIGLINT = 4,
69  PARTIBLITZ = 5,
70  PARTICRASH = 6,
71  PARTIGAS = 7,
72  PARTIFIRE = 9,
73  PARTIFIREZ = 10,
74  PARTIBLUE = 11,
75  PARTISELY = 12,
76  PARTISELR = 13,
77  PARTIGUN1 = 18,
78  PARTIGUN2 = 19,
79  PARTIGUN3 = 20,
80  PARTIGUN4 = 21,
81  PARTIFRAG = 22,
82  PARTIQUEUE = 23,
85  PARTISMOKE1 = 26,
86  PARTISMOKE2 = 27,
87  PARTISMOKE3 = 28,
88  PARTIBLOOD = 30,
89  PARTIBLOODM = 31,
90  PARTIVAPOR = 32,
91  PARTIVIRUS = 33,
92  PARTIRAY1 = 43,
93  PARTIRAY2 = 44,
94  PARTIRAY3 = 45,
95  PARTIFLAME = 47,
96  PARTIBUBBLE = 48,
97  PARTIFLIC = 49,
98  PARTIEJECT = 50,
99  PARTISCRAPS = 51,
100  PARTITOTO = 52,
101  PARTIERROR = 53,
103  PARTIINFO = 54,
104  PARTIQUARTZ = 55,
112  PARTIGUNDEL = 66,
113  PARTIPART = 67,
114  PARTITRACK1 = 68,
115  PARTITRACK2 = 69,
116  PARTITRACK3 = 70,
117  PARTITRACK4 = 71,
118  PARTITRACK5 = 72,
119  PARTITRACK6 = 73,
120  PARTITRACK7 = 74,
121  PARTITRACK8 = 75,
122  PARTITRACK9 = 76,
126  PARTIGLINTb = 88,
127  PARTIGLINTr = 89,
128  PARTILENS1 = 90,
129  PARTILENS2 = 91,
130  PARTILENS3 = 92,
131  PARTILENS4 = 93,
133  PARTISHOW = 95,
134  PARTICHOC = 96,
135  PARTIGFLAT = 97,
137  PARTIROOT = 100,
138  PARTIPLOUF0 = 101,
139  PARTIDROP = 106,
140  PARTIFOG0 = 107,
141  PARTIFOG1 = 108,
142  PARTIFOG2 = 109,
143  PARTIFOG3 = 110,
144  PARTIFOG4 = 111,
145  PARTIFOG5 = 112,
146  PARTIFOG6 = 113,
147  PARTIFOG7 = 114,
148  PARTILIMIT1 = 117,
149  PARTILIMIT2 = 118,
150  PARTILIMIT3 = 119,
151  PARTIWATER = 121,
152  PARTIEXPLOG1 = 122,
153  PARTIEXPLOG2 = 123,
154  PARTIBASE = 124,
155 };
156 
157 enum ParticlePhase
158 {
159  PARPHSTART = 0,
160  PARPHEND = 1,
161 };
162 
163 struct Particle
164 {
165  bool used = false;
166  bool ray = false; // TRUE -> ray with goal
167  unsigned short uniqueStamp = 0;
168  short sheet = 0; // sheet (0..n)
169  ParticleType type = {}; // type PARTI*
170  ParticlePhase phase = {}; // phase PARPH*
171  float mass = 0.0f; // mass of the particle (in rebounding)
172  float weight = 0.0f; // weight of the particle (for noise)
173  float duration = 0.0f; // length of life
174  Math::Vector pos; // absolute position (relative if object links)
175  Math::Vector goal; // goal position (if ray)
176  Math::Vector speed; // speed of displacement
177  float windSensitivity = 0.0f;
178  short bounce = 0; // number of rebounds
179  Math::Point dim; // dimensions of the rectangle
180  float zoom = 0.0f; // zoom (0..1)
181  float angle = 0.0f; // angle of rotation
182  float intensity = 0.0f; // intensity
183  Math::Point texSup; // coordinated upper texture
184  Math::Point texInf; // coordinated lower texture
185  float time = 0.0f; // age of the particle (0..n)
186  float phaseTime = 0.0f; // age at the beginning of phase
187  float testTime = 0.0f; // time since last test
188  CObject* objLink = nullptr; // father object (for example reactor)
189  CObject* objFather = nullptr; // father object (for example reactor)
190  short objRank = 0; // rank of the object, or -1
191  short trackRank = 0; // rank of the drag
192  char text = 0;
193  Color color = Color(1.0f, 1.0f, 1.0f, 1.0f);
194 };
195 
196 struct Track
197 {
198  char used = 0; // TRUE -> drag used
199  char drawParticle = 0;
200  float step = 0.0f; // duration of not
201  float last = 0.0f; // increase last not memorized
202  float intensity = 0.0f; // intensity at starting (0..1)
203  float width = 0.0f; // tail width
204  int posUsed = 0.0f; // number of positions in "pos"
205  int head = 0; // head to write index
206  Math::Vector pos[MAXTRACKLEN];
207  float len[MAXTRACKLEN] = {};
208 };
209 
211 {
212  TraceColor color = TraceColor::Black;
213  Math::Vector pos[4];
214 };
215 
216 
224 {
225 public:
226  CParticle(CEngine* engine);
227  ~CParticle();
228 
230  void SetDevice(CDevice* device);
231 
233  void FlushParticle();
234 
236  void FlushParticle(int sheet);
237 
239  int CreateParticle(Math::Vector pos, Math::Vector speed, Math::Point dim,
240  ParticleType type, float duration = 1.0f, float mass = 0.0f,
241  float windSensitivity = 1.0f, int sheet = 0);
242 
244  int CreateFrag(Math::Vector pos, Math::Vector speed, EngineTriangle* triangle,
245  ParticleType type, float duration = 1.0f, float mass = 0.0f,
246  float windSensitivity = 1.0f, int sheet = 0);
247 
249  int CreatePart(Math::Vector pos, Math::Vector speed, ParticleType type,
250  float duration = 1.0f, float mass = 0.0f, float weight = 0.0f,
251  float windSensitivity = 1.0f, int sheet = 0);
252 
254  int CreateRay(Math::Vector pos, Math::Vector goal, ParticleType type, Math::Point dim,
255  float duration = 1.0f, int sheet = 0);
256 
258  int CreateTrack(Math::Vector pos, Math::Vector speed, Math::Point dim, ParticleType type,
259  float duration = 1.0f, float mass = 0.0f, float length = 10.0f, float width = 1.0f);
260 
262  void CreateWheelTrace(const Math::Vector &p1, const Math::Vector &p2, const Math::Vector &p3,
263  const Math::Vector &p4, TraceColor color);
264 
266  void DeleteParticle(ParticleType type);
268  void DeleteParticle(int channel);
270  void SetObjectLink(int channel, CObject *object);
272  void SetObjectFather(int channel, CObject *object);
273  void SetPosition(int channel, Math::Vector pos);
274  void SetDimension(int channel, Math::Point dim);
275  void SetZoom(int channel, float zoom);
276  void SetAngle(int channel, float angle);
277  void SetIntensity(int channel, float intensity);
278  void SetParam(int channel, Math::Vector pos, Math::Point dim, float zoom, float angle, float intensity);
279  void SetPhase(int channel, ParticlePhase phase, float duration);
280 
282  Math::Vector GetPosition(int channel);
283 
285  Color GetFogColor(Math::Vector pos);
286 
288  void SetFrameUpdate(int sheet, bool update);
290  void FrameParticle(float rTime);
292  void DrawParticle(int sheet);
293 
295  bool ParticleExists(int channel);
296 
297 protected:
299  void DeleteRank(int rank);
305  void GetRankFromChannel(int &channel);
307  void DrawParticleTriangle(int i);
309  void DrawParticleNorm(int i);
311  void DrawParticleFlat(int i);
313  void DrawParticleFog(int i);
315  void DrawParticleRay(int i);
317  void DrawParticleSphere(int i);
319  void DrawParticleCylinder(int i);
321  void DrawParticleText(int i);
323  void DrawParticleWheel(int i);
325  CObject* SearchObjectGun(Math::Vector old, Math::Vector pos, ParticleType type, CObject *father);
327  CObject* SearchObjectRay(Math::Vector pos, Math::Vector goal, ParticleType type, CObject *father);
329  void Play(SoundType sound, Math::Vector pos, float amplitude);
331  bool TrackMove(int i, Math::Vector pos, float progress);
333  void TrackDraw(int i, ParticleType type);
334 
335 protected:
336  CEngine* m_engine = nullptr;
337  CDevice* m_device = nullptr;
338  CTerrain* m_terrain = nullptr;
339  CWater* m_water = nullptr;
340  CRobotMain* m_main = nullptr;
341  CSoundInterface* m_sound = nullptr;
342 
343  Particle m_particle[MAXPARTICULE*MAXPARTITYPE];
344  EngineTriangle m_triangle[MAXPARTICULE]; // triangle if PartiType == 0
345  Track m_track[MAXTRACK];
346  int m_wheelTraceTotal = 0;
347  int m_wheelTraceIndex = 0;
348  WheelTrace m_wheelTrace[MAXWHEELTRACE];
349  int m_totalInterface[MAXPARTITYPE][SH_MAX] = {};
350  bool m_frameUpdate[SH_MAX] = {};
351  int m_fogTotal = 0;
352  int m_fog[MAXPARTIFOG] = {};
353  int m_uniqueStamp = 0;
354  int m_exploGunCounter = 0;
355  float m_lastTimeGunDel = 0.0f;
356  float m_absTime = 0.0f;
357 };
358 
359 
360 } // namespace Gfx
< gravity root smoke
Definition: particle.h:138
< drag 12 (TODO: unused?)
Definition: particle.h:126
< drag 5
Definition: particle.h:119
< black smoke
Definition: particle.h:87
< reflection
Definition: particle.h:69
< red robot lights
Definition: particle.h:77
< gas from the reactor
Definition: particle.h:72
< fog 4
Definition: particle.h:145
ParticleType
Definition: particle.h:63
Main graphics engine - CEngine class.
< drag 10
Definition: particle.h:124
< drag 1
Definition: particle.h:115
< dust after fall
Definition: particle.h:71
< Robby says blah
Definition: particle.h:103
< Robby&#39;s reactor
Definition: particle.h:101
< shows a place
Definition: particle.h:134
< bullet destroyed by shield
Definition: particle.h:113
< black smoke
Definition: particle.h:86
< red reflection
Definition: particle.h:128
< bullet 4 (orgaball)
Definition: particle.h:81
< drop of water
Definition: particle.h:152
< drop
Definition: particle.h:140
< human blood
Definition: particle.h:89
< drag 9
Definition: particle.h:123
< Robby says yes
Definition: particle.h:104
unsigned short uniqueStamp
unique marker added to particle channel ID to make sure this is still the same particle ...
Definition: particle.h:167
< AlienQueen blood
Definition: particle.h:90
< the engine exhaust gas
Definition: particle.h:68
< lightning recharging battery
Definition: particle.h:70
< shows if the ground is flat
Definition: particle.h:136
< brilliance 2 (yellow)
Definition: particle.h:130
< ray 3 (ExchangePost)
Definition: particle.h:95
< drag 6
Definition: particle.h:120
< inflamed tail (TODO: unused?)
Definition: particle.h:83
< brilliance 1 (orange)
Definition: particle.h:129
< shows the limits 1
Definition: particle.h:149
< fog 6
Definition: particle.h:147
< reflection on button
Definition: particle.h:133
A triangle drawn by the graphics engine.
Definition: engine.h:154
< information sphere (emit)
Definition: particle.h:110
< yellow robot lights
Definition: particle.h:76
< drag 11
Definition: particle.h:125
< organic ball mother
Definition: particle.h:84
< shows the limits 2
Definition: particle.h:150
Definition: robotmain.h:159
Particle engine.
Definition: particle.h:223
< blue ball recycler
Definition: particle.h:137
< shows the limits 3
Definition: particle.h:151
< flame
Definition: particle.h:96
Definition: particle.h:210
< drag 3
Definition: particle.h:117
< explosion sphere
Definition: particle.h:106
< blue reflection
Definition: particle.h:127
< technology explosion
Definition: particle.h:66
< ray 1 (turn)
Definition: particle.h:93
2D point
Definition: point.h:50
< drag 8
Definition: particle.h:122
< triangular fragment
Definition: particle.h:82
< Robby says no
Definition: particle.h:102
< fireball grows
Definition: particle.h:74
< circles in the water
Definition: particle.h:98
Terrain loader/generator and manager.
Definition: terrain.h:147
Definition: particle.h:196
< black smoke
Definition: particle.h:88
< drag 4
Definition: particle.h:118
Namespace for (new) graphics code.
Definition: app.h:49
< fog 1
Definition: particle.h:142
< ball explosion 1
Definition: particle.h:153
The graphics engine.
Definition: engine.h:585
< fog 2
Definition: particle.h:143
< botanical sphere (gravity root)
Definition: particle.h:111
< splash
Definition: particle.h:139
SoundType
Enum representing sound file.
Definition: sound_type.h:34
< shock wave
Definition: particle.h:135
< waste from the reactor
Definition: particle.h:100
< fireball shrinks
Definition: particle.h:73
< bubble
Definition: particle.h:97
Water manager/renderer.
Definition: water.h:72
< fog 5
Definition: particle.h:146
< fog 7
Definition: particle.h:148
< energy sphere
Definition: particle.h:107
< ejection from the reactor
Definition: particle.h:99
3D (3x1) vector
Definition: vector.h:53
Defines the SoundType enum.
< fog 0
Definition: particle.h:141
< organic ball daughter
Definition: particle.h:85
< object part
Definition: particle.h:114
RGBA color.
Definition: color.h:39
< blue ball
Definition: particle.h:75
bool used
true if this channel is used, false if not
Definition: particle.h:165
< drag 7
Definition: particle.h:121
< bullet 3 (spider)
Definition: particle.h:80
< bullet 2 (ant)
Definition: particle.h:79
< shield sphere
Definition: particle.h:109
< analysis sphere
Definition: particle.h:108
< reflection crystal
Definition: particle.h:105
< organic explosion
Definition: particle.h:67
< virus (random letter)
Definition: particle.h:92
Base class for all 3D in-game objects.
Definition: object.h:63
< ray 2 (electric arc)
Definition: particle.h:94
< brilliance 3 (red)
Definition: particle.h:131
< brilliance 4 (violet)
Definition: particle.h:132
< bullet 1 (fireball)
Definition: particle.h:78
Sound plugin interface.
Definition: sound.h:60
< drag 2
Definition: particle.h:116
< steam
Definition: particle.h:91
< fog 3
Definition: particle.h:144
Abstract interface of graphics device.
Definition: device.h:323
< ball explosion 2
Definition: particle.h:154
< information sphere (receive)
Definition: particle.h:112
Definition: particle.h:163