From 6c678cf1ed7aa04c358af8462dc09159f0b9f7d1 Mon Sep 17 00:00:00 2001 From: Steven Casper Date: Sat, 6 Jul 2024 10:29:03 -0400 Subject: [PATCH] zEntPlayer progress (#292) * Replace externs with real data * 2 zEntPlayer functions --- src/SB/Core/x/xDebug.cpp | 2 + src/SB/Core/x/xDebug.h | 4 +- src/SB/Game/zEntPlayer.cpp | 223 +++++++++++++++++++++++++++++-------- src/SB/Game/zParPTank.h | 1 + 4 files changed, 181 insertions(+), 49 deletions(-) diff --git a/src/SB/Core/x/xDebug.cpp b/src/SB/Core/x/xDebug.cpp index 94b9f2360..cf6944c02 100644 --- a/src/SB/Core/x/xDebug.cpp +++ b/src/SB/Core/x/xDebug.cpp @@ -2,6 +2,8 @@ #include +uint32 gFrameCount; + extern float32 _781; // 0.0020833334f. extern float32 _783; // 0.0015625f. diff --git a/src/SB/Core/x/xDebug.h b/src/SB/Core/x/xDebug.h index 29826ed40..2c91c0046 100644 --- a/src/SB/Core/x/xDebug.h +++ b/src/SB/Core/x/xDebug.h @@ -5,6 +5,8 @@ #include +extern uint32 gFrameCount; + void xprintf(const char* msg, ...); int32 xDebugModeAdd(char* mode, void(*debugFunc)); void xDebugInit(); @@ -18,4 +20,4 @@ void xDebugUpdate(); float32 NSCREENY(float32 scale); float32 NSCREENX(float32 scale); -#endif \ No newline at end of file +#endif diff --git a/src/SB/Game/zEntPlayer.cpp b/src/SB/Game/zEntPlayer.cpp index 2ff920aa7..b0e85eb0d 100644 --- a/src/SB/Game/zEntPlayer.cpp +++ b/src/SB/Game/zEntPlayer.cpp @@ -2,14 +2,19 @@ #include #include +#include "iMath.h" #include "iSnd.h" +#include "xDebug.h" #include "xEnt.h" #include "xEntBoulder.h" #include "xEvent.h" +#include "xMath.h" +#include "xMathInlines.h" +#include "xMemMgr.h" #include "xSnd.h" #include "xVec3.h" -#include "xMemMgr.h" +#include "xVec3Inlines.h" #include "zBase.h" #include "zCamera.h" @@ -17,49 +22,91 @@ #include "zEntTeleportBox.h" #include "zGame.h" #include "zGameExtras.h" -#include "zNPCTypeTiki.h" #include "zGlobals.h" #include "zGoo.h" #include "zLasso.h" #include "zNPCTypeTiki.h" +#include "zNPCTypeTiki.h" #include "zNPCMessenger.h" +#include "zParPTank.h" #include "zMusic.h" #include "zThrown.h" -extern zGlobals globals; -extern uint32 sCurrentStreamSndID; +static xVec3 last_center; -extern zPlayerLassoInfo* sLassoInfo; +static uint32 sCurrentStreamSndID; +static float32 sPlayerSndSneakDelay; +static int32 sPlayerDiedLastTime; -extern uint32 sSpatulaGrabbed; -extern uint32 sShouldBubbleBowl; -extern float32 sBubbleBowlLastWindupTime; -extern float32 sBubbleBowlMultiplier; +static zPlayerLassoInfo* sLassoInfo; +static zLasso* sLasso; -extern zPlayerLassoInfo* sLassoInfo; -extern zLasso* sLasso; +static int32 in_goo; -extern int32 in_goo; -extern int32 sPlayerDiedLastTime; -extern int32 player_hit; -extern int32 player_hit_anim; -extern uint32 player_dead_anim; +int32 player_hit; +static int32 player_hit_anim = 1; +static uint32 player_dead_anim = 1; -extern float32 lbl_803CD5A0; // 0.0 -extern float32 lbl_803CD5F0; // 0.1 -extern float32 lbl_803CD62C; // 0.2 -extern float32 lbl_803CD588; // 0.5 -extern float32 lbl_803CD830; // 30.0 -extern float32 lbl_803CD638; // 10.0 +static uint32 last_frame; -// This needs to be const -// because the address is used in the context of a const char pointer -// when being passed to certain functions. -extern const int8 zEntPlayer_Strings[]; +static float32 sBubbleBowlLastWindupTime = -1.0f; +static float32 sBubbleBowlMultiplier = 1.0f; +static uint32 sShouldBubbleBowl; +static float32 sBubbleBowlTimer; +static uint32 sSpatulaGrabbed; // Multidimensional sound arrays for each player type -extern uint32 sPlayerSnd[ePlayer_MAXTYPES][ePlayerSnd_Total]; -extern uint32 sPlayerSndID[ePlayer_MAXTYPES][ePlayerSnd_Total]; +static uint32 sPlayerSnd[ePlayer_MAXTYPES][ePlayerSnd_Total] = {}; +static uint32 sPlayerSndRand[3][47] = {}; +static uint32 sPlayerSndID[ePlayer_MAXTYPES][ePlayerSnd_Total] = {}; + +void zEntPlayer_SpawnWandBubbles(xVec3* center, uint32 count) +{ + if (gFrameCount - last_frame > 5) + { + xVec3 wand; + xVec3ScaleC(&wand, (xVec3*)&globals.player.model_wand->Mat->at, 0.25f, 0.25f, 0.25f); + xVec3Sub(&last_center, center, &wand); + } + + xVec3 dir; + xVec3Sub(&dir, center, &last_center); + + uint32 num = 3; + if (count != 0) + { + num = count; + } + + xVec3* posbuf = (xVec3*)xMemPushTemp(num * 2 * sizeof(xVec3)); + xVec3* velbuf = posbuf + num; + if (posbuf) + { + xVec3* pp = posbuf; + xVec3* vp = velbuf; + uint32 j = 0; + for (; j < num; j++, pp++, vp++) + { + float32 f = (float32)j / (float32)num; + xVec3Lerp(pp, &last_center, center, f); + pp->x += 0.125f * (xurand() - 0.5f); + pp->y += 0.125f * (xurand() - 0.5f); + pp->z += 0.125f * (xurand() - 0.5f); + + f = 5.0f * xurand(); + xVec3ScaleC(vp, &dir, f, f, f); + vp->x += 0.25f * (xurand() - 0.5f); + vp->y += 0.25f * (xurand() - 0.5f); + vp->z += 0.25f * (xurand() - 0.5f); + } + + zParPTankSpawnBubbles(posbuf, velbuf, num, 1.0f); + xMemPopTemp(posbuf); + } + + last_center = *center; + last_frame = gFrameCount; +} void zEntPlayerKillCarry() { @@ -89,10 +136,6 @@ void zEntPlayerKillCarry() globals.player.carry.grabbed = NULL; } -void test(int32 a) -{ -} - void zEntPlayerControlOn(zControlOwner owner) { uint32 originalValue = globals.player.ControlOff; @@ -144,6 +187,96 @@ void SetPlayerKillsVillainTimer(float32 time) globals.player.VictoryTimer = time; } +static void DampenControls(float32* angle, float32* mag, float32 x, float32 y) +{ + *angle = xatan2(x, y); + + if (x > -globals.player.g.AnalogMin && x < globals.player.g.AnalogMin) + { + x = 0.0f; + } + + if (y > -globals.player.g.AnalogMin && y < globals.player.g.AnalogMin) + { + y = 0.0f; + } + + if (!x && !y) + { + *angle = 0.0f; + *mag = 0.0f; + return; + } + + if ((float)__fabs(x) > (float)__fabs(y)) + { + *mag = __fabs(x); + } + else + { + *mag = __fabs(y); + } + *mag = (*mag - globals.player.g.AnalogMin) / + (globals.player.g.AnalogMax - globals.player.g.AnalogMin); + + if (*mag < 0.0f) + { + *mag = 0.0f; + *angle = 0.0f; + } + else if (*mag > 1.0f) + { + *mag = 1.0f; + } +} + +static void CalcAnimSpeed(xEnt* ent, float f, float* pf) +{ + if (!pf[0]) + { + return; + } + + f = f / pf[0]; + if (f < pf[1]) + { + f = pf[1]; + } + else if (f > pf[2]) + { + f = pf[2]; + } + + ent->model->Anim->Single->CurrentSpeed = f; +} + +static void LeanUpdate(float32 a, float32 b) +{ + float abs = __fabs(a); + float lerp; + if (abs < 0.087266468f) + { + lerp = 0.0f; + } + else if (abs > 0.2617994f) + { + lerp = 1.0f; + } + else + { + lerp = 5.729578f * (abs - 0.087266468f); + } + + if (a > 0.0f) + { + lerp = -lerp; + } + lerp += 1.0f; + + float32 t = 6.0f * (lerp - globals.player.LeanLerp); + globals.player.LeanLerp += t * b; +} + void PlayerArrive(xEnt* ent, xBase* base) { globals.player.AutoMoveSpeed = 0; @@ -213,7 +346,7 @@ uint32 BbowlTossEndCB(xAnimTransition* tran, xAnimSingle* anim, void* param_3) xEntBoulder_BubbleBowl(sBubbleBowlMultiplier); globals.player.IsBubbleBowling = false; zEntPlayer_SNDStop(ePlayerSnd_BowlWindup); - zEntPlayer_SNDPlay(ePlayerSnd_BowlRelease, lbl_803CD5A0); + zEntPlayer_SNDPlay(ePlayerSnd_BowlRelease, 0.0f); return false; } @@ -272,7 +405,7 @@ uint32 GooDeathCB(xAnimTransition* tran, xAnimSingle* anim, void* param_3) { // Decompiled, but instructions are out of order? globals.player.Health = 0; - globals.player.DamageTimer = lbl_803CD638; // 10.0 + globals.player.DamageTimer = 10.0; // 10.0 zGooStopTide(); sPlayerDiedLastTime = 1; zEntPlayerControlOff(CONTROL_OWNER_GLOBAL); @@ -523,13 +656,7 @@ uint32 count_talk_anims(xAnimTable* anims) int8 talkAnimName[20]; int32 talkAnimCount = 0; - sprintf(talkAnimName, (zEntPlayer_Strings + 0x29ff), 1); - - // having this here is necessary for some reason - // The beginning address of the strings are stored in a register - // which is later added to in the loop itself - // Don't know if this will break when we substitute strings - const char* strings = zEntPlayer_Strings; + sprintf(talkAnimName, "Talk%02d", 1); for (xAnimState* state = anims->StateList; state != NULL; state = state->Next) { @@ -539,7 +666,7 @@ uint32 count_talk_anims(xAnimTable* anims) { break; } - sprintf(talkAnimName, (strings + 0x29ff), talkAnimCount + 1); + sprintf(talkAnimName, "Talk%02d", talkAnimCount + 1); } } @@ -635,13 +762,13 @@ void zEntPlayer_GiveSpatula(int32) { sSpatulaGrabbed = 1; - if (globals.player.ControlOffTimer < lbl_803CD5F0) + if (globals.player.ControlOffTimer < 0.1f) { - globals.player.ControlOffTimer = lbl_803CD5F0; + globals.player.ControlOffTimer = 0.1f; } - zNPCMsg_AreaNotify(NULL, NPC_MID_PLYRSPATULA, lbl_803CD830, 0x104, NPC_TYPE_UNKNOWN); - zMusicSetVolume(lbl_803CD588, lbl_803CD62C); + zNPCMsg_AreaNotify(NULL, NPC_MID_PLYRSPATULA, 30.0f, 0x104, NPC_TYPE_UNKNOWN); + zMusicSetVolume(0.5f, 0.2f); } #endif @@ -689,7 +816,7 @@ void zEntPlayer_GivePatsSocksCurrentLevel(int32 quantity) if (quantity > 0) { - zNPCMsg_AreaNotify(NULL, NPC_MID_PLYRSPATULA, lbl_803CD830, 0x104, NPC_TYPE_UNKNOWN); + zNPCMsg_AreaNotify(NULL, NPC_MID_PLYRSPATULA, 30.0f, 0x104, NPC_TYPE_UNKNOWN); } } @@ -710,7 +837,7 @@ void zEntPlayer_GiveLevelPickupCurrentLevel(int32 quantity) if (quantity > 0) { - zNPCMsg_AreaNotify(NULL, NPC_MID_PLYRSPATULA, lbl_803CD830, 0x104, NPC_TYPE_UNKNOWN); + zNPCMsg_AreaNotify(NULL, NPC_MID_PLYRSPATULA, 30.0f, 0x104, NPC_TYPE_UNKNOWN); } } diff --git a/src/SB/Game/zParPTank.h b/src/SB/Game/zParPTank.h index f262f2d27..1ca7487b8 100644 --- a/src/SB/Game/zParPTank.h +++ b/src/SB/Game/zParPTank.h @@ -23,6 +23,7 @@ struct zParPTank void zParPTankInit(); void zParPTankSceneEnter(); void zParPTankSceneExit(); +void zParPTankSpawnBubbles(xVec3* pos, xVec3* vel, uint32 count, float scale); void zParPTankSpawnSnow(xVec3* pos, xVec3* vel, uint32 count); void zParPTankExit(); void zParPTankRender();