wip procgen
This commit is contained in:
parent
a653eae745
commit
79a678f162
18 changed files with 1317 additions and 127 deletions
|
|
@ -3,11 +3,13 @@
|
|||
|
||||
#include "pxl8_bsp.h"
|
||||
#include "pxl8_macros.h"
|
||||
#include "pxl8_procgen.h"
|
||||
#include "pxl8_world.h"
|
||||
|
||||
struct pxl8_world {
|
||||
pxl8_bsp bsp;
|
||||
bool loaded;
|
||||
bool wireframe;
|
||||
u32 wireframe_color;
|
||||
};
|
||||
|
||||
|
|
@ -34,6 +36,29 @@ void pxl8_world_destroy(pxl8_world* world) {
|
|||
free(world);
|
||||
}
|
||||
|
||||
pxl8_result pxl8_world_generate(pxl8_world* world, const pxl8_procgen_params* params) {
|
||||
if (!world || !params) return PXL8_ERROR_INVALID_ARGUMENT;
|
||||
|
||||
if (world->loaded) {
|
||||
pxl8_bsp_destroy(&world->bsp);
|
||||
world->loaded = false;
|
||||
}
|
||||
|
||||
memset(&world->bsp, 0, sizeof(pxl8_bsp));
|
||||
|
||||
pxl8_result result = pxl8_procgen(&world->bsp, params);
|
||||
if (result != PXL8_OK) {
|
||||
pxl8_error("Failed to generate world");
|
||||
pxl8_bsp_destroy(&world->bsp);
|
||||
return result;
|
||||
}
|
||||
|
||||
world->loaded = true;
|
||||
pxl8_info("Generated world");
|
||||
|
||||
return PXL8_OK;
|
||||
}
|
||||
|
||||
pxl8_result pxl8_world_load(pxl8_world* world, const char* path) {
|
||||
if (!world || !path) return PXL8_ERROR_INVALID_ARGUMENT;
|
||||
|
||||
|
|
@ -59,7 +84,39 @@ pxl8_result pxl8_world_load(pxl8_world* world, const char* path) {
|
|||
void pxl8_world_render(pxl8_world* world, pxl8_gfx* gfx, pxl8_vec3 camera_pos) {
|
||||
if (!world || !gfx || !world->loaded) return;
|
||||
|
||||
pxl8_bsp_render_wireframe(gfx, &world->bsp, camera_pos, world->wireframe_color);
|
||||
static bool texture_generated = false;
|
||||
static u32 wall_texture_id = 0;
|
||||
if (!texture_generated) {
|
||||
u8 texture_data[64 * 64];
|
||||
|
||||
pxl8_procgen_tex_params tex_params = {
|
||||
.seed = 12345,
|
||||
.width = 64,
|
||||
.height = 64,
|
||||
.scale = 0.25f,
|
||||
.roughness = 0.5f,
|
||||
.base_color = 1,
|
||||
.variation = 3
|
||||
};
|
||||
|
||||
pxl8_procgen_tex(texture_data, &tex_params);
|
||||
|
||||
pxl8_result result = pxl8_gfx_create_texture(gfx, texture_data, 64, 64);
|
||||
if (result >= 0) {
|
||||
wall_texture_id = (u32)result;
|
||||
pxl8_gfx_upload_atlas(gfx);
|
||||
texture_generated = true;
|
||||
pxl8_info("Generated stone texture with ID: %u", wall_texture_id);
|
||||
} else {
|
||||
pxl8_error("Failed to create wall texture: %d", result);
|
||||
}
|
||||
}
|
||||
|
||||
if (world->wireframe) {
|
||||
pxl8_bsp_render_wireframe(gfx, &world->bsp, camera_pos, world->wireframe_color);
|
||||
} else {
|
||||
pxl8_bsp_render_solid(gfx, &world->bsp, camera_pos, wall_texture_id);
|
||||
}
|
||||
}
|
||||
|
||||
void pxl8_world_unload(pxl8_world* world) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue