improve sw renderer
This commit is contained in:
parent
415d424057
commit
39ee0fefb7
89 changed files with 9380 additions and 2307 deletions
|
|
@ -1,14 +1,14 @@
|
|||
#include "pxl8_repl.h"
|
||||
#include "pxl8_mem.h"
|
||||
|
||||
#include <poll.h>
|
||||
#include <pthread.h>
|
||||
#include <stdatomic.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
#include <linenoise.h>
|
||||
|
||||
#define PXL8_MAX_REPL_COMMAND_SIZE 4096
|
||||
|
|
@ -29,7 +29,7 @@ struct pxl8_repl {
|
|||
atomic_uint log_read_idx;
|
||||
|
||||
atomic_bool should_quit;
|
||||
pthread_t thread;
|
||||
SDL_Thread* thread;
|
||||
char accumulator[PXL8_MAX_REPL_COMMAND_SIZE];
|
||||
pxl8_repl_command command;
|
||||
};
|
||||
|
|
@ -56,15 +56,15 @@ static void pxl8_repl_completion(const char* buf, linenoiseCompletions* lc) {
|
|||
"pxl8.error", "pxl8.debug", "pxl8.trace"
|
||||
};
|
||||
|
||||
size_t buf_len = strlen(buf);
|
||||
usize buf_len = strlen(buf);
|
||||
|
||||
for (size_t i = 0; i < sizeof(fennel_keywords) / sizeof(fennel_keywords[0]); i++) {
|
||||
for (usize i = 0; i < sizeof(fennel_keywords) / sizeof(fennel_keywords[0]); i++) {
|
||||
if (strncmp(buf, fennel_keywords[i], buf_len) == 0) {
|
||||
linenoiseAddCompletion(lc, fennel_keywords[i]);
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < sizeof(pxl8_functions) / sizeof(pxl8_functions[0]); i++) {
|
||||
for (usize i = 0; i < sizeof(pxl8_functions) / sizeof(pxl8_functions[0]); i++) {
|
||||
if (strncmp(buf, pxl8_functions[i], buf_len) == 0) {
|
||||
linenoiseAddCompletion(lc, pxl8_functions[i]);
|
||||
}
|
||||
|
|
@ -105,7 +105,7 @@ static void pxl8_repl_flush_logs(pxl8_repl* repl) {
|
|||
fflush(stdout);
|
||||
}
|
||||
|
||||
static void* pxl8_repl_thread(void* arg) {
|
||||
static int pxl8_repl_thread(void* arg) {
|
||||
pxl8_repl* repl = (pxl8_repl*)arg;
|
||||
|
||||
printf("[pxl8 REPL] Fennel 1.6.0 - Tab for completion, Ctrl-D to exit\n");
|
||||
|
|
@ -204,8 +204,7 @@ static void* pxl8_repl_thread(void* arg) {
|
|||
lw = atomic_load(&repl->log_write_idx);
|
||||
}
|
||||
fflush(stdout);
|
||||
struct timespec ts = {.tv_sec = 0, .tv_nsec = 1000000};
|
||||
nanosleep(&ts, NULL);
|
||||
SDL_Delay(1);
|
||||
}
|
||||
atomic_store(&repl->cmd_complete, false);
|
||||
}
|
||||
|
|
@ -214,11 +213,11 @@ static void* pxl8_repl_thread(void* arg) {
|
|||
|
||||
pxl8_repl_flush_logs(repl);
|
||||
|
||||
return NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
pxl8_repl* pxl8_repl_create(void) {
|
||||
pxl8_repl* repl = (pxl8_repl*)calloc(1, sizeof(pxl8_repl));
|
||||
pxl8_repl* repl = (pxl8_repl*)pxl8_calloc(1, sizeof(pxl8_repl));
|
||||
if (!repl) return NULL;
|
||||
|
||||
repl->accumulator[0] = '\0';
|
||||
|
|
@ -237,8 +236,9 @@ pxl8_repl* pxl8_repl_create(void) {
|
|||
|
||||
g_repl = repl;
|
||||
|
||||
if (pthread_create(&repl->thread, NULL, pxl8_repl_thread, repl) != 0) {
|
||||
free(repl);
|
||||
repl->thread = SDL_CreateThread(pxl8_repl_thread, "pxl8-repl", repl);
|
||||
if (!repl->thread) {
|
||||
pxl8_free(repl);
|
||||
g_repl = NULL;
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -251,19 +251,18 @@ void pxl8_repl_destroy(pxl8_repl* repl) {
|
|||
|
||||
atomic_store(&repl->should_quit, true);
|
||||
|
||||
struct timespec ts = {.tv_sec = 0, .tv_nsec = 2000000};
|
||||
nanosleep(&ts, NULL);
|
||||
SDL_Delay(2);
|
||||
|
||||
printf("\r\033[K");
|
||||
fflush(stdout);
|
||||
|
||||
pthread_join(repl->thread, NULL);
|
||||
SDL_WaitThread(repl->thread, NULL);
|
||||
pxl8_repl_flush_logs(repl);
|
||||
|
||||
g_repl = NULL;
|
||||
|
||||
system("stty sane 2>/dev/null");
|
||||
free(repl);
|
||||
pxl8_free(repl);
|
||||
}
|
||||
|
||||
pxl8_repl_command* pxl8_repl_pop_command(pxl8_repl* repl) {
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
#include "pxl8_gui.h"
|
||||
#include "pxl8_log.h"
|
||||
#include "pxl8_macros.h"
|
||||
#include "pxl8_mem.h"
|
||||
#include "pxl8_script_ffi.h"
|
||||
|
||||
struct pxl8_script {
|
||||
|
|
@ -37,7 +38,7 @@ struct pxl8_script {
|
|||
static int pxl8_cart_loader(lua_State* L) {
|
||||
const char* found_path = lua_tostring(L, lua_upvalueindex(1));
|
||||
const char* code = lua_tostring(L, lua_upvalueindex(2));
|
||||
size_t code_len = lua_objlen(L, lua_upvalueindex(2));
|
||||
usize code_len = lua_objlen(L, lua_upvalueindex(2));
|
||||
bool is_fennel = lua_toboolean(L, lua_upvalueindex(3));
|
||||
|
||||
if (is_fennel) {
|
||||
|
|
@ -75,9 +76,9 @@ static int pxl8_cart_searcher(lua_State* L) {
|
|||
}
|
||||
|
||||
char path[512];
|
||||
size_t len = strlen(modname);
|
||||
size_t j = 0;
|
||||
for (size_t i = 0; i < len && j < sizeof(path) - 5; i++) {
|
||||
usize len = strlen(modname);
|
||||
usize j = 0;
|
||||
for (usize i = 0; i < len && j < sizeof(path) - 5; i++) {
|
||||
if (modname[i] == '.') {
|
||||
path[j++] = '/';
|
||||
} else {
|
||||
|
|
@ -114,9 +115,9 @@ static int pxl8_cart_searcher(lua_State* L) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
static void pxl8_script_repl_promote_locals(const char* input, char* output, size_t output_size) {
|
||||
size_t i = 0;
|
||||
size_t j = 0;
|
||||
static void pxl8_script_repl_promote_locals(const char* input, char* output, usize output_size) {
|
||||
usize i = 0;
|
||||
usize j = 0;
|
||||
bool in_string = false;
|
||||
bool in_comment = false;
|
||||
|
||||
|
|
@ -182,18 +183,18 @@ static void pxl8_script_set_error(pxl8_script* script, const char* error) {
|
|||
src += 9;
|
||||
const char* mod_start = src;
|
||||
while (*src && !(*src == '"' && *(src+1) == ']')) src++;
|
||||
size_t mod_len = src - mod_start;
|
||||
usize mod_len = src - mod_start;
|
||||
|
||||
if (mod_len > 4 && strncmp(mod_start, "pxl8", 4) == 0) {
|
||||
const char* prefix = "src/lua/";
|
||||
while (*prefix && dst < end) *dst++ = *prefix++;
|
||||
for (size_t i = 0; i < mod_len && dst < end; i++) {
|
||||
for (usize i = 0; i < mod_len && dst < end; i++) {
|
||||
*dst++ = (mod_start[i] == '.') ? '/' : mod_start[i];
|
||||
}
|
||||
const char* suffix = ".lua";
|
||||
while (*suffix && dst < end) *dst++ = *suffix++;
|
||||
} else {
|
||||
for (size_t i = 0; i < mod_len && dst < end; i++) {
|
||||
for (usize i = 0; i < mod_len && dst < end; i++) {
|
||||
*dst++ = mod_start[i];
|
||||
}
|
||||
}
|
||||
|
|
@ -244,13 +245,13 @@ static void pxl8_install_embed_searcher(lua_State* L) {
|
|||
}
|
||||
|
||||
pxl8_script* pxl8_script_create(bool repl_mode) {
|
||||
pxl8_script* script = (pxl8_script*)calloc(1, sizeof(pxl8_script));
|
||||
pxl8_script* script = (pxl8_script*)pxl8_calloc(1, sizeof(pxl8_script));
|
||||
if (!script) return NULL;
|
||||
script->repl_mode = repl_mode;
|
||||
|
||||
script->L = luaL_newstate();
|
||||
if (!script->L) {
|
||||
free(script);
|
||||
pxl8_free(script);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
@ -349,7 +350,7 @@ void pxl8_script_destroy(pxl8_script* script) {
|
|||
}
|
||||
lua_close(script->L);
|
||||
}
|
||||
free(script);
|
||||
pxl8_free(script);
|
||||
}
|
||||
|
||||
void pxl8_script_set_gfx(pxl8_script* script, pxl8_gfx* gfx) {
|
||||
|
|
@ -395,7 +396,7 @@ void pxl8_script_set_sys(pxl8_script* script, void* sys) {
|
|||
}
|
||||
}
|
||||
|
||||
static pxl8_result pxl8_script_prepare_path(pxl8_script* script, const char* filename, char* out_basename, size_t basename_size) {
|
||||
static pxl8_result pxl8_script_prepare_path(pxl8_script* script, const char* filename, char* out_basename, usize basename_size) {
|
||||
char filename_copy[PATH_MAX];
|
||||
pxl8_strncpy(filename_copy, filename, sizeof(filename_copy));
|
||||
|
||||
|
|
@ -470,7 +471,7 @@ static time_t get_latest_script_mod_time(const char* dir_path) {
|
|||
latest = subdir_time;
|
||||
}
|
||||
} else {
|
||||
size_t len = strlen(entry->d_name);
|
||||
usize len = strlen(entry->d_name);
|
||||
bool is_script = (len > 4 && strcmp(entry->d_name + len - 4, ".fnl") == 0) ||
|
||||
(len > 4 && strcmp(entry->d_name + len - 4, ".lua") == 0);
|
||||
|
||||
|
|
@ -618,8 +619,8 @@ static pxl8_result pxl8_script_eval_internal(pxl8_script* script, const char* co
|
|||
const char* error = lua_tostring(script->L, -1);
|
||||
if (error) {
|
||||
char cleaned_error[2048];
|
||||
size_t j = 0;
|
||||
for (size_t i = 0; error[i] && j < sizeof(cleaned_error) - 1; i++) {
|
||||
usize j = 0;
|
||||
for (usize i = 0; error[i] && j < sizeof(cleaned_error) - 1; i++) {
|
||||
if (error[i] == '\t') {
|
||||
cleaned_error[j++] = ' ';
|
||||
} else {
|
||||
|
|
@ -877,7 +878,7 @@ typedef struct {
|
|||
|
||||
static void ser_buffer_init(ser_buffer* buf) {
|
||||
buf->capacity = 1024;
|
||||
buf->data = malloc(buf->capacity);
|
||||
buf->data = pxl8_malloc(buf->capacity);
|
||||
buf->size = 0;
|
||||
}
|
||||
|
||||
|
|
@ -886,7 +887,7 @@ static void ser_buffer_grow(ser_buffer* buf, u32 needed) {
|
|||
while (buf->size + needed > buf->capacity) {
|
||||
buf->capacity *= 2;
|
||||
}
|
||||
buf->data = realloc(buf->data, buf->capacity);
|
||||
buf->data = pxl8_realloc(buf->data, buf->capacity);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -930,7 +931,7 @@ static void ser_write_value(ser_buffer* buf, lua_State* L, int idx, int depth) {
|
|||
ser_write_f64(buf, lua_tonumber(L, idx));
|
||||
break;
|
||||
case LUA_TSTRING: {
|
||||
size_t len;
|
||||
usize len;
|
||||
const char* str = lua_tolstring(L, idx, &len);
|
||||
ser_write_u8(buf, SER_STRING);
|
||||
ser_write_u32(buf, (u32)len);
|
||||
|
|
@ -1080,7 +1081,7 @@ void pxl8_script_deserialize_globals(pxl8_script* script, const u8* data, u32 si
|
|||
}
|
||||
|
||||
void pxl8_script_free_serialized(u8* data) {
|
||||
free(data);
|
||||
pxl8_free(data);
|
||||
}
|
||||
|
||||
pxl8_result pxl8_script_load_main(pxl8_script* script, const char* path) {
|
||||
|
|
|
|||
|
|
@ -11,6 +11,8 @@ static const char* pxl8_ffi_cdefs =
|
|||
"typedef int64_t i64;\n"
|
||||
"typedef float f32;\n"
|
||||
"typedef double f64;\n"
|
||||
"typedef size_t usize;\n"
|
||||
"typedef ptrdiff_t isize;\n"
|
||||
"typedef struct pxl8 pxl8;\n"
|
||||
"typedef struct pxl8_gfx pxl8_gfx;\n"
|
||||
"typedef struct { int x, y, w, h; } pxl8_bounds;\n"
|
||||
|
|
@ -27,11 +29,16 @@ static const char* pxl8_ffi_cdefs =
|
|||
"u8 pxl8_gfx_find_color(pxl8_gfx* gfx, u32 color);\n"
|
||||
"i32 pxl8_gfx_get_height(pxl8_gfx* ctx);\n"
|
||||
"typedef struct pxl8_palette pxl8_palette;\n"
|
||||
"pxl8_palette* pxl8_gfx_get_palette(pxl8_gfx* gfx);\n"
|
||||
"pxl8_palette* pxl8_gfx_palette(pxl8_gfx* gfx);\n"
|
||||
"u32 pxl8_palette_color(const pxl8_palette* pal, u8 idx);\n"
|
||||
"void pxl8_palette_set_rgb(pxl8_palette* pal, u8 idx, u8 r, u8 g, u8 b);\n"
|
||||
"void pxl8_gfx_set_palette_colors(pxl8_gfx* gfx, const u32* colors, u16 count);\n"
|
||||
"i32 pxl8_palette_index(const pxl8_palette* pal, u32 color);\n"
|
||||
"u8 pxl8_palette_ramp_index(const pxl8_palette* pal, u8 position);\n"
|
||||
"typedef struct pxl8_colormap pxl8_colormap;\n"
|
||||
"pxl8_colormap* pxl8_gfx_colormap(pxl8_gfx* gfx);\n"
|
||||
"void pxl8_set_colormap(pxl8_colormap* cm, const u8* data, u32 size);\n"
|
||||
"void pxl8_gfx_ensure_blend_tables(pxl8_gfx* gfx);\n"
|
||||
"i32 pxl8_gfx_get_width(pxl8_gfx* ctx);\n"
|
||||
"void pxl8_2d_circle(pxl8_gfx* ctx, i32 x, i32 y, i32 r, u32 color);\n"
|
||||
"void pxl8_2d_circle_fill(pxl8_gfx* ctx, i32 x, i32 y, i32 r, u32 color);\n"
|
||||
|
|
@ -192,21 +199,27 @@ static const char* pxl8_ffi_cdefs =
|
|||
"\n"
|
||||
"typedef struct pxl8_light {\n"
|
||||
" pxl8_vec3 position;\n"
|
||||
" f32 inv_radius_sq;\n"
|
||||
" u8 r, g, b;\n"
|
||||
" u8 intensity;\n"
|
||||
" f32 radius;\n"
|
||||
" f32 radius_sq;\n"
|
||||
" f32 inv_radius_sq;\n"
|
||||
"} pxl8_light;\n"
|
||||
"\n"
|
||||
"typedef struct pxl8_lights pxl8_lights;\n"
|
||||
"pxl8_lights* pxl8_lights_create(u32 capacity);\n"
|
||||
"void pxl8_lights_destroy(pxl8_lights* lights);\n"
|
||||
"void pxl8_lights_add(pxl8_lights* lights, f32 x, f32 y, f32 z, u8 r, u8 g, u8 b, u8 intensity, f32 radius);\n"
|
||||
"void pxl8_lights_clear(pxl8_lights* lights);\n"
|
||||
"u32 pxl8_lights_count(const pxl8_lights* lights);\n"
|
||||
"const pxl8_light* pxl8_lights_data(const pxl8_lights* lights);\n"
|
||||
"\n"
|
||||
"typedef struct pxl8_3d_uniforms {\n"
|
||||
" u8 ambient;\n"
|
||||
" pxl8_vec3 celestial_dir;\n"
|
||||
" f32 celestial_intensity;\n"
|
||||
" u8 fog_color;\n"
|
||||
" f32 fog_density;\n"
|
||||
" pxl8_light lights[16];\n"
|
||||
" u32 num_lights;\n"
|
||||
" f32 time;\n"
|
||||
"} pxl8_3d_uniforms;\n"
|
||||
"\n"
|
||||
|
|
@ -224,12 +237,14 @@ static const char* pxl8_ffi_cdefs =
|
|||
"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_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"
|
||||
"\n"
|
||||
"typedef enum pxl8_gfx_effect { PXL8_GFX_EFFECT_GLOWS = 0 } pxl8_gfx_effect;\n"
|
||||
"\n"
|
||||
"typedef enum pxl8_glow_shape { PXL8_GLOW_CIRCLE = 0, PXL8_GLOW_DIAMOND = 1, PXL8_GLOW_SHAFT = 2 } pxl8_glow_shape;\n"
|
||||
"\n"
|
||||
"typedef struct pxl8_glow_source {\n"
|
||||
"typedef struct pxl8_glow {\n"
|
||||
" u8 color;\n"
|
||||
" u16 depth;\n"
|
||||
" u8 height;\n"
|
||||
|
|
@ -238,22 +253,37 @@ static const char* pxl8_ffi_cdefs =
|
|||
" pxl8_glow_shape shape;\n"
|
||||
" i16 x;\n"
|
||||
" i16 y;\n"
|
||||
"} pxl8_glow_source;\n"
|
||||
"} pxl8_glow;\n"
|
||||
"\n"
|
||||
"void pxl8_gfx_apply_effect(pxl8_gfx* gfx, pxl8_gfx_effect effect, const void* params, u32 count);\n"
|
||||
"void pxl8_gfx_blend_tables_update(pxl8_gfx* gfx);\n"
|
||||
"\n"
|
||||
"typedef struct pxl8_glows pxl8_glows;\n"
|
||||
"pxl8_glows* pxl8_glows_create(u32 capacity);\n"
|
||||
"void pxl8_glows_destroy(pxl8_glows* glows);\n"
|
||||
"void pxl8_glows_add(pxl8_glows* glows, i16 x, i16 y, u8 radius, u16 intensity, u8 color, u8 shape);\n"
|
||||
"void pxl8_glows_clear(pxl8_glows* glows);\n"
|
||||
"u32 pxl8_glows_count(const pxl8_glows* glows);\n"
|
||||
"void pxl8_glows_render(pxl8_glows* glows, 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_3d_uniforms* uniforms);\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_clear(pxl8_gfx* gfx, u8 color);\n"
|
||||
"void pxl8_3d_clear_depth(pxl8_gfx* gfx);\n"
|
||||
"void pxl8_3d_draw_line(pxl8_gfx* gfx, pxl8_vec3 p0, pxl8_vec3 p1, u8 color);\n"
|
||||
"void pxl8_3d_end_frame(pxl8_gfx* gfx);\n"
|
||||
"u32 pxl8_3d_project_points(pxl8_gfx* gfx, const pxl8_vec3* in, pxl8_vec3* out, u32 count, const pxl8_mat4* transform);\n"
|
||||
"\n"
|
||||
"typedef enum pxl8_blend_mode { PXL8_BLEND_OPAQUE = 0, PXL8_BLEND_ALPHA_TEST, PXL8_BLEND_ALPHA, PXL8_BLEND_ADDITIVE } pxl8_blend_mode;\n"
|
||||
"\n"
|
||||
"typedef struct pxl8_material {\n"
|
||||
"typedef struct pxl8_gfx_material {\n"
|
||||
" char name[16];\n"
|
||||
" pxl8_vec3 u_axis;\n"
|
||||
" pxl8_vec3 v_axis;\n"
|
||||
" f32 u_offset;\n"
|
||||
" f32 v_offset;\n"
|
||||
" u32 texture_id;\n"
|
||||
" u32 lightmap_id;\n"
|
||||
" u8 alpha;\n"
|
||||
" u8 blend_mode;\n"
|
||||
" bool dither;\n"
|
||||
|
|
@ -261,13 +291,15 @@ static const char* pxl8_ffi_cdefs =
|
|||
" bool dynamic_lighting;\n"
|
||||
" bool per_pixel;\n"
|
||||
" bool vertex_color_passthrough;\n"
|
||||
" bool wireframe;\n"
|
||||
" f32 emissive_intensity;\n"
|
||||
"} pxl8_material;\n"
|
||||
"} pxl8_gfx_material;\n"
|
||||
"\n"
|
||||
"typedef struct pxl8_vertex {\n"
|
||||
" pxl8_vec3 position;\n"
|
||||
" pxl8_vec3 normal;\n"
|
||||
" f32 u, v;\n"
|
||||
" f32 lu, lv;\n"
|
||||
" u8 color;\n"
|
||||
" u8 light;\n"
|
||||
" u8 _pad[2];\n"
|
||||
|
|
@ -287,12 +319,16 @@ static const char* pxl8_ffi_cdefs =
|
|||
"void pxl8_mesh_clear(pxl8_mesh* mesh);\n"
|
||||
"u16 pxl8_mesh_push_vertex(pxl8_mesh* mesh, pxl8_vertex v);\n"
|
||||
"void pxl8_mesh_push_triangle(pxl8_mesh* mesh, u16 i0, u16 i1, u16 i2);\n"
|
||||
"void pxl8_3d_draw_mesh(pxl8_gfx* gfx, const pxl8_mesh* mesh, const pxl8_mat4* model, const pxl8_material* material);\n"
|
||||
"void pxl8_3d_draw_mesh(pxl8_gfx* gfx, const pxl8_mesh* mesh, const pxl8_mat4* model, const pxl8_gfx_material* material);\n"
|
||||
"\n"
|
||||
"u32 pxl8_hash32(u32 x);\n"
|
||||
"\n"
|
||||
"pxl8_mat4 pxl8_mat4_identity(void);\n"
|
||||
"pxl8_mat4 pxl8_mat4_lookat(pxl8_vec3 eye, pxl8_vec3 center, pxl8_vec3 up);\n"
|
||||
"pxl8_mat4 pxl8_mat4_mul(pxl8_mat4 a, pxl8_mat4 b);\n"
|
||||
"pxl8_mat4 pxl8_mat4_ortho(float left, float right, float bottom, float top, float near, float far);\n"
|
||||
"pxl8_mat4 pxl8_mat4_multiply(pxl8_mat4 a, pxl8_mat4 b);\n"
|
||||
"pxl8_vec3 pxl8_mat4_multiply_vec3(pxl8_mat4 m, pxl8_vec3 v);\n"
|
||||
"pxl8_vec4 pxl8_mat4_multiply_vec4(pxl8_mat4 m, pxl8_vec4 v);\n"
|
||||
"pxl8_mat4 pxl8_mat4_orthographic(float left, float right, float bottom, float top, float near, float far);\n"
|
||||
"pxl8_mat4 pxl8_mat4_perspective(float fov, float aspect, float near, float far);\n"
|
||||
"pxl8_mat4 pxl8_mat4_rotate_x(float angle);\n"
|
||||
"pxl8_mat4 pxl8_mat4_rotate_y(float angle);\n"
|
||||
|
|
@ -316,18 +352,76 @@ static const char* pxl8_ffi_cdefs =
|
|||
" int num_rooms;\n"
|
||||
"} pxl8_procgen_params;\n"
|
||||
"\n"
|
||||
"typedef struct pxl8_procgen_tex_params {\n"
|
||||
" char name[16];\n"
|
||||
" unsigned int seed;\n"
|
||||
" int width;\n"
|
||||
" int height;\n"
|
||||
" float scale;\n"
|
||||
" float roughness;\n"
|
||||
" unsigned char base_color;\n"
|
||||
" unsigned char variation;\n"
|
||||
"} pxl8_procgen_tex_params;\n"
|
||||
"typedef enum pxl8_graph_op {\n"
|
||||
" PXL8_OP_CONST = 0,\n"
|
||||
" PXL8_OP_INPUT_AGE,\n"
|
||||
" PXL8_OP_INPUT_SEED,\n"
|
||||
" PXL8_OP_INPUT_TIME,\n"
|
||||
" PXL8_OP_INPUT_X,\n"
|
||||
" PXL8_OP_INPUT_Y,\n"
|
||||
"\n"
|
||||
"void pxl8_procgen_tex(u8* buffer, const pxl8_procgen_tex_params* params);\n"
|
||||
" PXL8_OP_ABS,\n"
|
||||
" PXL8_OP_CEIL,\n"
|
||||
" PXL8_OP_COS,\n"
|
||||
" PXL8_OP_FLOOR,\n"
|
||||
" PXL8_OP_FRACT,\n"
|
||||
" PXL8_OP_NEGATE,\n"
|
||||
" PXL8_OP_SIN,\n"
|
||||
" PXL8_OP_SQRT,\n"
|
||||
"\n"
|
||||
" PXL8_OP_ADD,\n"
|
||||
" PXL8_OP_DIV,\n"
|
||||
" PXL8_OP_MAX,\n"
|
||||
" PXL8_OP_MIN,\n"
|
||||
" PXL8_OP_MOD,\n"
|
||||
" PXL8_OP_MUL,\n"
|
||||
" PXL8_OP_POW,\n"
|
||||
" PXL8_OP_SUB,\n"
|
||||
"\n"
|
||||
" PXL8_OP_CLAMP,\n"
|
||||
" PXL8_OP_LERP,\n"
|
||||
" PXL8_OP_SELECT,\n"
|
||||
" PXL8_OP_SMOOTHSTEP,\n"
|
||||
"\n"
|
||||
" PXL8_OP_NOISE_FBM,\n"
|
||||
" PXL8_OP_NOISE_PERLIN,\n"
|
||||
" PXL8_OP_NOISE_RIDGED,\n"
|
||||
" PXL8_OP_NOISE_TURBULENCE,\n"
|
||||
" PXL8_OP_NOISE_VALUE,\n"
|
||||
"\n"
|
||||
" PXL8_OP_VORONOI_CELL,\n"
|
||||
" PXL8_OP_VORONOI_EDGE,\n"
|
||||
" PXL8_OP_VORONOI_ID,\n"
|
||||
"\n"
|
||||
" PXL8_OP_GRADIENT_LINEAR,\n"
|
||||
" PXL8_OP_GRADIENT_RADIAL,\n"
|
||||
"\n"
|
||||
" PXL8_OP_QUANTIZE,\n"
|
||||
" PXL8_OP_COUNT\n"
|
||||
"} pxl8_graph_op;\n"
|
||||
"\n"
|
||||
"typedef struct pxl8_node {\n"
|
||||
" u8 in[4];\n"
|
||||
" u8 op;\n"
|
||||
" u8 out;\n"
|
||||
" f32 param;\n"
|
||||
"} pxl8_node;\n"
|
||||
"\n"
|
||||
"typedef struct pxl8_graph {\n"
|
||||
" u32 capacity;\n"
|
||||
" u32 count;\n"
|
||||
" pxl8_node* nodes;\n"
|
||||
" u8 output_reg;\n"
|
||||
" u32 seed;\n"
|
||||
"} pxl8_graph;\n"
|
||||
"\n"
|
||||
"pxl8_graph* pxl8_graph_create(u32 capacity);\n"
|
||||
"void pxl8_graph_destroy(pxl8_graph* graph);\n"
|
||||
"void pxl8_graph_clear(pxl8_graph* graph);\n"
|
||||
"u8 pxl8_graph_add_node(pxl8_graph* graph, pxl8_graph_op op, u8 in0, u8 in1, u8 in2, u8 in3, f32 param);\n"
|
||||
"void pxl8_graph_set_output(pxl8_graph* graph, u8 reg);\n"
|
||||
"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"
|
||||
"typedef struct pxl8_bsp_face pxl8_bsp_face;\n"
|
||||
|
|
@ -350,12 +444,13 @@ static const char* pxl8_ffi_cdefs =
|
|||
"bool pxl8_world_is_loaded(const pxl8_world* world);\n"
|
||||
"void pxl8_world_render(pxl8_world* world, pxl8_gfx* gfx, pxl8_vec3 camera_pos);\n"
|
||||
"pxl8_vec3 pxl8_world_resolve_collision(const pxl8_world* world, pxl8_vec3 from, pxl8_vec3 to, float radius);\n"
|
||||
"void pxl8_world_set_wireframe(pxl8_world* world, bool enabled);\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"
|
||||
"void pxl8_gui_begin_frame(pxl8_gui_state* state);\n"
|
||||
"void pxl8_gui_end_frame(pxl8_gui_state* state);\n"
|
||||
"void pxl8_gui_begin_frame(pxl8_gui_state* state, pxl8_gfx* gfx);\n"
|
||||
"void pxl8_gui_end_frame(pxl8_gui_state* state, pxl8_gfx* gfx);\n"
|
||||
"void pxl8_gui_cursor_move(pxl8_gui_state* state, i32 x, i32 y);\n"
|
||||
"void pxl8_gui_cursor_down(pxl8_gui_state* state);\n"
|
||||
"void pxl8_gui_cursor_up(pxl8_gui_state* state);\n"
|
||||
|
|
@ -486,40 +581,40 @@ static const char* pxl8_ffi_cdefs =
|
|||
"bool pxl8_bit_test(u32 val, u8 bit);\n"
|
||||
"void pxl8_bit_toggle(u32* val, u8 bit);\n"
|
||||
"\n"
|
||||
"void pxl8_pack_u8(u8* buf, size_t offset, u8 val);\n"
|
||||
"void pxl8_pack_u16_be(u8* buf, size_t offset, u16 val);\n"
|
||||
"void pxl8_pack_u16_le(u8* buf, size_t offset, u16 val);\n"
|
||||
"void pxl8_pack_u32_be(u8* buf, size_t offset, u32 val);\n"
|
||||
"void pxl8_pack_u32_le(u8* buf, size_t offset, u32 val);\n"
|
||||
"void pxl8_pack_u64_be(u8* buf, size_t offset, u64 val);\n"
|
||||
"void pxl8_pack_u64_le(u8* buf, size_t offset, u64 val);\n"
|
||||
"void pxl8_pack_i8(u8* buf, size_t offset, i8 val);\n"
|
||||
"void pxl8_pack_i16_be(u8* buf, size_t offset, i16 val);\n"
|
||||
"void pxl8_pack_i16_le(u8* buf, size_t offset, i16 val);\n"
|
||||
"void pxl8_pack_i32_be(u8* buf, size_t offset, i32 val);\n"
|
||||
"void pxl8_pack_i32_le(u8* buf, size_t offset, i32 val);\n"
|
||||
"void pxl8_pack_i64_be(u8* buf, size_t offset, i64 val);\n"
|
||||
"void pxl8_pack_i64_le(u8* buf, size_t offset, i64 val);\n"
|
||||
"void pxl8_pack_f32_be(u8* buf, size_t offset, f32 val);\n"
|
||||
"void pxl8_pack_f32_le(u8* buf, size_t offset, f32 val);\n"
|
||||
"void pxl8_pack_f64_be(u8* buf, size_t offset, f64 val);\n"
|
||||
"void pxl8_pack_f64_le(u8* buf, size_t offset, f64 val);\n"
|
||||
"void pxl8_pack_u8(u8* buf, usize offset, u8 val);\n"
|
||||
"void pxl8_pack_u16_be(u8* buf, usize offset, u16 val);\n"
|
||||
"void pxl8_pack_u16_le(u8* buf, usize offset, u16 val);\n"
|
||||
"void pxl8_pack_u32_be(u8* buf, usize offset, u32 val);\n"
|
||||
"void pxl8_pack_u32_le(u8* buf, usize offset, u32 val);\n"
|
||||
"void pxl8_pack_u64_be(u8* buf, usize offset, u64 val);\n"
|
||||
"void pxl8_pack_u64_le(u8* buf, usize offset, u64 val);\n"
|
||||
"void pxl8_pack_i8(u8* buf, usize offset, i8 val);\n"
|
||||
"void pxl8_pack_i16_be(u8* buf, usize offset, i16 val);\n"
|
||||
"void pxl8_pack_i16_le(u8* buf, usize offset, i16 val);\n"
|
||||
"void pxl8_pack_i32_be(u8* buf, usize offset, i32 val);\n"
|
||||
"void pxl8_pack_i32_le(u8* buf, usize offset, i32 val);\n"
|
||||
"void pxl8_pack_i64_be(u8* buf, usize offset, i64 val);\n"
|
||||
"void pxl8_pack_i64_le(u8* buf, usize offset, i64 val);\n"
|
||||
"void pxl8_pack_f32_be(u8* buf, usize offset, f32 val);\n"
|
||||
"void pxl8_pack_f32_le(u8* buf, usize offset, f32 val);\n"
|
||||
"void pxl8_pack_f64_be(u8* buf, usize offset, f64 val);\n"
|
||||
"void pxl8_pack_f64_le(u8* buf, usize offset, f64 val);\n"
|
||||
"\n"
|
||||
"u8 pxl8_unpack_u8(const u8* buf, size_t offset);\n"
|
||||
"u16 pxl8_unpack_u16_be(const u8* buf, size_t offset);\n"
|
||||
"u16 pxl8_unpack_u16_le(const u8* buf, size_t offset);\n"
|
||||
"u32 pxl8_unpack_u32_be(const u8* buf, size_t offset);\n"
|
||||
"u32 pxl8_unpack_u32_le(const u8* buf, size_t offset);\n"
|
||||
"u64 pxl8_unpack_u64_be(const u8* buf, size_t offset);\n"
|
||||
"u64 pxl8_unpack_u64_le(const u8* buf, size_t offset);\n"
|
||||
"i8 pxl8_unpack_i8(const u8* buf, size_t offset);\n"
|
||||
"i16 pxl8_unpack_i16_be(const u8* buf, size_t offset);\n"
|
||||
"i16 pxl8_unpack_i16_le(const u8* buf, size_t offset);\n"
|
||||
"i32 pxl8_unpack_i32_be(const u8* buf, size_t offset);\n"
|
||||
"i32 pxl8_unpack_i32_le(const u8* buf, size_t offset);\n"
|
||||
"i64 pxl8_unpack_i64_be(const u8* buf, size_t offset);\n"
|
||||
"i64 pxl8_unpack_i64_le(const u8* buf, size_t offset);\n"
|
||||
"f32 pxl8_unpack_f32_be(const u8* buf, size_t offset);\n"
|
||||
"f32 pxl8_unpack_f32_le(const u8* buf, size_t offset);\n"
|
||||
"f64 pxl8_unpack_f64_be(const u8* buf, size_t offset);\n"
|
||||
"f64 pxl8_unpack_f64_le(const u8* buf, size_t offset);\n";
|
||||
"u8 pxl8_unpack_u8(const u8* buf, usize offset);\n"
|
||||
"u16 pxl8_unpack_u16_be(const u8* buf, usize offset);\n"
|
||||
"u16 pxl8_unpack_u16_le(const u8* buf, usize offset);\n"
|
||||
"u32 pxl8_unpack_u32_be(const u8* buf, usize offset);\n"
|
||||
"u32 pxl8_unpack_u32_le(const u8* buf, usize offset);\n"
|
||||
"u64 pxl8_unpack_u64_be(const u8* buf, usize offset);\n"
|
||||
"u64 pxl8_unpack_u64_le(const u8* buf, usize offset);\n"
|
||||
"i8 pxl8_unpack_i8(const u8* buf, usize offset);\n"
|
||||
"i16 pxl8_unpack_i16_be(const u8* buf, usize offset);\n"
|
||||
"i16 pxl8_unpack_i16_le(const u8* buf, usize offset);\n"
|
||||
"i32 pxl8_unpack_i32_be(const u8* buf, usize offset);\n"
|
||||
"i32 pxl8_unpack_i32_le(const u8* buf, usize offset);\n"
|
||||
"i64 pxl8_unpack_i64_be(const u8* buf, usize offset);\n"
|
||||
"i64 pxl8_unpack_i64_le(const u8* buf, usize offset);\n"
|
||||
"f32 pxl8_unpack_f32_be(const u8* buf, usize offset);\n"
|
||||
"f32 pxl8_unpack_f32_le(const u8* buf, usize offset);\n"
|
||||
"f64 pxl8_unpack_f64_be(const u8* buf, usize offset);\n"
|
||||
"f64 pxl8_unpack_f64_le(const u8* buf, usize offset);\n";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue