Process particles with gamestate processing

main
Cameron Murphy Reikes 2 years ago
parent f780a14406
commit 643479df1d

@ -26,7 +26,7 @@
#define DEBUG_TOOLS
#define CHIPMUNK_INTEGRITY_CHECK
// #define FAT_THRUSTERS
#define NO_GRAVITY
// #define NO_GRAVITY
// #define NO_SUNS
#else

@ -1593,6 +1593,7 @@ static cpVect get_global_hand_pos(cpVect world_mouse_pos, bool *hand_at_arms_len
global_hand_pos = cpvadd(global_hand_pos, entity_pos(myentity()));
return global_hand_pos;
}
static void frame(void)
{
PROFILE_SCOPE("frame")
@ -1977,6 +1978,24 @@ static void frame(void)
{
uint64_t tick_to_predict = tick(&gs);
apply_this_tick_of_input_to_player(tick_to_predict);
// process particles
{
double dt = TIMESTEP;
PARTICLES_ITER(p)
{
if (p->alive)
{
p->alive_for += dt;
p->pos = cpvadd(p->pos, cpvmult(p->vel, dt));
if (p->alive_for > 1.0)
{
p->alive = false;
}
}
}
}
process(&gs, TIMESTEP);
time_to_process -= TIMESTEP;
}
@ -2192,17 +2211,11 @@ static void frame(void)
{
if (p->alive)
{
p->alive_for += dt;
p->pos = cpvadd(p->pos, cpvmult(p->vel, dt));
if (p->alive_for > 1.0)
{
p->alive = false;
}
set_color_values(1.0, 1.0, 1.0, 1.0 - clamp01(p->alive_for));
pipeline_scope(goodpixel_pipeline)
{
sgp_set_image(0, image_pip);
draw_texture_centered(p->pos, 0.15 * p->scaling);
draw_texture_centered(p->pos, 0.2 * p->scaling);
sgp_reset_image(0);
}
}
@ -2233,11 +2246,15 @@ static void frame(void)
rotate_at(entity_rotation(g) + rotangle(b->compass_rotation), entity_pos(b).x, entity_pos(b).y);
if (b->box_type == BoxThruster)
{
// spawn particles
{
cpVect particle_vel = box_vel(b);
particle_vel = cpvadd(particle_vel, cpvmult(box_facing_vector(b), 0.5 + hash11(exec_time)*0.2)); // move outwards from thruster
particle_vel = cpvspin(particle_vel, hash11(exec_time)*0.1);
cpVect additional_vel = cpvmult(box_facing_vector(b), 0.5 + hash11(exec_time) * 0.2); // move outwards from thruster
additional_vel = cpvspin(additional_vel, hash11(exec_time) * 0.1); // some spin
particle_vel = cpvadd(particle_vel, additional_vel);
new_particle(cpvadd(entity_pos(b), cpvmult(box_facing_vector(b), BOX_SIZE * 0.5)), particle_vel);
}
transform_scope()
{
set_color_values(1.0, 1.0, 1.0, 1.0);

Loading…
Cancel
Save