]> git.bts.cx Git - benzene.git/blob - src/bz/fx/particle_simulation.c
Fixed Aseprite rendering system
[benzene.git] / src / bz / fx / particle_simulation.c
1 #include <bz/fx/particle_simulation_internal.h>
2
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>
8
9 BZParticleSimulationID bzFXCreateParticleSimulation(BZMemoryArenaID arena, size_t maxParticles, BZParticleSystemID system, const char *identifierFmt, ...) {
10 BZParticleSimulationID simulation = bzMemoryAlloc(arena, sizeof(BZParticleSimulation));
11 simulation->system = system;
12
13 simulation->maxParticles = maxParticles;//10 * 1024;
14 simulation->nextParticle = 0;
15
16 simulation->time = 0;
17
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 *));
28
29 return simulation;
30 }
31
32 void bzFXUpdateParticleSystem(BZParticleSimulationID simulation, float deltaTime) {
33 simulation->time += deltaTime;//1.0f / 30.0f;
34 bzFXUpdateParticleSystemParticles(simulation->system,
35 simulation->maxParticles,
36 simulation->time,
37 simulation->spawnTime,
38 simulation->lifetime,
39 simulation->positionX,
40 simulation->positionY,
41 simulation->size,
42 simulation->baseAngle,
43 simulation->angle,
44 simulation->color,
45 simulation->alpha,
46 simulation->userData);
47 }
48
49 void bzFXSpawnParticles(BZParticleSimulationID simulation, BZIdentifierHash eventIdentifier, const BZVector *position, const float angle) {
50 BZParticleSystemID particleSystem = simulation->system;
51 simulation->nextParticle += bzFXSpawnParticleSystemParticles(particleSystem,
52 eventIdentifier,
53 position, angle,
54 simulation->maxParticles, simulation->nextParticle,
55 simulation->time,
56 simulation->spawnTime,
57 simulation->lifetime,
58 simulation->positionX,
59 simulation->positionY,
60 simulation->size,
61 simulation->baseAngle,
62 simulation->angle,
63 simulation->color,
64 simulation->alpha,
65 simulation->userData);
66 simulation->nextParticle %= simulation->maxParticles;
67 }
68
69 void bzFXDespawnParticle(BZParticleSimulationID simulation, size_t idx) {
70 simulation->lifetime[idx] = 0.0f;
71 }