From f863ba9401a69de6a304feac2a8d2e9bcaf47ab6 Mon Sep 17 00:00:00 2001 From: energydrink02 <136357605+energydrink02@users.noreply.github.com> Date: Thu, 15 May 2025 22:05:00 +0200 Subject: [PATCH 1/2] Complete xTimer --- configure.py | 2 +- src/SB/Core/x/xTimer.cpp | 57 +++++++++++++++++++++++++++++++++++++--- src/SB/Core/x/xTimer.h | 2 +- 3 files changed, 56 insertions(+), 5 deletions(-) diff --git a/configure.py b/configure.py index 099975196..4be6cb5ed 100644 --- a/configure.py +++ b/configure.py @@ -361,7 +361,7 @@ def MatchingFor(*versions): Object(Equivalent, "SB/Core/x/xstransvc.cpp"), Object(NonMatching, "SB/Core/x/xString.cpp"), Object(Matching, "SB/Core/x/xSurface.cpp"), - Object(NonMatching, "SB/Core/x/xTimer.cpp"), + Object(Matching, "SB/Core/x/xTimer.cpp"), Object(NonMatching, "SB/Core/x/xTRC.cpp"), Object(Matching, "SB/Core/x/xutil.cpp"), Object(Matching, "SB/Core/x/xVec3.cpp"), diff --git a/src/SB/Core/x/xTimer.cpp b/src/SB/Core/x/xTimer.cpp index 7383cb632..36f7425ad 100644 --- a/src/SB/Core/x/xTimer.cpp +++ b/src/SB/Core/x/xTimer.cpp @@ -2,6 +2,8 @@ #include "xMath.h" #include +#include "zTalkBox.h" +#include "zGlobals.h" static U32 sPauseTimerHash[] = { @@ -17,7 +19,7 @@ static U32 sPauseTimerHash[] = 0xBC345A9B, 0xBC345AA4, }; -F32 GetRandomizedTime(xTimerAsset* tasset) +static F32 GetRandomizedTime(xTimerAsset* tasset) { U32 halfRangeMilli = 1000.0f * tasset->randomRange; if (halfRangeMilli == 0) { @@ -50,7 +52,7 @@ void xTimerLoad(xTimer* ent, xSerial* s) s->Read(&ent->secondsLeft); } -S32 xTimer_ObjIDIsPauseTimer(U32 id) +static S32 xTimer_ObjIDIsPauseTimer(U32 id) { if (id == 0xCB3F6340) return TRUE; if (id >= 0x016FC9F0 && id <= 0x016FC9F9) return TRUE; @@ -95,4 +97,53 @@ void xTimerReset(xTimer* ent) ent->state = 0; ent->secondsLeft = GetRandomizedTime(ent->tasset); ent->flags = 0; -} \ No newline at end of file +} + +S32 xTimerEventCB(xBase* from, xBase* to, U32 toEvent, const F32* toParam, xBase* toParamWidget) +{ + xTimer* t = (xTimer*)to; + + switch (toEvent) + { + case eEventRun: + t->state = 1; + break; + case eEventStop: + if (t->state == 1) + { + t->state = 0; + } + break; + case eEventReset: + xTimerReset(t); + break; + case eEventExpired: + t->state = 0; + break; + case eEventTimerSet: + t->secondsLeft = toParam[0]; + break; + case eEventTimerAdd: + t->secondsLeft += toParam[0]; + break; + } + + return 1; +} + +void xTimerUpdate(xBase* to, xScene* sc, F32 dt) +{ + xTimer* t = (xTimer*)to; + + if (t->state != 1) + return; + + if ((t->flags & 1) != 0 && globals.player.ControlOff && ztalkbox::get_active() != NULL) + return; + + t->secondsLeft -= dt; + if (t->secondsLeft <= 0.0f) + { + zEntEvent(t, t, eEventExpired); + } +} diff --git a/src/SB/Core/x/xTimer.h b/src/SB/Core/x/xTimer.h index 51dc08651..6e8034864 100644 --- a/src/SB/Core/x/xTimer.h +++ b/src/SB/Core/x/xTimer.h @@ -25,7 +25,7 @@ void xTimerInit(xBase* b, xTimerAsset* tasset); void xTimerReset(xTimer* ent); void xTimerSave(xTimer* ent, xSerial* s); void xTimerLoad(xTimer* ent, xSerial* s); -S32 xTimerEventCB(xBase*, xBase* to, U32 toEvent, const F32* toParam, xBase*); +S32 xTimerEventCB(xBase* from , xBase* to, U32 toEvent, const F32* toParam, xBase* toParamWidget); void xTimerUpdate(xBase* to, xScene*, F32 dt); #endif From 1bd047daa9cc85432cb795c3cb4228b672346f6d Mon Sep 17 00:00:00 2001 From: energydrink02 <136357605+energydrink02@users.noreply.github.com> Date: Thu, 15 May 2025 22:30:19 +0200 Subject: [PATCH 2/2] reorder functions --- src/SB/Core/x/xTimer.cpp | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/SB/Core/x/xTimer.cpp b/src/SB/Core/x/xTimer.cpp index 36f7425ad..2e7adc8d5 100644 --- a/src/SB/Core/x/xTimer.cpp +++ b/src/SB/Core/x/xTimer.cpp @@ -36,22 +36,6 @@ void xTimerInit(void* b, void* tasset) xTimerInit((xBase*)b, (xTimerAsset*)tasset); } -void xTimerSave(xTimer* ent, xSerial* s) -{ - xBaseSave(ent, s); - - s->Write(ent->state); - s->Write(ent->secondsLeft); -} - -void xTimerLoad(xTimer* ent, xSerial* s) -{ - xBaseLoad(ent, s); - - s->Read(&ent->state); - s->Read(&ent->secondsLeft); -} - static S32 xTimer_ObjIDIsPauseTimer(U32 id) { if (id == 0xCB3F6340) return TRUE; @@ -99,6 +83,22 @@ void xTimerReset(xTimer* ent) ent->flags = 0; } +void xTimerSave(xTimer* ent, xSerial* s) +{ + xBaseSave(ent, s); + + s->Write(ent->state); + s->Write(ent->secondsLeft); +} + +void xTimerLoad(xTimer* ent, xSerial* s) +{ + xBaseLoad(ent, s); + + s->Read(&ent->state); + s->Read(&ent->secondsLeft); +} + S32 xTimerEventCB(xBase* from, xBase* to, U32 toEvent, const F32* toParam, xBase* toParamWidget) { xTimer* t = (xTimer*)to;