Scene.set() JS lifecycle, UI sprite caching, emulator test scripts
- Add Scene.set(module) so JerryScript can switch scenes via
require()'d {init, update, dispose} modules; wire it into
engineUpdate() and rework overworldscene.js/init.js to the new shape.
- Fix scriptManagerExecFile() never pushing its own file's directory
onto the require() dir stack, breaking relative require() calls from
a top-level entry script (e.g. init.js -> ./overworldscene.js).
- Cache sprite geometry across frames for uislider/uitab/uiframe
(dialogs/textbox/settings) and give uitextbox a per-page glyph cache
instead of one spriteBatchBuffer call per visible character. uiconsole
drops its alloc/free vertex buffer for a fixed-size one. uifps skips
rebuilding its label when the text hasn't changed.
- Add PSP_OPTIMIZATION_PLAN.md and a handful of UI/spritebatch unit
tests covering the new caching logic.
- Add Dolphin/PPSSPP emulator smoke-test scripts (+ Docker variants and
CI jobs) for GameCube/Wii/PSP.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -17,20 +17,18 @@
|
||||
#include "display/mesh/plane.h"
|
||||
#include "display/mesh/capsule.h"
|
||||
#include "script/scriptmanager.h"
|
||||
#include "script/module/scene/modulescene.h"
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifndef DUSK_ASSETS_DIR
|
||||
#error "DUSK_ASSETS_DIR must be defined"
|
||||
#endif
|
||||
|
||||
// Reads the real, shipped overworldscene.js from disk (not a copy embedded
|
||||
// in this test) so this test actually verifies what ships.
|
||||
static char_t *readScriptSource(void) {
|
||||
static char_t *readFile(const char_t *relativePath) {
|
||||
char_t path[512];
|
||||
snprintf(
|
||||
path, sizeof(path), "%s/scripts/overworldscene.js", DUSK_ASSETS_DIR
|
||||
);
|
||||
snprintf(path, sizeof(path), "%s/%s", DUSK_ASSETS_DIR, relativePath);
|
||||
|
||||
FILE *f = fopen(path, "rb");
|
||||
assert_non_null(f);
|
||||
@@ -47,6 +45,26 @@ static char_t *readScriptSource(void) {
|
||||
return buf;
|
||||
}
|
||||
|
||||
// Runs the real, shipped overworldscene.js through Scene.set() the same
|
||||
// way require()/init.js would -- not a copy embedded in this test, so
|
||||
// this actually verifies what ships.
|
||||
static errorret_t installOverworldScene(void) {
|
||||
char_t *fileSrc = readFile("scripts/overworldscene.js");
|
||||
|
||||
const char_t *prefix = "var module = { exports: {} };\n(function(module){\n";
|
||||
const char_t *suffix = "\n})(module);\nScene.set(module.exports);";
|
||||
size_t wrappedLen = strlen(prefix) + strlen(fileSrc) + strlen(suffix);
|
||||
char_t *wrapped = (char_t *)memoryAllocate(wrappedLen + 1);
|
||||
snprintf(
|
||||
wrapped, wrappedLen + 1, "%s%s%s", prefix, fileSrc, suffix
|
||||
);
|
||||
memoryFree(fileSrc);
|
||||
|
||||
errorret_t ret = scriptManagerExec(wrapped, NULL);
|
||||
memoryFree(wrapped);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int overworld_setup(void **state) {
|
||||
sceneInit();
|
||||
|
||||
@@ -71,9 +89,7 @@ static int overworld_teardown(void **state) {
|
||||
}
|
||||
|
||||
static void test_overworldscene_builds_expected_entities(void **state) {
|
||||
char_t *src = readScriptSource();
|
||||
errorret_t ret = scriptManagerExec(src, NULL);
|
||||
memoryFree(src);
|
||||
errorret_t ret = installOverworldScene();
|
||||
assert_true(errorIsOk(ret));
|
||||
|
||||
sceneid_t sceneId = sceneGetActive();
|
||||
@@ -195,9 +211,7 @@ static void test_overworldscene_builds_expected_entities(void **state) {
|
||||
}
|
||||
|
||||
static void test_overworldscene_update_orbits_camera(void **state) {
|
||||
char_t *src = readScriptSource();
|
||||
errorret_t ret = scriptManagerExec(src, NULL);
|
||||
memoryFree(src);
|
||||
errorret_t ret = installOverworldScene();
|
||||
assert_true(errorIsOk(ret));
|
||||
|
||||
sceneid_t sceneId = sceneGetActive();
|
||||
@@ -210,7 +224,7 @@ static void test_overworldscene_update_orbits_camera(void **state) {
|
||||
// Drive one frame with a known delta and confirm the camera orbited by
|
||||
// exactly angle = delta * speed (0.1 * 0.5 = 0.05 rad).
|
||||
TIME.delta = 0.1f;
|
||||
ret = scriptManagerCallGlobal("update");
|
||||
ret = moduleSceneUpdateCurrent();
|
||||
assert_true(errorIsOk(ret));
|
||||
|
||||
vec3 camPosition;
|
||||
@@ -227,6 +241,66 @@ static void test_overworldscene_update_orbits_camera(void **state) {
|
||||
TIME.delta = 0.0f;
|
||||
}
|
||||
|
||||
static void test_scene_set_switches_and_disposes(void **state) {
|
||||
errorret_t ret = installOverworldScene();
|
||||
assert_true(errorIsOk(ret));
|
||||
assert_true(sceneGetActive() != SCENE_ID_INVALID);
|
||||
|
||||
// Install a second, trivial scene module in place of the first. This
|
||||
// must: call the first module's dispose(), destroy its scene, then
|
||||
// create+activate a new one and call the new module's init().
|
||||
ret = scriptManagerExec(
|
||||
"var switchState = { updateCount: 0, disposed: false };\n"
|
||||
"Scene.set({\n"
|
||||
" init: function() { var e = new Entity(); e.add(POSITION); },\n"
|
||||
" update: function() { switchState.updateCount++; },\n"
|
||||
" dispose: function() { switchState.disposed = true; }\n"
|
||||
"});",
|
||||
NULL
|
||||
);
|
||||
assert_true(errorIsOk(ret));
|
||||
|
||||
sceneid_t secondSceneId = sceneGetActive();
|
||||
assert_true(secondSceneId != SCENE_ID_INVALID);
|
||||
|
||||
entitymanager_t *mgr = sceneGetEntities(secondSceneId);
|
||||
assert_true(
|
||||
entityGetComponent(mgr, 0, COMPONENT_TYPE_POSITION) !=
|
||||
COMPONENT_ID_INVALID
|
||||
);
|
||||
// The first module's plane entity (entity 1, POSITION+PHYSICS+
|
||||
// RENDERABLE) must be gone -- proves the old scene was actually torn
|
||||
// down, not just deactivated. (Scene IDs are a small reused pool --
|
||||
// SCENE_COUNT_MAX slots -- so secondSceneId == firstSceneId here is
|
||||
// expected, not a bug: sceneCreate() picks the first free slot, and
|
||||
// destroying firstSceneId frees that exact slot right back up.)
|
||||
assert_true(
|
||||
entityGetComponent(mgr, 1, COMPONENT_TYPE_POSITION) ==
|
||||
COMPONENT_ID_INVALID
|
||||
);
|
||||
|
||||
ret = moduleSceneUpdateCurrent();
|
||||
assert_true(errorIsOk(ret));
|
||||
|
||||
jerry_value_t result;
|
||||
ret = scriptManagerExec("switchState.updateCount", &result);
|
||||
assert_true(errorIsOk(ret));
|
||||
assert_true(jerry_value_is_number(result));
|
||||
assert_int_equal((int)jerry_value_as_number(result), 1);
|
||||
jerry_value_free(result);
|
||||
|
||||
// Switching again must call the second module's dispose().
|
||||
ret = scriptManagerExec(
|
||||
"Scene.set({ init: function() {} });", NULL
|
||||
);
|
||||
assert_true(errorIsOk(ret));
|
||||
|
||||
ret = scriptManagerExec("switchState.disposed", &result);
|
||||
assert_true(errorIsOk(ret));
|
||||
assert_true(jerry_value_is_true(result));
|
||||
jerry_value_free(result);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
assertInit();
|
||||
const struct CMUnitTest tests[] = {
|
||||
@@ -238,6 +312,10 @@ int main(void) {
|
||||
test_overworldscene_update_orbits_camera,
|
||||
overworld_setup, overworld_teardown
|
||||
),
|
||||
cmocka_unit_test_setup_teardown(
|
||||
test_scene_set_switches_and_disposes,
|
||||
overworld_setup, overworld_teardown
|
||||
),
|
||||
};
|
||||
return cmocka_run_group_tests(tests, NULL, NULL);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user