From ad789329d1614dac83a0a2ae18f802cad29d9800 Mon Sep 17 00:00:00 2001 From: En Yi Date: Mon, 20 Nov 2023 22:06:58 +0800 Subject: [PATCH] Add emitter component Also, add funciton to check if emitter handle is still alive --- engine/EC.h | 8 ++++++++ engine/engine_conf.h | 2 +- engine/mempool.c | 2 ++ engine/particle_sys.c | 7 +++++++ engine/particle_sys.h | 3 +-- 5 files changed, 19 insertions(+), 3 deletions(-) diff --git a/engine/EC.h b/engine/EC.h index 8de97b7..2ae79ea 100644 --- a/engine/EC.h +++ b/engine/EC.h @@ -26,6 +26,7 @@ typedef enum ComponentEnum { CLIFETIMER_T, CWATERRUNNER_T, CAIRTIMER_T, + CEMITTER_T, } ComponentEnum_t; typedef enum MovementMode { @@ -215,6 +216,13 @@ typedef struct _CMoveable_t { bool gridmove; } CMoveable_t; +typedef uint16_t EmitterHandle; +typedef struct _CEmitter_t +{ + EmitterHandle handle; + Vector2 offset; +} CEmitter_t; + static inline void set_bbox(CBBox_t* p_bbox, unsigned int x, unsigned int y) { p_bbox->size.x = x; diff --git a/engine/engine_conf.h b/engine/engine_conf.h index 15baff0..e141a6e 100644 --- a/engine/engine_conf.h +++ b/engine/engine_conf.h @@ -17,6 +17,6 @@ #define MAX_TILE_TYPES 16 #define N_TAGS 10 -#define N_COMPONENTS 14 +#define N_COMPONENTS 15 #define MAX_COMP_POOL_SIZE 1024 #endif // _ENGINE_CONF_H diff --git a/engine/mempool.c b/engine/mempool.c index 3cd1d99..51190e3 100644 --- a/engine/mempool.c +++ b/engine/mempool.c @@ -77,6 +77,7 @@ static CMoveable_t cmoveable_buffer[MAX_COMP_POOL_SIZE]; static CLifeTimer_t clifetimer_buffer[MAX_COMP_POOL_SIZE]; static CWaterRunner_t cwaterrunner_buffer[32]; static CAirTimer_t cairtimer_buffer[8]; // Only player is expected to have this +static CEmitter_t cemitter_buffer[MAX_COMP_POOL_SIZE]; // Only player is expected to have this // Static allocate mempools static MemPool_t comp_mempools[N_COMPONENTS] = { @@ -94,6 +95,7 @@ static MemPool_t comp_mempools[N_COMPONENTS] = { {clifetimer_buffer, MAX_COMP_POOL_SIZE, sizeof(CLifeTimer_t), NULL, {0}}, {cwaterrunner_buffer, 32, sizeof(CWaterRunner_t), NULL, {0}}, {cairtimer_buffer, 8, sizeof(CAirTimer_t), NULL, {0}}, + {cemitter_buffer, MAX_COMP_POOL_SIZE, sizeof(CEmitter_t), NULL, {0}}, }; static MemPool_t ent_mempool = { .buffer = entity_buffer, diff --git a/engine/particle_sys.c b/engine/particle_sys.c index b231cc0..1ddc141 100644 --- a/engine/particle_sys.c +++ b/engine/particle_sys.c @@ -126,6 +126,13 @@ void unload_emitter_handle(ParticleSystem_t* system, EmitterHandle handle) system->emitters[handle].finished = true; } +bool is_emitter_handle_alive(ParticleSystem_t* system, EmitterHandle handle) +{ + if (handle == 0) return false; + + return system->emitters[handle].active; +} + EmitterHandle play_particle_emitter(ParticleSystem_t* system, const ParticleEmitter_t* in_emitter) { EmitterHandle idx = load_in_particle_emitter(system, in_emitter); diff --git a/engine/particle_sys.h b/engine/particle_sys.h index f8b36e4..9d5dc04 100644 --- a/engine/particle_sys.h +++ b/engine/particle_sys.h @@ -7,8 +7,6 @@ #include #include -typedef uint16_t EmitterHandle; - typedef enum PartEmitterType { EMITTER_UNKNOWN = 0, @@ -86,6 +84,7 @@ void play_emitter_handle(ParticleSystem_t* system, EmitterHandle handle); void stop_emitter_handle(ParticleSystem_t* system, EmitterHandle handle); void update_emitter_handle_position(ParticleSystem_t* system, EmitterHandle handle, Vector2 pos); void unload_emitter_handle(ParticleSystem_t* system, EmitterHandle handle); +bool is_emitter_handle_alive(ParticleSystem_t* system, EmitterHandle handle); void update_particle_system(ParticleSystem_t* system); void draw_particle_system(ParticleSystem_t* system);