refactor separate framework from game code, add demo3d

This commit is contained in:
asrael 2026-04-14 01:28:38 -05:00
parent 19ae869769
commit 40f5cdcaa5
92 changed files with 2665 additions and 6547 deletions

View file

@ -238,27 +238,27 @@ static const char* pxl8_ffi_cdefs =
" f32 time;\n"
"} pxl8_3d_uniforms;\n"
"\n"
"typedef struct pxl8_3d_camera pxl8_3d_camera;\n"
"pxl8_3d_camera* pxl8_3d_camera_create(void);\n"
"void pxl8_3d_camera_destroy(pxl8_3d_camera* cam);\n"
"void pxl8_3d_camera_set_perspective(pxl8_3d_camera* cam, f32 fov, f32 aspect, f32 near, f32 far);\n"
"void pxl8_3d_camera_set_position(pxl8_3d_camera* cam, pxl8_vec3 pos);\n"
"void pxl8_3d_camera_set_rotation(pxl8_3d_camera* cam, f32 pitch, f32 yaw, f32 roll);\n"
"void pxl8_3d_camera_lookat(pxl8_3d_camera* cam, pxl8_vec3 eye, pxl8_vec3 target, pxl8_vec3 up);\n"
"pxl8_vec3 pxl8_3d_camera_get_forward(const pxl8_3d_camera* cam);\n"
"pxl8_vec3 pxl8_3d_camera_get_position(const pxl8_3d_camera* cam);\n"
"pxl8_vec3 pxl8_3d_camera_get_right(const pxl8_3d_camera* cam);\n"
"pxl8_vec3 pxl8_3d_camera_get_up(const pxl8_3d_camera* cam);\n"
"pxl8_mat4 pxl8_3d_camera_get_view(const pxl8_3d_camera* cam);\n"
"pxl8_mat4 pxl8_3d_camera_get_projection(const pxl8_3d_camera* cam);\n"
"void pxl8_3d_camera_update(pxl8_3d_camera* cam, f32 dt);\n"
"typedef struct pxl8_camera3d pxl8_camera3d;\n"
"pxl8_camera3d* pxl8_camera3d_create(void);\n"
"void pxl8_camera3d_destroy(pxl8_camera3d* cam);\n"
"void pxl8_camera3d_set_perspective(pxl8_camera3d* cam, f32 fov, f32 aspect, f32 near, f32 far);\n"
"void pxl8_camera3d_set_position(pxl8_camera3d* cam, pxl8_vec3 pos);\n"
"void pxl8_camera3d_set_rotation(pxl8_camera3d* cam, f32 pitch, f32 yaw, f32 roll);\n"
"void pxl8_camera3d_lookat(pxl8_camera3d* cam, pxl8_vec3 eye, pxl8_vec3 target, pxl8_vec3 up);\n"
"pxl8_vec3 pxl8_camera3d_get_forward(const pxl8_camera3d* cam);\n"
"pxl8_vec3 pxl8_camera3d_get_position(const pxl8_camera3d* cam);\n"
"pxl8_vec3 pxl8_camera3d_get_right(const pxl8_camera3d* cam);\n"
"pxl8_vec3 pxl8_camera3d_get_up(const pxl8_camera3d* cam);\n"
"pxl8_mat4 pxl8_camera3d_get_view(const pxl8_camera3d* cam);\n"
"pxl8_mat4 pxl8_camera3d_get_projection(const pxl8_camera3d* cam);\n"
"void pxl8_camera3d_update(pxl8_camera3d* cam, f32 dt);\n"
"typedef struct pxl8_projected_point { i32 x; i32 y; f32 depth; bool visible; } pxl8_projected_point;\n"
"pxl8_projected_point pxl8_3d_camera_world_to_screen(const pxl8_3d_camera* cam, pxl8_vec3 world_pos, u32 screen_width, u32 screen_height);\n"
"pxl8_projected_point pxl8_camera3d_world_to_screen(const pxl8_camera3d* cam, pxl8_vec3 world_pos, u32 screen_width, u32 screen_height);\n"
"\n"
"void pxl8_gfx_blend_tables_update(pxl8_gfx* gfx);\n"
"void pxl8_gfx_colormap_update(pxl8_gfx* gfx);\n"
"\n"
"void pxl8_3d_begin_frame(pxl8_gfx* gfx, const pxl8_3d_camera* camera, const pxl8_lights* lights, const pxl8_3d_uniforms* uniforms);\n"
"void pxl8_3d_begin_frame(pxl8_gfx* gfx, const pxl8_camera3d* camera, const pxl8_lights* lights, const pxl8_3d_uniforms* uniforms);\n"
"void pxl8_3d_clear(pxl8_gfx* gfx, u8 color);\n"
"void pxl8_3d_clear_depth(pxl8_gfx* gfx);\n"
"void pxl8_3d_clear_stencil(pxl8_gfx* gfx, uint8_t value);\n"
@ -408,50 +408,6 @@ static const char* pxl8_ffi_cdefs =
"void pxl8_graph_set_seed(pxl8_graph* graph, u32 seed);\n"
"void pxl8_graph_eval_texture(const pxl8_graph* graph, u8* buffer, i32 width, i32 height);\n"
"\n"
"typedef struct pxl8_bsp pxl8_bsp;\n"
"\n"
"u32 pxl8_bsp_face_count(const pxl8_bsp* bsp);\n"
"pxl8_vec3 pxl8_bsp_face_normal(const pxl8_bsp* bsp, u32 face_id);\n"
"void pxl8_bsp_face_set_material(pxl8_bsp* bsp, u32 face_id, u16 material_id);\n"
"u8 pxl8_bsp_light_at(const pxl8_bsp* bsp, f32 x, f32 y, f32 z, u8 ambient);\n"
"\n"
"typedef struct pxl8_world_chunk {\n"
" u32 id;\n"
" u32 version;\n"
" pxl8_bsp* bsp;\n"
"} pxl8_world_chunk;\n"
"\n"
"typedef struct pxl8_world pxl8_world;\n"
"\n"
"typedef struct pxl8_ray {\n"
" pxl8_vec3 normal;\n"
" pxl8_vec3 point;\n"
" float fraction;\n"
" bool hit;\n"
"} pxl8_ray;\n"
"\n"
"pxl8_world* pxl8_get_world(pxl8* sys);\n"
"pxl8_world_chunk* pxl8_world_active_chunk(pxl8_world* world);\n"
"bool pxl8_world_point_solid(const pxl8_world* world, float x, float y, float z);\n"
"pxl8_ray pxl8_world_ray(const pxl8_world* world, pxl8_vec3 from, pxl8_vec3 to);\n"
"pxl8_ray pxl8_world_sweep(const pxl8_world* world, pxl8_vec3 from, pxl8_vec3 to, float radius);\n"
"void pxl8_world_render(pxl8_world* world, pxl8_gfx* gfx, pxl8_vec3 camera_pos);\n"
"void pxl8_world_set_bsp_material(pxl8_world* world, u16 material_id, const pxl8_gfx_material* material);\n"
"\n"
"typedef struct pxl8_sim_entity {\n"
" pxl8_vec3 pos;\n"
" pxl8_vec3 vel;\n"
" f32 yaw;\n"
" f32 pitch;\n"
" u32 flags;\n"
" u16 kind;\n"
" u16 _pad;\n"
"} pxl8_sim_entity;\n"
"\n"
"void pxl8_world_init_local_player(pxl8_world* world, f32 x, f32 y, f32 z);\n"
"void pxl8_world_set_look(pxl8_world* world, f32 yaw, f32 pitch);\n"
"pxl8_sim_entity* pxl8_world_local_player(pxl8_world* world);\n"
"\n"
"typedef struct { i32 cursor_x; i32 cursor_y; bool cursor_down; bool cursor_clicked; u32 hot_id; u32 active_id; } pxl8_gui_state;\n"
"pxl8_gui_state* pxl8_gui_state_create(void);\n"
"void pxl8_gui_state_destroy(pxl8_gui_state* state);\n"
@ -533,95 +489,12 @@ static const char* pxl8_ffi_cdefs =
"\n"
"typedef struct pxl8_net pxl8_net;\n"
"typedef struct pxl8_net_config { const char* address; u16 port; } pxl8_net_config;\n"
"typedef enum pxl8_cmd_type { PXL8_CMD_NONE = 0, PXL8_CMD_SPAWN_ENTITY } pxl8_cmd_type;\n"
"\n"
"typedef struct pxl8_command_msg {\n"
" u16 cmd_type;\n"
" u8 payload[64];\n"
" u16 payload_size;\n"
" u64 tick;\n"
"} pxl8_command_msg;\n"
"\n"
"typedef struct pxl8_input_msg {\n"
" u32 buttons;\n"
" f32 look_dx;\n"
" f32 look_dy;\n"
" f32 move_x;\n"
" f32 move_y;\n"
" f32 yaw;\n"
" u64 tick;\n"
" u64 timestamp;\n"
"} pxl8_input_msg;\n"
"\n"
"typedef struct pxl8_sim_config {\n"
" f32 move_speed;\n"
" f32 ground_accel;\n"
" f32 air_accel;\n"
" f32 stop_speed;\n"
" f32 friction;\n"
" f32 gravity;\n"
" f32 jump_velocity;\n"
" f32 player_radius;\n"
" f32 player_height;\n"
" f32 max_pitch;\n"
"} pxl8_sim_config;\n"
"\n"
"typedef struct pxl8_sim_world {\n"
" const pxl8_bsp* chunks[9];\n"
" i32 center_cx;\n"
" i32 center_cz;\n"
" f32 chunk_size;\n"
"} pxl8_sim_world;\n"
"\n"
"void pxl8_sim_move_player(pxl8_sim_entity* ent, const pxl8_input_msg* input, const pxl8_sim_world* world, const pxl8_sim_config* cfg, f32 dt);\n"
"void pxl8_sim_integrate(pxl8_sim_entity* ent, const pxl8_sim_world* world, const pxl8_sim_config* cfg, f32 dt);\n"
"pxl8_vec3 pxl8_sim_trace(const pxl8_sim_world* world, pxl8_vec3 from, pxl8_vec3 to, f32 radius, f32 height);\n"
"bool pxl8_sim_check_ground(const pxl8_sim_world* world, pxl8_vec3 pos, f32 radius);\n"
"\n"
"pxl8_sim_world pxl8_world_sim_world(const pxl8_world* world, pxl8_vec3 pos);\n"
"void pxl8_world_set_sim_config(pxl8_world* world, const pxl8_sim_config* config);\n"
"void pxl8_world_push_input(pxl8_world* world, const pxl8_input_msg* input);\n"
"\n"
"typedef struct pxl8_entity_state {\n"
" u64 entity_id;\n"
" u8 userdata[56];\n"
"} pxl8_entity_state;\n"
"\n"
"typedef struct pxl8_snapshot_header {\n"
" u16 entity_count;\n"
" u16 event_count;\n"
" u64 player_id;\n"
" u64 tick;\n"
" f32 time;\n"
"} pxl8_snapshot_header;\n"
"\n"
"i32 pxl8_net_connect(pxl8_net* net);\n"
"bool pxl8_net_connected(const pxl8_net* net);\n"
"pxl8_net* pxl8_net_create(const pxl8_net_config* config);\n"
"void pxl8_net_destroy(pxl8_net* net);\n"
"void pxl8_net_disconnect(pxl8_net* net);\n"
"const pxl8_entity_state* pxl8_net_entities(const pxl8_net* net);\n"
"const u8* pxl8_net_entity_prev_userdata(const pxl8_net* net, u64 entity_id);\n"
"const u8* pxl8_net_entity_userdata(const pxl8_net* net, u64 entity_id);\n"
"const pxl8_input_msg* pxl8_net_input_at(const pxl8_net* net, u64 tick);\n"
"u64 pxl8_net_input_oldest_tick(const pxl8_net* net);\n"
"void pxl8_net_input_push(pxl8_net* net, const pxl8_input_msg* input);\n"
"f32 pxl8_net_lerp_alpha(const pxl8_net* net);\n"
"bool pxl8_net_needs_correction(const pxl8_net* net);\n"
"u64 pxl8_net_player_id(const pxl8_net* net);\n"
"i32 pxl8_net_chunk_cx(const pxl8_net* net);\n"
"i32 pxl8_net_chunk_cz(const pxl8_net* net);\n"
"bool pxl8_net_has_chunk(const pxl8_net* net);\n"
"bool pxl8_net_poll(pxl8_net* net);\n"
"u8* pxl8_net_predicted_state(pxl8_net* net);\n"
"void pxl8_net_predicted_tick_set(pxl8_net* net, u64 tick);\n"
"i32 pxl8_net_send_command(pxl8_net* net, const pxl8_command_msg* cmd);\n"
"i32 pxl8_net_send_input(pxl8_net* net, const pxl8_input_msg* input);\n"
"i32 pxl8_net_spawn(pxl8_net* net, f32 x, f32 y, f32 z, f32 yaw, f32 pitch);\n"
"const pxl8_snapshot_header* pxl8_net_snapshot(const pxl8_net* net);\n"
"u64 pxl8_net_tick(const pxl8_net* net);\n"
"void pxl8_net_update(pxl8_net* net, f32 dt);\n"
"pxl8_net* pxl8_get_net(const pxl8* sys);\n"
"\n"
"void pxl8_bit_clear(u32* val, u8 bit);\n"
"u32 pxl8_bit_count(u32 val);\n"