Finish JerryScript Entity/Scene wiring; remove JSON serialize/deserialize

Register Entity, the generic Component wrapper, and Scene as JerryScript
classes (modulelist.c ties them together, plus their .d.ts stubs), so
scenes/entities can be built from script going forward instead of the
JSON scene format.

With scripting now the intended authoring path, drop the JSON
serialize/deserialize machinery entirely: componentdefinition_t's
serialize/deserialize callbacks, every component's *Serialize/
*Deserialize function, entitySerialize/entityDeserialize,
sceneSerialize/sceneDeserialize, and the "prefabs/<name>.json"/
"scenes/<name>.json" asset fallback in entityPrefabResolveAndApply/
scenePrefabResolveAndApply (C-coded prefabs only now). physicsshape.c
and its test are removed outright since they only existed for this.
game.c's test scene now comes from the existing overworldSceneCreate()
C builder instead of loading the now-deleted assets/scenes/test.json.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-30 11:19:08 -05:00
parent 015d90519f
commit e61914bad4
53 changed files with 576 additions and 2081 deletions
-45
View File
@@ -94,50 +94,6 @@ static void test_entityPositionParentChildWorldTransform(void **state) {
assert_int_equal(memoryGetAllocatedCount(), 0);
}
static void test_entityPositionDeserializeLookAt(void **state) {
entitymanager_t mgr;
entityManagerInit(&mgr);
entityid_t entity = entityManagerAdd(&mgr);
componentid_t comp = entityAddComponent(
&mgr, entity, COMPONENT_TYPE_POSITION
);
const char_t *json =
"{ \"x\": 0, \"y\": 5, \"z\": 10, "
"\"lookAt\": { \"x\": 0, \"y\": 0, \"z\": 0 } }";
yyjson_doc *doc = yyjson_read(json, strlen(json), YYJSON_READ_NOFLAG);
assert_non_null(doc);
errorret_t ret = entityPositionDeserialize(
&mgr, entity, comp, yyjson_doc_get_root(doc)
);
yyjson_doc_free(doc);
assert_true(errorIsOk(ret));
// The eye point decoded back out of localTransform should match "x"/"y"/"z".
vec3 eye;
entityPositionGetLocalPosition(&mgr, entity, comp, eye);
assert_float_equal(eye[0], 0.0f, 0.0001f);
assert_float_equal(eye[1], 5.0f, 0.0001f);
assert_float_equal(eye[2], 10.0f, 0.0001f);
// Forward (-local Z, see entityCameraGetForward's convention) should
// point from eye toward the lookAt target (the origin here).
mat4 transform;
entityPositionGetLocalTransform(&mgr, entity, comp, transform);
vec3 forward = { -transform[2][0], -transform[2][1], -transform[2][2] };
glm_vec3_normalize(forward);
vec3 toTarget = { -eye[0], -eye[1], -eye[2] };
glm_vec3_normalize(toTarget);
assert_float_equal(glm_vec3_dot(forward, toTarget), 1.0f, 0.001f);
entityManagerDispose(&mgr);
assert_int_equal(memoryGetAllocatedCount(), 0);
}
static void test_entityPositionDisposeDeep(void **state) {
entitymanager_t mgr;
entityManagerInit(&mgr);
@@ -167,7 +123,6 @@ int main(int argc, char **argv) {
const struct CMUnitTest tests[] = {
cmocka_unit_test(test_entityPositionLocalGetSet),
cmocka_unit_test(test_entityPositionParentChildWorldTransform),
cmocka_unit_test(test_entityPositionDeserializeLookAt),
cmocka_unit_test(test_entityPositionDisposeDeep),
};
-51
View File
@@ -110,56 +110,6 @@ static void test_entityTriggerDefaultsAndAccessors(void **state) {
assert_int_equal(memoryGetAllocatedCount(), 0);
}
static void test_entityTriggerSerializeRoundTrip(void **state) {
entitymanager_t mgr;
entityManagerInit(&mgr);
entityid_t entity = entityManagerAdd(&mgr);
componentid_t trig = entityAddComponent(
&mgr, entity, COMPONENT_TYPE_TRIGGER
);
physicsshape_t sphere = {
.type = PHYSICS_SHAPE_SPHERE,
.data.sphere.radius = 3.0f
};
entityTriggerSetShape(&mgr, entity, trig, sphere);
entityTriggerSetCollideMask(&mgr, entity, trig, 0x4);
yyjson_mut_doc *doc = yyjson_mut_doc_new(NULL);
yyjson_mut_val *root = yyjson_mut_obj(doc);
yyjson_mut_doc_set_root(doc, root);
assert_true(
errorIsOk(entityTriggerSerialize(&mgr, entity, trig, doc, root))
);
size_t len = 0;
char_t *jsonStr = yyjson_mut_write(doc, 0, &len);
assert_non_null(jsonStr);
yyjson_mut_doc_free(doc);
yyjson_doc *readDoc = yyjson_read(jsonStr, len, 0);
free(jsonStr);
assert_non_null(readDoc);
entityid_t entity2 = entityManagerAdd(&mgr);
componentid_t trig2 = entityAddComponent(
&mgr, entity2, COMPONENT_TYPE_TRIGGER
);
assert_true(errorIsOk(entityTriggerDeserialize(
&mgr, entity2, trig2, yyjson_doc_get_root(readDoc)
)));
yyjson_doc_free(readDoc);
physicsshape_t got = entityTriggerGetShape(&mgr, entity2, trig2);
assert_int_equal(got.type, PHYSICS_SHAPE_SPHERE);
assert_float_equal(got.data.sphere.radius, 3.0f, 0.0001f);
assert_int_equal(entityTriggerGetCollideMask(&mgr, entity2, trig2), 0x4);
entityManagerDispose(&mgr);
assert_int_equal(memoryGetAllocatedCount(), 0);
}
static void test_entityTriggerEventSubscription(void **state) {
test_resetCallbackCounts();
@@ -203,7 +153,6 @@ static void test_entityTriggerEventSubscription(void **state) {
int main(int argc, char **argv) {
const struct CMUnitTest tests[] = {
cmocka_unit_test(test_entityTriggerDefaultsAndAccessors),
cmocka_unit_test(test_entityTriggerSerializeRoundTrip),
cmocka_unit_test(test_entityTriggerEventSubscription),
};
-1
View File
@@ -9,5 +9,4 @@ include(dusktest)
dusktest(test_physicstest.c)
dusktest(test_physicsworld.c)
dusktest(test_physicsshapemesh.c)
dusktest(test_physicsshape.c)
dusktest(test_triggersystem.c)
-153
View File
@@ -1,153 +0,0 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "dusktest.h"
#include "util/memory.h"
#include "physics/physicsshape.h"
static yyjson_val *test_roundTripToImmutable(
yyjson_mut_doc *doc,
yyjson_mut_val *root,
yyjson_doc **outReadDoc
) {
size_t len = 0;
char_t *jsonStr = yyjson_mut_write(doc, 0, &len);
assert_non_null(jsonStr);
yyjson_mut_doc_free(doc);
*outReadDoc = yyjson_read(jsonStr, len, 0);
free(jsonStr);
assert_non_null(*outReadDoc);
return yyjson_doc_get_root(*outReadDoc);
}
static void test_physicsShapeCubeRoundTrip(void **state) {
physicsshape_t shape = {
.type = PHYSICS_SHAPE_CUBE,
.data.cube.halfExtents = { 1.0f, 2.0f, 3.0f }
};
yyjson_mut_doc *doc = yyjson_mut_doc_new(NULL);
yyjson_mut_val *root = yyjson_mut_obj(doc);
yyjson_mut_doc_set_root(doc, root);
assert_true(errorIsOk(physicsShapeSerialize(doc, root, &shape)));
yyjson_doc *readDoc;
yyjson_val *root2 = test_roundTripToImmutable(doc, root, &readDoc);
physicsshape_t got;
assert_true(errorIsOk(
physicsShapeDeserialize(yyjson_obj_get(root2, "shape"), &got)
));
yyjson_doc_free(readDoc);
assert_int_equal(got.type, PHYSICS_SHAPE_CUBE);
assert_float_equal(got.data.cube.halfExtents[0], 1.0f, 0.0001f);
assert_float_equal(got.data.cube.halfExtents[1], 2.0f, 0.0001f);
assert_float_equal(got.data.cube.halfExtents[2], 3.0f, 0.0001f);
}
static void test_physicsShapeSphereRoundTrip(void **state) {
physicsshape_t shape = {
.type = PHYSICS_SHAPE_SPHERE,
.data.sphere.radius = 4.5f
};
yyjson_mut_doc *doc = yyjson_mut_doc_new(NULL);
yyjson_mut_val *root = yyjson_mut_obj(doc);
yyjson_mut_doc_set_root(doc, root);
assert_true(errorIsOk(physicsShapeSerialize(doc, root, &shape)));
yyjson_doc *readDoc;
yyjson_val *root2 = test_roundTripToImmutable(doc, root, &readDoc);
physicsshape_t got;
assert_true(errorIsOk(
physicsShapeDeserialize(yyjson_obj_get(root2, "shape"), &got)
));
yyjson_doc_free(readDoc);
assert_int_equal(got.type, PHYSICS_SHAPE_SPHERE);
assert_float_equal(got.data.sphere.radius, 4.5f, 0.0001f);
}
static void test_physicsShapeCapsuleRoundTrip(void **state) {
physicsshape_t shape = {
.type = PHYSICS_SHAPE_CAPSULE,
.data.capsule = { .radius = 0.5f, .halfHeight = 1.5f }
};
yyjson_mut_doc *doc = yyjson_mut_doc_new(NULL);
yyjson_mut_val *root = yyjson_mut_obj(doc);
yyjson_mut_doc_set_root(doc, root);
assert_true(errorIsOk(physicsShapeSerialize(doc, root, &shape)));
yyjson_doc *readDoc;
yyjson_val *root2 = test_roundTripToImmutable(doc, root, &readDoc);
physicsshape_t got;
assert_true(errorIsOk(
physicsShapeDeserialize(yyjson_obj_get(root2, "shape"), &got)
));
yyjson_doc_free(readDoc);
assert_int_equal(got.type, PHYSICS_SHAPE_CAPSULE);
assert_float_equal(got.data.capsule.radius, 0.5f, 0.0001f);
assert_float_equal(got.data.capsule.halfHeight, 1.5f, 0.0001f);
}
static void test_physicsShapePlaneRoundTrip(void **state) {
physicsshape_t shape = {
.type = PHYSICS_SHAPE_PLANE,
.data.plane = { .normal = { 0.0f, 1.0f, 0.0f }, .distance = 2.0f }
};
yyjson_mut_doc *doc = yyjson_mut_doc_new(NULL);
yyjson_mut_val *root = yyjson_mut_obj(doc);
yyjson_mut_doc_set_root(doc, root);
assert_true(errorIsOk(physicsShapeSerialize(doc, root, &shape)));
yyjson_doc *readDoc;
yyjson_val *root2 = test_roundTripToImmutable(doc, root, &readDoc);
physicsshape_t got;
assert_true(errorIsOk(
physicsShapeDeserialize(yyjson_obj_get(root2, "shape"), &got)
));
yyjson_doc_free(readDoc);
assert_int_equal(got.type, PHYSICS_SHAPE_PLANE);
assert_float_equal(got.data.plane.normal[1], 1.0f, 0.0001f);
assert_float_equal(got.data.plane.distance, 2.0f, 0.0001f);
}
static void test_physicsShapeDeserializeUnknownTypeFails(void **state) {
const char_t *json = "{\"shape\":{\"type\":\"NOT_A_SHAPE\"}}";
yyjson_doc *readDoc = yyjson_read(json, strlen(json), YYJSON_READ_NOFLAG);
assert_non_null(readDoc);
physicsshape_t got;
errorret_t ret = physicsShapeDeserialize(
yyjson_obj_get(yyjson_doc_get_root(readDoc), "shape"), &got
);
assert_true(errorIsNotOk(ret));
errorCatch(ret);
yyjson_doc_free(readDoc);
}
int main(int argc, char **argv) {
const struct CMUnitTest tests[] = {
cmocka_unit_test(test_physicsShapeCubeRoundTrip),
cmocka_unit_test(test_physicsShapeSphereRoundTrip),
cmocka_unit_test(test_physicsShapeCapsuleRoundTrip),
cmocka_unit_test(test_physicsShapePlaneRoundTrip),
cmocka_unit_test(test_physicsShapeDeserializeUnknownTypeFails),
};
return cmocka_run_group_tests(tests, NULL, NULL);
}
-78
View File
@@ -11,7 +11,6 @@
#include "scene/scene.h"
#include "entity/entitymanager.h"
#include "entity/component/display/entityposition.h"
#include "yyjson.h"
static void countingUpdateCallback(
entitymanager_t *mgr,
@@ -139,82 +138,6 @@ static void test_sceneUpdateOnlyRunsFixedUpdateOnNonDynamicFrames(void **state)
assert_int_equal(memoryGetAllocatedCount(), 0);
}
static void test_sceneSerializeDeserializeParentLink(void **state) {
sceneInit();
sceneid_t sceneA = sceneCreate();
entitymanager_t *mgrA = sceneGetEntities(sceneA);
entityid_t parent = entityManagerAdd(mgrA);
componentid_t parentPos = entityAddComponent(
mgrA, parent, COMPONENT_TYPE_POSITION
);
entitySetName(mgrA, parent, "root");
entityPositionSetLocalPosition(mgrA, parent, parentPos, (vec3){ 10, 0, 0 });
entityid_t child = entityManagerAdd(mgrA);
componentid_t childPos = entityAddComponent(
mgrA, child, COMPONENT_TYPE_POSITION
);
entityPositionSetLocalPosition(mgrA, child, childPos, (vec3){ 1, 0, 0 });
entityPositionSetParent(mgrA, child, childPos, parent, parentPos);
vec3 childWorldBefore;
entityPositionGetWorldPosition(mgrA, child, childPos, childWorldBefore);
assert_float_equal(childWorldBefore[0], 11.0f, 0.0001f);
yyjson_mut_doc *doc = yyjson_mut_doc_new(NULL);
yyjson_mut_val *root = yyjson_mut_obj(doc);
yyjson_mut_doc_set_root(doc, root);
errorret_t ret = sceneSerialize(sceneA, doc, root);
assert_true(errorIsOk(ret));
size_t len = 0;
char_t *jsonStr = yyjson_mut_write(doc, 0, &len);
assert_non_null(jsonStr);
yyjson_mut_doc_free(doc);
yyjson_doc *readDoc = yyjson_read(jsonStr, len, 0);
free(jsonStr);
assert_non_null(readDoc);
sceneid_t sceneB = sceneCreate();
entitymanager_t *mgrB = sceneGetEntities(sceneB);
ret = sceneDeserialize(sceneB, yyjson_doc_get_root(readDoc));
yyjson_doc_free(readDoc);
assert_true(errorIsOk(ret));
entityid_t reloadedParent = entityFindByName(mgrB, "root");
assert_true(reloadedParent != ENTITY_ID_INVALID);
entityid_t reloadedChild = ENTITY_ID_INVALID;
for(entityid_t i = 0; i < ENTITY_COUNT_MAX; i++) {
if(!(mgrB->entities[i].state & ENTITY_STATE_ACTIVE)) continue;
if(i == reloadedParent) continue;
reloadedChild = i;
break;
}
assert_true(reloadedChild != ENTITY_ID_INVALID);
componentid_t reloadedChildPos = entityGetComponent(
mgrB, reloadedChild, COMPONENT_TYPE_POSITION
);
assert_true(reloadedChildPos != COMPONENT_ID_INVALID);
assert_int_equal(
entityPositionGetParent(mgrB, reloadedChild, reloadedChildPos),
reloadedParent
);
vec3 childWorldAfter;
entityPositionGetWorldPosition(
mgrB, reloadedChild, reloadedChildPos, childWorldAfter
);
assert_float_equal(childWorldAfter[0], childWorldBefore[0], 0.0001f);
sceneDispose();
assert_int_equal(memoryGetAllocatedCount(), 0);
}
static void test_sceneDestroyClearsActive(void **state) {
sceneInit();
@@ -235,7 +158,6 @@ int main(int argc, char **argv) {
cmocka_unit_test(test_sceneEntitiesAreIsolatedPerScene),
cmocka_unit_test(test_sceneFixedUpdateOnlyTicksActiveScene),
cmocka_unit_test(test_sceneUpdateOnlyRunsFixedUpdateOnNonDynamicFrames),
cmocka_unit_test(test_sceneSerializeDeserializeParentLink),
cmocka_unit_test(test_sceneDestroyClearsActive),
};