Add delta time into particle system updates
Only update the callbacks to use itscene_man
parent
0a3f56f730
commit
c76ceba9bf
|
@ -163,7 +163,7 @@ void update_particle_system(ParticleSystem_t* system, float delta_time)
|
|||
|
||||
if (emitter->emitter_update_func != NULL && emitter->active)
|
||||
{
|
||||
emitter->active = emitter->emitter_update_func(emitter);
|
||||
emitter->active = emitter->emitter_update_func(emitter, delta_time);
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < emitter->n_particles; ++i)
|
||||
|
@ -175,7 +175,7 @@ void update_particle_system(ParticleSystem_t* system, float delta_time)
|
|||
{
|
||||
if (emitter->update_func != NULL)
|
||||
{
|
||||
emitter->update_func(emitter->particles + i, emitter->user_data);
|
||||
emitter->update_func(emitter->particles + i, emitter->user_data, delta_time);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -29,8 +29,8 @@ typedef struct Particle
|
|||
|
||||
typedef struct ParticleEmitter ParticleEmitter_t;
|
||||
|
||||
typedef void (*particle_update_func_t)(Particle_t* part, void* user_data);
|
||||
typedef bool (*emitter_check_func_t)(const ParticleEmitter_t* emitter);
|
||||
typedef void (*particle_update_func_t)(Particle_t* part, void* user_data, float delta_time);
|
||||
typedef bool (*emitter_check_func_t)(const ParticleEmitter_t* emitter, float delta_time);
|
||||
|
||||
typedef struct EmitterConfig
|
||||
{
|
||||
|
|
|
@ -6,9 +6,9 @@
|
|||
#include "constants.h"
|
||||
static const Vector2 GRAVITY = {0, GRAV_ACCEL};
|
||||
|
||||
void simple_particle_system_update(Particle_t* part, void* user_data)
|
||||
void simple_particle_system_update(Particle_t* part, void* user_data, float delta_time)
|
||||
{
|
||||
float delta_time = *(float*)user_data; // TODO: Will need to think about delta time handling
|
||||
(void)user_data;
|
||||
part->rotation += part->angular_vel;
|
||||
|
||||
part->velocity =
|
||||
|
@ -44,7 +44,7 @@ void simple_particle_system_update(Particle_t* part, void* user_data)
|
|||
}
|
||||
}
|
||||
|
||||
static bool check_mouse_click(const ParticleEmitter_t* emitter)
|
||||
static bool check_mouse_click(const ParticleEmitter_t* emitter, float delta_time)
|
||||
{
|
||||
return IsMouseButtonDown(MOUSE_RIGHT_BUTTON);
|
||||
}
|
||||
|
@ -108,7 +108,7 @@ int main(void)
|
|||
.update_func = &simple_particle_system_update,
|
||||
.emitter_update_func = &check_mouse_click,
|
||||
.spr = (tex.width == 0) ? NULL : &spr,
|
||||
.user_data = &delta_time,
|
||||
.user_data = NULL,
|
||||
};
|
||||
|
||||
bool key_press = false;
|
||||
|
|
|
@ -6,9 +6,9 @@
|
|||
#include "constants.h"
|
||||
#include <stdio.h>
|
||||
|
||||
void simple_particle_system_update(Particle_t* part, void* user_data);
|
||||
void floating_particle_system_update(Particle_t* part, void* user_data);
|
||||
bool check_in_water(const ParticleEmitter_t* emitter);
|
||||
void simple_particle_system_update(Particle_t* part, void* user_data, float delta_time);
|
||||
void floating_particle_system_update(Particle_t* part, void* user_data, float delta_time);
|
||||
bool check_in_water(const ParticleEmitter_t* emitter, float delta_time);
|
||||
|
||||
static const Vector2 GRAVITY = {0, GRAV_ACCEL};
|
||||
static const Vector2 UPTHRUST = {0, -GRAV_ACCEL * 1.1};
|
||||
|
@ -2158,19 +2158,20 @@ static inline bool is_point_in_water(Vector2 pos, TileGrid_t tilemap)
|
|||
);
|
||||
}
|
||||
|
||||
bool check_in_water(const ParticleEmitter_t* emitter)
|
||||
bool check_in_water(const ParticleEmitter_t* emitter, float delta_time)
|
||||
{
|
||||
(void)delta_time;
|
||||
|
||||
LevelScene_t* scene = (LevelScene_t*)emitter->user_data;
|
||||
TileGrid_t tilemap = scene->data.tilemap;
|
||||
return is_point_in_water(emitter->position, tilemap);
|
||||
}
|
||||
|
||||
void simple_particle_system_update(Particle_t* part, void* user_data)
|
||||
void simple_particle_system_update(Particle_t* part, void* user_data, float delta_time)
|
||||
{
|
||||
LevelScene_t* scene = (LevelScene_t*)user_data;
|
||||
TileGrid_t tilemap = scene->data.tilemap;
|
||||
|
||||
float delta_time = scene->scene.delta_time;
|
||||
part->velocity =
|
||||
Vector2Add(
|
||||
part->velocity,
|
||||
|
@ -2208,12 +2209,11 @@ void simple_particle_system_update(Particle_t* part, void* user_data)
|
|||
}
|
||||
}
|
||||
|
||||
void simple_float_particle_system_update(Particle_t* part, void* user_data)
|
||||
void simple_float_particle_system_update(Particle_t* part, void* user_data, float delta_time)
|
||||
{
|
||||
LevelScene_t* scene = (LevelScene_t*)user_data;
|
||||
TileGrid_t tilemap = scene->data.tilemap;
|
||||
|
||||
float delta_time = scene->scene.delta_time;
|
||||
part->position = Vector2Add(
|
||||
part->position,
|
||||
Vector2Scale(part->velocity, delta_time)
|
||||
|
@ -2236,9 +2236,9 @@ void simple_float_particle_system_update(Particle_t* part, void* user_data)
|
|||
}
|
||||
}
|
||||
|
||||
void floating_particle_system_update(Particle_t* part, void* user_data)
|
||||
void floating_particle_system_update(Particle_t* part, void* user_data, float delta_time)
|
||||
{
|
||||
simple_float_particle_system_update(part, user_data);
|
||||
simple_float_particle_system_update(part, user_data, delta_time);
|
||||
|
||||
LevelScene_t* scene = (LevelScene_t*)user_data;
|
||||
TileGrid_t tilemap = scene->data.tilemap;
|
||||
|
|
Loading…
Reference in New Issue