refactor: reorganize pxl8 into client/src/ module structure

- core/: main entry, types, logging, I/O, RNG
- asset/: ase loader, cart, save, embed
- gfx/: graphics, animation, atlas, fonts, tilemap, transitions
- sfx/: audio
- script/: lua/fennel runtime, REPL
- hal/: platform abstraction (SDL3)
- world/: BSP, world, procedural gen
- math/: math utilities
- game/: GUI, replay
- lua/: Lua API modules
This commit is contained in:
asrael 2026-01-12 21:46:31 -06:00
parent 272e0bc615
commit 39b604b333
106 changed files with 6078 additions and 3715 deletions

View file

@ -0,0 +1,61 @@
#include "pxl8_font.h"
#include <stdlib.h>
#include <string.h>
pxl8_result pxl8_font_create_atlas(const pxl8_font* font, u8** atlas_data, i32* atlas_width, i32* atlas_height) {
if (!font || !atlas_data || !atlas_width || !atlas_height) {
return PXL8_ERROR_NULL_POINTER;
}
i32 glyphs_per_row = 16;
i32 rows_needed = (font->glyph_count + glyphs_per_row - 1) / glyphs_per_row;
*atlas_width = glyphs_per_row * font->default_width;
*atlas_height = rows_needed * font->default_height;
i32 atlas_size = (*atlas_width) * (*atlas_height);
*atlas_data = (u8*)malloc(atlas_size);
if (!*atlas_data) {
return PXL8_ERROR_OUT_OF_MEMORY;
}
memset(*atlas_data, 0, atlas_size);
for (u32 i = 0; i < font->glyph_count; i++) {
const pxl8_glyph* glyph = &font->glyphs[i];
i32 atlas_x = (i % glyphs_per_row) * font->default_width;
i32 atlas_y = (i / glyphs_per_row) * font->default_height;
for (i32 y = 0; y < glyph->height && y < font->default_height; y++) {
for (i32 x = 0; x < glyph->width && x < font->default_width; x++) {
i32 atlas_idx = (atlas_y + y) * (*atlas_width) + (atlas_x + x);
if (glyph->format == PXL8_FONT_FORMAT_INDEXED) {
u8 pixel_byte = glyph->data.indexed[y];
u8 pixel_bit = (pixel_byte >> x) & 1;
(*atlas_data)[atlas_idx] = pixel_bit ? 255 : 0;
} else {
i32 glyph_idx = y * 8 + x;
u32 rgba_pixel = glyph->data.rgba[glyph_idx];
(*atlas_data)[atlas_idx] = (rgba_pixel >> 24) & 0xFF;
}
}
}
}
return PXL8_OK;
}
const pxl8_glyph* pxl8_font_find_glyph(const pxl8_font* font, u32 codepoint) {
if (!font || !font->glyphs) return NULL;
for (u32 i = 0; i < font->glyph_count; i++) {
if (font->glyphs[i].codepoint == codepoint) {
return &font->glyphs[i];
}
}
return NULL;
}