fully compiles

This commit is contained in:
2025-05-22 13:23:13 -05:00
parent a204fce4b5
commit 51940080a8
8 changed files with 81 additions and 151 deletions

View File

@@ -246,10 +246,10 @@ foreach file : src
endforeach endforeach
if get_option('editor') if get_option('editor')
sources += 'source/qjs_imgui.cpp' # sources += 'source/qjs_imgui.cpp'
foreach imgui : imsrc # foreach imgui : imsrc
sources += tp / 'imgui' / imgui # sources += tp / 'imgui' / imgui
endforeach # endforeach
endif endif
includers = [] includers = []

View File

@@ -60,6 +60,8 @@ Object.defineProperty(Function.prototype, "hashify", {
var io = use_embed('io') var io = use_embed('io')
globalThis.console = use_embed('console')
var RESPATH = 'scripts/modules/resources.js' var RESPATH = 'scripts/modules/resources.js'
var canonical = io.realdir(RESPATH) + 'resources.js' var canonical = io.realdir(RESPATH) + 'resources.js'
var content = io.slurp(RESPATH) var content = io.slurp(RESPATH)
@@ -144,7 +146,7 @@ function console_rec(category, priority, line, file, msg) {
} }
io.mkdir('.prosperon') io.mkdir('.prosperon')
var logfile = io.open('.prosperon/log.txt') var logfile //= io.open('.prosperon/log.txt')
function pprint(msg, lvl = 0) { function pprint(msg, lvl = 0) {
if (!logfile) return if (!logfile) return

View File

@@ -7,6 +7,7 @@ rectangle packing, etc.
` `
var io = use('io') var io = use('io')
var os = use('os')
var res = use('resources') var res = use('resources')
var render = use('render') var render = use('render')

View File

@@ -1,6 +1,6 @@
var io = use_embed('io') var io = use_embed('io');
var miniz = use_embed('miniz') var miniz = use_embed('miniz');
var os = use_embed('os') var os = use_embed('os');
// Merge of the old resources.js and packer.js functionalities // Merge of the old resources.js and packer.js functionalities
var Resources = {} var Resources = {}

View File

@@ -2,7 +2,6 @@
#include "font.h" #include "font.h"
#include "datastream.h" #include "datastream.h"
#include "qjs_sdl.h" #include "qjs_sdl.h"
#include "qjs_sdl_gpu.h"
#include "qjs_io.h" #include "qjs_io.h"
#include "transform.h" #include "transform.h"
#include "stb_ds.h" #include "stb_ds.h"
@@ -1959,6 +1958,8 @@ static const JSCFunctionListEntry js_console_funcs[] = {
MIST_FUNC_DEF(console,print,1), MIST_FUNC_DEF(console,print,1),
}; };
JSC_CCALL(debug_stack_depth, return number2js(js,js_debugger_stack_depth(js))) JSC_CCALL(debug_stack_depth, return number2js(js,js_debugger_stack_depth(js)))
JSC_CCALL(debug_build_backtrace, return js_debugger_build_backtrace(js,NULL)) JSC_CCALL(debug_build_backtrace, return js_debugger_build_backtrace(js,NULL))
JSC_CCALL(debug_closure_vars, return js_debugger_closure_variables(js,argv[0])) JSC_CCALL(debug_closure_vars, return js_debugger_closure_variables(js,argv[0]))
@@ -2683,17 +2684,6 @@ JSC_CCALL(os_unneeded,
SDL_UnlockMutex(actor->msg_mutex); SDL_UnlockMutex(actor->msg_mutex);
) )
JSValue js_os_get_trace(JSContext *js, JSValue self)
{
return JS_NewBool(js, trace);
}
JSValue js_os_set_trace(JSContext *js, JSValue self, JSValue value)
{
trace = JS_ToBool(js, value);
return JS_UNDEFINED;
}
JSC_CCALL(os_destroy, JSC_CCALL(os_destroy,
prosperon_rt *rt = JS_GetContextOpaque(js); prosperon_rt *rt = JS_GetContextOpaque(js);
rt->need_stop = 1; rt->need_stop = 1;
@@ -2765,7 +2755,7 @@ JSC_CCALL(os_memstate,
JSC_CCALL(os_gc, JS_RunGC(JS_GetRuntime(js)) ) JSC_CCALL(os_gc, JS_RunGC(JS_GetRuntime(js)) )
JSC_SSCALL(os_eval, JSC_SSCALL(os_eval,
ret = JS_Eval(js,str,strlen(str),str2,JS_EVAL_TYPE_GLOBAL); ret = JS_Eval(js,str2,strlen(str2),str,JS_EVAL_TYPE_GLOBAL);
) )
JSC_CCALL(os_mem_limit, JS_SetMemoryLimit(JS_GetRuntime(js), js2number(js,argv[0]))) JSC_CCALL(os_mem_limit, JS_SetMemoryLimit(JS_GetRuntime(js), js2number(js,argv[0])))
@@ -2898,6 +2888,18 @@ JSC_CCALL(graphics_save_jpg,
return JS_ThrowInternalError(js, "Could not write png"); return JS_ThrowInternalError(js, "Could not write png");
) )
int sort_sprite(const sprite *a, const sprite *b)
{
if (a->layer != b->layer) return a->layer - b->layer;
if (a->pos.Y != b->pos.Y)
return (b->pos.Y - a->pos.Y);
if (JS_VALUE_GET_PTR(a->image) != JS_VALUE_GET_PTR(b->image))
return JS_VALUE_GET_PTR(a->image) < JS_VALUE_GET_PTR(b->image) ? -1 : 1;
return 0;
}
JSC_CCALL(gpu_make_sprite_queue, JSC_CCALL(gpu_make_sprite_queue,
sprite *sprites = NULL; sprite *sprites = NULL;
size_t quads = 0; size_t quads = 0;
@@ -3034,6 +3036,52 @@ JSC_CCALL(gpu_make_sprite_queue,
JS_FreeValue(js, mesh); JS_FreeValue(js, mesh);
) )
typedef struct {
JSValue val;
void *ptr;
size_t size;
int need_new;
} BufferCheckResult;
static BufferCheckResult get_or_extend_buffer(
JSContext *js,
JSValue old_mesh,
const char *prop,
size_t needed_size,
int type,
int elements_per_item,
int copy,
int index
) {
BufferCheckResult res = { JS_UNDEFINED, NULL, 0, 0 };
if (!JS_IsUndefined(old_mesh)) {
JSValue old_buf = JS_GetProperty(js, old_mesh, prop);
if (!JS_IsUndefined(old_buf)) {
size_t old_size;
void *data = get_gpu_buffer(js, old_buf, NULL, &old_size);
if (data && old_size >= needed_size) {
// Old buffer is large enough
res.val = old_buf; // keep it
res.ptr = data;
res.size = old_size;
return res;
}
JS_FreeValue(js, old_buf);
}
}
// If we reach here, we need a new buffer
res.need_new = 1;
return res;
}
static HMM_Vec3 base_quad[4] = {
{0.0,0.0,1.0},
{1.0,0.0,1.0},
{0.0,1.0,1.0},
{1.0,1.0,1.0}
};
JSC_CCALL(gpu_make_sprite_mesh, JSC_CCALL(gpu_make_sprite_mesh,
size_t quads = JS_ArrayLength(js, argv[0]); size_t quads = JS_ArrayLength(js, argv[0]);
size_t verts = quads*4; size_t verts = quads*4;
@@ -3413,6 +3461,11 @@ JSValue js_debug_use(JSContext *js) {
return mod; return mod;
} }
JSValue js_console_use(JSContext *js) {
JSValue mod = JS_NewObject(js);
JS_SetPropertyFunctionList(js,mod,js_console_funcs,countof(js_console_funcs));
return mod;
}
JSC_CCALL(os_value_id, JSC_CCALL(os_value_id,
JS_SetPropertyStr(js, argv[0], "id", number2js(js, (uintptr_t)JS_VALUE_GET_PTR(argv[0]))); JS_SetPropertyStr(js, argv[0], "id", number2js(js, (uintptr_t)JS_VALUE_GET_PTR(argv[0])));
@@ -3424,7 +3477,7 @@ JSC_CCALL(os_value_id,
#include "qjs_blob.h" #include "qjs_blob.h"
#include "qjs_http.h" #include "qjs_http.h"
JSValue js_imgui_use(JSContext *js); //JSValue js_imgui_use(JSContext *js);
#define MISTLINE(NAME) (ModuleEntry){#NAME, js_##NAME##_use} #define MISTLINE(NAME) (ModuleEntry){#NAME, js_##NAME##_use}
void ffi_load(JSContext *js) void ffi_load(JSContext *js)
@@ -3448,7 +3501,7 @@ void ffi_load(JSContext *js)
arrput(rt->module_registry, MISTLINE(soloud)); arrput(rt->module_registry, MISTLINE(soloud));
arrput(rt->module_registry, MISTLINE(layout)); arrput(rt->module_registry, MISTLINE(layout));
arrput(rt->module_registry, MISTLINE(miniz)); arrput(rt->module_registry, MISTLINE(miniz));
arrput(rt->module_registry, MISTLINE(imgui)); // arrput(rt->module_registry, MISTLINE(imgui));
arrput(rt->module_registry, ((ModuleEntry){"camera", js_camera_use})); arrput(rt->module_registry, ((ModuleEntry){"camera", js_camera_use}));
arrput(rt->module_registry, MISTLINE(debug)); arrput(rt->module_registry, MISTLINE(debug));
arrput(rt->module_registry, MISTLINE(dmon)); arrput(rt->module_registry, MISTLINE(dmon));
@@ -3460,6 +3513,7 @@ void ffi_load(JSContext *js)
arrput(rt->module_registry, MISTLINE(blob)); arrput(rt->module_registry, MISTLINE(blob));
arrput(rt->module_registry, MISTLINE(http)); arrput(rt->module_registry, MISTLINE(http));
arrput(rt->module_registry, ((ModuleEntry){"sdl_audio", js_sdl_audio_use})); arrput(rt->module_registry, ((ModuleEntry){"sdl_audio", js_sdl_audio_use}));
arrput(rt->module_registry, MISTLINE(console));
#ifdef TRACY_ENABLE #ifdef TRACY_ENABLE
arrput(rt->module_registry, MISTLINE(tracy)); arrput(rt->module_registry, MISTLINE(tracy));
@@ -3481,7 +3535,7 @@ void ffi_load(JSContext *js)
js_input_use(js); // Handles input js_input_use(js); // Handles input
js_camera_use(js); // Handles camera js_camera_use(js); // Handles camera
js_sdl_audio_use(js); // Handles SDL_AudioStream and other SDL classes js_sdl_audio_use(js); // Handles SDL_AudioStream and other SDL classes
js_sdl_gpu_use(js); // Handles all GPU classes // js_sdl_gpu_use(js); // Handles all GPU classes
js_io_use(js); // Handles PHYSFS_File js_io_use(js); // Handles PHYSFS_File
QJSCLASSPREP_FUNCS(renderer_ctx) QJSCLASSPREP_FUNCS(renderer_ctx)

View File

@@ -379,63 +379,6 @@ JSC_CCALL(os_destroy,
rt->need_stop = 1; rt->need_stop = 1;
) )
JSValue js_actor_delay(JSContext *js, JSValue self, int argc, JSValue *argv) {
if (!JS_IsFunction(js, argv[0]))
return JS_ThrowReferenceError(js, "Argument must be a function.");
prosperon_rt *actor = JS_GetContextOpaque(js);
double seconds;
JS_ToFloat64(js, &seconds, argv[1]);
if (seconds <= 0) {
SDL_LockMutex(actor->msg_mutex);
JSValue cb = JS_DupValue(js, argv[0]);
arrput(actor->events, cb);
SDL_UnlockMutex(actor->msg_mutex);
return JS_NewInt32(js, -1);
}
Uint64 ns = seconds * SDL_NS_PER_SECOND;
Uint32 id = SDL_AddTimerNS(ns, actor_timer_cb, actor);
SDL_LockMutex(actor->msg_mutex);
JSValue cb = JS_DupValue(js, argv[0]);
hmput(actor->timers, id, cb);
if (actor->ar) {
SDL_RemoveTimer(actor->ar);
actor->ar = 0;
}
SDL_UnlockMutex(actor->msg_mutex);
return JS_NewUint32(js, id);
}
JSValue js_actor_removetimer(JSContext *js, JSValue self, int argc, JSValue *argv) {
prosperon_rt *actor = JS_GetContextOpaque(js);
Uint32 timer_id;
JS_ToUint32(js, &timer_id, argv[0]);
if (timer_id == -1) return JS_UNDEFINED;
SDL_RemoveTimer(timer_id);
JSValue cb = JS_UNDEFINED;
SDL_LockMutex(actor->msg_mutex);
int id = hmgeti(actor->timers, timer_id);
if (id != -1) {
cb = actor->timers[id].value;
hmdel(actor->timers, timer_id);
}
SDL_UnlockMutex(actor->msg_mutex);
JS_FreeValue(js,cb);
return JS_UNDEFINED;
}
JSValue js_os_ioactor(JSContext *js, JSValue self, int argc, JSValue *argv) {
return JS_NewString(js, io_actor->id);
}
static const JSCFunctionListEntry js_os_funcs[] = { static const JSCFunctionListEntry js_os_funcs[] = {
MIST_FUNC_DEF(os, make_transform, 0), MIST_FUNC_DEF(os, make_transform, 0),
MIST_FUNC_DEF(os, clean_transforms, 0), MIST_FUNC_DEF(os, clean_transforms, 0),

View File

@@ -9,45 +9,6 @@
#include "stb_dxt.h" #include "stb_dxt.h"
typedef struct {
JSValue val;
void *ptr;
size_t size;
int need_new;
} BufferCheckResult;
static BufferCheckResult get_or_extend_buffer(
JSContext *js,
JSValue old_mesh,
const char *prop,
size_t needed_size,
int type,
int elements_per_item,
int copy,
int index
) {
BufferCheckResult res = { JS_UNDEFINED, NULL, 0, 0 };
if (!JS_IsUndefined(old_mesh)) {
JSValue old_buf = JS_GetProperty(js, old_mesh, prop);
if (!JS_IsUndefined(old_buf)) {
size_t old_size;
void *data = get_gpu_buffer(js, old_buf, NULL, &old_size);
if (data && old_size >= needed_size) {
// Old buffer is large enough
res.val = old_buf; // keep it
res.ptr = data;
res.size = old_size;
return res;
}
JS_FreeValue(js, old_buf);
}
}
// If we reach here, we need a new buffer
res.need_new = 1;
return res;
}
// Global GPU device and window // Global GPU device and window
static SDL_GPUDevice *global_gpu; static SDL_GPUDevice *global_gpu;
@@ -1355,14 +1316,6 @@ JSC_CCALL(gpu_texture,
return jstex; return jstex;
) )
static HMM_Vec3 base_quad[4] = {
{0.0,0.0,1.0},
{1.0,0.0,1.0},
{0.0,1.0,1.0},
{1.0,1.0,1.0}
};
typedef struct { typedef struct {
text_vert vert[4]; text_vert vert[4];
} quad; } quad;

View File

@@ -10,29 +10,6 @@ int sort_sprite_backtofront(const sprite *a, const sprite *b);
int sort_sprite_fronttoback(const sprite *a, const sprite *b); int sort_sprite_fronttoback(const sprite *a, const sprite *b);
int sort_sprite_texture(const sprite *a, const sprite *b); int sort_sprite_texture(const sprite *a, const sprite *b);
// Buffer check result structure
typedef struct {
JSValue val;
void *ptr;
size_t size;
int need_new;
} BufferCheckResult;
// Function for buffer management
BufferCheckResult get_or_extend_buffer(
JSContext *js,
JSValue old_mesh,
const char *prop,
size_t needed_size,
int type,
int elements_per_item,
int copy,
int index
);
// Base quad for sprite rendering
extern HMM_Vec3 base_quad[4];
JSValue js_sdl_gpu_use(JSContext *js); JSValue js_sdl_gpu_use(JSContext *js);
#endif #endif