1 #include <bz/fx/particle_simulation_internal.h>
3 #include <bz/fx/particle_system_internal.h>
4 #include <bz/math/math.h>
5 #include <bz/math/random.h>
6 #include <bz/memory/allocator.h>
7 #include <bz/types/identifier.h>
9 BZParticleSimulationID
bzFXCreateParticleSimulation(BZMemoryArenaID arena
, size_t maxParticles
, BZParticleSystemID system
, const char *identifierFmt
, ...) {
10 BZParticleSimulationID simulation
= bzMemoryAlloc(arena
, sizeof(BZParticleSimulation
));
11 simulation
->system
= system
;
13 simulation
->maxParticles
= maxParticles
;//10 * 1024;
14 simulation
->nextParticle
= 0;
18 simulation
->spawnTime
= bzMemoryAlloc(arena
, simulation
->maxParticles
* sizeof(float));
19 simulation
->lifetime
= bzMemoryAlloc(arena
, simulation
->maxParticles
* sizeof(float));
20 simulation
->positionX
= bzMemoryAlloc(arena
, simulation
->maxParticles
* sizeof(float));
21 simulation
->positionY
= bzMemoryAlloc(arena
, simulation
->maxParticles
* sizeof(float));
22 simulation
->size
= bzMemoryAlloc(arena
, simulation
->maxParticles
* sizeof(float));
23 simulation
->baseAngle
= bzMemoryAlloc(arena
, simulation
->maxParticles
* sizeof(float));
24 simulation
->angle
= bzMemoryAlloc(arena
, simulation
->maxParticles
* sizeof(float));
25 simulation
->color
= bzMemoryAlloc(arena
, simulation
->maxParticles
* sizeof(float));
26 simulation
->alpha
= bzMemoryAlloc(arena
, simulation
->maxParticles
* sizeof(float));
27 simulation
->userData
= bzMemoryAlloc(arena
, simulation
->maxParticles
* sizeof(void *));
32 void bzFXUpdateParticleSystem(BZParticleSimulationID simulation
, float deltaTime
) {
33 simulation
->time
+= deltaTime
;//1.0f / 30.0f;
34 bzFXUpdateParticleSystemParticles(simulation
->system
,
35 simulation
->maxParticles
,
37 simulation
->spawnTime
,
39 simulation
->positionX
,
40 simulation
->positionY
,
42 simulation
->baseAngle
,
46 simulation
->userData
);
49 void bzFXSpawnParticles(BZParticleSimulationID simulation
, BZIdentifierHash eventIdentifier
, const BZVector
*position
, const float angle
) {
50 BZParticleSystemID particleSystem
= simulation
->system
;
51 simulation
->nextParticle
+= bzFXSpawnParticleSystemParticles(particleSystem
,
54 simulation
->maxParticles
, simulation
->nextParticle
,
56 simulation
->spawnTime
,
58 simulation
->positionX
,
59 simulation
->positionY
,
61 simulation
->baseAngle
,
65 simulation
->userData
);
66 simulation
->nextParticle
%= simulation
->maxParticles
;
69 void bzFXDespawnParticle(BZParticleSimulationID simulation
, size_t idx
) {
70 simulation
->lifetime
[idx
] = 0.0f
;