World of Might and Magic  0.2.0
Open reimplementation of Might and Magic 6 7 8 game engine
ParticleEngine.cpp
См. документацию.
2 
3 #include "Engine/Engine.h"
4 #include "Engine/LOD.h"
5 #include "Engine/OurMath.h"
6 #include "Engine/Time.h"
7 
8 #include "Outdoor.h"
9 #include "Viewport.h"
10 
11 #include "Sprites.h"
12 
14 
15 //----- (00440DF5) --------------------------------------------------------
16 void TrailParticleGenerator::AddParticle(int x, int y, int z, int bgr16) {
20  particles[num_particles].time_to_live = rand() % 64 + 256;
22  particles[num_particles].bgr16 = bgr16;
23 
24  num_particles++;
25  assert(num_particles < 100);
26 }
27 
28 //----- (00440E91) --------------------------------------------------------
30  int bgr16) {
31  for (int i = 0; i < 5 + rand() % 6; ++i)
32  AddParticle(rand() % 33 + x - 16, rand() % 33 + y - 16, rand() % 33 + z,
33  bgr16);
34 }
35 
36 //----- (00440F07) --------------------------------------------------------
38  for (uint i = 0; i < 100; ++i) {
39  if (particles[i].time_left > 0) {
40  particles[i].x += rand() % 5 + 4;
41  particles[i].y += rand() % 5 - 2;
42  particles[i].z += rand() % 5 - 2;
44  }
45  }
46 }
47 
48 //----- (0048AAC5) --------------------------------------------------------
50  for (uint i = 0; i < 500; ++i)
51  memset(&pParticles[i], 0, sizeof(pParticles[i]));
52 
54 }
55 
56 //----- (0048AAF6) --------------------------------------------------------
58  memset(pParticles, 0, 500 * sizeof(*pParticles));
59  uStartParticle = 500;
60  uEndParticle = 0;
61  uTimeElapsed = 0;
62 }
63 
64 //----- (0048AB23) --------------------------------------------------------
66  signed int v2; // eax@2
67  Particle *v3; // edx@2
68  Particle *v4; // esi@10
69  int v5; // ecx@10
70  // char v6; // zf@10
71 
72  if (!pMiscTimer->bPaused) {
73  v2 = 0;
74  v3 = (Particle *)this;
75  do {
76  if (v3->type == ParticleType_Invalid) break;
77  ++v2;
78  ++v3;
79  } while (v2 < 500);
80  if (v2 < 500) {
81  if (v2 < this->uStartParticle) this->uStartParticle = v2;
82  if (v2 > this->uEndParticle) this->uEndParticle = v2;
83  v4 = &this->pParticles[v2];
84  v4->type = a2->type;
85  v4->x = a2->x;
86  v4->y = a2->y;
87  v4->z = a2->z;
88  v4->_x = a2->x;
89  v4->_y = a2->y;
90  v4->_z = a2->z;
91  v4->flt_10 = a2->r;
92  v4->flt_14 = a2->g;
93  v4->flt_18 = a2->b;
94  v5 = a2->uDiffuse;
95  v4->uParticleColor = v5;
96  v4->uLightColor_bgr = v5;
97  // v6 = (v4->uType & 4) == 0;
98  v4->timeToLive = a2->timeToLive;
99  v4->texture = a2->texture;
100  v4->particle_size = a2->particle_size;
101  if (v4->type & ParticleType_Rotating) {
102  v4->rotation_speed = (rand() % 256) - 128;
103  v4->angle = rand();
104  } else {
105  v4->rotation_speed = 0;
106  v4->angle = 0;
107  }
108  }
109  }
110 }
111 
112 //----- (0048ABF3) --------------------------------------------------------
115  pLines.uNumLines = 0;
116 
118  // if (render->pRenderD3D)
119  {
120  if (pLines.uNumLines) {
122  /*render->pRenderD3D->pDevice->SetTexture(0, 0);
123  render->pRenderD3D->pDevice->DrawPrimitive(
124  D3DPT_LINELIST,
125  D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1,
126  pLines.pLineVertices,
127  pLines.uNumLines,
128  D3DDP_DONOTLIGHT);*/
129  }
130  }
131 }
132 
133 //----- (0048AC65) --------------------------------------------------------
135  unsigned int time; // edi@1
136  // int v5; // eax@3
137  // char v6; // sf@4
138  float v7; // ST4C_4@11
139  double v8; // st7@12
140  // int v9; // eax@12
141  // double v10; // st7@14
142  signed int v19; // [sp+38h] [bp-14h]@1
143  int v20; // [sp+3Ch] [bp-10h]@1
144  unsigned int time_; // [sp+40h] [bp-Ch]@1
145  int v22; // [sp+44h] [bp-8h]@12
146 
147  v20 = 0;
148  time = pMiscTimer->bPaused == 0 ? pEventTimer->uTimeElapsed : 0;
149  v19 = 500;
150  time_ = pMiscTimer->bPaused == 0 ? pEventTimer->uTimeElapsed : 0;
151 
152  for (uint i = uStartParticle; i <= uEndParticle; ++i) {
153  Particle *p = &pParticles[i];
154 
155  if (p->type == ParticleType_Invalid) continue;
156 
157  if (p->timeToLive <= time) {
158  p->timeToLive = 0;
159  p->type = ParticleType_Invalid;
160  continue;
161  }
162  p->timeToLive -= time;
163 
164  if (p->type & ParticleType_Line) {
165  p->_x = p->x;
166  p->_y = p->y;
167  p->_z = p->z;
168  }
169 
170  if (p->type & ParticleType_1)
171  p->flt_18 = p->flt_18 - (double)(signed int)time_ * 5.0;
172 
173  if (p->type & ParticleType_8) {
174  v7 = (double)(signed int)time_;
175  *(float *)&p->x += (double)(rand() % 5 - 2) * v7 / 16.0f;
176  *(float *)&p->y += (double)(rand() % 5 - 2) * v7 / 16.0f;
177  *(float *)&p->z += (double)(rand() % 5 + 4) * v7 / 16.0f;
178  }
179  v8 = (double)(signed int)time_ / 128.0f;
180  // v9 = (signed int)(time * p->rotation_speed) / 16;
181 
182  p->x += v8 * p->flt_10;
183  p->y += v8 * p->flt_14;
184  p->z += v8 * p->flt_18;
185 
186  p->angle += time * p->rotation_speed / 16;
187  v22 = 2 * p->timeToLive;
188  if (v22 >= 255) v22 = 255;
189  // v10 = (double)v22 * 0.0039215689;
190  p->uLightColor_bgr = ((uint)floorf(p->b * (v22 / 255.0f) + 0.5) << 16) |
191  ((uint)floorf(p->g * (v22 / 255.0f) + 0.5) << 8) |
192  ((uint)floorf(p->r * (v22 / 255.0f) + 0.5) << 0);
193  if (i < v19) v19 = i;
194  if (i > v20) v20 = i;
195  }
196 
197  uEndParticle = v20;
198  uStartParticle = v19;
199 }
200 
201 //----- (0048AE74) --------------------------------------------------------
203  unsigned int uParticleID) {
204  Particle *pParticle; // esi@1
205  int y_int_; // [sp+10h] [bp-40h]@2
206  int x_int; // [sp+20h] [bp-30h]@2
207  int z_int_; // [sp+24h] [bp-2Ch]@2
208 
209  pParticle = &this->pParticles[uParticleID];
210  if (pParticle->type == ParticleType_Invalid) return 0;
211  // uParticleID = LODWORD(pParticle->x);
212  // v56 = *(float *)&uParticleID + 6.7553994e15;
213  x_int = floorf(pParticle->x + 0.5f);
214  // uParticleID = LODWORD(pParticle->y);
215  // y_int_ = *(float *)&uParticleID + 6.7553994e15;
216  y_int_ = floorf(pParticle->y + 0.5f);
217  // uParticleID = LODWORD(pParticle->z);
218  // z_int_ = *(float *)&uParticleID + 6.7553994e15;
219  z_int_ = floorf(pParticle->z + 0.5f);
220 
221  /*fixed x, y, z;*/
222  int xt, yt, zt;
223 
224  /*if (!pIndoorCameraD3D->ApplyViewTransform_TrueIfStillVisible_BLV(
225  x_int, y_int_, z_int_, &x, &y, &z, 1))
226  return false;*/
227  if (!pIndoorCameraD3D->ViewClip(x_int, y_int_, z_int_, &xt, &yt, &zt, 0)) return false;
228 
229  /*pIndoorCameraD3D->Project(x.GetInt(), y.GetInt(), z.GetInt(),
230  &pParticle->uScreenSpaceX,
231  &pParticle->uScreenSpaceY);*/
232  pIndoorCameraD3D->Project(xt, yt, zt, &pParticle->uScreenSpaceX, &pParticle->uScreenSpaceY);
233 
235  pParticle->fov_x = pIndoorCameraD3D->fov_x;
236  } else {
237  pParticle->fov_x = pODMRenderParams->int_fov_rad;
238  }
239 
240 
241  // pParticle->fov_x = pIndoorCameraD3D->fov_x; //
242  pParticle->fov_y = pIndoorCameraD3D->fov_y;
243 
244  /*pParticle->screenspace_scale = fixed::FromFloat(pParticle->particle_size) *
245  fixed::FromFloat(pParticle->fov_x) / x;*/
246 
247  pParticle->screenspace_scale = fixed::FromFloat(pParticle->particle_size) *
248  fixed::FromFloat(pParticle->fov_x) / fixed::FromInt(xt);
249 
250  /*pParticle->zbuffer_depth = x.GetInt();*/
251  pParticle->zbuffer_depth = xt;
252 
253  return true;
254 }
255 
256 
257 
258 //----- (0048BBA6) --------------------------------------------------------
260  SoftwareBillboard v15; // [sp+Ch] [bp-58h]@1
261 
262  v15.sParentBillboardID = -1;
263 
264  for (uint i = uStartParticle; i < uEndParticle; ++i) {
265  Particle *p = &pParticles[i];
266 
267  if (p->type == ParticleType_Invalid) continue;
268 
269  if (!ViewProject_TrueIfStillVisible_BLV(i)) continue;
270 
271  if (true) {
272  /*p->uScreenSpaceX >= pBLVRenderParams->uViewportX &&
273  p->uScreenSpaceX < pBLVRenderParams->uViewportZ &&
274  p->uScreenSpaceY >= pBLVRenderParams->uViewportY &&
275  p->uScreenSpaceY < pBLVRenderParams->uViewportW) { */
276  if (p->type & ParticleType_Diffuse) {
277  // v14 = &pParticles[i];
278  v15.screenspace_projection_factor_x = p->screenspace_scale.GetFloat();
279  v15.screenspace_projection_factor_y = p->screenspace_scale.GetFloat();
280  v15.screen_space_x = p->uScreenSpaceX;
281  v15.screen_space_y = p->uScreenSpaceY;
282  v15.object_pid = p->object_pid;
283  v15.screen_space_z = p->zbuffer_depth;
284  render->MakeParticleBillboardAndPush(
285  &v15, 0, p->uLightColor_bgr, p->angle);
286  } else if (p->type & ParticleType_Line) { // type doesnt appear to be used
287  if (pLines.uNumLines < 100) {
289  p->uScreenSpaceX;
291  p->uScreenSpaceY;
293  1.0 - 1.0 / (p->zbuffer_depth * 0.061758894);
296  p->uLightColor_bgr;
300 
302  p->uScreenSpaceZ; // where is this set?
304  p->uScreenSpaceW;
306  1.0 - 1.0 / ((short)p->sZValue2 * 0.061758894);
307  pLines.pLineVertices[2 * pLines.uNumLines + 1].rhw = 1.0;
309  p->uLightColor_bgr;
312  0.0;
314  .texcoord.y = 0.0;
315  }
316  } else if (p->type & ParticleType_Bitmap) {
317  v15.screenspace_projection_factor_x = p->screenspace_scale.GetFloat();
318  v15.screenspace_projection_factor_y = p->screenspace_scale.GetFloat();
319  v15.screen_space_x = p->uScreenSpaceX;
320  v15.screen_space_y = p->uScreenSpaceY;
321  v15.object_pid = p->object_pid;
322  v15.screen_space_z = p->zbuffer_depth;
323  render->MakeParticleBillboardAndPush(
324  &v15, p->texture, p->uLightColor_bgr, p->angle);
325  } else if (p->type & ParticleType_Sprite) {
326  v15.screenspace_projection_factor_x = p->screenspace_scale.GetFloat();
327  v15.screenspace_projection_factor_y = p->screenspace_scale.GetFloat();
328  v15.screen_space_x = p->uScreenSpaceX;
329  v15.screen_space_y = p->uScreenSpaceY;
330  v15.object_pid = p->object_pid;
331  v15.screen_space_z = p->zbuffer_depth;
332  render->MakeParticleBillboardAndPush(
333  &v15, p->texture, p->uLightColor_bgr, p->angle);
334  }
335  }
336  }
337 }
338 
Particle_sw::z
float z
Definition: ParticleEngine.h:22
ParticleEngine.h
ParticleEngine::Draw
void Draw()
Definition: ParticleEngine.cpp:113
Particle::flt_10
float flt_10
Definition: ParticleEngine.h:45
fixed::FromFloat
static fixed FromFloat(float f)
Definition: OurMath.h:25
Viewport.h
Particle_sw::b
float b
Definition: ParticleEngine.h:25
Timer::uTimeElapsed
unsigned int uTimeElapsed
Definition: Time.h:133
TrailParticleGenerator::UpdateParticles
void UpdateParticles()
Definition: ParticleEngine.cpp:37
LOD.h
TrailParticleGenerator::particles
TrailParticle particles[100]
Definition: ParticleEngine.h:159
Vec3_float_::x
float x
Definition: VectorTypes.h:89
RenderVertexD3D3::pos
Vec3_float_ pos
Definition: IRender.h:130
z
GLdouble GLdouble z
Definition: SDL_opengl_glext.h:407
Particle::uScreenSpaceY
int uScreenSpaceY
Definition: ParticleEngine.h:64
ParticleEngine::UpdateParticles
void UpdateParticles()
Definition: ParticleEngine.cpp:134
Particle::timeToLive
int timeToLive
Definition: ParticleEngine.h:54
SoftwareBillboard::screenspace_projection_factor_y
float screenspace_projection_factor_y
Definition: IRender.h:177
Timer::bPaused
unsigned int bPaused
Definition: Time.h:127
Particle::uLightColor_bgr
int uLightColor_bgr
Definition: ParticleEngine.h:78
SoftwareBillboard::screenspace_projection_factor_x
float screenspace_projection_factor_x
Definition: IRender.h:176
ParticleEngine::ViewProject_TrueIfStillVisible_BLV
bool ViewProject_TrueIfStillVisible_BLV(unsigned int uParticleID)
Definition: ParticleEngine.cpp:202
Particle_sw::r
float r
Definition: ParticleEngine.h:23
Particle::uParticleColor
unsigned int uParticleColor
Definition: ParticleEngine.h:52
Vec3_float_::y
float y
Definition: VectorTypes.h:90
Vec3_float_::z
float z
Definition: VectorTypes.h:91
TrailParticle::z
int16_t z
Definition: ParticleEngine.h:134
Engine.h
RenderVertexD3D3::texcoord
Vec2_float_ texcoord
Definition: IRender.h:134
trail_particle_generator
TrailParticleGenerator trail_particle_generator
Definition: ParticleEngine.cpp:13
Particle::screenspace_scale
fixed screenspace_scale
Definition: ParticleEngine.h:75
fixed::FromInt
static fixed FromInt(int value)
Definition: OurMath.h:29
Particle_sw::type
unsigned int type
Definition: ParticleEngine.h:19
y
EGLSurface EGLint EGLint y
Definition: SDL_egl.h:1596
RenderVertexD3D3::rhw
float rhw
Definition: IRender.h:131
Particle
Definition: ParticleEngine.h:40
ParticleEngine::ResetParticles
void ResetParticles()
Definition: ParticleEngine.cpp:57
TrailParticle::time_left
int16_t time_left
Definition: ParticleEngine.h:135
SoftwareBillboard
Definition: IRender.h:170
Particle::fov_x
float fov_x
Definition: ParticleEngine.h:76
ParticleType_1
@ ParticleType_1
Definition: ParticleEngine.h:7
TrailParticle::time_to_live
int16_t time_to_live
Definition: ParticleEngine.h:136
p
GLfloat GLfloat p
Definition: SDL_opengl_glext.h:11093
Particle::flt_18
float flt_18
Definition: ParticleEngine.h:47
x
EGLSurface EGLint x
Definition: SDL_egl.h:1596
TrailParticleGenerator::AddParticle
void AddParticle(int x, int y, int z, int bgr16)
Definition: ParticleEngine.cpp:16
Particle_sw::timeToLive
int timeToLive
Definition: ParticleEngine.h:27
SoftwareBillboard::screen_space_z
short screen_space_z
Definition: IRender.h:175
IndoorCameraD3D::ViewClip
bool ViewClip(int x, int y, int z, int *transformed_x, int *transformed_y, int *transformed_z, bool dont_show=false)
Definition: IndoorCameraD3D.cpp:172
Particle::x
float x
Definition: ParticleEngine.h:42
RenderVertexD3D3::diffuse
unsigned int diffuse
Definition: IRender.h:132
IndoorCameraD3D::Project
void Project(int x, int y, int z, int *screenspace_x, int *screenspace_y)
Definition: IndoorCameraD3D.cpp:1137
ParticleType_Line
@ ParticleType_Line
Definition: ParticleEngine.h:11
TrailParticle::x
int16_t x
Definition: ParticleEngine.h:132
Particle_sw
Definition: ParticleEngine.h:18
ParticleEngine::pParticles
Particle pParticles[500]
Definition: ParticleEngine.h:104
f
GLfloat f
Definition: SDL_opengl_glext.h:1873
ParticleType_Diffuse
@ ParticleType_Diffuse
Definition: ParticleEngine.h:10
TrailParticleGenerator
Definition: ParticleEngine.h:149
Particle_sw::y
float y
Definition: ParticleEngine.h:21
Particle_sw::g
float g
Definition: ParticleEngine.h:24
Particle::rotation_speed
int rotation_speed
Definition: ParticleEngine.h:61
SoftwareBillboard::screen_space_x
int screen_space_x
Definition: IRender.h:173
Particle::fov_y
float fov_y
Definition: ParticleEngine.h:77
stru2_LineList::pLineVertices
RenderVertexD3D3 pLineVertices[48]
Definition: ParticleEngine.h:86
IndoorCameraD3D::fov_y
float fov_y
Definition: IndoorCameraD3D.h:193
ParticleEngine::AddParticle
void AddParticle(Particle_sw *a2)
Definition: ParticleEngine.cpp:65
pMiscTimer
Timer * pMiscTimer
Definition: Time.cpp:7
Outdoor.h
Particle::_y
float _y
Definition: ParticleEngine.h:59
LEVEL_Indoor
@ LEVEL_Indoor
Definition: Indoor.h:286
ParticleType_Sprite
@ ParticleType_Sprite
Definition: ParticleEngine.h:13
TrailParticleGenerator::GenerateTrailParticles
void GenerateTrailParticles(int x, int y, int z, int bgr16)
Definition: ParticleEngine.cpp:29
SoftwareBillboard::screen_space_y
int screen_space_y
Definition: IRender.h:174
ParticleEngine::ParticleEngine
ParticleEngine()
Definition: ParticleEngine.cpp:49
stru2_LineList::uNumLines
unsigned int uNumLines
Definition: ParticleEngine.h:85
pODMRenderParams
ODMRenderParams * pODMRenderParams
Definition: Outdoor.cpp:49
Particle::z
float z
Definition: ParticleEngine.h:44
ParticleEngine::uStartParticle
int uStartParticle
Definition: ParticleEngine.h:108
Particle::flt_14
float flt_14
Definition: ParticleEngine.h:46
ParticleType_8
@ ParticleType_8
Definition: ParticleEngine.h:9
Particle_sw::texture
Texture * texture
Definition: ParticleEngine.h:28
ParticleType_Invalid
@ ParticleType_Invalid
Definition: ParticleEngine.h:6
v2
GLfloat GLfloat GLfloat v2
Definition: SDL_opengl_glext.h:695
uint
unsigned int uint
Definition: MM7.h:4
v3
GLfloat GLfloat GLfloat GLfloat v3
Definition: SDL_opengl_glext.h:696
SoftwareBillboard::sParentBillboardID
int sParentBillboardID
Definition: IRender.h:188
Particle::particle_size
float particle_size
Definition: ParticleEngine.h:57
ParticleEngine::uEndParticle
int uEndParticle
Definition: ParticleEngine.h:109
Particle_sw::particle_size
float particle_size
Definition: ParticleEngine.h:30
ParticleEngine::uTimeElapsed
int uTimeElapsed
Definition: ParticleEngine.h:110
ParticleType_Rotating
@ ParticleType_Rotating
Definition: ParticleEngine.h:8
Particle::type
unsigned int type
Definition: ParticleEngine.h:41
ParticleEngine::DrawParticles_BLV
void DrawParticles_BLV()
Definition: ParticleEngine.cpp:259
Particle_sw::x
float x
Definition: ParticleEngine.h:20
Particle::_x
float _x
Definition: ParticleEngine.h:58
OurMath.h
uCurrentlyLoadedLevelType
LEVEL_TYPE uCurrentlyLoadedLevelType
Definition: Indoor.cpp:52
IndoorCameraD3D::fov_x
float fov_x
Definition: IndoorCameraD3D.h:192
ODMRenderParams::int_fov_rad
int int_fov_rad
Definition: IRender.h:79
TrailParticle::y
int16_t y
Definition: ParticleEngine.h:133
TrailParticle::bgr16
int16_t bgr16
Definition: ParticleEngine.h:141
ParticleType_Bitmap
@ ParticleType_Bitmap
Definition: ParticleEngine.h:12
Particle::uScreenSpaceX
int uScreenSpaceX
Definition: ParticleEngine.h:63
Particle::texture
Texture * texture
Definition: ParticleEngine.h:55
ParticleEngine::pLines
stru2_LineList pLines
Definition: ParticleEngine.h:105
RenderVertexD3D3::specular
unsigned int specular
Definition: IRender.h:133
Particle::_z
float _z
Definition: ParticleEngine.h:60
Particle::zbuffer_depth
short zbuffer_depth
Definition: ParticleEngine.h:71
TrailParticleGenerator::num_particles
int num_particles
Definition: ParticleEngine.h:160
Particle::y
float y
Definition: ParticleEngine.h:43
pIndoorCameraD3D
IndoorCameraD3D * pIndoorCameraD3D
Definition: IndoorCameraD3D.cpp:21
pEventTimer
Timer * pEventTimer
Definition: Time.cpp:8
Sprites.h
Particle::angle
int angle
Definition: ParticleEngine.h:62
SoftwareBillboard::object_pid
unsigned short object_pid
Definition: IRender.h:190
Time.h
render
std::shared_ptr< IRender > render
Definition: RenderOpenGL.cpp:52
Particle_sw::uDiffuse
unsigned int uDiffuse
Definition: ParticleEngine.h:26