From 6edd278e8baeb3143510c532c426046c841a8709 Mon Sep 17 00:00:00 2001 From: Luis Michaelis Date: Thu, 29 Feb 2024 17:43:50 +0100 Subject: [PATCH] feat(World): add savegame APIs --- include/zenkit-capi/World.h | 70 ++++++++ src/World.cc | 324 ++++++++++++++++++++++++++++++++++++ 2 files changed, 394 insertions(+) diff --git a/include/zenkit-capi/World.h b/include/zenkit-capi/World.h index 4fd00f7..ef67dc8 100644 --- a/include/zenkit-capi/World.h +++ b/include/zenkit-capi/World.h @@ -13,10 +13,20 @@ #ifdef __cplusplus #include using ZkWorld = ZkSharedHandle; +using ZkCutscenePlayer = ZkSharedHandle; +using ZkSkyController = ZkSharedHandle; #else typedef struct ZkInternal_World ZkWorld; +typedef struct ZkInternal_CutscenePlayer ZkCutscenePlayer; +typedef struct ZkInternal_SkyController ZkSkyController; #endif +typedef struct { + ZkNpc* npc; + ZkVec3f position; + float timer; +} ZkSpawnLocation; + ZKC_API ZkWorld* ZkWorld_load(ZkRead* buf); ZKC_API ZkWorld* ZkWorld_loadPath(ZkString path); ZKC_API ZkWorld* ZkWorld_loadVfs(ZkVfs* vfs, ZkString name); @@ -29,3 +39,63 @@ ZKC_API ZkBspTree const* ZkWorld_getBspTree(ZkWorld const* slf); ZKC_API ZkSize ZkWorld_getRootObjectCount(ZkWorld const* slf); ZKC_API ZkVirtualObject const* ZkWorld_getRootObject(ZkWorld const* slf, ZkSize i); ZKC_API void ZkWorld_enumerateRootObjects(ZkWorld const* slf, ZkVirtualObjectEnumerator cb, void* ctx); +ZKC_API void ZkWorld_addRootObject(ZkWorld* slf, ZkVirtualObject* val); +ZKC_API void ZkWorld_clearRootObjects(ZkWorld* slf); + +ZKC_API ZkBool ZkWorld_getNpcSpawnEnabled(ZkWorld const* slf); +ZKC_API void ZkWorld_setNpcSpawnEnabled(ZkWorld* slf, ZkBool val); +ZKC_API int ZkWorld_getNpcSpawnFlags(ZkWorld const* slf); +ZKC_API void ZkWorld_setNpcSpawnFlags(ZkWorld* slf, int val); + +ZKC_API ZkSize ZkWorld_getNpcCount(ZkWorld const* slf); +ZKC_API ZkNpc* ZkWorld_getNpc(ZkWorld const* slf, ZkSize i); +ZKC_API void ZkWorld_clearNpcs(ZkWorld* slf); +ZKC_API void ZkWorld_removeNpc(ZkWorld* slf, ZkSize i); +ZKC_API void ZkWorld_addNpc(ZkWorld* slf, ZkNpc* npc); + +ZKC_API ZkSize ZkWorld_getSpawnLocationCount(ZkWorld const* slf); +ZKC_API ZkSpawnLocation ZkWorld_getSpawnLocation(ZkWorld* slf, ZkSize i); +ZKC_API void ZkWorld_clearSpawnLocations(ZkWorld* slf); +ZKC_API void ZkWorld_addSpawnLocation(ZkWorld* slf, ZkSpawnLocation val); +ZKC_API void ZkWorld_removeSpawnLoaction(ZkWorld* slf, ZkSize i); + +ZKC_API ZkCutscenePlayer* ZkWorld_getCutscenePlayer(ZkWorld const* slf); +ZKC_API void ZkWorld_setCutscenePlayer(ZkWorld* slf, ZkCutscenePlayer* val); +ZKC_API ZkSkyController* ZkWorld_getSkyController(ZkWorld const* slf); +ZKC_API void ZkWorld_setSkyController(ZkWorld* slf, ZkSkyController* val); + +ZKC_API ZkCutscenePlayer* ZkCutscenePlayer_new(void); +ZKC_API void ZkCutscenePlayer_del(ZkCutscenePlayer* slf); + +ZKC_API int32_t ZkCutscenePlayer_getLastProcessDay(ZkCutscenePlayer const* slf); +ZKC_API int32_t ZkCutscenePlayer_getLastProcessHour(ZkCutscenePlayer const* slf); +ZKC_API int32_t ZkCutscenePlayer_getPlayListCount(ZkCutscenePlayer const* slf); +ZKC_API void ZkCutscenePlayer_setLastProcessDay(ZkCutscenePlayer* slf, int32_t val); +ZKC_API void ZkCutscenePlayer_setLastProcessHour(ZkCutscenePlayer* slf, int32_t val); +ZKC_API void ZkCutscenePlayer_setPlayListCount(ZkCutscenePlayer* slf, int32_t val); + +ZKC_API ZkSkyController* ZkSkyContoller_new(void); +ZKC_API void ZkSkyContoller_del(ZkSkyController* slf); + +ZKC_API float ZkSkyController_getMasterTime(ZkSkyController const* slf); +ZKC_API float ZkSkyController_getRainWeight(ZkSkyController const* slf); +ZKC_API float ZkSkyController_getRainStart(ZkSkyController const* slf); +ZKC_API float ZkSkyController_getRainStop(ZkSkyController const* slf); +ZKC_API float ZkSkyController_getRainSctTimer(ZkSkyController const* slf); +ZKC_API float ZkSkyController_getRainSndVol(ZkSkyController const* slf); +ZKC_API float ZkSkyController_getDayCtr(ZkSkyController const* slf); +ZKC_API float ZkSkyController_getFadeScale(ZkSkyController const* slf); +ZKC_API ZkBool ZkSkyController_getRenderLightning(ZkSkyController const* slf); +ZKC_API ZkBool ZkSkyController_getIsRaining(ZkSkyController const* slf); +ZKC_API int ZkSkyController_getRainCtr(ZkSkyController const* slf); +ZKC_API void ZkSkyController_setMasterTime(ZkSkyController* slf, float val); +ZKC_API void ZkSkyController_setRainWeight(ZkSkyController* slf, float val); +ZKC_API void ZkSkyController_setRainStart(ZkSkyController* slf, float val); +ZKC_API void ZkSkyController_setRainStop(ZkSkyController* slf, float val); +ZKC_API void ZkSkyController_setRainSctTimer(ZkSkyController* slf, float val); +ZKC_API void ZkSkyController_setRainSndVol(ZkSkyController* slf, float val); +ZKC_API void ZkSkyController_setDayCtr(ZkSkyController* slf, float val); +ZKC_API void ZkSkyController_setFadeScale(ZkSkyController* slf, float val); +ZKC_API void ZkSkyController_setRenderLightning(ZkSkyController* slf, ZkBool val); +ZKC_API void ZkSkyController_setIsRaining(ZkSkyController* slf, ZkBool val); +ZKC_API void ZkSkyController_setRainCtr(ZkSkyController* slf, int val); diff --git a/src/World.cc b/src/World.cc index 1be6dfc..7cd5efb 100644 --- a/src/World.cc +++ b/src/World.cc @@ -98,3 +98,327 @@ void ZkWorld_enumerateRootObjects(ZkWorld const* slf, ZkVirtualObjectEnumerator if (cb(ctx, &obj)) break; } } + +void ZkWorld_addRootObject(ZkWorld* slf, ZkVirtualObject* val) { + ZKC_TRACE_FN(); + ZKC_CHECK_NULLV(slf, val); + SLF->world_vobs.push_back(*val); +} + +void ZkWorld_clearRootObjects(ZkWorld* slf) { + ZKC_TRACE_FN(); + ZKC_CHECK_NULLV(slf); + SLF->world_vobs.clear(); +} + +ZkBool ZkWorld_getNpcSpawnEnabled(ZkWorld const* slf) { + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); + return SLF->npc_spawn_enabled; +} + +void ZkWorld_setNpcSpawnEnabled(ZkWorld* slf, ZkBool val) { + ZKC_TRACE_FN(); + ZKC_CHECK_NULLV(slf); + SLF->npc_spawn_enabled = val; +} + +int ZkWorld_getNpcSpawnFlags(ZkWorld const* slf) { + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); + return SLF->npc_spawn_flags; +} + +void ZkWorld_setNpcSpawnFlags(ZkWorld* slf, int val) { + ZKC_TRACE_FN(); + ZKC_CHECK_NULLV(slf); + SLF->npc_spawn_flags = val; +} + +ZkSize ZkWorld_getNpcCount(ZkWorld const* slf) { + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); + return SLF->npcs.size(); +} + +ZkNpc* ZkWorld_getNpc(ZkWorld const* slf, ZkSize i) { + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); + ZKC_CHECK_LEN(SLF->npcs, i); + return &SLF->npcs[i]; +} + +void ZkWorld_clearNpcs(ZkWorld* slf) { + ZKC_TRACE_FN(); + ZKC_CHECK_NULLV(slf); + SLF->npcs.clear(); +} + +void ZkWorld_removeNpc(ZkWorld* slf, ZkSize i) { + ZKC_TRACE_FN(); + ZKC_CHECK_NULLV(slf); + ZKC_CHECK_LENV(SLF->npcs, i); + SLF->npcs.erase(SLF->npcs.begin() + static_cast(i)); +} + +void ZkWorld_addNpc(ZkWorld* slf, ZkNpc* npc) { + ZKC_TRACE_FN(); + ZKC_CHECK_NULLV(slf); + SLF->npcs.push_back(*npc); +} + +ZkSize ZkWorld_getSpawnLocationCount(ZkWorld const* slf) { + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); + return SLF->npc_spawns.size(); +} + +ZkSpawnLocation ZkWorld_getSpawnLocation(ZkWorld* slf, ZkSize i) { + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); + ZKC_CHECK_LEN(SLF->npc_spawns, i); + + auto& s = SLF->npc_spawns[i]; + return { + &s.npc, + s.position, + s.timer + }; +} + +void ZkWorld_clearSpawnLocations(ZkWorld* slf) { + ZKC_TRACE_FN(); + ZKC_CHECK_NULLV(slf); + SLF->npc_spawns.clear(); +} + +void ZkWorld_addSpawnLocation(ZkWorld* slf, ZkSpawnLocation val) { + ZKC_TRACE_FN(); + ZKC_CHECK_NULLV(slf); + + SLF->npc_spawns.push_back({ + *val.npc, + val.position, + val.timer, + }); +} + +void ZkWorld_removeSpawnLoaction(ZkWorld* slf, ZkSize i) { + ZKC_TRACE_FN(); + ZKC_CHECK_NULLV(slf); + ZKC_CHECK_LENV(SLF->npc_spawns, i); + SLF->npc_spawns.erase(SLF->npc_spawns.begin() + static_cast(i)); +} + +ZkCutscenePlayer* ZkWorld_getCutscenePlayer(ZkWorld const* slf) { + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); + return &SLF->player; +} + +void ZkWorld_setCutscenePlayer(ZkWorld* slf, ZkCutscenePlayer* val) { + ZKC_TRACE_FN(); + ZKC_CHECK_NULLV(slf); + SLF->player = val ? *val : nullptr; +} + +ZkSkyController* ZkWorld_getSkyController(ZkWorld const* slf) { + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); + return &SLF->sky_controller; +} + +void ZkWorld_setSkyController(ZkWorld* slf, ZkSkyController* val) { + ZKC_TRACE_FN(); + ZKC_CHECK_NULLV(slf); + SLF->sky_controller = val ? *val : nullptr; +} + +ZkCutscenePlayer* ZkCutscenePlayer_new(void) { + ZKC_TRACE_FN(); + return new ZkCutscenePlayer {std::make_shared()}; +} + +void ZkCutscenePlayer_del(ZkCutscenePlayer* slf) { + ZKC_TRACE_FN(); + delete slf; +} + +int32_t ZkCutscenePlayer_getLastProcessDay(ZkCutscenePlayer const* slf) { + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); + return SLF->last_process_day; +} + +int32_t ZkCutscenePlayer_getLastProcessHour(ZkCutscenePlayer const* slf) { + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); + return SLF->last_process_hour; +} + +int32_t ZkCutscenePlayer_getPlayListCount(ZkCutscenePlayer const* slf) { + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); + return SLF->play_list_count; +} + +void ZkCutscenePlayer_setLastProcessDay(ZkCutscenePlayer* slf, int32_t val) { + ZKC_TRACE_FN(); + ZKC_CHECK_NULLV(slf); + SLF->last_process_day = val; +} + +void ZkCutscenePlayer_setLastProcessHour(ZkCutscenePlayer* slf, int32_t val) { + ZKC_TRACE_FN(); + ZKC_CHECK_NULLV(slf); + SLF->last_process_hour = val; +} + +void ZkCutscenePlayer_setPlayListCount(ZkCutscenePlayer* slf, int32_t val) { + ZKC_TRACE_FN(); + ZKC_CHECK_NULLV(slf); + SLF->play_list_count = val; +} + +ZkSkyController* ZkSkyContoller_new(void) { + ZKC_TRACE_FN(); + return new ZkSkyController {std::make_shared()}; +} + +void ZkSkyContoller_del(ZkSkyController* slf) { + ZKC_TRACE_FN(); + delete slf; +} + +float ZkSkyController_getMasterTime(ZkSkyController const* slf) { + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); + return SLF->master_time; +} + +float ZkSkyController_getRainWeight(ZkSkyController const* slf) { + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); + return SLF->rain_weight; +} + +float ZkSkyController_getRainStart(ZkSkyController const* slf) { + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); + return SLF->rain_start; +} + +float ZkSkyController_getRainStop(ZkSkyController const* slf) { + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); + return SLF->rain_stop; +} + +float ZkSkyController_getRainSctTimer(ZkSkyController const* slf) { + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); + return SLF->rain_sct_timer; +} + +float ZkSkyController_getRainSndVol(ZkSkyController const* slf) { + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); + return SLF->rain_snd_vol; +} + +float ZkSkyController_getDayCtr(ZkSkyController const* slf) { + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); + return SLF->day_ctr; +} + +float ZkSkyController_getFadeScale(ZkSkyController const* slf) { + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); + return SLF->fade_scale; +} + +ZkBool ZkSkyController_getRenderLightning(ZkSkyController const* slf) { + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); + return SLF->render_lightning; +} + +ZkBool ZkSkyController_getIsRaining(ZkSkyController const* slf) { + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); + return SLF->is_raining; +} + +int ZkSkyController_getRainCtr(ZkSkyController const* slf) { + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); + return SLF->rain_ctr; +} + +void ZkSkyController_setMasterTime(ZkSkyController* slf, float val) { + ZKC_TRACE_FN(); + ZKC_CHECK_NULLV(slf); + SLF->master_time = val; +} + +void ZkSkyController_setRainWeight(ZkSkyController* slf, float val) { + ZKC_TRACE_FN(); + ZKC_CHECK_NULLV(slf); + SLF->rain_weight = val; +} + +void ZkSkyController_setRainStart(ZkSkyController* slf, float val) { + ZKC_TRACE_FN(); + ZKC_CHECK_NULLV(slf); + SLF->rain_start = val; +} + +void ZkSkyController_setRainStop(ZkSkyController* slf, float val) { + ZKC_TRACE_FN(); + ZKC_CHECK_NULLV(slf); + SLF->rain_stop = val; +} + +void ZkSkyController_setRainSctTimer(ZkSkyController* slf, float val) { + ZKC_TRACE_FN(); + ZKC_CHECK_NULLV(slf); + SLF->rain_sct_timer = val; +} + +void ZkSkyController_setRainSndVol(ZkSkyController* slf, float val) { + ZKC_TRACE_FN(); + ZKC_CHECK_NULLV(slf); + SLF->rain_snd_vol = val; +} + +void ZkSkyController_setDayCtr(ZkSkyController* slf, float val) { + ZKC_TRACE_FN(); + ZKC_CHECK_NULLV(slf); + SLF->day_ctr = val; +} + +void ZkSkyController_setFadeScale(ZkSkyController* slf, float val) { + ZKC_TRACE_FN(); + ZKC_CHECK_NULLV(slf); + SLF->fade_scale = val; +} + +void ZkSkyController_setRenderLightning(ZkSkyController* slf, ZkBool val) { + ZKC_TRACE_FN(); + ZKC_CHECK_NULLV(slf); + SLF->render_lightning = val; +} + +void ZkSkyController_setIsRaining(ZkSkyController* slf, ZkBool val) { + ZKC_TRACE_FN(); + ZKC_CHECK_NULLV(slf); + SLF->is_raining = val; +} + +void ZkSkyController_setRainCtr(ZkSkyController* slf, int val) { + ZKC_TRACE_FN(); + ZKC_CHECK_NULLV(slf); + SLF->rain_ctr = val; +} +