2024-03-25 14:59:00 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "types.h"
|
|
|
|
#include "render_util.h"
|
|
|
|
#include "util/tree.h"
|
|
|
|
#include "util/vector.h"
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2024-04-16 21:08:21 +08:00
|
|
|
#define PARTICLE_LAYER_COUNT 4
|
|
|
|
|
|
|
|
|
2024-03-25 14:59:00 +08:00
|
|
|
// A particle instance.
|
|
|
|
typedef struct {
|
|
|
|
uintptr_t id; // ID.
|
|
|
|
double size, sizedec; // Diameter & decrease speed, size=0 and the particle is removed
|
|
|
|
Duration tolive; // Time desiginated to live, 0 for forever
|
|
|
|
TimePoint addtime; // Time when this particle is added
|
|
|
|
|
|
|
|
Vec2 pos, vec; // Center & Speed
|
|
|
|
double vec_friction; // Friction, fraction of Vec per second
|
|
|
|
|
|
|
|
const FillMode *mode; // Fill Modes, NULL for default mode (solid fill)
|
|
|
|
} Particle;
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct _App App;
|
|
|
|
|
|
|
|
// Particle system.
|
|
|
|
typedef struct {
|
|
|
|
App *super;
|
2024-04-16 21:08:21 +08:00
|
|
|
tree_Tree *parts[PARTICLE_LAYER_COUNT]; // uintptr_t -> struct Particle
|
2024-03-25 14:59:00 +08:00
|
|
|
vector_Vector *deleted_ids;
|
|
|
|
uintptr_t maxID;
|
|
|
|
} System_Particle;
|
|
|
|
|
|
|
|
System_Particle *particle_NewSystem(App *super);
|
|
|
|
void particle_DeleteSystem(System_Particle *sys);
|
|
|
|
|
|
|
|
void particle_Advance(System_Particle *sys, Duration deltaTime);
|
|
|
|
void particle_Render(System_Particle *sys);
|
|
|
|
|
|
|
|
|
|
|
|
// Emit a particle here.
|
2024-04-16 21:08:21 +08:00
|
|
|
void particle_Emit(System_Particle *sys, int layer, Vec2 pos, Vec2 vec, double vec_friction, double size, double sizedec, Duration tolive, const FillMode *fill);
|
2024-03-25 14:59:00 +08:00
|
|
|
|
2024-04-11 17:01:22 +08:00
|
|
|
// Clear all particles.
|
|
|
|
void particle_Clear(System_Particle *sys);
|
|
|
|
|
2024-03-25 14:59:00 +08:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|