improve sw renderer
This commit is contained in:
parent
415d424057
commit
39ee0fefb7
89 changed files with 9380 additions and 2307 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue