72 lines
1.9 KiB
C
72 lines
1.9 KiB
C
/**
|
|
* Copyright (c) 2026 Dominic Masters
|
|
*
|
|
* This software is released under the MIT License.
|
|
* https://opensource.org/licenses/MIT
|
|
*/
|
|
|
|
#include "game/game.h"
|
|
#include "scene/scene.h"
|
|
#include "scene/overworldscene.h"
|
|
#include "assert/assert.h"
|
|
#include "asset/asset.h"
|
|
#include "yyjson.h"
|
|
|
|
#define GAME_TEST_SCENE_ASSET "scenes/test.json"
|
|
|
|
errorret_t gameInit(void) {
|
|
// overworldSceneCreate();
|
|
|
|
sceneid_t testSceneId = sceneCreate();
|
|
|
|
// Exercises sceneDeserialize() end-to-end: a camera looking at a
|
|
// colored cube that falls under gravity onto a static ground plane,
|
|
// described entirely as JSON rather than built with the entity API.
|
|
assetentry_t *sceneEntry = assetLock(
|
|
GAME_TEST_SCENE_ASSET, ASSET_LOADER_TYPE_JSON, NULL
|
|
);
|
|
errorret_t ret = assetRequireLoaded(sceneEntry);
|
|
if(errorIsOk(ret)) {
|
|
ret = sceneDeserialize(
|
|
testSceneId, yyjson_doc_get_root(sceneEntry->data.json)
|
|
);
|
|
}
|
|
assetUnlockEntry(sceneEntry);
|
|
errorChain(ret);
|
|
|
|
// Test-only: print a debug message whenever an entity enters "testArea"
|
|
// (see assets/scenes/test.json), exercising the TRIGGER component.
|
|
entitymanager_t *mgr = sceneGetEntities(testSceneId);
|
|
entityid_t testAreaEntity = entityFindByName(mgr, "testArea");
|
|
if(testAreaEntity != ENTITY_ID_INVALID) {
|
|
componentid_t testAreaTrig = entityGetComponent(
|
|
mgr, testAreaEntity, COMPONENT_TYPE_TRIGGER
|
|
);
|
|
entityTriggerOnEnterAdd(
|
|
mgr, testAreaEntity, testAreaTrig, gameTestAreaOnEnter, NULL
|
|
);
|
|
}
|
|
|
|
sceneSetActive(testSceneId);
|
|
errorOk();
|
|
}
|
|
|
|
errorret_t gameUpdate(void) {
|
|
errorOk();
|
|
}
|
|
|
|
errorret_t gameDispose(void) {
|
|
errorOk();
|
|
}
|
|
|
|
void gameTestAreaOnEnter(
|
|
entitymanager_t *mgr,
|
|
const entityid_t triggerEntityId,
|
|
const componentid_t triggerComponentId,
|
|
const entityid_t otherEntityId,
|
|
const componentid_t otherComponentId,
|
|
void *user
|
|
) {
|
|
logDebug("testArea: entity %d entered", otherEntityId);
|
|
}
|