From 283c618560e27518cea38f965b33c8b6afcf76ae Mon Sep 17 00:00:00 2001 From: tgsm Date: Wed, 3 Jul 2024 14:16:47 -0500 Subject: [PATCH] Finish matching zPendulum --- configure.py | 2 +- src/SB/Game/zPendulum.cpp | 162 ++++++++++++++++++++++++++++++++++++-- src/SB/Game/zPendulum.h | 2 +- 3 files changed, 156 insertions(+), 10 deletions(-) diff --git a/configure.py b/configure.py index 16d0f80bf..d9a59965d 100644 --- a/configure.py +++ b/configure.py @@ -374,7 +374,7 @@ def Rel(lib_name: str, objects: List[Object]) -> Dict[str, Any]: Object(NonMatching, "SB/Game/zMusic.cpp"), Object(Equivalent, "SB/Game/zParCmd.cpp"), Object(Matching, "SB/Game/zParEmitter.cpp"), - Object(NonMatching, "SB/Game/zPendulum.cpp"), + Object(Matching, "SB/Game/zPendulum.cpp"), Object(Matching, "SB/Game/zPickupTable.cpp"), Object(NonMatching, "SB/Game/zPlatform.cpp"), Object(Matching, "SB/Game/zPortal.cpp"), diff --git a/src/SB/Game/zPendulum.cpp b/src/SB/Game/zPendulum.cpp index 1cc206ad5..adb375532 100644 --- a/src/SB/Game/zPendulum.cpp +++ b/src/SB/Game/zPendulum.cpp @@ -1,6 +1,11 @@ #include "zPendulum.h" +#include "zGlobals.h" +#include "zCollGeom.h" +#include "zShrapnel.h" #include "xEnt.h" +#include "xEntMotion.h" +#include "xMath.h" #include @@ -9,28 +14,27 @@ void zPendulum_Init(void* pend, void* asset) zPendulum_Init((_zPendulum*)pend, (xEntAsset*)asset); } -#if 0 -//WIP. void zPendulum_Init(_zPendulum* pend, xEntAsset* asset) { + zEntInit((zEnt*)pend, asset, 'PEND'); + xEntMotionAsset* motionAsset = (xEntMotionAsset*)(asset + 1); if (pend->linkCount != 0) { - //TODO!!! + pend->link = (xLinkAsset*)(motionAsset + 1); } else { pend->link = NULL; } - pend->update = zPendulum_Update; - pend->move = zPendulum_Move; + pend->update = (xEntUpdateCallback)zPendulum_Update; + pend->move = (xEntMoveCallback)zPendulum_Move; pend->eventFunc = zPendulumEventCB; pend->transl = zPendulumTranslate; + zEntReset((zEnt*)pend); - //zEntMotionInit(&pend->motion, (xEnt*)pend, (xEntMotionAsset*)asset->) TODO!!! + xEntMotionInit(&pend->motion, (xEnt*)pend, motionAsset); } -#endif - void zPendulum_Save(_zPendulum* pend, xSerial* s) { zEntSave((zEnt*)pend, s); @@ -46,6 +50,64 @@ void zPendulum_Setup(_zPendulum* pend, xScene* sc) zEntSetup((zEnt*)pend); } +void zPendulum_Reset(_zPendulum* pend, xScene* sc) +{ + zEntReset((zEnt*)pend); + xEntMotionInit(&pend->motion, (xEnt*)pend, (xEntMotionAsset*)(pend->asset + 1)); + xEntMotionReset(&pend->motion, sc); + + xEntMotionAsset* asset = pend->motion.asset; + pend->lt = 0.0f; + pend->q1t = 1.0f - (asset->pen.phase / (2.0f * PI)); + pend->q3t = 0.5f - (asset->pen.phase / (2.0f * PI)); + if (pend->q1t <= 0.0f) + { + pend->q1t += 1.0f; + } + if (pend->q1t > 1.0f) + { + pend->q1t -= 1.0f; + } + if (pend->q3t <= 0.0f) + { + pend->q3t += 1.0f; + } + if (pend->q3t > 1.0f) + { + pend->q3t -= 1.0f; + } + + pend->q1t *= asset->pen.period; + pend->q3t *= asset->pen.period; +} + +void zPendulum_Update(_zPendulum* pend, xScene* sc, float32 dt) +{ + float32 lt, t; + + xEntUpdate((xEnt*)pend, sc, dt); + + t = pend->motion.t; + lt = pend->lt; + xEntMotionPenData* pen = &pend->motion.asset->pen; + + if (t < lt) + { + t += pen->period; + } + + if (lt <= pend->q1t && t > pend->q1t) + { + zEntEvent((xBase*)pend, eEventSwoosh); + } + else if (lt <= pend->q3t && t > pend->q3t) + { + zEntEvent((xBase*)pend, eEventSwoosh); + } + + pend->lt = pend->motion.t; +} + void zPendulum_Move(_zPendulum* pend, xScene* sc, float32 dt, xEntFrame* frame) { xEntMotionMove(&pend->motion, sc, dt, frame); @@ -56,3 +118,87 @@ void zPendulumTranslate(xEnt* xent, xVec3* dpos, xMat4x3* dmat) xEntDefaultTranslate(xent, dpos, dmat); xEntMotionTranslate(&((_zPendulum*)xent)->motion, dpos, dmat); } + +int32 zPendulumEventCB(xBase* from, xBase* to, uint32 toEvent, const float32* toParam, xBase* b3) +{ + _zPendulum* pend = (_zPendulum*)to; + + switch (toEvent) + { + case eEventRun: + xEntMotionRun(&pend->motion); + break; + case eEventStop: + xEntMotionStop(&pend->motion); + break; + case eEventReset: + zPendulum_Reset(pend, globals.sceneCur); + break; + case eEventVisible: + case eEventFastVisible: + xEntShow((xEnt*)pend); + break; + case eEventInvisible: + case eEventFastInvisible: + xEntHide((xEnt*)pend); + break; + case eEventCollision_Visible_On: + xEntShow((xEnt*)pend); + case eEventCollisionOn: + pend->chkby = XENT_COLLTYPE_PLYR | XENT_COLLTYPE_NPC; + pend->bupdate(pend, (xVec3*)&pend->model->Mat->pos); + break; + case eEventCollision_Visible_Off: + xEntHide((xEnt*)pend); + case eEventCollisionOff: + pend->chkby = XENT_COLLTYPE_NONE; + break; + case eEventCameraCollideOn: + zCollGeom_CamEnable((xEnt*)pend); + break; + case eEventCameraCollideOff: + zCollGeom_CamDisable((xEnt*)pend); + break; + case eEventAnimPlay: + case eEventAnimPlayLoop: + case eEventAnimStop: + case eEventAnimPause: + case eEventAnimResume: + case eEventAnimTogglePause: + case eEventAnimPlayRandom: + case eEventAnimPlayMaybe: + zEntAnimEvent((zEnt*)pend, toEvent, toParam); + break; + case eEventSetUpdateDistance: + { + if (globals.updateMgr == NULL) + { + break; + } + + if (*toParam <= 0.0f) + { + xUpdateCull_SetCB(globals.updateMgr, pend, xUpdateCull_AlwaysTrueCB, NULL); + } + else + { + float32 unk = SQR(*toParam); + xUpdateCull_SetCB(globals.updateMgr, pend, xUpdateCull_DistanceSquaredCB, + *(void**)&unk); + } + + break; + } + case eEventLaunchShrapnel: + { + zShrapnelAsset* shrapnel = (zShrapnelAsset*)b3; + if (shrapnel != NULL && shrapnel->initCB != NULL) + { + shrapnel->initCB(shrapnel, pend->model, NULL, NULL); + } + break; + } + } + + return 1; +} diff --git a/src/SB/Game/zPendulum.h b/src/SB/Game/zPendulum.h index 8eb182d99..e3965f8f4 100644 --- a/src/SB/Game/zPendulum.h +++ b/src/SB/Game/zPendulum.h @@ -24,7 +24,7 @@ void zPendulum_Reset(_zPendulum* pend, xScene* sc); void zPendulum_Update(_zPendulum* pend, xScene* sc, float32 dt); void zPendulum_Move(_zPendulum* pend, xScene* sc, float32 dt, xEntFrame* frame); void zPendulumTranslate(xEnt* xent, xVec3* dpos, xMat4x3* dmat); -int32 zPendulumEventCB(xBase* to, uint32 toEvent, uint32 event, float32* toParam, +int32 zPendulumEventCB(xBase* from, xBase* to, uint32 event, const float32* toParam, xBase* toParamWidget); #endif