cleanup
This commit is contained in:
parent
9f96626ea7
commit
6a02b24ae6
29 changed files with 653 additions and 583 deletions
|
|
@ -4,31 +4,6 @@
|
|||
#include <stdlib.h>
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
void pxl8_vfx_copper_bars(pxl8_gfx_ctx* ctx, pxl8_copper_bar* bars, u32 bar_count, f32 time) {
|
||||
if (!ctx || !bars) return;
|
||||
|
||||
for (u32 i = 0; i < bar_count; i++) {
|
||||
pxl8_copper_bar* bar = &bars[i];
|
||||
f32 y = bar->base_y + bar->amplitude * sinf(time * bar->speed + bar->phase);
|
||||
i32 y_int = (i32)y;
|
||||
|
||||
for (i32 dy = 0; dy <= bar->height; dy++) {
|
||||
f32 position = (f32)dy / (f32)bar->height;
|
||||
f32 gradient = 1.0f - 2.0f * fabsf(position - 0.5f);
|
||||
|
||||
u8 color_idx;
|
||||
if (gradient > 0.8f) {
|
||||
color_idx = bar->fade_color;
|
||||
} else {
|
||||
u8 range = bar->fade_color - bar->color;
|
||||
color_idx = bar->color + (u8)(gradient * range);
|
||||
}
|
||||
|
||||
pxl8_rect_fill(ctx, 0, y_int + dy, ctx->framebuffer_width, 1, color_idx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void pxl8_vfx_plasma(pxl8_gfx_ctx* ctx, f32 time, f32 scale1, f32 scale2, u8 palette_offset) {
|
||||
if (!ctx || !ctx->framebuffer) return;
|
||||
|
||||
|
|
@ -50,6 +25,31 @@ void pxl8_vfx_plasma(pxl8_gfx_ctx* ctx, f32 time, f32 scale1, f32 scale2, u8 pal
|
|||
}
|
||||
}
|
||||
|
||||
void pxl8_vfx_raster_bars(pxl8_gfx_ctx* ctx, pxl8_raster_bar* bars, u32 bar_count, f32 time) {
|
||||
if (!ctx || !bars) return;
|
||||
|
||||
for (u32 i = 0; i < bar_count; i++) {
|
||||
pxl8_raster_bar* bar = &bars[i];
|
||||
f32 y = bar->base_y + bar->amplitude * sinf(time * bar->speed + bar->phase);
|
||||
i32 y_int = (i32)y;
|
||||
|
||||
for (i32 dy = 0; dy <= bar->height; dy++) {
|
||||
f32 position = (f32)dy / (f32)bar->height;
|
||||
f32 gradient = 1.0f - 2.0f * fabsf(position - 0.5f);
|
||||
|
||||
u8 color_idx;
|
||||
if (gradient > 0.8f) {
|
||||
color_idx = bar->fade_color;
|
||||
} else {
|
||||
u8 range = bar->fade_color - bar->color;
|
||||
color_idx = bar->color + (u8)(gradient * range);
|
||||
}
|
||||
|
||||
pxl8_rect_fill(ctx, 0, y_int + dy, ctx->framebuffer_width, 1, color_idx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void pxl8_vfx_rotozoom(pxl8_gfx_ctx* ctx, f32 angle, f32 zoom, i32 cx, i32 cy) {
|
||||
if (!ctx || !ctx->framebuffer) return;
|
||||
|
||||
|
|
@ -141,15 +141,16 @@ void pxl8_vfx_water_ripple(pxl8_gfx_ctx* ctx, f32* height_map, i32 drop_x, i32 d
|
|||
|
||||
void pxl8_vfx_particles_clear(pxl8_particle_system* sys) {
|
||||
if (!sys || !sys->particles) return;
|
||||
|
||||
|
||||
for (u32 i = 0; i < sys->max_count; i++) {
|
||||
sys->particles[i].life = 0;
|
||||
sys->particles[i].flags = 0;
|
||||
}
|
||||
sys->alive_count = 0;
|
||||
sys->spawn_timer = 0;
|
||||
}
|
||||
|
||||
void pxl8_vfx_particles_destroy(pxl8_particle_system* sys) {
|
||||
void pxl8_vfx_particles_free(pxl8_particle_system* sys) {
|
||||
if (!sys) return;
|
||||
|
||||
if (sys->particles) {
|
||||
|
|
@ -272,13 +273,14 @@ void pxl8_vfx_particles_update(pxl8_particle_system* sys, f32 dt) {
|
|||
|
||||
void pxl8_vfx_explosion(pxl8_particle_system* sys, i32 x, i32 y, u32 color, f32 force) {
|
||||
if (!sys) return;
|
||||
|
||||
|
||||
sys->x = x;
|
||||
sys->y = y;
|
||||
sys->spread_x = sys->spread_y = 2.0f;
|
||||
sys->gravity_x = 0;
|
||||
sys->gravity_y = 200.0f;
|
||||
sys->drag = 0.95f;
|
||||
sys->update_fn = NULL;
|
||||
|
||||
for (u32 i = 0; i < 50 && i < sys->max_count; i++) {
|
||||
pxl8_particle* p = &sys->particles[i];
|
||||
|
|
@ -353,7 +355,7 @@ static void rain_spawn(pxl8_particle* p, void* userdata) {
|
|||
|
||||
void pxl8_vfx_rain(pxl8_particle_system* sys, i32 width, f32 wind) {
|
||||
if (!sys) return;
|
||||
|
||||
|
||||
sys->x = width / 2.0f;
|
||||
sys->y = -10;
|
||||
sys->spread_x = width;
|
||||
|
|
@ -363,6 +365,7 @@ void pxl8_vfx_rain(pxl8_particle_system* sys, i32 width, f32 wind) {
|
|||
sys->drag = 1.0f;
|
||||
sys->spawn_rate = 100.0f;
|
||||
sys->spawn_fn = rain_spawn;
|
||||
sys->update_fn = NULL;
|
||||
}
|
||||
|
||||
static void smoke_spawn(pxl8_particle* p, void* userdata) {
|
||||
|
|
@ -388,12 +391,13 @@ void pxl8_vfx_smoke(pxl8_particle_system* sys, i32 x, i32 y, u8 color) {
|
|||
sys->drag = 0.96f;
|
||||
sys->spawn_rate = 20.0f;
|
||||
sys->spawn_fn = smoke_spawn;
|
||||
sys->update_fn = NULL;
|
||||
sys->userdata = (void*)(uintptr_t)color;
|
||||
}
|
||||
|
||||
static void snow_spawn(pxl8_particle* p, void* userdata) {
|
||||
(void)userdata;
|
||||
p->start_color = 15 + (rand() % 2);
|
||||
p->start_color = 8 + (rand() % 3);
|
||||
p->end_color = 10;
|
||||
p->color = p->start_color;
|
||||
p->max_life = 4.0f;
|
||||
|
|
@ -403,16 +407,17 @@ static void snow_spawn(pxl8_particle* p, void* userdata) {
|
|||
|
||||
void pxl8_vfx_snow(pxl8_particle_system* sys, i32 width, f32 wind) {
|
||||
if (!sys) return;
|
||||
|
||||
|
||||
sys->x = width / 2.0f;
|
||||
sys->y = -10;
|
||||
sys->spread_x = width;
|
||||
sys->spread_y = 0;
|
||||
sys->gravity_x = wind;
|
||||
sys->gravity_y = 30.0f;
|
||||
sys->drag = 0.99f;
|
||||
sys->drag = 1.0f;
|
||||
sys->spawn_rate = 30.0f;
|
||||
sys->spawn_fn = snow_spawn;
|
||||
sys->update_fn = NULL;
|
||||
}
|
||||
|
||||
static void sparks_spawn(pxl8_particle* p, void* userdata) {
|
||||
|
|
@ -440,6 +445,7 @@ void pxl8_vfx_sparks(pxl8_particle_system* sys, i32 x, i32 y, u32 color) {
|
|||
sys->drag = 0.97f;
|
||||
sys->spawn_rate = 40.0f;
|
||||
sys->spawn_fn = sparks_spawn;
|
||||
sys->update_fn = NULL;
|
||||
sys->userdata = (void*)(uintptr_t)color;
|
||||
}
|
||||
|
||||
|
|
@ -450,6 +456,7 @@ void pxl8_vfx_starfield(pxl8_particle_system* sys, f32 speed, f32 spread) {
|
|||
sys->gravity_x = sys->gravity_y = 0;
|
||||
sys->drag = 1.0f;
|
||||
sys->spawn_rate = 0;
|
||||
sys->update_fn = NULL;
|
||||
|
||||
for (u32 i = 0; i < sys->max_count; i++) {
|
||||
pxl8_particle* p = &sys->particles[i];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue