JacksEscape/particle.h
2024-04-16 21:08:21 +08:00

58 lines
1.4 KiB
C

#pragma once
#include "types.h"
#include "render_util.h"
#include "util/tree.h"
#include "util/vector.h"
#ifdef __cplusplus
extern "C" {
#endif
#define PARTICLE_LAYER_COUNT 4
// 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;
tree_Tree *parts[PARTICLE_LAYER_COUNT]; // uintptr_t -> struct Particle
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.
void particle_Emit(System_Particle *sys, int layer, Vec2 pos, Vec2 vec, double vec_friction, double size, double sizedec, Duration tolive, const FillMode *fill);
// Clear all particles.
void particle_Clear(System_Particle *sys);
#ifdef __cplusplus
}
#endif