Skip to content

Commit

Permalink
zEntPlayer progress (#292)
Browse files Browse the repository at this point in the history
* Replace externs with real data

* 2 zEntPlayer functions
  • Loading branch information
SquareMan authored Jul 6, 2024
1 parent 94b9170 commit 6c678cf
Show file tree
Hide file tree
Showing 4 changed files with 181 additions and 49 deletions.
2 changes: 2 additions & 0 deletions src/SB/Core/x/xDebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include <types.h>

uint32 gFrameCount;

extern float32 _781; // 0.0020833334f.
extern float32 _783; // 0.0015625f.

Expand Down
4 changes: 3 additions & 1 deletion src/SB/Core/x/xDebug.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

#include <types.h>

extern uint32 gFrameCount;

void xprintf(const char* msg, ...);
int32 xDebugModeAdd(char* mode, void(*debugFunc));
void xDebugInit();
Expand All @@ -18,4 +20,4 @@ void xDebugUpdate();
float32 NSCREENY(float32 scale);
float32 NSCREENX(float32 scale);

#endif
#endif
223 changes: 175 additions & 48 deletions src/SB/Game/zEntPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,64 +2,111 @@
#include <stdio.h>
#include <string.h>

#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"
#include "zEntPlayer.h"
#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()
{
Expand Down Expand Up @@ -89,10 +136,6 @@ void zEntPlayerKillCarry()
globals.player.carry.grabbed = NULL;
}

void test(int32 a)
{
}

void zEntPlayerControlOn(zControlOwner owner)
{
uint32 originalValue = globals.player.ControlOff;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
{
Expand All @@ -539,7 +666,7 @@ uint32 count_talk_anims(xAnimTable* anims)
{
break;
}
sprintf(talkAnimName, (strings + 0x29ff), talkAnimCount + 1);
sprintf(talkAnimName, "Talk%02d", talkAnimCount + 1);
}
}

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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);
}
}

Expand Down
1 change: 1 addition & 0 deletions src/SB/Game/zParPTank.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 6c678cf

Please sign in to comment.