add save and bundle pxl8 with game for standalone game distribution
This commit is contained in:
parent
b1e8525c3e
commit
04d3af11a9
25 changed files with 1173 additions and 346 deletions
|
|
@ -23,7 +23,7 @@ typedef struct pxl8_sdl3_context {
|
|||
u32 atlas_height;
|
||||
} pxl8_sdl3_context;
|
||||
|
||||
static void* sdl3_create(pxl8_color_mode mode, pxl8_resolution resolution,
|
||||
static void* sdl3_create(pxl8_pixel_mode mode, pxl8_resolution resolution,
|
||||
const char* title, i32 win_w, i32 win_h) {
|
||||
(void)mode;
|
||||
|
||||
|
|
@ -120,7 +120,7 @@ static void sdl3_present(void* platform_data) {
|
|||
|
||||
static void sdl3_upload_framebuffer(void* platform_data, const u8* fb,
|
||||
i32 w, i32 h, const u32* palette,
|
||||
pxl8_color_mode mode) {
|
||||
pxl8_pixel_mode mode) {
|
||||
if (!platform_data || !fb) return;
|
||||
|
||||
pxl8_sdl3_context* ctx = (pxl8_sdl3_context*)platform_data;
|
||||
|
|
@ -133,16 +133,15 @@ static void sdl3_upload_framebuffer(void* platform_data, const u8* fb,
|
|||
ctx->rgba_buffer_size = needed_size;
|
||||
}
|
||||
|
||||
if (mode == PXL8_COLOR_MODE_HICOLOR) {
|
||||
if (mode == PXL8_PIXEL_HICOLOR) {
|
||||
const u16* fb16 = (const u16*)fb;
|
||||
for (i32 i = 0; i < w * h; i++) {
|
||||
ctx->rgba_buffer[i] = pxl8_rgb565_to_rgba32(fb16[i]);
|
||||
}
|
||||
} else {
|
||||
u32 palette_size = pxl8_get_palette_size(mode);
|
||||
for (i32 i = 0; i < w * h; i++) {
|
||||
u8 index = fb[i];
|
||||
ctx->rgba_buffer[i] = (index < palette_size) ? palette[index] : 0xFF000000;
|
||||
ctx->rgba_buffer[i] = palette[index];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -150,7 +149,7 @@ static void sdl3_upload_framebuffer(void* platform_data, const u8* fb,
|
|||
}
|
||||
|
||||
static void sdl3_upload_atlas(void* platform_data, const pxl8_atlas* atlas,
|
||||
const u32* palette, pxl8_color_mode mode) {
|
||||
const u32* palette, pxl8_pixel_mode mode) {
|
||||
if (!platform_data || !atlas) return;
|
||||
|
||||
pxl8_sdl3_context* ctx = (pxl8_sdl3_context*)platform_data;
|
||||
|
|
@ -195,17 +194,16 @@ static void sdl3_upload_atlas(void* platform_data, const pxl8_atlas* atlas,
|
|||
ctx->rgba_buffer_size = needed_size;
|
||||
}
|
||||
|
||||
if (mode == PXL8_COLOR_MODE_HICOLOR) {
|
||||
if (mode == PXL8_PIXEL_HICOLOR) {
|
||||
const u16* atlas16 = (const u16*)atlas_pixels;
|
||||
for (u32 i = 0; i < atlas_w * atlas_h; i++) {
|
||||
u16 pixel = atlas16[i];
|
||||
ctx->rgba_buffer[i] = (pixel != 0) ? pxl8_rgb565_to_rgba32(pixel) : 0x00000000;
|
||||
}
|
||||
} else {
|
||||
u32 palette_size = pxl8_get_palette_size(mode);
|
||||
for (u32 i = 0; i < atlas_w * atlas_h; i++) {
|
||||
u8 index = atlas_pixels[i];
|
||||
ctx->rgba_buffer[i] = (index < palette_size) ? palette[index] : 0x00000000;
|
||||
ctx->rgba_buffer[i] = palette[index];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -331,11 +329,11 @@ SDL_AppResult SDL_AppEvent(void* appstate, SDL_Event* event) {
|
|||
i32 window_width, window_height;
|
||||
SDL_GetWindowSize(window, &window_width, &window_height);
|
||||
|
||||
pxl8_resolution resolution = pxl8_get_resolution(sys);
|
||||
pxl8_size render_size = pxl8_get_resolution_dimensions(resolution);
|
||||
i32 render_w = pxl8_gfx_get_width(gfx);
|
||||
i32 render_h = pxl8_gfx_get_height(gfx);
|
||||
|
||||
pxl8_bounds window_bounds = {0, 0, window_width, window_height};
|
||||
pxl8_viewport vp = pxl8_gfx_viewport(window_bounds, render_size.w, render_size.h);
|
||||
pxl8_viewport vp = pxl8_gfx_viewport(window_bounds, render_w, render_h);
|
||||
|
||||
input->mouse_x = (i32)((window_mouse_x - vp.offset_x) / vp.scale);
|
||||
input->mouse_y = (i32)((window_mouse_y - vp.offset_y) / vp.scale);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue