Builds again?

This commit is contained in:
2026-06-06 16:42:12 -05:00
parent 79054080c0
commit bbe0e48d23
3 changed files with 1 additions and 139 deletions
-1
View File
@@ -59,7 +59,6 @@ errorret_t engineInit(const int32_t argc, const char_t **argv) {
consolePrint("Engine initialized");
errorChain(scriptExecFile("init.js"));
errorChain(sceneSet("testscene.js"));
errorOk();
}
-95
View File
@@ -27,20 +27,6 @@ errorret_t sceneInit(void) {
}
void sceneUpdate(void) {
if((SCENE.state & SCENE_STATE_LOADED) == 0) return;
if((SCENE.state & SCENE_STATE_INITIALIZED) == 0) {
errorret_t ret = sceneCallScriptMethod(SCENE.jsInit, "init");
if(errorIsNotOk(ret)) {
errorCatch(errorPrint(ret));
errorCatch(errorPrint(sceneDispose()));
return;
}
SCENE.state |= SCENE_STATE_INITIALIZED;
}
errorCatch(errorPrint(sceneCallScriptMethod(SCENE.jsUpdate, "update")));
}
errorret_t sceneRender(void) {
@@ -78,87 +64,6 @@ errorret_t sceneRender(void) {
errorOk();
}
errorret_t sceneSet(const char_t *jsFile) {
assertStrLenMin(jsFile, 1, "jsFile cannot be empty");
// Dispose any active scene before switching.
errorChain(sceneDispose());
// // Lock the asset
// assetloaderinput_t input;
// memoryZero(&input, sizeof(input));
// assetentry_t *entry = assetLock(jsFile, ASSET_LOADER_TYPE_SCRIPT, &input);
// if(!entry) errorThrow("sceneSet: failed to lock '%s'", jsFile);
// // Wait for loaded.
// errorret_t err = assetRequireLoaded(entry);
// if(errorIsNotOk(err)) {
// assetUnlockEntry(entry);
// errorChain(err);
// }
// // Any export?
// if(entry->data.script.exportedModule == 0) {
// assetUnlockEntry(entry);
// errorThrow("sceneSet: '%s' produced no exports", jsFile);
// }
// // Copy the exports reference before unlocking (entry may be reaped).
// jerry_value_t exports = jerry_value_copy(entry->data.script.exportedModule);
// assetUnlockEntry(entry);
// // Extract the three lifecycle callbacks.
// SCENE.jsInit = sceneExtractFn(exports, "init");
// SCENE.jsUpdate = sceneExtractFn(exports, "update");
// SCENE.jsDispose = sceneExtractFn(exports, "dispose");
// jerry_value_free(exports);
SCENE.state |= SCENE_STATE_LOADED;
errorOk();
}
errorret_t sceneCallScriptMethod(jerry_value_t fn, const char_t *name) {
assertStrLenMin(name, 1, "name cannot be empty");
if(!jerry_value_is_function(fn)) {
errorOk();
}
jerry_value_t ret = jerry_call(fn, jerry_undefined(), NULL, 0);
if(jerry_value_is_exception(ret)) {
char_t buf[256];
moduleBaseExceptionMessage(ret, buf, sizeof(buf));
errorThrow("Scene script exception in %s: %s", name, buf);
}
jerry_value_free(ret);
errorOk();
}
jerry_value_t sceneExtractFn(jerry_value_t obj, const char_t *name) {
jerry_value_t val = moduleBaseGetProp(obj, name);
if(jerry_value_is_function(val)) return val;
jerry_value_free(val);
return jerry_undefined();
}
errorret_t sceneDispose(void) {
if((SCENE.state & SCENE_STATE_LOADED) == 0) {
errorOk();
}
if((SCENE.state & SCENE_STATE_INITIALIZED) != 0) {
errorChain(sceneCallScriptMethod(SCENE.jsDispose, "dispose"));
}
jerry_value_free(SCENE.jsDispose);
jerry_value_free(SCENE.jsInit);
jerry_value_free(SCENE.jsUpdate);
SCENE.jsDispose = jerry_undefined();
SCENE.jsInit = jerry_undefined();
SCENE.jsUpdate = jerry_undefined();
SCENE.state = 0;
errorOk();
}
+1 -43
View File
@@ -7,16 +7,9 @@
#pragma once
#include "error/error.h"
#include <jerryscript.h>
#define SCENE_STATE_LOADED 0x01
#define SCENE_STATE_INITIALIZED 0x02
typedef struct {
jerry_value_t jsInit;
jerry_value_t jsUpdate;
jerry_value_t jsDispose;
uint8_t state;
void *nothing;
} scene_t;
extern scene_t SCENE;
@@ -37,41 +30,6 @@ void sceneUpdate(void);
*/
errorret_t sceneRender(void);
/**
* Requests a scene transition. The pending script scene (set via
* scriptSceneSetPending) will be activated at the start of the next
* sceneUpdate call.
*/
// void sceneSet(void);
/**
* Loads a JS file as a module, extracts the .init / .update / .dispose
* callbacks from its exports, and stores them ready for the scene loop.
* Disposes any previously active scene first.
*
* @param jsFile Asset path of the script (e.g. "testscene.js").
*/
errorret_t sceneSet(const char_t *jsFile);
/**
* Calls a scene script method and logs any exception.
*
* @param fn The function to call. If not a function, this is a no-op.
* @param name The name of the method (for logging purposes).
* @return Error state (if any).
*/
errorret_t sceneCallScriptMethod(jerry_value_t fn, const char_t *name);
/**
* Extracts a function from a scene module export. If the property doesn't
* exist or isn't a function, returns undefined.
*
* @param obj The module exports object.
* @param name The name of the property to extract.
* @return The extracted function, or undefined.
*/
jerry_value_t sceneExtractFn(jerry_value_t obj, const char_t *name);
/**
* Disposes the active scene immediately.
*/