refactor atlas implementation
This commit is contained in:
parent
6008ebf5ed
commit
c662c550df
12 changed files with 867 additions and 303 deletions
|
|
@ -28,11 +28,11 @@ struct pxl8_particles {
|
|||
void* userdata;
|
||||
};
|
||||
|
||||
void pxl8_vfx_plasma(pxl8_gfx* ctx, f32 time, f32 scale1, f32 scale2, u8 palette_offset) {
|
||||
if (!ctx || !pxl8_gfx_get_framebuffer(ctx)) return;
|
||||
|
||||
for (i32 y = 0; y < pxl8_gfx_get_height(ctx); y++) {
|
||||
for (i32 x = 0; x < pxl8_gfx_get_width(ctx); x++) {
|
||||
void pxl8_vfx_plasma(pxl8_gfx* gfx, f32 time, f32 scale1, f32 scale2, u8 palette_offset) {
|
||||
if (!gfx || !pxl8_gfx_get_framebuffer(gfx)) return;
|
||||
|
||||
for (i32 y = 0; y < pxl8_gfx_get_height(gfx); y++) {
|
||||
for (i32 x = 0; x < pxl8_gfx_get_width(gfx); x++) {
|
||||
f32 v1 = sinf(x * scale1 + time);
|
||||
f32 v2 = sinf(y * scale1 + time * 0.7f);
|
||||
f32 v3 = sinf((x + y) * scale2 + time * 1.3f);
|
||||
|
|
@ -44,13 +44,13 @@ void pxl8_vfx_plasma(pxl8_gfx* ctx, f32 time, f32 scale1, f32 scale2, u8 palette
|
|||
if (normalized > 1.0f) normalized = 1.0f;
|
||||
u8 color = palette_offset + (u8)(15.0f * normalized);
|
||||
|
||||
pxl8_pixel(ctx, x, y, color);
|
||||
pxl8_pixel(gfx, x, y, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void pxl8_vfx_raster_bars(pxl8_gfx* ctx, pxl8_raster_bar* bars, u32 bar_count, f32 time) {
|
||||
if (!ctx || !bars) return;
|
||||
void pxl8_vfx_raster_bars(pxl8_gfx* gfx, pxl8_raster_bar* bars, u32 bar_count, f32 time) {
|
||||
if (!gfx || !bars) return;
|
||||
|
||||
for (u32 i = 0; i < bar_count; i++) {
|
||||
pxl8_raster_bar* bar = &bars[i];
|
||||
|
|
@ -72,24 +72,24 @@ void pxl8_vfx_raster_bars(pxl8_gfx* ctx, pxl8_raster_bar* bars, u32 bar_count, f
|
|||
color_idx = bar->color - 1;
|
||||
}
|
||||
|
||||
pxl8_rect_fill(ctx, 0, y_int + dy, pxl8_gfx_get_width(ctx), 1, color_idx);
|
||||
pxl8_rect_fill(gfx, 0, y_int + dy, pxl8_gfx_get_width(gfx), 1, color_idx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void pxl8_vfx_rotozoom(pxl8_gfx* ctx, f32 angle, f32 zoom, i32 cx, i32 cy) {
|
||||
if (!ctx || !pxl8_gfx_get_framebuffer(ctx)) return;
|
||||
void pxl8_vfx_rotozoom(pxl8_gfx* gfx, f32 angle, f32 zoom, i32 cx, i32 cy) {
|
||||
if (!gfx || !pxl8_gfx_get_framebuffer(gfx)) return;
|
||||
|
||||
f32 cos_a = cosf(angle);
|
||||
f32 sin_a = sinf(angle);
|
||||
|
||||
u8* temp_buffer = (u8*)SDL_malloc(pxl8_gfx_get_width(ctx) * pxl8_gfx_get_height(ctx));
|
||||
u8* temp_buffer = (u8*)SDL_malloc(pxl8_gfx_get_width(gfx) * pxl8_gfx_get_height(gfx));
|
||||
if (!temp_buffer) return;
|
||||
|
||||
SDL_memcpy(temp_buffer, pxl8_gfx_get_framebuffer(ctx), pxl8_gfx_get_width(ctx) * pxl8_gfx_get_height(ctx));
|
||||
SDL_memcpy(temp_buffer, pxl8_gfx_get_framebuffer(gfx), pxl8_gfx_get_width(gfx) * pxl8_gfx_get_height(gfx));
|
||||
|
||||
for (i32 y = 0; y < pxl8_gfx_get_height(ctx); y++) {
|
||||
for (i32 x = 0; x < pxl8_gfx_get_width(ctx); x++) {
|
||||
for (i32 y = 0; y < pxl8_gfx_get_height(gfx); y++) {
|
||||
for (i32 x = 0; x < pxl8_gfx_get_width(gfx); x++) {
|
||||
f32 dx = x - cx;
|
||||
f32 dy = y - cy;
|
||||
|
||||
|
|
@ -99,8 +99,8 @@ void pxl8_vfx_rotozoom(pxl8_gfx* ctx, f32 angle, f32 zoom, i32 cx, i32 cy) {
|
|||
i32 sx = (i32)src_x;
|
||||
i32 sy = (i32)src_y;
|
||||
|
||||
if (sx >= 0 && sx < pxl8_gfx_get_width(ctx) && sy >= 0 && sy < pxl8_gfx_get_height(ctx)) {
|
||||
pxl8_gfx_get_framebuffer(ctx)[y * pxl8_gfx_get_width(ctx) + x] = temp_buffer[sy * pxl8_gfx_get_width(ctx) + sx];
|
||||
if (sx >= 0 && sx < pxl8_gfx_get_width(gfx) && sy >= 0 && sy < pxl8_gfx_get_height(gfx)) {
|
||||
pxl8_gfx_get_framebuffer(gfx)[y * pxl8_gfx_get_width(gfx) + x] = temp_buffer[sy * pxl8_gfx_get_width(gfx) + sx];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -108,38 +108,41 @@ void pxl8_vfx_rotozoom(pxl8_gfx* ctx, f32 angle, f32 zoom, i32 cx, i32 cy) {
|
|||
SDL_free(temp_buffer);
|
||||
}
|
||||
|
||||
void pxl8_vfx_tunnel(pxl8_gfx* ctx, f32 time, f32 speed, f32 twist) {
|
||||
if (!ctx || !pxl8_gfx_get_framebuffer(ctx)) return;
|
||||
|
||||
f32 cx = pxl8_gfx_get_width(ctx) / 2.0f;
|
||||
f32 cy = pxl8_gfx_get_height(ctx) / 2.0f;
|
||||
|
||||
for (i32 y = 0; y < pxl8_gfx_get_height(ctx); y++) {
|
||||
for (i32 x = 0; x < pxl8_gfx_get_width(ctx); x++) {
|
||||
void pxl8_vfx_tunnel(pxl8_gfx* gfx, f32 time, f32 speed, f32 twist) {
|
||||
if (!gfx || !pxl8_gfx_get_framebuffer(gfx)) return;
|
||||
|
||||
f32 cx = pxl8_gfx_get_width(gfx) / 2.0f;
|
||||
f32 cy = pxl8_gfx_get_height(gfx) / 2.0f;
|
||||
u32 palette_size = pxl8_gfx_get_palette_size(gfx);
|
||||
if (palette_size == 0) palette_size = 256;
|
||||
|
||||
for (i32 y = 0; y < pxl8_gfx_get_height(gfx); y++) {
|
||||
for (i32 x = 0; x < pxl8_gfx_get_width(gfx); x++) {
|
||||
f32 dx = x - cx;
|
||||
f32 dy = y - cy;
|
||||
f32 dist = sqrtf(dx * dx + dy * dy);
|
||||
|
||||
|
||||
if (dist > 1.0f) {
|
||||
f32 angle = atan2f(dy, dx);
|
||||
f32 u = angle * 0.159f + twist * sinf(time * 0.5f);
|
||||
f32 v = 256.0f / dist + time * speed;
|
||||
|
||||
|
||||
u8 tx = (u8)((i32)(u * 256.0f) & 0xFF);
|
||||
u8 ty = (u8)((i32)(v * 256.0f) & 0xFF);
|
||||
u8 color = tx ^ ty;
|
||||
|
||||
pxl8_pixel(ctx, x, y, color);
|
||||
u8 pattern = tx ^ ty;
|
||||
u8 color = (pattern / 8) % palette_size;
|
||||
|
||||
pxl8_pixel(gfx, x, y, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void pxl8_vfx_water_ripple(pxl8_gfx* ctx, f32* height_map, i32 drop_x, i32 drop_y, f32 damping) {
|
||||
if (!ctx || !height_map) return;
|
||||
void pxl8_vfx_water_ripple(pxl8_gfx* gfx, f32* height_map, i32 drop_x, i32 drop_y, f32 damping) {
|
||||
if (!gfx || !height_map) return;
|
||||
|
||||
i32 w = pxl8_gfx_get_width(ctx);
|
||||
i32 h = pxl8_gfx_get_height(ctx);
|
||||
i32 w = pxl8_gfx_get_width(gfx);
|
||||
i32 h = pxl8_gfx_get_height(gfx);
|
||||
|
||||
static f32* prev_height = NULL;
|
||||
if (!prev_height) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue