From 56fc25d27d34845a559ba0b8436e30d529863050 Mon Sep 17 00:00:00 2001 From: John Alanbrook Date: Mon, 27 Jan 2025 15:13:02 -0600 Subject: [PATCH] add prosperon use --- scripts/engine.js | 10 +++--- scripts/log.js | 37 +++++++++++++++++++++- scripts/prosperon.js | 26 ++++++++++++++++ scripts/resources.js | 1 + scripts/sound.js | 4 ++- source/jsffi.c | 73 ++++++++++++++++++++++---------------------- 6 files changed, 109 insertions(+), 42 deletions(-) create mode 100644 scripts/prosperon.js diff --git a/scripts/engine.js b/scripts/engine.js index ee4dcae6..c686d022 100644 --- a/scripts/engine.js +++ b/scripts/engine.js @@ -22,8 +22,8 @@ Object.defineProperty(Function.prototype, "hashify", { }); var io = use_embed('io') -io.mount(io.basedir() + "core/scripts/") -io.mount(io.basedir() + "core/") +io.mount("core/scripts") +io.mount("core") var canonical = io.realdir('resources.js') + 'resources.js' var content = io.slurp('resources.js') @@ -461,8 +461,6 @@ try{ return underling; }; -actor.spawn.doc = `Create a new actor, using this actor as the overling, initializing it with 'script' and with data (as a JSON or Nota file) from 'config'.`; - actor.clear = function actor_clear() { this[UNDERLINGS].forEach(p => { @@ -499,5 +497,9 @@ var search = use('search') actor[UNDERLINGS] = new Set() +var log = use('log') +log.enable("dbg", {console:true}) +log.dbg("TEST") + globalThis.mixin("color"); globalThis.mixin("std") diff --git a/scripts/log.js b/scripts/log.js index 9f465f90..4a136de9 100644 --- a/scripts/log.js +++ b/scripts/log.js @@ -1,3 +1,38 @@ -var log = {} +var io = use('io') + +var log = { + // Holds config per log name + config: {}, + + // Enable a named log, generating a method if needed + enable(name, outputs) { + if (!this.config[name]) this.config[name] = { enabled: false, outputs: [] } + this.config[name].enabled = true + if (!Array.isArray(outputs) && outputs != null) outputs = [outputs] + if (outputs) outputs.forEach(o => this.config[name].outputs.push(o)) + + // Dynamically add log method if it doesn't exist + if (!this[name]) { + this[name] = msg => this._write(name, msg) + } + }, + + // Disable a named log + disable(name) { + if (this.config[name]) this.config[name].enabled = false + }, + + // Internal method to actually write the log + _write(name, msg) { + let c = this.config[name] + if (!c || !c.enabled) return + let entry = '[' + name + '] ' + msg + c.outputs.forEach(o => { + if (o.console) console.print(entry + '\n') + if (o.file) o.file.write(entry + '\n') + if (o.buffer) o.buffer.push(entry) + }) + } +} return log diff --git a/scripts/prosperon.js b/scripts/prosperon.js new file mode 100644 index 00000000..34553d1a --- /dev/null +++ b/scripts/prosperon.js @@ -0,0 +1,26 @@ +var pr = {} + +var default = { + title: "Prosperon", + width: 1280, + height: 720, + size: [1280,720], + icon: os.make_texture(io.slurpbytes('icons/moon.gif')), + high_dpi: 0, + alpha: 1, + fullscreen: 0, + sample_count: 1, + enable_clipboard: true, + enable_dragndrop: true, + max_dropped_files: 1, + swap_interval: 1, + name: "Prosperon", + version:"432r23a", + identifier: "world.pockle.prosperon", + creator: "Pockle World LLC", + copyright: "Copyright Pockle World 2025", + type: "application", + url: "https://prosperon.dev" +} + +return pr diff --git a/scripts/resources.js b/scripts/resources.js index 66b86874..514199bd 100644 --- a/scripts/resources.js +++ b/scripts/resources.js @@ -35,6 +35,7 @@ function find_ext(file, ext) { if (io.exists(attempt)) return attempt } + console.log(`Unable to find a file ${file} from extensions ${ext}`) return undefined } diff --git a/scripts/sound.js b/scripts/sound.js index d39cadf3..47204275 100644 --- a/scripts/sound.js +++ b/scripts/sound.js @@ -1,6 +1,8 @@ //var soloud = use('soloud') var tween = use('tween') var io = use('io') +var res = use('resources') + soloud.init(); var audio = {}; @@ -8,7 +10,7 @@ var pcms = {}; audio.pcm = function pcm(file) { - file = Resources.find_sound(file); + file = res.find_sound(file); if (!file) throw new Error(`Could not findfile ${file}`); if (pcms[file]) return pcms[file]; var newpcm = soloud.load_wav_mem(io.slurpbytes(file)); diff --git a/source/jsffi.c b/source/jsffi.c index dc903d02..f7047d63 100644 --- a/source/jsffi.c +++ b/source/jsffi.c @@ -1670,22 +1670,28 @@ JSC_CCALL(spline_catmull, HMM_Vec2 *points = js2cpvec2arr(js,argv[0]); float param = js2number(js,argv[1]); HMM_Vec2 *samples = catmull_rom_ma_v2(points,param); + + if (!samples) + ret = JS_UNDEFINED; + else + ret = vecarr2js(js,samples, arrlen(samples)); + arrfree(points); - if (!samples) return JS_UNDEFINED; - JSValue arr = vecarr2js(js,samples, arrlen(samples)); arrfree(samples); - return arr; ) JSC_CCALL(spline_bezier, HMM_Vec2 *points = js2cpvec2arr(js,argv[0]); float param = js2number(js,argv[1]); HMM_Vec2 *samples = catmull_rom_ma_v2(points,param); - arrfree(points); - if (!samples) return JS_UNDEFINED; - JSValue arr = vecarr2js(js,samples, arrlen(samples)); + + if (!samples) + ret = JS_UNDEFINED; + else + ret = vecarr2js(js,samples, arrlen(samples)); + arrfree(samples); - return arr; + arrfree(points); ) static const JSCFunctionListEntry js_spline_funcs[] = { @@ -1760,7 +1766,7 @@ JSValue js_vector_dot(JSContext *js, JSValue self, int argc, JSValue *argv) { return JS_UNDEFINED; }; -JSC_CCALL(vector_project, return vec22js(js,HMM_ProjV2(js2vec2(js,argv[0]), js2vec2(js,argv[1])))) +JSC_CCALL(vector_project, ret = vec22js(js,HMM_ProjV2(js2vec2(js,argv[0]), js2vec2(js,argv[1])))) JSC_CCALL(vector_midpoint, HMM_Vec2 a = js2vec2(js,argv[0]); @@ -1773,12 +1779,12 @@ JSC_CCALL(vector_midpoint, JSC_CCALL(vector_distance, HMM_Vec2 a = js2vec2(js,argv[0]); HMM_Vec2 b = js2vec2(js,argv[1]); - return number2js(js,HMM_DistV2(a,b)); + ret = number2js(js,HMM_DistV2(a,b)); ) JSC_CCALL(vector_angle, HMM_Vec2 a = js2vec2(js,argv[0]); - return angle2js(js,atan2(a.y,a.x)); + ret= angle2js(js,atan2(a.y,a.x)); ) /* Given a series of points p, computes a new series with them expanded on either side by d */ @@ -1877,7 +1883,7 @@ JSC_CCALL(vector_add, HMM_Vec4 a = js2vec4(js,argv[0]); HMM_Vec4 b = js2vec4(js,argv[1]); HMM_Vec4 c = HMM_AddV4(a,b); - return vec42js(js,c); + ret = vec42js(js,c); ) JSC_CCALL(vector_norm, @@ -1895,7 +1901,7 @@ JSC_CCALL(vector_norm, for (int i = 0; i < len; i++) JS_SetPropertyUint32(js, newarr, i, number2js(js,js_getnum_uint32(js, argv[0],i)/length)); - return newarr; + ret = newarr; ) JSC_CCALL(vector_angle_between, @@ -1905,7 +1911,7 @@ JSC_CCALL(vector_angle_between, case 3: return angle2js(js,HMM_AngleV3(js2vec3(js,argv[0]), js2vec3(js,argv[1]))); case 4: return angle2js(js,HMM_AngleV4(js2vec4(js,argv[0]), js2vec4(js,argv[1]))); } - return angle2js(js,0); + ret = angle2js(js,0); ) JSC_CCALL(vector_lerp, @@ -1913,7 +1919,7 @@ JSC_CCALL(vector_lerp, double f = js2number(js,argv[1]); double t = js2number(js,argv[2]); - return number2js(js,(f-s)*t+s); + ret = number2js(js,(f-s)*t+s); ) int gcd(int a, int b) { @@ -1923,13 +1929,13 @@ int gcd(int a, int b) { } JSC_CCALL(vector_gcd, - return number2js(js,gcd(js2number(js,argv[0]), js2number(js,argv[1]))); + ret = number2js(js,gcd(js2number(js,argv[0]), js2number(js,argv[1]))); ) JSC_CCALL(vector_lcm, double a = js2number(js,argv[0]); double b = js2number(js,argv[1]); - return number2js(js,(a*b)/gcd(a,b)); + ret = number2js(js,(a*b)/gcd(a,b)); ) JSC_CCALL(vector_clamp, @@ -2241,7 +2247,7 @@ JS_FreeCString(JS,str); \ JS_FreeValue(js,v); \ } \ -JSC_SCALL(os_engine_start, +JSC_CCALL(os_engine_start, JSValue p = argv[0]; JS_SDL_PROP(js, p, SDL_PROP_APP_METADATA_NAME_STRING, name) JS_SDL_PROP(js, p, SDL_PROP_APP_METADATA_VERSION_STRING, version) @@ -2718,7 +2724,7 @@ SDL_GPUShaderFormat js2SDL_GPUShaderFormat(JSContext *js, JSValue v) return format; } -JSC_SCALL(SDL_Window_make_gpu, +JSC_CCALL(SDL_Window_make_gpu, const char *name = JS_ToCString(js,argv[1]); SDL_PropertiesID props = SDL_CreateProperties(); SDL_SetStringProperty(props, SDL_PROP_GPU_DEVICE_CREATE_NAME_STRING, name); @@ -5646,11 +5652,6 @@ JSC_SCALL(io_writepath, if (!PHYSFS_setWriteDir(str)) ret = JS_ThrowReferenceError(js,"%s", PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode())); ) -JSC_SSCALL(io_gamemode, - const char *prefdir = PHYSFS_getPrefDir(str, str2); - PHYSFS_setWriteDir(prefdir); -) - struct globdata { JSContext *js; JSValue arr; @@ -5728,15 +5729,17 @@ JSC_CCALL(io_userdir, return JS_NewString(js,PHYSFS_getUserDir())) JSC_SCALL(io_open, PHYSFS_File *f = PHYSFS_openWrite(str); if (!f) - return JS_ThrowReferenceError(js,"%s", PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode())); - - ret = PHYSFS_File2js(js,f); + ret = JS_ThrowReferenceError(js,"%s", PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode())); + else + ret = PHYSFS_File2js(js,f); ) JSC_SCALL(io_realdir, const char *real = PHYSFS_getRealDir(str); - if (!real) return JS_UNDEFINED; - ret = JS_NewString(js,real); + if (!real) + ret = JS_UNDEFINED; + else + ret = JS_NewString(js,real); ) JSC_CCALL(io_searchpath, @@ -5762,7 +5765,6 @@ static const JSCFunctionListEntry js_io_funcs[] = { MIST_FUNC_DEF(io,basedir, 0), MIST_FUNC_DEF(io, userdir, 0), MIST_FUNC_DEF(io, realdir, 1), - MIST_FUNC_DEF(io, gamemode, 2), MIST_FUNC_DEF(io, open, 2), MIST_FUNC_DEF(io, searchpath, 0), }; @@ -6519,7 +6521,7 @@ JSC_CCALL(os_make_transform, ) JSC_CCALL(os_make_sprite, return sprite2js(js,make_sprite())) -JSC_SCALL(os_system, return number2js(js,system(str)); ) +JSC_SCALL(os_system, ret = number2js(js,system(str)); ) JSC_SCALL(os_model_buffer, /* @@ -7304,10 +7306,13 @@ JSC_SCALL(os_use_embed, if (strcmp(str,module_registry[i].name) == 0) { JSValue mod = JS_NewObject(js); JS_SetPropertyFunctionList(js,mod,module_registry[i].fn, module_registry[i].fn_count); - return mod; + ret = mod; + break; } } - return JS_ThrowReferenceError(js,"Library %s could not be found embedded"); + + if (JS_IsUndefined(ret)) + ret = JS_ThrowReferenceError(js,"Library %s could not be found embedded", str); ) JSC_SCALL(os_use_dyn, @@ -7326,10 +7331,6 @@ JSC_SCALL(os_use_dyn, SDL_UnloadObject(ptr); ) - - - - JSC_CCALL(qtree_insert, qtree tree = js2qtree(js,self); JSValue v = argv[0];