diff --git a/include/dolphin/gx/GXGeometry.h b/include/dolphin/gx/GXGeometry.h index 188fa7a59..d9f47ba8d 100644 --- a/include/dolphin/gx/GXGeometry.h +++ b/include/dolphin/gx/GXGeometry.h @@ -36,6 +36,22 @@ static inline void GXEnd(void) { #endif } +static inline void GXTexCoord2s16(int r3, int r4) // possible inline req. +{ + int ptr = 0xcc010000; + *(short*)((char*)(ptr) - 0x8000) = r3; + *(short*)((char*)(ptr) - 0x8000) = r4; +} + + +static inline void GXPosition3s16(int r3, int r4, int r5) // possible inline req. +{ + int ptr = 0xcc010000; + *(short*)((char*)(ptr) - 0x8000) = r3; + *(short*)((char*)(ptr) - 0x8000) = r4; + *(short*)((char*)(ptr) - 0x8000) = r5; +} + void GXSetLineWidth(u8 width, GXTexOffset texOffsets); void GXSetPointSize(u8 pointSize, GXTexOffset texOffsets); void GXEnableTexOffsets(GXTexCoordID coord, u8 line_enable, u8 point_enable); diff --git a/src/SB/Core/gc/iSystem.h b/src/SB/Core/gc/iSystem.h index 81c15e80c..83191f2a5 100644 --- a/src/SB/Core/gc/iSystem.h +++ b/src/SB/Core/gc/iSystem.h @@ -18,6 +18,8 @@ void** psGetMemoryFunctions(); void iVSync(); U16 my_dsc(U16 dsc); +void iSystemInit(U32 options); +void iSystemExit(); void MemoryProtectionErrorHandler(U16 last, OSContext* ctx, U64 unk1, U64 unk2); void TRCInit(); diff --git a/src/SB/Core/gc/iTRC.cpp b/src/SB/Core/gc/iTRC.cpp index 58c37af85..c4e17697b 100644 --- a/src/SB/Core/gc/iTRC.cpp +++ b/src/SB/Core/gc/iTRC.cpp @@ -1,6 +1,5 @@ #include "iTRC.h" -#include #include #include #include @@ -9,6 +8,8 @@ #include #include #include +#include +#include #include #include @@ -18,6 +19,12 @@ extern void GXPosition3s16(S32, S32, S32); extern void GXTexCoord2s16(S32, S32); +// FIXME: These should be in a RW header somewhere +extern GXRenderModeObj* _RwDlRenderMode; +extern "C" { +void RwGameCubeGetXFBs(void*, void*); +} + namespace ROMFont { OSFontHeader* mFontData; @@ -60,6 +67,40 @@ BOOL ROMFont::Init() return OSInitFont(ROMFont::mFontData); } +void ROMFont::InitDisplay(_GXRenderModeObj* InRenderMode) +{ + GXColor clr = { 0 }; + Mtx44 mtx; + Mtx idt; + + mRenderMode = InRenderMode; + void** xfb = &mXFBs[1]; + RwGameCubeGetXFBs(&mXFBs[0], &mXFBs[1]); + mCurrentFrameBuffer = *xfb; + + ROMFont::InitGX(); + ROMFont::InitVI(); + + GXSetCopyClear(clr, 0xffffff); + C_MTXOrtho(mtx, 0.0f, mRenderMode->efbHeight, 0.0f, mRenderMode->fbWidth, 0.0f, 10000.0f); + GXSetProjection(mtx, GX_ORTHOGRAPHIC); + PSMTXIdentity(idt); + GXLoadPosMtxImm(idt, 0); + GXSetCurrentMtx(0); + GXSetZMode(TRUE, GX_ALWAYS, TRUE); + GXSetNumChans(0); + GXSetNumTevStages(1); + GXSetTevOp(GX_TEVSTAGE0, GX_REPLACE); + GXSetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR_NULL); + GXSetBlendMode(GX_BM_BLEND, GX_BL_ONE, GX_BL_ONE, GX_LO_CLEAR); + GXClearVtxDesc(); + GXSetVtxDesc(GX_VA_POS, GX_DIRECT); + GXSetVtxDesc(GX_VA_TEX0, GX_DIRECT); + GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_NRM_NBT, GX_RGBA4, 0); + GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_NRM_NBT, GX_RGBA4, 0); + return; +} + void ROMFont::InitGX() { U16 scaledHeight; @@ -289,11 +330,20 @@ void ResetButton::SetSndKillFunction(void (*Func)()) void ResetButton::CheckResetButton() { + // TODO + + OSGetResetButtonState(); + PADRecalibrate(0xf0000000); + VISetBlack(TRUE); + VIFlush(); + VIWaitForRetrace(); + OSEnableInterrupts(); + DVDGetDriveStatus(); } -bool iTRCDisk::Init(void) +void iTRCDisk::Init() { - return ROMFont::Init(); + ROMFont::Init(); } void iTRCDisk::SetErrorMessage(const char* message) @@ -338,11 +388,45 @@ void iTRCDisk::SetMovieResumeFunction(void (*Func)()) bool iTRCDisk::IsDiskIDed() { - return false; + S32 diskChk; + bool diskIDed; + + diskIDed = false; + diskChk = DVDCheckDisk(); + + if ((diskChk != FALSE) && (diskChk = DVDGetDriveStatus(), diskChk == FALSE)) + { + diskIDed = true; + } + return diskIDed; } void iTRCDisk::DisplayErrorMessage() { + S32 tempVar; + GXCullMode* getMode = 0; + GXCullMode setMode = GX_CULL_ALL; + _GXRenderModeObj* gxRender = 0; + + tempVar = strcmp(mMessage, ""); + + if (tempVar != 0) + { + GXGetCullMode(getMode); // (local_18) + ROMFont::InitDisplay(gxRender); + iTRCDisk::SetDVDState(); + while (tempVar != 0) + { + ROMFont::DrawTextBox(0x32, 0xaa, 0x244, 100, mMessage); + if (tempVar != -1) + { + ResetButton::CheckResetButton(); + } + iTRCDisk::SetDVDState(); + } + iTRCDisk::ResetMessage(); + GXSetCullMode(setMode); + } } void iTRCDisk::SetDVDState() diff --git a/src/SB/Core/gc/iTRC.h b/src/SB/Core/gc/iTRC.h index ea6740aac..9323c6df1 100644 --- a/src/SB/Core/gc/iTRC.h +++ b/src/SB/Core/gc/iTRC.h @@ -3,9 +3,14 @@ #include #include +#include #include #include +#include #include +#include +#include +#include #include "xPad.h" @@ -23,6 +28,7 @@ namespace ROMFont extern bool mFirstFrame; BOOL Init(); + void InitDisplay(_GXRenderModeObj* gxRender); void InitGX(); void InitVI(); void RenderBegin(); @@ -53,7 +59,7 @@ namespace iTRCDisk void SetMovieSuspendFunction(void (*)(void)); void SetMovieResumeFunction(void (*)(void)); bool CheckDVDAndResetState(); - bool Init(); + void Init(); void ResetMessage(); void DisplayErrorMessage(); void SetDVDState(); diff --git a/src/SB/Core/x/xCamera.cpp b/src/SB/Core/x/xCamera.cpp index 2400691f4..8b448d509 100644 --- a/src/SB/Core/x/xCamera.cpp +++ b/src/SB/Core/x/xCamera.cpp @@ -12,59 +12,18 @@ #include #include -struct cameraFXShake -{ - F32 magnitude; - xVec3 dir; - F32 cycleTime; - F32 cycleMax; - F32 dampen; - F32 dampenRate; - F32 rotate_magnitude; - F32 radius; - xVec3* epicenterP; - xVec3 epicenter; - xVec3* player; -}; - -struct cameraFXZoom -{ - F32 holdTime; - F32 vel; - F32 accel; - F32 distance; - U32 mode; - F32 velCur; - F32 distanceCur; - F32 holdTimeCur; -}; + #define CAMERAFX_ZOOM_MODE_0 0 #define CAMERAFX_ZOOM_MODE_1 1 #define CAMERAFX_ZOOM_MODE_2 2 #define CAMERAFX_ZOOM_MODE_3 3 -struct cameraFX -{ - S32 type; - S32 flags; - F32 elapsedTime; - F32 maxTime; - union - { - cameraFXShake shake; - cameraFXZoom zoom; - }; -}; + #define CAMERAFX_TYPE_SHAKE 2 -struct cameraFXTableEntry -{ - S32 type; - void (*func)(cameraFX*, F32, xMat4x3*, xMat4x3*); - void (*funcKill)(cameraFX*); -}; + extern F32 _764; extern F32 _765; @@ -104,15 +63,6 @@ extern F32 _1758; extern F32 _1766; extern F32 _1772; -extern S32 sCamCollis; -extern volatile S32 xcam_collis_owner_disable; -extern S32 xcam_do_collis; -extern F32 xcam_collis_radius; -extern F32 xcam_collis_stiffness; -extern RpAtomic* sInvisWallHack; -extern xMat4x3 sCameraFXMatOld; -extern cameraFX sCameraFX[10]; -extern cameraFXTableEntry sCameraFXTable[3]; static void xCameraFXInit(); void add_camera_tweaks(); diff --git a/src/SB/Core/x/xCamera.h b/src/SB/Core/x/xCamera.h index b7780fdb1..ba85e32af 100644 --- a/src/SB/Core/x/xCamera.h +++ b/src/SB/Core/x/xCamera.h @@ -10,6 +10,64 @@ #include +struct cameraFXShake +{ + F32 magnitude; + xVec3 dir; + F32 cycleTime; + F32 cycleMax; + F32 dampen; + F32 dampenRate; + F32 rotate_magnitude; + F32 radius; + xVec3* epicenterP; + xVec3 epicenter; + xVec3* player; +}; + +struct cameraFXZoom +{ + F32 holdTime; + F32 vel; + F32 accel; + F32 distance; + U32 mode; + F32 velCur; + F32 distanceCur; + F32 holdTimeCur; +}; + +struct cameraFX +{ + S32 type; + S32 flags; + F32 elapsedTime; + F32 maxTime; + union + { + cameraFXShake shake; + cameraFXZoom zoom; + }; +}; + +struct cameraFXTableEntry +{ + S32 type; + void (*func)(cameraFX*, F32, xMat4x3*, xMat4x3*); + void (*funcKill)(cameraFX*); +}; + +extern S32 sCamCollis; +extern volatile S32 xcam_collis_owner_disable; +extern S32 xcam_do_collis; +extern F32 xcam_collis_radius; +extern F32 xcam_collis_stiffness; +extern RpAtomic* sInvisWallHack; +extern xMat4x3 sCameraFXMatOld; +extern cameraFX sCameraFX[10]; +extern cameraFXTableEntry sCameraFXTable[3]; + + struct xScene; enum _tagTransType diff --git a/src/SB/Core/x/xCollide.cpp b/src/SB/Core/x/xCollide.cpp index 61690de15..7e63b2888 100644 --- a/src/SB/Core/x/xCollide.cpp +++ b/src/SB/Core/x/xCollide.cpp @@ -240,3 +240,18 @@ U32 xSphereHitsSphere(const xSphere* a, const xSphere* b, xCollis* coll) } return uVar1; } + +void xParabolaRecenter(xParabola* p, F32 newZeroT) +{ + xVec3 newPos; + xVec3 newVel; + + xParabolaEvalPos(p, &newPos, newZeroT); + xParabolaEvalVel(p, &newVel, newZeroT); + + xVec3Copy(&p->initPos, &newPos); + xVec3Copy(&p->initVel, &newVel); + + p->maxTime -= newZeroT; + p->minTime -= newZeroT; +} diff --git a/src/SB/Core/x/xCollide.h b/src/SB/Core/x/xCollide.h index c42bc32de..331393247 100644 --- a/src/SB/Core/x/xCollide.h +++ b/src/SB/Core/x/xCollide.h @@ -124,6 +124,7 @@ U32 xSphereHitsModel(const xSphere* b, const xModelInstance* m, xCollis* coll); S32 xParabolaHitsEnv(xParabola* p, const xEnv* env, xCollis* colls); void xParabolaEvalPos(const xParabola*, xVec3*, F32); void xParabolaEvalVel(const xParabola*, xVec3*, F32); +void xParabolaRecenter(xParabola* p, F32 newZeroT); void xVec3AddScaled(xVec3*, const xVec3*, F32); xVec3 xCollisTriHit(const xCollis::tri_data& tri, const xModelInstance& model); diff --git a/src/SB/Core/x/xFX.h b/src/SB/Core/x/xFX.h index 9a0397239..3ccbb3bd0 100644 --- a/src/SB/Core/x/xFX.h +++ b/src/SB/Core/x/xFX.h @@ -83,6 +83,8 @@ struct xFXRibbon extern xFXRing ringlist[RING_COUNT]; +void xFXStartup(); +void xFXShutdown(); void xFXInit(); xFXRing* xFXRingCreate(const xVec3* pos, const xFXRing* params); void xFXRingRender(); diff --git a/src/SB/Core/x/xGlobals.h b/src/SB/Core/x/xGlobals.h index b254ffeed..7370ccc9b 100644 --- a/src/SB/Core/x/xGlobals.h +++ b/src/SB/Core/x/xGlobals.h @@ -20,7 +20,7 @@ struct xGlobals _tagxPad* pad1; _tagxPad* pad2; _tagxPad* pad3; - S32 profile; + S32 profile; //0x32c // 0x330 in globals char profFunc[6][128]; diff --git a/src/SB/Core/x/xMemMgr.h b/src/SB/Core/x/xMemMgr.h index 0e03b488f..b6c5be5e2 100644 --- a/src/SB/Core/x/xMemMgr.h +++ b/src/SB/Core/x/xMemMgr.h @@ -99,7 +99,7 @@ S32 xMemPushBase(); S32 xMemPopBase(U32 heapID, S32 depth); S32 xMemPopBase(S32 depth); S32 xMemGetBase(U32 heapID); -void xMemRegisterBaseNotifyFunc(void (*func)()); +void xMemRegisterBaseNotifyFunc(void (*)(void)); S32 xMemGetBase(); void xMemPoolAddElements(xMemPool* pool, void* buffer, U32 count); void xMemPoolSetup(xMemPool* pool, void* buffer, U32 nextOffset, U32 flags, diff --git a/src/SB/Core/x/xScrFx.h b/src/SB/Core/x/xScrFx.h index 2d1162fcf..f708156ee 100644 --- a/src/SB/Core/x/xScrFx.h +++ b/src/SB/Core/x/xScrFx.h @@ -6,6 +6,9 @@ #include +void xScrFxInit (); +void xScrFxLetterBoxSetSize(F32); +void xScrFxLetterBoxSetAlpha(F32); void xScrFxUpdate(RwCamera* cam, F32 dt); void xScrFxRender(RwCamera*); void xScrFxDrawScreenSizeRectangle(); diff --git a/src/SB/Core/x/xVec3Inlines.h b/src/SB/Core/x/xVec3Inlines.h index a09f84803..ea61a801e 100644 --- a/src/SB/Core/x/xVec3Inlines.h +++ b/src/SB/Core/x/xVec3Inlines.h @@ -18,6 +18,7 @@ F32 xVec3Dist(const xVec3* a, const xVec3* b); F32 xVec3Dist2(const xVec3* vecA, const xVec3* vecB); F32 xVec3Length2(const xVec3* vec); F32 xVec3LengthFast(F32 x, F32 y, F32 z); +F32 xVec3LengthFast(const xVec3* vec); void xVec3AddScaled(xVec3* o, const xVec3* v, F32 s); inline void xVec3SMulBy(xVec3* v, F32 s) diff --git a/src/SB/Core/x/xserializer.h b/src/SB/Core/x/xserializer.h index bf1d59819..f9b229172 100644 --- a/src/SB/Core/x/xserializer.h +++ b/src/SB/Core/x/xserializer.h @@ -12,6 +12,12 @@ struct st_SERIAL_CLIENTINFO S32 actsize; }; +struct st_SERIAL_PERCID_SIZE +{ + U32 idtag; + S32 needsize; +}; + struct xSerial { U32 idtag; @@ -44,6 +50,8 @@ struct xSerial void operator delete(void*); }; +void xSerialStartup(S32, st_SERIAL_PERCID_SIZE*); +void xSerialShutdown(); void xSerialTraverse(S32 (*func)(U32 clientID, xSerial* xser)); void xSerialWipeMainBuffer(); S32 xSerial_svgame_register(st_XSAVEGAME_DATA* sgctxt, en_SAVEGAME_MODE mode); diff --git a/src/SB/Game/zAssetTypes.h b/src/SB/Game/zAssetTypes.h index e583102e5..d270158d2 100644 --- a/src/SB/Game/zAssetTypes.h +++ b/src/SB/Game/zAssetTypes.h @@ -39,6 +39,8 @@ class HackModelRadius { F32 radius; }; +void zAssetStartup(); +void zAssetShutdown(); void FootstepHackSceneEnter(); void jsp_shadow_hack(xJSPHeader* param_1); diff --git a/src/SB/Game/zCamera.cpp b/src/SB/Game/zCamera.cpp index 9b7367413..b3b63c3ca 100644 --- a/src/SB/Game/zCamera.cpp +++ b/src/SB/Game/zCamera.cpp @@ -95,7 +95,7 @@ static F32 rewardTiltAmount = -0.22f; extern zGlobals globals; extern const xVec3 g_O3; -extern F32 gSkipTimeFlythrough; + namespace { diff --git a/src/SB/Game/zCamera.h b/src/SB/Game/zCamera.h index 1d33f203b..5318d6685 100644 --- a/src/SB/Game/zCamera.h +++ b/src/SB/Game/zCamera.h @@ -90,6 +90,8 @@ extern F32 zcam_overrot_velmax; extern F32 zcam_overrot_tmanual; extern F32 zcam_mintgtheight; +extern F32 gSkipTimeFlythrough; + void zCameraReset(xCamera* cam); void zCameraSetBbounce(S32 bbouncing); void zCameraSetHighbounce(S32 hbounce); diff --git a/src/SB/Game/zCameraTweak.cpp b/src/SB/Game/zCameraTweak.cpp index 62407fcaf..81bf0035d 100644 --- a/src/SB/Game/zCameraTweak.cpp +++ b/src/SB/Game/zCameraTweak.cpp @@ -1,22 +1,229 @@ #include "zCameraTweak.h" - +#include "xEvent.h" +#include "xMath.h" +#include "xMathInlines.h" +#include "iMath.h" +#include "zCamera.h" #include -static float sCamPitch; -static float sCamH; -static float sCamD; +static S32 sCamTweakCount; +static zCamTweak sCamTweakList[8]; +static F32 sCamTweakLerp; +static F32 sCamTweakTime; +static F32 sCamTweakPitch[2]; +static F32 sCamTweakDistMult[2]; +static F32 sCamTweakPitchCur; +static F32 sCamTweakDistMultCur; +static F32 sCamD; +static F32 sCamH; +static F32 sCamPitch; +static zCamTweakLook zcam_neartweak; +static zCamTweakLook zcam_fartweak; -F32 zCameraTweakGlobal_GetPitch() +static void zCameraTweak_LookPreCalc(zCamTweakLook* tlook, F32 d, F32 h, F32 pitch) { - return sCamPitch; + F32 tan = itan(pitch); + F32 deltaH = d * tan; + tlook->h = h - deltaH; + tlook->dist = xsqrt(deltaH * deltaH + d * d); + tlook->pitch = pitch; } -F32 zCameraTweakGlobal_GetH() +void zCameraTweakGlobal_Init() { - return sCamH; + zCameraTweak_LookPreCalc(&zcam_neartweak, zcam_near_d, zcam_near_h, zcam_near_pitch); + zCameraTweak_LookPreCalc(&zcam_fartweak, zcam_far_d, zcam_far_h, zcam_far_pitch); + zCameraTweakGlobal_Reset(); +} + +void zCameraTweakGlobal_Add(U32 owner, F32 priority, F32 time, F32 pitch, F32 distMult) +{ + S32 i; + S32 j; + + for (i = 0; i < sCamTweakCount; i++) + { + if (sCamTweakList[i].owner == owner) + { + return; + } + } + + for (i = 0; i < sCamTweakCount; i++) + { + if (priority >= sCamTweakList[i].priority) + { + for (j = sCamTweakCount; j >= i + 1; j--) + { + sCamTweakList[j] = sCamTweakList[j - 1]; + } + break; + } + } + + sCamTweakList[i].owner = owner; + sCamTweakList[i].priority = priority; + sCamTweakList[i].time = time > 0.001f ? time : 0.001f; + sCamTweakList[i].pitch = DEG2RAD(pitch); + sCamTweakList[i].distMult = distMult > 0.001f ? distMult : 0.001f; + + sCamTweakCount++; + + if (i == 0) + { + sCamTweakPitch[1] = + sCamTweakPitch[1] * sCamTweakLerp + sCamTweakPitch[0] * (1.0f - sCamTweakLerp); + sCamTweakDistMult[1] = + sCamTweakDistMult[1] * sCamTweakLerp + sCamTweakDistMult[0] * (1.0f - sCamTweakLerp); + sCamTweakLerp = 1.0f; + sCamTweakTime = sCamTweakList[0].time; + sCamTweakPitch[0] = sCamTweakList[0].pitch; + sCamTweakDistMult[0] = sCamTweakList[0].distMult; + } +} + +void zCameraTweakGlobal_Remove(U32 owner) +{ + S32 i; + S32 j; + + for (i = 0; i < sCamTweakCount; i++) + { + if (sCamTweakList[i].owner == owner) + { + if (i == 0) + { + sCamTweakPitch[1] = + sCamTweakPitch[1] * sCamTweakLerp + sCamTweakPitch[0] * (1.0f - sCamTweakLerp); + sCamTweakDistMult[1] = sCamTweakDistMult[1] * sCamTweakLerp + + sCamTweakDistMult[0] * (1.0f - sCamTweakLerp); + sCamTweakLerp = 1.0f; + sCamTweakTime = sCamTweakList[0].time; + sCamTweakPitch[0] = sCamTweakCount < 2 ? 0.0f : sCamTweakList[1].pitch; + sCamTweakDistMult[0] = sCamTweakCount < 2 ? 1.0f : sCamTweakList[1].distMult; + } + + for (j = i; j < sCamTweakCount; j--) + { + sCamTweakList[j] = sCamTweakList[j + 1]; + } + + sCamTweakCount--; + return; + } + } +} + +void zCameraTweakGlobal_Reset() +{ + sCamTweakCount = 0; + sCamTweakPitch[0] = 0.0f; + sCamTweakPitch[1] = 0.0f; + sCamTweakDistMult[0] = 1.0f; + sCamTweakDistMult[1] = 1.0f; + sCamTweakTime = 0.1f; + sCamTweakLerp = 0.0f; + sCamTweakPitchCur = 0.0f; + sCamTweakDistMultCur = 1.0f; + return; +} + +void zCameraTweakGlobal_Update(F32 dt) +{ + sCamTweakLerp -= dt / sCamTweakTime; + if (sCamTweakLerp < 0.0f) + { + sCamTweakLerp = 0.0f; + } + + zCamTweakLook* tlook = &zcam_fartweak; + sCamTweakPitchCur = + sCamTweakPitch[1] * sCamTweakLerp + sCamTweakPitch[0] * (1.0f - sCamTweakLerp); + sCamTweakDistMultCur = + sCamTweakDistMult[1] * sCamTweakLerp + sCamTweakDistMult[0] * (1.0f - sCamTweakLerp); + + tlook = zcam_near != 0 ? &zcam_neartweak : tlook; + sCamD = sCamTweakDistMultCur * tlook->dist * icos(tlook->pitch + sCamTweakPitchCur); + sCamH = sCamTweakDistMultCur * tlook->dist * isin(tlook->pitch + sCamTweakPitchCur) + tlook->h; + sCamPitch = tlook->pitch + sCamTweakPitchCur; } F32 zCameraTweakGlobal_GetD() { return sCamD; } + +F32 zCameraTweakGlobal_GetH() +{ + return sCamH; +} + +F32 zCameraTweakGlobal_GetPitch() +{ + return sCamPitch; +} + +void zCameraTweak_Init(xBase& data, xDynAsset& asset, size_t) +{ + zCameraTweak_Init((zCameraTweak*)(&data), (CameraTweak_asset*)&asset); +} + +void zCameraTweak_Init(zCameraTweak* tweak, CameraTweak_asset* asset) +{ + xBaseInit((xBase*)tweak, (xBaseAsset*)asset); + + tweak->casset = asset; + tweak->eventFunc = zCameraTweak_EventCB; + + if (tweak->linkCount != 0) + { + tweak->link = (xLinkAsset*)(asset + 1); + } + else + { + tweak->link = NULL; + } +} + +void zCameraTweak_Save(zCameraTweak* tweak, xSerial* s) +{ + xBaseSave((xBase*)tweak, s); +} + +void zCameraTweak_Load(zCameraTweak* tweak, xSerial* s) +{ + xBaseLoad((xBase*)tweak, s); +} + +S32 zCameraTweak_EventCB(xBase* from, xBase* to, U32 toEvent, const F32* toParam, xBase* b3) +{ + zCameraTweak* tweak = (zCameraTweak*)to; + + switch (toEvent) + { + case eEventEnable: + xBaseEnable(tweak); + break; + + case eEventDisable: + xBaseDisable(tweak); + break; + + case eEventRun: + if (xBaseIsEnabled(tweak)) + { + zCameraTweakGlobal_Add(tweak->id, tweak->casset->priority, tweak->casset->time, + tweak->casset->pitch_adjust, tweak->casset->dist_adjust); + } + break; + + case eEventStop: + if (xBaseIsEnabled(tweak)) + { + zCameraTweakGlobal_Remove(tweak->id); + } + break; + } + + return 1; +} diff --git a/src/SB/Game/zCameraTweak.h b/src/SB/Game/zCameraTweak.h index ab90cbc6d..89902c6c8 100644 --- a/src/SB/Game/zCameraTweak.h +++ b/src/SB/Game/zCameraTweak.h @@ -18,13 +18,36 @@ struct zCameraTweak : xBase CameraTweak_asset* casset; }; -F32 zCameraTweakGlobal_GetPitch(); -F32 zCameraTweakGlobal_GetH(); +struct zCamTweak +{ + U32 owner; + F32 priority; + F32 time; + F32 pitch; + F32 distMult; +}; + +struct zCamTweakLook +{ + F32 h; + F32 dist; + F32 pitch; +}; + +void zCameraTweakGlobal_Init(); +void zCameraTweakGlobal_Add(U32 owner, F32 priority, F32 time, F32 pitch, F32 distMult); +void zCameraTweakGlobal_Remove(U32 owner); +void zCameraTweakGlobal_Reset(); +void zCameraTweakGlobal_Update(F32 dt); F32 zCameraTweakGlobal_GetD(); +F32 zCameraTweakGlobal_GetH(); +F32 zCameraTweakGlobal_GetPitch(); void zCameraTweakGlobal_Update(F32 dt); void zCameraTweakGlobal_Reset(); void zCameraTweak_Init(xBase& data, xDynAsset& asset, size_t); +void zCameraTweak_Init(zCameraTweak* tweak, CameraTweak_asset* asset); void zCameraTweak_Save(zCameraTweak* tweak, xSerial* s); void zCameraTweak_Load(zCameraTweak* tweak, xSerial* s); +S32 zCameraTweak_EventCB(xBase* from, xBase* to, U32 toEvent, const F32* toParam, xBase* b3); #endif diff --git a/src/SB/Game/zCutsceneMgr.cpp b/src/SB/Game/zCutsceneMgr.cpp index b9252bb43..576fb6b6d 100644 --- a/src/SB/Game/zCutsceneMgr.cpp +++ b/src/SB/Game/zCutsceneMgr.cpp @@ -91,7 +91,6 @@ static S32 gCutsceneSkipOK; static S32 donpcfx; static U8 ents_hidden; static S32 s_atomicNumber; -extern F32 gSkipTimeCutscene; void zCutsceneMgrInit(void* b, void* tasset) { diff --git a/src/SB/Game/zCutsceneMgr.h b/src/SB/Game/zCutsceneMgr.h index 5c2719f1a..0ccf86cde 100644 --- a/src/SB/Game/zCutsceneMgr.h +++ b/src/SB/Game/zCutsceneMgr.h @@ -4,6 +4,9 @@ #include "xCutsceneMgr.h" #include "rpworld.h" +extern F32 gSkipTimeCutscene; + + struct xScene; struct zCutsceneMgr : xCutsceneMgr { diff --git a/src/SB/Game/zEntPlayer.h b/src/SB/Game/zEntPlayer.h index 28893cd1a..00ce06680 100644 --- a/src/SB/Game/zEntPlayer.h +++ b/src/SB/Game/zEntPlayer.h @@ -398,6 +398,8 @@ void zEntPlayer_GiveHealth(S32); void zEntPlayer_GiveSpatula(S32); void zEntPlayer_GivePatsSocksCurrentLevel(S32 quantity); +static float CalcJumpImpulse(zJumpParam*, const zPlayerSettings*); + void zEntPlayer_LoadCheckPoint(); void zEntPlayer_MinimalRender(zEnt* ent); diff --git a/src/SB/Game/zEntPlayerBungeeState.cpp b/src/SB/Game/zEntPlayerBungeeState.cpp index 4c082af31..2353d7dd8 100644 --- a/src/SB/Game/zEntPlayerBungeeState.cpp +++ b/src/SB/Game/zEntPlayerBungeeState.cpp @@ -5,7 +5,6 @@ #include "xCamera.h" #include "xDebug.h" #include "xFX.h" -#include "xIni.h" #include "xLinkAsset.h" #include "xMath.h" #include "xMathInlines.h" diff --git a/src/SB/Game/zEntPlayerBungeeState.h b/src/SB/Game/zEntPlayerBungeeState.h index e8f9466fa..11fd9fa05 100644 --- a/src/SB/Game/zEntPlayerBungeeState.h +++ b/src/SB/Game/zEntPlayerBungeeState.h @@ -3,6 +3,8 @@ #include "xDynAsset.h" #include "xEnt.h" +#include "xIni.h" + namespace bungee_state { @@ -82,6 +84,7 @@ namespace bungee_state void destroy(); void insert_animations(xAnimTable& table); void stop(); + void load_settings(xIniFile& ini); } // namespace bungee_state #endif diff --git a/src/SB/Game/zGlobals.h b/src/SB/Game/zGlobals.h index 348052ad4..836012320 100644 --- a/src/SB/Game/zGlobals.h +++ b/src/SB/Game/zGlobals.h @@ -294,15 +294,15 @@ struct zPlayerGlobals U32 SlideTrackSliding; U32 SlideTrackCount; xEnt* SlideTrackEnt[111]; - U32 SlideNotGroundedSinceSlide; + U32 SlideNotGroundedSinceSlide; //0x1f10 xVec3 SlideTrackDir; xVec3 SlideTrackVel; - F32 SlideTrackDecay; + F32 SlideTrackDecay; //0x1f2c F32 SlideTrackLean; - F32 SlideTrackLand; + F32 SlideTrackLand; // 0x1f34 U8 sb_model_indices[14]; xModelInstance* sb_models[14]; - U32 currentPlayer; + U32 currentPlayer; //0x1f80 xVec3 PredictRotate; xVec3 PredictTranslate; F32 PredictAngV; @@ -323,5 +323,6 @@ struct zGlobals : xGlobals extern zGlobals globals; extern xGlobals* xglobals; +extern zGlobalSettings* sglobals; #endif diff --git a/src/SB/Game/zMain.cpp b/src/SB/Game/zMain.cpp index 88d6b3413..882c0a69e 100644 --- a/src/SB/Game/zMain.cpp +++ b/src/SB/Game/zMain.cpp @@ -5,8 +5,86 @@ #include #include -void iEnvStartup() +#include "iSystem.h" +#include "xMemMgr.h" +#include "zVar.h" +#include "zAssetTypes.h" +#include "xTRC.h" +#include "iTime.h" +#include "zDispatcher.h" +#include "xserializer.h" +#include "xScrFX.h" +#include "xFX.h" +#include "xParMgr.h" +#include "zParCmd.h" +#include "zCameraTweak.h" +#include "zShrapnel.h" +#include "zNPCMgr.h" +#include "xCamera.h" +#include "zCamera.h" +#include "zCutsceneMgr.h" +#include "zEntPlayerBungeeState.h" + +S32 percentageDone; +_tagxPad* gDebugPad; +S32 sShowMenuOnBoot; +S32 gGameSfxReport; + +void zLedgeAdjust(zLedgeGrabParams* params); + +void main(S32 argc, char** argv) { + U32 options; + S32 i; + char* tmpStr; + + memset(&globals, 0, 0x1fc8); + globals.firstStartPressed = TRUE; + iSystemInit(FALSE); // 0x6d2 + zMainOutputMgrSetup(); + xMemRegisterBaseNotifyFunc(zMainMemLvlChkCB); + zMainInitGlobals(); + var_init(); + zAssetStartup(); + zMainLoadFontHIP(); + xfont::init(); + zMainFirstScreen(1); + zMainShowProgressBar(); + xTRCInit(); + zMainReadINI(); + iFuncProfileParse(tmpStr = "scooby.elf", globals.profile); + xUtilStartup(); + xSerialStartup(0x80, (st_SERIAL_PERCID_SIZE*)&g_xser_sizeinfo); + zDispatcher_Startup(); + xScrFxInit(); + xFXStartup(); + zMainShowProgressBar(); + xParMgrInit(); + zParCmdInit(); + iEnvStartup(); + zEntPickup_Startup(); + zCameraTweakGlobal_Init(); + globals.option_vibration = 1; // 0x6c0 + globals.pad0 = xPadEnable(globals.currentActivePad); // 0x6d1 + globals.pad1 = 0; + gDebugPad = 0; + xPadRumbleEnable(globals.currentActivePad, globals.option_vibration); // 0x6d1, 0x6c0 + xSGStartup(); + xDebugTimestampScreen(); + zShrapnel_GameInit(); + zMainShowProgressBar(); + xBehaveMgr_Startup(); + zNPCMgr_Startup(); + zMainLoop(); + zNPCMgr_Shutdown(); + xBehaveMgr_Shutdown(); + zAssetShutdown(); + xFXShutdown(); + zDispatcher_Shutdown(); + xSGShutdown(); + xSerialShutdown(); + xUtilShutdown(); + iSystemExit(); } void zMainOutputMgrSetup() @@ -25,6 +103,481 @@ void zMainInitGlobals() iTimeGet(); } +void ParseFloatList(F32* dest, char* strbuf, S32 max) +{ + xStrParseFloatList(dest, strbuf, max); +} + +void zMainParseINIGlobals(xIniFile* ini) +{ + F32 fVar1; + U32 use_degrees; + double dVar7; + + globals.player.g.AnalogMin = xIniGetInt(ini, "g.AnalogMin", 0x20); + globals.player.g.AnalogMax = xIniGetInt(ini, "g.AnalogMax", 0x6e); + xScrFxLetterBoxSetSize(xIniGetFloat(ini, "ScrFxLetterBoxSize", 0.0f)); + xScrFxLetterBoxSetAlpha(xIniGetInt(ini, "ScrFxLetterBoxAlpha", 0xff)); + globals.player.g.InitialShinyCount = xIniGetInt(ini, "g.InitialShinyCount", 0); + globals.player.g.InitialSpatulaCount = xIniGetInt(ini, "g.InitialSpatulaCount", 0); + globals.player.g.ShinyValuePurple = xIniGetInt(ini, "g.ShinyValuePurple", 100); + globals.player.g.ShinyValueBlue = xIniGetInt(ini, "g.ShinyValueBlue", 0x19); + globals.player.g.ShinyValueGreen = xIniGetInt(ini, "g.ShinyValueGreen", 10); + globals.player.g.ShinyValueYellow = xIniGetInt(ini, "g.ShinyValueYellow", 5); + globals.player.g.ShinyValueRed = xIniGetInt(ini, "g.ShinyValueRed", 1); + globals.player.g.ShinyValueCombo0 = xIniGetInt(ini, "g.ShinyValueCombo0", 0); + globals.player.g.ShinyValueCombo1 = xIniGetInt(ini, "g.ShinyValueCombo1", 0); + globals.player.g.ShinyValueCombo2 = xIniGetInt(ini, "g.ShinyValueCombo2", 2); + globals.player.g.ShinyValueCombo3 = xIniGetInt(ini, "g.ShinyValueCombo3", 3); + globals.player.g.ShinyValueCombo4 = xIniGetInt(ini, "g.ShinyValueCombo4", 3); + globals.player.g.ShinyValueCombo5 = xIniGetInt(ini, "g.ShinyValueCombo5", 5); + globals.player.g.ShinyValueCombo6 = xIniGetInt(ini, "g.ShinyValueCombo6", 10); + globals.player.g.ShinyValueCombo7 = xIniGetInt(ini, "g.ShinyValueCombo7", 0xf); + globals.player.g.ShinyValueCombo8 = xIniGetInt(ini, "g.ShinyValueCombo8", 0x14); + globals.player.g.ShinyValueCombo9 = xIniGetInt(ini, "g.ShinyValueCombo9", 0x19); + globals.player.g.ShinyValueCombo10 = xIniGetInt(ini, "g.ShinyValueCombo10", 0x1e); + globals.player.g.ShinyValueCombo11 = xIniGetInt(ini, "g.ShinyValueCombo11", 0x28); + globals.player.g.ShinyValueCombo12 = xIniGetInt(ini, "g.ShinyValueCombo12", 0x32); + globals.player.g.ShinyValueCombo13 = xIniGetInt(ini, "g.ShinyValueCombo13", 0x3c); + globals.player.g.ShinyValueCombo14 = xIniGetInt(ini, "g.ShinyValueCombo14", 0x4b); + globals.player.g.ShinyValueCombo15 = xIniGetInt(ini, "g.ShinyValueCombo15", 100); + + globals.player.g.ComboTimer = xIniGetFloat(ini, "g.ComboTimer", 1.0f); // @1002; + globals.player.g.SundaeTime = xIniGetFloat(ini, "g.SundaeTime", 6.0f); // @1003; + globals.player.g.SundaeMult = xIniGetFloat(ini, "g.SundaeMult", 1.5f); // @1004; + globals.player.g.BBashTime = xIniGetFloat(ini, "g.BBashTime", 0.3f); // @1005; + globals.player.g.BBashDelay = xIniGetFloat(ini, "g.BBashDelay", 0.15f); // @1006; + globals.player.g.BBashCVTime = xIniGetFloat(ini, "g.BBashCVTime", 0.15f); // @1006; + globals.player.g.BBashHeight = xIniGetFloat(ini, "g.BBashHeight", 3.0f); // @1007; + globals.player.g.BBounceSpeed = xIniGetFloat(ini, "g.BBounceSpeed", 10.0f); // @1008; + globals.player.g.BSpinMinFrame = xIniGetFloat(ini, "g.BSpinMinFrame", 2.0f); // @1009; + globals.player.g.BSpinMaxFrame = xIniGetFloat(ini, "g.BSpinMaxFrame", 20.0f); // @1010; + globals.player.g.BSpinRadius = xIniGetFloat(ini, "g.BSpinRadius", 0.3f); // @1005; + globals.player.g.BSpinMinFrame *= 0.033333335f; // @909 + globals.player.g.BSpinMaxFrame *= 0.033333335f; // @909 + globals.player.g.SandyMeleeMinFrame = xIniGetFloat(ini, "g.SandyMeleeMinFrame", 1.0f); // @1002; + globals.player.g.SandyMeleeMaxFrame = xIniGetFloat(ini, "g.SandyMeleeMaxFrame", 9.0f); // @1011; + globals.player.g.SandyMeleeRadius = xIniGetFloat(ini, "g.SandyMeleeRadius", 0.3f); // @1005; + globals.player.g.SandyMeleeMinFrame *= 0.033333335f; // @909 + globals.player.g.SandyMeleeMaxFrame *= 0.033333335f; // @909 + globals.player.g.DamageTimeHit = xIniGetFloat(ini, "g.DamageTimeHit", 0.5f); // @1012; + globals.player.g.DamageTimeSurface = xIniGetFloat(ini, "g.DamageTimeSurface", 1.0f); // @1002; + globals.player.g.DamageTimeEGen = xIniGetFloat(ini, "g.DamageTimeEGen", 1.0f); // @1002; + globals.player.g.DamageSurfKnock = xIniGetFloat(ini, "g.DamageSurfKnock", 1.75f); // @1013; + globals.player.g.DamageGiveHealthKnock = + xIniGetFloat(ini, "g.DamageGiveHealthKnock", 1.75f); // @1013; + globals.player.g.BubbleBowlTimeDelay = + xIniGetFloat(ini, "g.BubbleBowlTimeDelay", 1.0f); // @1002; + globals.player.g.BubbleBowlLaunchPosLeft = + xIniGetFloat(ini, "g.BubbleBowlLaunchPosLeft", 0.0f); // @ 1001; + globals.player.g.BubbleBowlLaunchPosUp = + xIniGetFloat(ini, "g.BubbleBowlLaunchPosUp", 1.0f); // @ 1002; + globals.player.g.BubbleBowlLaunchPosAt = + xIniGetFloat(ini, "g.BubbleBowlLaunchPosAt", 1.5f); // @ 1004; + globals.player.g.BubbleBowlLaunchVelLeft = + xIniGetFloat(ini, "g.BubbleBowlLaunchVelLeft", 0.0f); // @ 1001; + globals.player.g.BubbleBowlLaunchVelUp = + xIniGetFloat(ini, "g.BubbleBowlLaunchVelUp", 0.0f); // @ 1001; + globals.player.g.BubbleBowlLaunchVelAt = + xIniGetFloat(ini, "g.BubbleBowlLaunchVelAt", 10.0f); // @ 1008; + globals.player.g.BubbleBowlPercentIncrease = + xIniGetFloat(ini, "g.BubbleBowlPercentIncrease", 0.85f); // @ 1014; + globals.player.g.BubbleBowlMinSpeed = + xIniGetFloat(ini, "g.BubbleBowlMinSpeed", 0.1f); // @ 1015; + globals.player.g.BubbleBowlMinRecoverTime = + xIniGetFloat(ini, "g.BubbleBowlMinRecoverTime", 0.15f); // @ 1006; + globals.player.g.SlideAccelVelMin = xIniGetFloat(ini, "g.SlideAccelVelMin", 6.0f); // @ 1003; + globals.player.g.SlideAccelVelMax = xIniGetFloat(ini, "g.SlideAccelVelMax", 9.0f); // @ 1011; + globals.player.g.SlideAccelStart = xIniGetFloat(ini, "g.SlideAccelStart", 9.0f); // @ 1011; + globals.player.g.SlideAccelEnd = xIniGetFloat(ini, "g.SlideAccelEnd", 4.5f); // @ 1016; + globals.player.g.SlideAccelPlayerFwd = + xIniGetFloat(ini, "g.SlideAccelPlayerFwd", 5.0f); // @ 1017; + globals.player.g.SlideAccelPlayerBack = + xIniGetFloat(ini, "g.SlideAccelPlayerBack", 5.0f); // @ 1017; + globals.player.g.SlideAccelPlayerSide = + xIniGetFloat(ini, "g.SlideAccelPlayerSide", 15.0f); // @ 1018; + globals.player.g.SlideVelMaxStart = xIniGetFloat(ini, "g.SlideVelMaxStart", 12.0f); // @ 1019; + globals.player.g.SlideVelMaxEnd = xIniGetFloat(ini, "g.SlideVelMaxEnd", 17.0f); // @ 1020; + globals.player.g.SlideVelMaxIncTime = + xIniGetFloat(ini, "g.SlideVelMaxIncTime", 6.0f); // @ 1003; + globals.player.g.SlideVelMaxIncAccel = + xIniGetFloat(ini, "g.SlideVelMaxIncAccel", 1.0f); // @ 1002; + globals.player.g.SlideAirHoldTime = xIniGetFloat(ini, "g.SlideAirHoldTime", 1.0f); // @ 1002; + globals.player.g.SlideAirSlowTime = xIniGetFloat(ini, "g.SlideAirSlowTime", 1.5f); // @ 1004; + globals.player.g.SlideAirDblHoldTime = + xIniGetFloat(ini, "g.SlideAirDblHoldTime", 1.0f); // @ 1002; + globals.player.g.SlideAirDblSlowTime = + xIniGetFloat(ini, "g.SlideAirDblSlowTime", 1.5f); // @ 1004; + globals.player.g.SlideVelDblBoost = xIniGetFloat(ini, "g.SlideVelDblBoost", 6.0f); // @ 1003; + + globals.player.g.TakeDamage = xIniGetInt(ini, "g.TakeDamage", 1); + globals.player.g.CheatSpongeball = xIniGetInt(ini, "g.CheatSpongeball", 0); + globals.player.g.CheatPlayerSwitch = xIniGetInt(ini, "g.CheatPlayerSwitch", 0); + globals.player.g.CheatAlwaysPortal = xIniGetInt(ini, "g.CheatAlwaysPortal", 0); + globals.player.g.CheatFlyToggle = xIniGetInt(ini, "g.CheatFlyToggle", 0); + globals.player.g.DisableForceConversation = xIniGetInt(ini, "g.DisableForceConversation", 0); + + globals.player.g.CheatFlyToggle = 0; + globals.player.g.CheatAlwaysPortal = 0; + + globals.player.g.StartSlideAngle = xIniGetFloat(ini, "g.StartSlideAngle", 30.0f); // @ 1021; + globals.player.g.StopSlideAngle = xIniGetFloat(ini, "g.StopSlideAngle", 10.0f); // @ 1008; + globals.player.g.RotMatchMaxAngle = xIniGetFloat(ini, "g.RotMatchMaxAngle", 30.0f); // @ 1021; + globals.player.g.RotMatchMatchTime = xIniGetFloat(ini, "g.RotMatchMatchTime", 0.1f); // @ 1015; + globals.player.g.RotMatchRelaxTime = xIniGetFloat(ini, "g.RotMatchRelaxTime", 0.3f); // @ 1005 + globals.player.g.Gravity = xIniGetFloat(ini, "g.Gravity", 30.0f); // @ 1021 + + globals.player.g.StartSlideAngle = DEG2RAD(globals.player.g.StartSlideAngle); + globals.player.g.StopSlideAngle = DEG2RAD(globals.player.g.StopSlideAngle); + globals.player.g.RotMatchMaxAngle = DEG2RAD(globals.player.g.RotMatchMaxAngle); + + use_degrees = xIniGetFloat(ini, "zcam_highbounce_pitch", 180.0f) != 180.0f; + xcam_collis_radius = xIniGetFloat(ini, "xcam_collis_radius", xcam_collis_radius); + xcam_collis_stiffness = xIniGetFloat(ini, "xcam_collis_stiffness", xcam_collis_stiffness); + zcam_pad_pyaw_scale = xIniGetFloat(ini, "zcam_pad_pyaw_scale", zcam_pad_pyaw_scale); + zcam_pad_pitch_scale = xIniGetFloat(ini, "zcam_pad_pitch_scale", zcam_pad_pitch_scale); + zcam_near_d = xIniGetFloat(ini, "zcam_near_d", zcam_near_d); + zcam_near_h = xIniGetFloat(ini, "zcam_near_h", zcam_near_h); + zcam_pad_pyaw_scale = xIniGetFloat(ini, "zcam_pad_pyaw_scale", zcam_pad_pyaw_scale); + zcam_near_pitch = xIniGetFloat(ini, "zcam_near_pitch", + use_degrees ? RAD2DEG(zcam_near_pitch) : zcam_near_pitch); + + zcam_far_d = xIniGetFloat(ini, "zcam_far_d", zcam_far_d); + zcam_far_h = xIniGetFloat(ini, "zcam_far_h", zcam_far_h); + zcam_far_pitch = + xIniGetFloat(ini, "zcam_far_pitch", use_degrees ? RAD2DEG(zcam_far_pitch) : zcam_far_pitch); + + zcam_above_d = xIniGetFloat(ini, "zcam_above_d", zcam_above_d); + zcam_above_h = xIniGetFloat(ini, "zcam_above_h", zcam_above_h); + zcam_above_pitch = xIniGetFloat(ini, "zcam_above_pitch", + use_degrees ? RAD2DEG(zcam_above_pitch) : zcam_above_pitch); + + zcam_below_d = xIniGetFloat(ini, "zcam_below_d", zcam_below_d); + zcam_below_h = xIniGetFloat(ini, "zcam_below_h", zcam_below_h); + zcam_below_pitch = xIniGetFloat(ini, "zcam_below_pitch", + use_degrees ? RAD2DEG(zcam_below_pitch) : zcam_below_pitch); + + zcam_highbounce_d = xIniGetFloat(ini, "zcam_highbounce_d", zcam_highbounce_d); + zcam_highbounce_h = xIniGetFloat(ini, "zcam_highbounce_h", zcam_highbounce_h); + zcam_highbounce_pitch = + xIniGetFloat(ini, "zcam_highbounce_pitch", + use_degrees ? RAD2DEG(zcam_highbounce_pitch) : zcam_highbounce_pitch); + + zcam_wall_d = xIniGetFloat(ini, "zcam_wall_d", zcam_wall_d); + zcam_wall_h = xIniGetFloat(ini, "zcam_wall_h", zcam_wall_h); + zcam_wall_pitch = xIniGetFloat(ini, "zcam_wall_pitch", + use_degrees ? RAD2DEG(zcam_wall_pitch) : zcam_wall_pitch); + + zcam_overrot_min = xIniGetFloat(ini, "zcam_overrot_min", DEG2RAD(zcam_overrot_min)); + zcam_overrot_mid = xIniGetFloat(ini, "zcam_overrot_mid", DEG2RAD(zcam_overrot_mid)); + zcam_overrot_max = xIniGetFloat(ini, "zcam_overrot_max", DEG2RAD(zcam_overrot_max)); + + zcam_overrot_rate = xIniGetFloat(ini, "zcam_overrot_rate", zcam_overrot_rate); + zcam_overrot_tstart = xIniGetFloat(ini, "zcam_overrot_tstart", zcam_overrot_tstart); + zcam_overrot_tend = xIniGetFloat(ini, "zcam_overrot_tend", zcam_overrot_tend); + zcam_overrot_velmin = xIniGetFloat(ini, "zcam_overrot_velmin", zcam_overrot_velmin); + zcam_overrot_velmax = xIniGetFloat(ini, "zcam_overrot_velmax", zcam_overrot_velmax); + zcam_overrot_tmanual = xIniGetFloat(ini, "zcam_overrot_tmanual", zcam_overrot_tmanual); + + if (use_degrees) + { + zcam_near_pitch = DEG2RAD(zcam_near_pitch); + zcam_far_pitch = DEG2RAD(zcam_far_pitch); + zcam_above_pitch = DEG2RAD(zcam_above_pitch); + zcam_below_pitch = DEG2RAD(zcam_below_pitch); + zcam_highbounce_pitch = DEG2RAD(zcam_highbounce_pitch); + zcam_wall_pitch = DEG2RAD(zcam_wall_pitch); + } + + zcam_overrot_min = DEG2RAD(zcam_overrot_min); + zcam_overrot_mid = DEG2RAD(zcam_overrot_mid); + zcam_overrot_max = DEG2RAD(zcam_overrot_max); + + // tgsm: this seems fucky + gSkipTimeCutscene = xIniGetFloat(ini, "gSkipTimeCutscene", gSkipTimeCutscene); + dVar7 = xIniGetFloat(ini, "gSkipTimeFlythrough", gSkipTimeFlythrough); + fVar1 = 1.0f; // @ 1002 + if (1.0f < gSkipTimeCutscene) + { + fVar1 = gSkipTimeCutscene; + } + gSkipTimeFlythrough = 0.0f; + if (0.0f < dVar7) + { + gSkipTimeFlythrough = dVar7; + } + gSkipTimeCutscene = fVar1; + + globals.player.carry.minDist = xIniGetFloat(ini, "carry.minDist", 0.675f); // @1024; + globals.player.carry.maxDist = xIniGetFloat(ini, "carry.maxDist", 1.9f); // @1025; + globals.player.carry.minHeight = xIniGetFloat(ini, "carry.minHeight", -0.2f); // @1026; + globals.player.carry.maxHeight = xIniGetFloat(ini, "carry.maxHeight", 0.4f); // @1027; + globals.player.carry.maxCosAngle = xIniGetFloat(ini, "carry.maxCosAngle", 45.0f); // @1028; + globals.player.carry.throwMinDist = xIniGetFloat(ini, "carry.throwMinDist", 1.5f); // @1004; + globals.player.carry.throwMaxDist = xIniGetFloat(ini, "carry.throwMaxDist", 12.0f); // @1019; + globals.player.carry.throwMinHeight = + xIniGetFloat(ini, "carry.throwMinHeight", -3.0f); // @1029; + globals.player.carry.throwMaxHeight = xIniGetFloat(ini, "carry.throwMaxHeight", 5.0f); // @1017; + globals.player.carry.throwMaxStack = xIniGetFloat(ini, "carry.throwMaxStack", 2.75f); // @1030; + globals.player.carry.throwMaxCosAngle = + xIniGetFloat(ini, "carry.throwMaxCosAngle", 25.0f); // @1031; + globals.player.carry.grabLerpMin = xIniGetFloat(ini, "carry.grabLerpMin", 0.0f); // @1001; + globals.player.carry.grabLerpMax = xIniGetFloat(ini, "carry.grabLerpMax", 0.2f); // @1032; + globals.player.carry.throwGravity = xIniGetFloat(ini, "carry.throwGravity", 30.0f); // @1021; + globals.player.carry.throwHeight = xIniGetFloat(ini, "carry.throwHeight", 3.75f); // @1033; + globals.player.carry.throwDistance = xIniGetFloat(ini, "carry.throwDistance", 10.0f); // @1008; + globals.player.carry.fruitFloorDecayMin = + xIniGetFloat(ini, "carry.fruitFloorDecayMin", 0.3f); // @1005; + globals.player.carry.fruitFloorDecayMax = + xIniGetFloat(ini, "carry.fruitFloorDecayMax", 6.0f); // @1003; + globals.player.carry.fruitFloorBounce = + xIniGetFloat(ini, "carry.fruitFloorBounce", 0.15f); // @1006; + globals.player.carry.fruitFloorFriction = + xIniGetFloat(ini, "carry.fruitFloorFriction", 0.4f); // @1027; + globals.player.carry.fruitCeilingBounce = + xIniGetFloat(ini, "carry.fruitCeilingBounce", 0.1f); // @1015; + globals.player.carry.fruitWallBounce = + xIniGetFloat(ini, "carry.fruitWallBounce", 0.5f); // @1012; + globals.player.carry.fruitLifetime = xIniGetFloat(ini, "carry.fruitLifetime", 15.0f); // @1018; + + globals.player.carry.maxCosAngle = icos(DEG2RAD(globals.player.carry.maxCosAngle)); + globals.player.carry.throwMaxCosAngle = icos(DEG2RAD(globals.player.carry.throwMaxCosAngle)); + + globals.player.g.PowerUp[0] = xIniGetInt(ini, "g.BubbleBowl", 0); // Not sure about this + globals.player.g.PowerUp[1] = xIniGetInt(ini, "g.CruiseBubble", 0); // Not sure about this + + memcpy(globals.player.g.InitialPowerUp, globals.player.g.PowerUp, 2); + + { + static F32 fbuf[] = { 0.6f, 3.0f, 7.0f, 0.1f, 0.5f, 1.0f }; + ParseFloatList((F32*)memcpy(&globals.player.sb.MoveSpeed, fbuf, sizeof(fbuf)), + xIniGetString(ini, "sb.MoveSpeed", 0), 6); + } + { + static F32 fbuf[] = { 1.5f, 0.5f, 1.5f }; + ParseFloatList((F32*)memcpy(&globals.player.sb.AnimSneak, fbuf, sizeof(fbuf)), + xIniGetString(ini, "sb.AnimSneak", 0), 3); + } + { + static F32 fbuf[] = { 3.0f, 0.5f, 2.5f }; + ParseFloatList((F32*)memcpy(&globals.player.sb.AnimWalk, fbuf, sizeof(fbuf)), + xIniGetString(ini, "sb.AnimWalk", 0), 3); + } + { + static F32 fbuf[] = { 3.0f, 0.5f, 2.5f }; + ParseFloatList((F32*)memcpy(&globals.player.sb.AnimRun, fbuf, sizeof(fbuf)), + xIniGetString(ini, "sb.AnimRun", 0), 3); + } + + globals.player.sb.JumpGravity = xIniGetFloat(ini, "sb.JumpGravity", 7.0f); // @1034; + globals.player.sb.GravSmooth = xIniGetFloat(ini, "sb.GravSmooth", 0.25f); // @1035; + globals.player.sb.FloatSpeed = xIniGetFloat(ini, "sb.FloatSpeed", 1.0f); // @1002; + globals.player.sb.ButtsmashSpeed = xIniGetFloat(ini, "sb.ButtsmashSpeed", 5.0f); // @1017; + globals.player.sb.ledge.animGrab = xIniGetFloat(ini, "sb.ledge.animGrab", 3.0f); // @1007; + + zLedgeAdjust(&globals.player.sb.ledge); + bungee_state::load_settings(*ini); + //oob_state::load_settings(xIniFile&) + //ztalkbox::load_settings(*ini); + + { + static F32 fbuf[] = { 2.0f, 0.7f, 0.35f, 0.0f }; + ParseFloatList((F32*)memcpy(&globals.player.sb.Jump, fbuf, sizeof(fbuf)), + xIniGetString(ini, "sb.Jump", 0), 4); + } + { + static F32 fbuf[] = { 1.0f, 0.7f, 0.35f, 0.0f }; + ParseFloatList((F32*)memcpy(&globals.player.sb.Double, fbuf, sizeof(fbuf)), + xIniGetString(ini, "sb.Double", 0), 4); + } + { + static F32 fbuf[] = { 1.5f, 0.2f, 0.2f, 0.0f }; + ParseFloatList((F32*)memcpy(&globals.player.sb.Bounce, fbuf, sizeof(fbuf)), + xIniGetString(ini, "sb.Bounce", 0), 4); + } + { + static F32 fbuf[] = { 3.0f, 0.2f, 0.2f, 0.0f }; + ParseFloatList((F32*)memcpy(&globals.player.sb.Spring, fbuf, sizeof(fbuf)), + xIniGetString(ini, "sb.Spring", 0), 4); + } + { + static F32 fbuf[] = { 0.0f, 0.0f, 0.0f, 0.0f }; + ParseFloatList((F32*)memcpy(&globals.player.sb.Wall, fbuf, sizeof(fbuf)), + xIniGetString(ini, "sb.Wall", 0), 4); + } + + globals.player.sb.WallJumpVelocity = xIniGetFloat(ini, "sb.WallJumpVelocity", 0.0f); // @1001; + globals.player.sb.spin_damp_xz = xIniGetFloat(ini, "sb.spin_damp_xz", 15.0f); // @1018; + globals.player.sb.spin_damp_y = xIniGetFloat(ini, "sb.spin_damp_y", 15.0f); // @1018; + + globals.player.s = &globals.player.sb; + + CalcJumpImpulse(&globals.player.sb.Jump, NULL); + CalcJumpImpulse(&globals.player.sb.Double, NULL); + CalcJumpImpulse(&globals.player.sb.Bounce, NULL); + CalcJumpImpulse(&globals.player.sb.Spring, NULL); + CalcJumpImpulse(&globals.player.sb.Wall, NULL); + + globals.player.sb_model_indices[0] = + xIniGetInt(ini, "SB.model_index.body", + 0); // These next 13 are either "sb_models" or "sb_model_indices" + globals.player.sb_model_indices[1] = xIniGetInt(ini, "SB.model_index.arm_l", 1); + globals.player.sb_model_indices[2] = xIniGetInt(ini, "SB.model_index.arm_r", 2); + globals.player.sb_model_indices[3] = xIniGetInt(ini, "SB.model_index.ass", 3); + globals.player.sb_model_indices[4] = xIniGetInt(ini, "SB.model_index.underwear", 4); + globals.player.sb_model_indices[5] = xIniGetInt(ini, "SB.model_index.wand", 5); + globals.player.sb_model_indices[6] = xIniGetInt(ini, "SB.model_index.tongue", 6); + globals.player.sb_model_indices[7] = xIniGetInt(ini, "SB.model_index.bubble_helmet", 7); + globals.player.sb_model_indices[8] = xIniGetInt(ini, "SB.model_index.bubble_shoe_l", 8); + globals.player.sb_model_indices[9] = xIniGetInt(ini, "SB.model_index.bubble_shoe_r", 9); + globals.player.sb_model_indices[13] = xIniGetInt(ini, "SB.model_index.shadow_wand", 10); + globals.player.sb_model_indices[11] = xIniGetInt(ini, "SB.model_index.shadow_arm_l", 11); + globals.player.sb_model_indices[12] = xIniGetInt(ini, "SB.model_index.shadow_arm_r", 12); + globals.player.sb_model_indices[10] = xIniGetInt(ini, "SB.model_index.shadow_body", 13); + + { + static F32 fbuf[] = { 0.6f, 3.0f, 7.0f, 0.1f, 0.5f, 1.0f }; + ParseFloatList((F32*)memcpy(&globals.player.patrick.MoveSpeed, fbuf, sizeof(fbuf)), + xIniGetString(ini, "patrick.MoveSpeed", 0), 6); + } + { + static F32 fbuf[] = { 1.5f, 0.5f, 1.5f }; + ParseFloatList((F32*)memcpy(&globals.player.patrick.AnimSneak, fbuf, sizeof(fbuf)), + xIniGetString(ini, "patrick.AnimSneak", 0), 3); + } + { + static F32 fbuf[] = { 3.0f, 0.5f, 2.5f }; + ParseFloatList((F32*)memcpy(&globals.player.patrick.AnimWalk, fbuf, sizeof(fbuf)), + xIniGetString(ini, "patrick.AnimWalk", 0), 3); + } + { + static F32 fbuf[] = { 3.0f, 0.5f, 2.5f }; + ParseFloatList((F32*)memcpy(&globals.player.patrick.AnimRun, fbuf, sizeof(fbuf)), + xIniGetString(ini, "patrick.AnimRun", 0), 3); + } + + globals.player.patrick.JumpGravity = xIniGetFloat(ini, "patrick.JumpGravity", 7.0f); // @1034; + globals.player.patrick.GravSmooth = xIniGetFloat(ini, "patrick.GravSmooth", 0.25f); // @1035; + globals.player.patrick.FloatSpeed = xIniGetFloat(ini, "patrick.FloatSpeed", 1.0f); // @1002; + globals.player.patrick.ButtsmashSpeed = + xIniGetFloat(ini, "patrick.ButtsmashSpeed", 5.0f); // @1017; + globals.player.patrick.ledge.animGrab = + xIniGetFloat(ini, "patrick.ledge.animGrab", 3.0f); // @1007; + + zLedgeAdjust(&globals.player.patrick.ledge); + + { + static F32 fbuf[] = { 2.0f, 0.7f, 0.35f, 0.0f }; + ParseFloatList((F32*)memcpy(&globals.player.patrick.Jump, fbuf, sizeof(fbuf)), + xIniGetString(ini, "patrick.Jump", 0), 4); + } + { + static F32 fbuf[] = { 1.0f, 0.7f, 0.35f, 0.0f }; + ParseFloatList((F32*)memcpy(&globals.player.patrick.Double, fbuf, sizeof(fbuf)), + xIniGetString(ini, "patrick.Double", 0), 4); + } + { + static F32 fbuf[] = { 1.5f, 0.2f, 0.2f, 0.0f }; + ParseFloatList((F32*)memcpy(&globals.player.patrick.Bounce, fbuf, sizeof(fbuf)), + xIniGetString(ini, "patrick.Bounce", 0), 4); + } + { + static F32 fbuf[] = { 3.0f, 0.2f, 0.2f, 0.0f }; + ParseFloatList((F32*)memcpy(&globals.player.patrick.Spring, fbuf, sizeof(fbuf)), + xIniGetString(ini, "patrick.Spring", 0), 4); + } + { + static F32 fbuf[] = { 0.0f, 0.0f, 0.0f, 0.0f }; + ParseFloatList((F32*)memcpy(&globals.player.patrick.Wall, fbuf, sizeof(fbuf)), + xIniGetString(ini, "patrick.Wall", 0), 4); + } + + globals.player.s = &globals.player.sb; + + CalcJumpImpulse(&globals.player.patrick.Jump, NULL); + CalcJumpImpulse(&globals.player.patrick.Double, NULL); + CalcJumpImpulse(&globals.player.patrick.Bounce, NULL); + CalcJumpImpulse(&globals.player.patrick.Spring, NULL); + CalcJumpImpulse(&globals.player.patrick.Wall, NULL); + + globals.player.patrick.WallJumpVelocity = + xIniGetFloat(ini, "patrick.WallJumpVelocity", 0.0f); // @1001; + + { + static F32 fbuf[] = { 0.6f, 3.0f, 7.0f, 0.1f, 0.5f, 1.0f }; + ParseFloatList((F32*)memcpy(&globals.player.sandy.MoveSpeed, fbuf, sizeof(fbuf)), + xIniGetString(ini, "sandy.MoveSpeed", 0), 6); + } + { + static F32 fbuf[] = { 1.5f, 0.5f, 1.5f }; + ParseFloatList((F32*)memcpy(&globals.player.sandy.AnimSneak, fbuf, sizeof(fbuf)), + xIniGetString(ini, "sandy.AnimSneak", 0), 3); + } + { + static F32 fbuf[] = { 3.0f, 0.5f, 2.5f }; + ParseFloatList((F32*)memcpy(&globals.player.sandy.AnimWalk, fbuf, sizeof(fbuf)), + xIniGetString(ini, "sandy.AnimWalk", 0), 3); + } + { + static F32 fbuf[] = { 3.0f, 0.5f, 2.5f }; + ParseFloatList((F32*)memcpy(&globals.player.sandy.AnimRun, fbuf, sizeof(fbuf)), + xIniGetString(ini, "sandy.AnimRun", 0), 3); + } + + globals.player.sandy.JumpGravity = xIniGetFloat(ini, "sandy.JumpGravity", 7.0f); // @1034; + globals.player.sandy.GravSmooth = xIniGetFloat(ini, "sandy.GravSmooth", 0.25f); // @1035; + globals.player.sandy.FloatSpeed = xIniGetFloat(ini, "sandy.FloatSpeed", 1.0f); // @1002; + globals.player.sandy.ButtsmashSpeed = xIniGetFloat(ini, "sandy.ButtsmashSpeed", 5.0f); // @1017; + globals.player.sandy.ledge.animGrab = xIniGetFloat(ini, "sandy.ledge.animGrab", 3.0f); // @1007; + + zLedgeAdjust(&globals.player.sandy.ledge); + + { + static F32 fbuf[] = { 2.0f, 0.7f, 0.35f, 0.0f }; + ParseFloatList((F32*)memcpy(&globals.player.sandy.Jump, fbuf, sizeof(fbuf)), + xIniGetString(ini, "sandy.Jump", 0), 4); + } + { + static F32 fbuf[] = { 1.0f, 0.7f, 0.35f, 0.0f }; + ParseFloatList((F32*)memcpy(&globals.player.sandy.Double, fbuf, sizeof(fbuf)), + xIniGetString(ini, "sandy.Double", 0), 4); + } + { + static F32 fbuf[] = { 1.5f, 0.2f, 0.2f, 0.0f }; + ParseFloatList((F32*)memcpy(&globals.player.sandy.Bounce, fbuf, sizeof(fbuf)), + xIniGetString(ini, "sandy.Bounce", 0), 4); + } + { + static F32 fbuf[] = { 3.0f, 0.2f, 0.2f, 0.0f }; + ParseFloatList((F32*)memcpy(&globals.player.sandy.Spring, fbuf, sizeof(fbuf)), + xIniGetString(ini, "sandy.Spring", 0), 4); + } + { + static F32 fbuf[] = { 0.0f, 0.0f, 0.0f, 0.0f }; + ParseFloatList((F32*)memcpy(&globals.player.sandy.Wall, fbuf, sizeof(fbuf)), + xIniGetString(ini, "sandy.Wall", 0), 4); + } + + globals.player.s = &globals.player.sb; + + CalcJumpImpulse(&globals.player.sandy.Jump, NULL); + CalcJumpImpulse(&globals.player.sandy.Double, NULL); + CalcJumpImpulse(&globals.player.sandy.Bounce, NULL); + CalcJumpImpulse(&globals.player.sandy.Spring, NULL); + CalcJumpImpulse(&globals.player.sandy.Wall, NULL); + + globals.player.sandy.WallJumpVelocity = + xIniGetFloat(ini, "sandy.WallJumpVelocity", 0.0f); // @1001; + + sShowMenuOnBoot = xIniGetInt(ini, "ShowMenuOnBoot", 1); + gGameSfxReport = xIniGetInt(ini, "SFXReport", 0); + + globals.player.s = &globals.player.sb; + globals.player.sb.pcType = ePlayer_SB; + globals.player.patrick.pcType = ePlayer_Patrick; + globals.player.sandy.pcType = ePlayer_Sandy; +} + void zMainMemLvlChkCB() { zSceneMemLvlChkCB(); @@ -32,5 +585,60 @@ void zMainMemLvlChkCB() void zLedgeAdjust(zLedgeGrabParams* params) { - params->animGrab *= (1.0f/30); -} \ No newline at end of file + params->animGrab *= (1.0f / 30); +} + +void zMainShowProgressBar() +{ +} + +void zMainLoop() +{ + S64 t; + U32* preinit; + RpAtomic* modl; + //RpAtomic* modl; + //RpAtomic* modl; + U32 newGameSceneID; + U32 iconDataSize; + void* iconData; + U32 gameSceneID; + U32 menuModeID; + //int8 @5697; + U32 preinit_bubble_matfx[6]; + U32 preinit_shiny_models[8]; + U32 preinit_ADC_models[10]; +} + +void zMainReadINI() +{ + char* str; + void* buf; + U32 size; + xIniFile* ini; +} + +void zMainFirstScreen(int) +{ +} + +void zMainMemCardSpaceQuery() +{ + S32 bytesNeeded; + S32 availOnDisk; + S32 neededFiles; + S32 do_chk; + S32 fullCard; + U8 formatInProgress; + U8 formatFailed; + eStartupErrors startupError; + S32 status; +} + +void zMainLoadFontHIP() +{ +} + +void iEnvStartup() +{ +} diff --git a/src/SB/Game/zMain.h b/src/SB/Game/zMain.h index 8d045881c..c19b8f4f1 100644 --- a/src/SB/Game/zMain.h +++ b/src/SB/Game/zMain.h @@ -1,4 +1,33 @@ #ifndef ZMAIN_H #define ZMAIN_H +#include +#include "xIni.h" +#include "xserializer.h" + +st_SERIAL_PERCID_SIZE* g_xser_sizeinfo; + +enum eStartupErrors +{ + eNoError, + eNoFormat, + eDamagedCard, + eWrongDevice, + eNoCards, + eCorruptFile, + eNoController, +}; + +void main(S32 argc, char** argv); +void iEnvStartup(); +void zMainOutputMgrSetup(); +void zMainInitGlobals(); +void zMainParseINIGlobals(xIniFile* ini); +void zMainMemLvlChkCB(); +void zMainShowProgressBar(); +void zMainLoop(); +void zMainReadINI(); +void zMainFirstScreen(int); +void zMainLoadFontHIP(); + #endif \ No newline at end of file diff --git a/src/SB/Game/zNPCTypeBossPlankton.cpp b/src/SB/Game/zNPCTypeBossPlankton.cpp index d4b8aa740..f06fbbf43 100644 --- a/src/SB/Game/zNPCTypeBossPlankton.cpp +++ b/src/SB/Game/zNPCTypeBossPlankton.cpp @@ -2,8 +2,6 @@ #include -// pr comment retry - #define f1585 1.0f #define f1586 0.0f #define f1657 0.2f @@ -69,32 +67,46 @@ xAnimTable* ZNPC_AnimTable_BossPlankton() xAnimTableNewState(table, g_strz_bossanim[ANIM_Idle01], 0x10, 0, 1.0f, NULL, NULL, 0.0f, NULL, NULL, xAnimDefaultBeforeEnter, NULL, NULL); + ourAnims[0] = 3; xAnimTableNewState(table, g_strz_bossanim[ANIM_Taunt01], 0x20, 0, 1.0f, NULL, NULL, 0.0f, NULL, NULL, xAnimDefaultBeforeEnter, NULL, NULL); + ourAnims[0] = 0x42; xAnimTableNewState(table, g_strz_bossanim[ANIM_move], 0x10, 0, f1585, NULL, NULL, f1586, NULL, NULL, xAnimDefaultBeforeEnter, NULL, NULL); + ourAnims[0] = 0x43; xAnimTableNewState(table, g_strz_bossanim[ANIM_stun_begin], 0x20, 0, f1585, NULL, NULL, f1586, NULL, NULL, xAnimDefaultBeforeEnter, NULL, NULL); + ourAnims[0] = 0x44; xAnimTableNewState(table, g_strz_bossanim[ANIM_stun_loop], 0x10, 0, f1585, NULL, NULL, f1586, NULL, NULL, xAnimDefaultBeforeEnter, NULL, NULL); + ourAnims[0] = 0x45; xAnimTableNewState(table, g_strz_bossanim[ANIM_stun_end], 0x20, 0, f1585, NULL, NULL, f1586, NULL, NULL, xAnimDefaultBeforeEnter, NULL, NULL); + ourAnims[0] = 0x46; xAnimTableNewState(table, g_strz_bossanim[ANIM_attack_beam_begin], 0x20, 0, f1585, NULL, NULL, f1586, NULL, NULL, xAnimDefaultBeforeEnter, NULL, NULL); + ourAnims[0] = 0x47; xAnimTableNewState(table, g_strz_bossanim[ANIM_attack_beam_loop], 0x10, 0, f1585, NULL, NULL, f1586, NULL, NULL, xAnimDefaultBeforeEnter, NULL, NULL); + ourAnims[0] = 0x48; xAnimTableNewState(table, g_strz_bossanim[ANIM_attack_beam_end], 0x20, 0, f1585, NULL, NULL, f1586, NULL, NULL, xAnimDefaultBeforeEnter, NULL, NULL); + ourAnims[0] = 0x49; xAnimTableNewState(table, g_strz_bossanim[ANIM_attack_wall_begin], 0x20, 0, f1585, NULL, NULL, f1586, NULL, NULL, xAnimDefaultBeforeEnter, NULL, NULL); + ourAnims[0] = 0x4a; xAnimTableNewState(table, g_strz_bossanim[ANIM_attack_wall_loop], 0x10, 0, f1585, NULL, NULL, f1586, NULL, NULL, xAnimDefaultBeforeEnter, NULL, NULL); + ourAnims[0] = 0x4b; xAnimTableNewState(table, g_strz_bossanim[ANIM_attack_wall_end], 0x20, 0, f1585, NULL, NULL, f1586, NULL, NULL, xAnimDefaultBeforeEnter, NULL, NULL); + ourAnims[0] = 0x4c; xAnimTableNewState(table, g_strz_bossanim[ANIM_attack_missle], 0x20, 0, f1585, NULL, NULL, f1586, NULL, NULL, xAnimDefaultBeforeEnter, NULL, NULL); + ourAnims[0] = 0x4d; xAnimTableNewState(table, g_strz_bossanim[ANIM_attack_bomb], 0x20, 0, f1585, NULL, NULL, f1586, NULL, NULL, xAnimDefaultBeforeEnter, NULL, NULL); + ourAnims[0] = 0; NPCC_BuildStandardAnimTran(table, g_strz_bossanim, ourAnims, 1, f1657); diff --git a/src/SB/Game/zNPCTypeBossSB2.cpp b/src/SB/Game/zNPCTypeBossSB2.cpp index 89d99eaa0..7448a4529 100644 --- a/src/SB/Game/zNPCTypeBossSB2.cpp +++ b/src/SB/Game/zNPCTypeBossSB2.cpp @@ -308,7 +308,7 @@ void zNPCB_SB2::ThanksImDone() flag.dizzy = false; } -void zNPCB_SB2::reset_speed() //tweak in .bss +void zNPCB_SB2::reset_speed() { turn.accel = 0; turn.max_vel = 0; @@ -316,7 +316,7 @@ void zNPCB_SB2::reset_speed() //tweak in .bss S32 zNPCB_SB2::player_platform() { - return 0; // to-do + return 0; // TODO } void zNPCB_SB2::activate_hand(zNPCB_SB2::hand_enum, bool) @@ -336,7 +336,7 @@ void zNPCB_SB2::deactivate_hand(zNPCB_SB2::hand_enum) S32 zNPCB_SB2::player_on_ground() const { return 0; - // to-do + // TODO } void zNPCB_SB2::abandon_slugs() diff --git a/src/SB/Game/zNPCTypeDutchman.cpp b/src/SB/Game/zNPCTypeDutchman.cpp index e1fedb7b9..780574740 100644 --- a/src/SB/Game/zNPCTypeDutchman.cpp +++ b/src/SB/Game/zNPCTypeDutchman.cpp @@ -30,6 +30,8 @@ namespace #define ANIM_Attack02End01 18 //0x48 #define ANIM_LassoGrab01 19 //0x4c +U32 dutchman_count; + //13 new states //8 new transitions xAnimTable* ZNPC_AnimTable_Dutchman() @@ -252,7 +254,7 @@ void zNPCDutchman::kill_wave(zNPCDutchman::wave_data& wave) kill_sound(1, wave.sound_handle); } -void zNPCDutchman::start_eye_glow() //Matches but the data is fucked +void zNPCDutchman::start_eye_glow() { flag.eye_glow = true; eye_glow.size = 1; diff --git a/src/SB/Game/zNPCTypeDutchman.h b/src/SB/Game/zNPCTypeDutchman.h index 697c0d75e..aaab93642 100644 --- a/src/SB/Game/zNPCTypeDutchman.h +++ b/src/SB/Game/zNPCTypeDutchman.h @@ -386,7 +386,7 @@ struct zNPCGoalDutchmanDeath : zNPCGoalCommon }; xAnimTable* ZNPC_AnimTable_Dutchman(); -U32 dutchman_count; + void Exit(); #endif diff --git a/src/SB/Game/zNPCTypeKingJelly.cpp b/src/SB/Game/zNPCTypeKingJelly.cpp index ee1ad099f..e6d281062 100644 --- a/src/SB/Game/zNPCTypeKingJelly.cpp +++ b/src/SB/Game/zNPCTypeKingJelly.cpp @@ -11,7 +11,7 @@ #define ANIM_Unknown 0 // 0x0 #define ANIM_Idle01 1 // 0x04 -#define ANIM_Idle02 2 // 0x08 animetable new state +#define ANIM_Idle02 2 // 0x08 #define ANIM_Idle03 3 // 0xC #define ANIM_Fidget01 4 // #define ANIM_Fidget02 5 @@ -285,49 +285,11 @@ void zNPCKingJelly::enable_child(zNPCKingJelly::child_data& child) } } -// probably how many times the jellyfish can hit the player for that round -// whatever round it is, add one. -// Round = 0, max strikes = 1 -// Round = 1, max strikes = 2 -// Round = 2, max strikes = 3 S32 zNPCKingJelly::max_strikes() { return round + 1; } -//void zNPCKingJelly::update_round() -//{ -// if (life == 0) -// { -// store zero in something?? -// 0x2bc -// round = 0; -// return; -// } - -//round = life-- * 3; - -// updating 0x2bc -// round = - -/* - // Done - if (*(int *)(param_1 + 0x2c4) == 0) { - *(undefined4 *)(param_1 + 700) = 0; - return; - } - // 0x2BC - - ???? - *(int *)(param_1 + 700) = 2 - ((*(int *)(param_1 + 0x2c4) + -1) * 3) / DAT_80328544; - round = 2 - ((life) + -1) * 3) / DAT_80328544; - */ -// life--; -// tweak(); -// tweak(); -//tweak(); -//} - void zNPCKingJelly::on_change_ambient_ring(const tweak_info&) { } @@ -419,11 +381,6 @@ void zNPCKingJelly::show_shower_model() void zNPCKingJelly::reset_curtain() { - // f0 = data shit - // r4 = 0x10b0 - // 0x24 = f0 - // r3 = 0x10a8 - // 0x24 = f0 // 0x24 model??? } S32 zNPCGoalKJIdle::Exit(float dt, void* updCtxt) diff --git a/src/SB/Game/zNPCTypePrawn.cpp b/src/SB/Game/zNPCTypePrawn.cpp index 49e7b3bbd..a5ceaf4e7 100644 --- a/src/SB/Game/zNPCTypePrawn.cpp +++ b/src/SB/Game/zNPCTypePrawn.cpp @@ -11,7 +11,7 @@ #define ANIM_Unknown 0 // 0x0 #define ANIM_Idle01 1 // 0x04 -#define ANIM_Idle02 2 // 0x08 animtable new state +#define ANIM_Idle02 2 // 0x08 #define ANIM_Idle03 3 // 0xC #define ANIM_Fidget01 4 // #define ANIM_Fidget02 5 @@ -247,7 +247,7 @@ void aqua_beam::reset() // I don't know whats wrong here. Probably a simple erro ring_sounds = 0; } -void aqua_beam::start() //100% code match, data does not match +void aqua_beam::start() { firing = 1; time = 0.0f; diff --git a/src/SB/Game/zParCmd.h b/src/SB/Game/zParCmd.h index 047d05a3c..7f81b8e6a 100644 --- a/src/SB/Game/zParCmd.h +++ b/src/SB/Game/zParCmd.h @@ -4,5 +4,6 @@ // Note: all the xParCmd structs and functions are defined in xParCmd.h, don't redefine them here void zParCmdFindClipVolumes(); +void zParCmdInit(); #endif \ No newline at end of file diff --git a/src/SB/Game/zShrapnel.cpp b/src/SB/Game/zShrapnel.cpp index 305fd9a64..3e1657251 100644 --- a/src/SB/Game/zShrapnel.cpp +++ b/src/SB/Game/zShrapnel.cpp @@ -1,3 +1,887 @@ +#include +#include "iModel.h" + +#include "xColor.h" +#include "xSnd.h" +#include "xstransvc.h" + +#include "zGlobals.h" #include "zShrapnel.h" +#include "zLightning.h" -#include +static xMat4x3 tmpMat; +static zFrag sFragPool[150]; +static zFrag sFirstFreeFrag; +static zFrag sFirstActiveFrag; +static zFrag sProjectileList; +static zFrag sLightningList; +static zFrag sParticleList; +static zFrag sSoundList; +static _tagLightningAdd sLightningAddInfo; +static zFragProjectileAsset sCinProj; + +static S32 sNumActiveFrags; +static RpAtomic* sCinModel; +static void(*sCinCB)(zFrag*, zFragAsset*); +static zFrag* sCinFrag; + +static void zShrapnel_DestructObjInit(zShrapnelAsset* shrap, xModelInstance* parent, xVec3* initOffset, void(*cb)(zFrag*, zFragAsset*)); +static void zShrapnel_BB03FloorInit(zShrapnelAsset* shrap, xModelInstance* parent, xVec3* initOffset, void(*cb)(zFrag*, zFragAsset*)); +static void zShrapnel_BB03FloorChildInit(zShrapnelAsset* shrap, xModelInstance* parent, xVec3* initOffset, void(*cb)(zFrag*, zFragAsset*)); +static void zShrapnel_GlobalRobotInit(zShrapnelAsset* shrap, xModelInstance* parent, xVec3* initOffset, void(*cb)(zFrag*, zFragAsset*)); +static void zShrapnel_SpongebobInit(zShrapnelAsset* shrap, xModelInstance* parent, xVec3* initOffset, void(*cb)(zFrag*, zFragAsset*)); + +static zShrapnelInitTable sShrapnelTable[6] = +{ + { "destruct_obj_shrapnel", zShrapnel_DestructObjInit, 0}, + { "bb03_floor_shrapnel", zShrapnel_BB03FloorInit, 0}, + { "bb03_floor_child_shrapnel", zShrapnel_BB03FloorChildInit, 0}, + { "allrobots_shrapnel", zShrapnel_GlobalRobotInit, 0}, + { "spongebob_shrapnel", zShrapnel_SpongebobInit, 0}, + { NULL, NULL, 0} +}; + + +zFrag* zFrag_Alloc(zFragType type) +{ + if (sNumActiveFrags == 150) + { + return NULL; + } + + zFrag* result = sFirstFreeFrag.next; + if (result->prev != NULL) + { + result->prev->next = result->next; + } + + if (result->next != NULL) + { + result->next->prev = result->prev; + } + + result->next = sFirstActiveFrag.next; + result->prev = &sFirstActiveFrag; + + if (result->next != NULL) + { + result->next->prev = result; + } + + if (result->prev != NULL) + { + result->prev->next = result; + } + + sNumActiveFrags++; + result->type = type; + + return result; +} + +// equivalent +void zFrag_Free(zFrag* frag) +{ + frag->type = eFragInactive; + + if (frag->next != NULL) + { + frag->next->prev = frag->prev; + } + + if (frag->prev != NULL) + { + frag->prev->next = frag->next; + } + + sNumActiveFrags--; + frag->next = sFirstFreeFrag.next; + frag->prev = &sFirstFreeFrag; + + if (frag->next != NULL) + { + frag->next->prev = frag; + } + + if (frag->prev != NULL) + { + frag->prev->next = frag; + } +} + +// equivalent +void zShrapnel_GameInit() +{ + zShrapnelInitTable* curr = sShrapnelTable; + S32 i = 0; + while (curr->name != NULL) + { + curr->ID = xStrHash(curr->name); + i++; + curr = (zShrapnelInitTable*)(sShrapnelTable + i); + } + + sLightningAddInfo.type = 3; + sLightningAddInfo.flags = 0x30; + sLightningAddInfo.thickness = 1.0f; + sLightningAddInfo.color = xColorFromRGBA(255, 255, 255, 255); + sLightningAddInfo.arc_height = 0.1f; + + sCinProj.type = eFragProjectile; + sCinProj.id = 0; + sCinProj.parentID[0] = 0; + sCinProj.parentID[1] = 0; + sCinProj.lifetime = 0.0f; + sCinProj.delay = 0.0f; + sCinProj.modelInfoID = 0; + sCinProj.modelFile = NULL; + sCinProj.launch.type = eFragLocBone; + xVec3Init((xVec3*)&sCinProj.launch.info.bone.offset, 0.0f, 0.0f, 0.0f); + sCinProj.launch.info.bone.index = 0; + sCinProj.vel.type = eFragLocBone; + xVec3Init((xVec3*)&sCinProj.vel.info.bone.offset, 0.0f, 0.0f, 0.0f); + sCinProj.vel.info.bone.index = 0; + sCinProj.bounce = 0.0f; + sCinProj.maxBounces = -1; + sCinProj.flags = 0x48; + sCinProj.childID = 0; + sCinProj.child = NULL; + sCinProj.minScale = 1.0f; + sCinProj.maxScale = 1.0f; + sCinProj.scaleCurveID = 0; + sCinProj.scaleCurve = NULL; + sCinProj.gravity = 0.0f; + +} + +void zShrapnel_ProjectileSceneInit(zFragProjectileAsset* asset) +{ + if (asset->modelInfoID != 0) + { + asset->modelFile = (RpAtomic*)xSTFindAsset(asset->modelInfoID, NULL); + } + + if (asset->scaleCurveID != 0) + { + asset->scaleCurve = (xCurveAsset*)xSTFindAsset(asset->scaleCurveID, NULL); + } + + if (asset->childID != 0) + { + asset->child = (zShrapnelAsset*)xSTFindAsset(asset->childID, NULL); + } +} + +void zShrapnel_ParticleSceneInit(zFragParticleAsset* asset) +{ + if (asset->parEmitterID != 0) + { + asset->parEmitter = zParEmitterFind(asset->parEmitterID); + } +} + +// equivalent +void zShrapnel_SetShrapnelAssetInitCB(zShrapnelAsset* sasset) +{ + sasset->initCB = zShrapnel_DefaultInit; + zShrapnelInitTable* curr = sShrapnelTable; + + while (curr->name != NULL) + { + if (curr->ID == sasset->shrapnelID) + { + sasset->initCB = curr->initCB; + return; + } + curr++; + } +} + +void zShrapnel_Update(F32 dt) +{ + if (sNumActiveFrags == 0) + return; + + zFrag* curr = sFirstActiveFrag.next; + while (curr != NULL) + { + zFrag* next = curr->next; + + if (curr->delay > 0.0f) + { + curr->delay -= dt; + } + else + { + if (curr->update != NULL) + { + curr->update(curr, dt); + } + } + curr = next; + } + + if (sProjectileList.next != NULL) + { + zFrag_ProjectileManager(dt); + } + + if (sLightningList.next != NULL) + { + zFrag_LightningManager(dt); + } + + if (sParticleList.next != NULL) + { + zFrag_ParticleManager(dt); + } + + if (sSoundList.next != NULL) + { + zFrag_SoundManager(dt); + } + +} + +void zShrapnel_Reset() +{ + if (sNumActiveFrags == 0) + return; + + zFrag* frag = sProjectileList.next; + while (frag != NULL) + { + zFrag* next = frag->next; + + if (frag->info.projectile.model != NULL) + { + xModelInstanceFree(frag->info.projectile.model); + } + zFrag_Free(frag); + frag = next; + } +} + +void zShrapnel_Render() +{ + if (sNumActiveFrags != 0 && sProjectileList.next != NULL) + { + zFrag_ProjectileRenderer(); + } +} + +static void CinFragCB(zFrag* frag, zFragAsset* asset) +{ + F32 time = frag->delay + frag->lifetime + 1.0f; + + if (time > sCinFrag->lifetime) + { + sCinFrag->lifetime = time; + } + + if (sCinCB != NULL) + { + sCinCB(frag, asset); + } +} + +// equivalent +void zShrapnel_CinematicInit(zShrapnelAsset* shrap, RpAtomic* cinModel, RwMatrixTag* animMat, xVec3* initVel, void(*cb)(zFrag*, zFragAsset*)) +{ + if (cinModel == NULL || shrap == NULL || animMat == NULL) + return; + + zFrag* frag = zFrag_Alloc(eFragProjectile); + frag->parent[0] = NULL; + frag->parent[1] = NULL; + sCinProj.modelFile = cinModel; + + zFrag_DefaultInit(frag, &sCinProj); + + xModelInstance* model = frag->info.projectile.model; + if (model == NULL) + { + zFrag_Free(frag); + } + else + { + model->Data = sCinModel; + xMat3x3Copy((xMat4x3*)model->Mat, &g_I3); + xVec3Copy((xVec3*)&model->Mat->pos, (xVec3*)&animMat->pos); + + for (S32 i = 1; i < model->BoneCount; i++) + { + xMat4x3Copy((xMat4x3*)model->Mat + i, (xMat4x3*)animMat + i); + } + + sCinCB = cb; + sCinFrag = frag; + shrap->initCB(shrap, model, initVel, CinFragCB); + sCinCB = NULL; + sCinFrag = NULL; + sCinProj.modelFile = NULL; + } +} + +void zFragLoc_Setup(zFragLocation* loc, xModelInstance* parent) +{ + if ((S32)(loc->type & 0xfffffffe) == 4) + { + iModelTagSetup(&loc->info.tag, parent->Data, loc->info.tag.v.x, loc->info.tag.v.y, loc->info.tag.v.z); + } +} + +void zFragLoc_InitDir(zFragLocation* loc, xVec3* vec, xModelInstance* parent) +{ + switch ((loc->type) & 0xfffffffe) + { + case eFragLocBone: + xMat3x3RMulVec(vec, (xMat3x3*)parent->Mat, &loc->info.bone.offset); + break; + case eFragLocBoneLocal: + S32 index = loc->info.bone.index; + if (index >= parent->BoneCount) + { + index = 0; + } + + if (index == 0) + { + xMat4x3Copy(&tmpMat, (xMat4x3*)parent->Mat); + xMat3x3RMulVec(vec, (xMat3x3*)parent->Mat, &loc->info.bone.offset); + } + else + { + xMat4x3 tmpMat; + xMat4x3Mul(&tmpMat, (xMat4x3*)(parent->Mat + index), (xMat4x3*)parent->Mat); + xMat3x3RMulVec(vec, (xMat3x3*)&tmpMat, &loc->info.bone.offset); + } + break; + case eFragLocTag: + iModelTagEval(parent->Data, &loc->info.tag, parent->Mat, vec); + break; + } +} + +void zFrag_DefaultInit(zFrag* frag, zFragAsset* fasset) +{ + frag->alivetime = 0.0f; + frag->lifetime = fasset->lifetime; + frag->delay = fasset->delay; + + switch (fasset->type) + { + case eFragProjectile: + zFragProjectileAsset* passet = (zFragProjectileAsset*)fasset; + + frag->info.projectile.fasset = passet; + frag->update = zFrag_DefaultProjectileUpdate; + + if (passet->modelFile != NULL) + { + frag->info.projectile.model = xModelInstanceAlloc(passet->modelFile, NULL, 0, 0, NULL); + } + else + { + frag->info.projectile.model = NULL; + } + + if (frag->info.projectile.model == NULL) + { + zFrag_Free(frag); + } + else if (frag->info.projectile.model != NULL) + { + if (frag->parent[0] != NULL && (passet->flags & 0x10) == 0) + { + zFrag_ProjectileSetupPath(frag, passet); + } + + frag->info.projectile.model->LightKit = globals.player.ent.lightKit; + frag->info.projectile.alpha = 1.0f; + frag->info.projectile.numBounces = 0; + frag->info.projectile.scale = passet->minScale; + + if (passet->scaleCurve != NULL) + { + frag->info.projectile.scale *= xCurveAssetEvaluate(passet->scaleCurve, 0.0f); + } + } + break; + + case eFragLightning: + zFragLightningAsset* lasset = (zFragLightningAsset*)fasset; + + frag->info.lightning.fasset = lasset; + frag->update = zFrag_DefaultLightningUpdate; + + if (frag->parent[0] != NULL && frag->parent[1] != NULL) + { + zFragLoc_Setup(&lasset->start, frag->parent[0]); + zFragLoc_Setup(&lasset->end, frag->parent[1]); + } + break; + + case eFragParticle: + zFragParticleAsset* prasset = (zFragParticleAsset*)fasset; + + frag->info.particle.fasset = prasset; + frag->update = zFrag_DefaultParticleUpdate; + + if (frag->parent[0] != NULL) + { + zFragLoc_Setup(&prasset->source, frag->parent[0]); + zFragLoc_Setup(&prasset->vel, frag->parent[0]); + } + break; + + case eFragSound: + zFragSoundAsset* sasset = (zFragSoundAsset*)fasset; + + frag->info.sound.fasset = sasset; + frag->update = zFrag_DefaultSoundUpdate; + + if (frag->parent[0] != NULL) + { + zFragLoc_Setup(&sasset->source, frag->parent[0]); + zFragLoc_InitVec(&sasset->source, &frag->info.sound.location, frag->parent[0]); + } + break; + case eFragShockwave: + break; + } +} + +void zFrag_DefaultParticleUpdate(zFrag* frag, F32 param_2) +{ + zFragParticleAsset* passet = frag->info.particle.fasset; + + zFragLoc_InitVec(&passet->source, &passet->emit.pos, frag->parent[0]); + zFragLoc_InitDir(&passet->vel, &passet->emit.vel, frag->parent[0]); + + if (frag->prev != NULL) + { + frag->prev->next = frag->next; + } + + if (frag->next != NULL) + { + frag->next->prev = frag->prev; + } + + frag->next = sParticleList.next; + frag->prev = &sParticleList; + + if (frag->prev != NULL) + { + frag->prev->next = frag; + } + + if (frag->next != NULL) + { + frag->next->prev = frag; + } +} + +void zFrag_ParticleManager(F32 dt) +{ + zFrag* frag = sParticleList.next; + + while (frag != NULL) + { + zFrag* next = frag->next; + zFragParticleAsset* passet = frag->info.particle.fasset; + + frag->lifetime -= dt; + frag->alivetime += dt; + + if (frag->lifetime < 0.0f) + { + zFrag_Free(frag); + } + else + { + if ((passet->source.type & eFragLocBoneUpdated) != 0) + { + zFragLoc_InitVec(&passet->source, &passet->emit.pos, frag->parent[0]); + } + + if ((passet->vel.type & eFragLocBoneUpdated) != 0) + { + zFragLoc_InitDir(&passet->vel, &passet->emit.vel, frag->parent[0]); + } + + frag = next; + + if (passet->parEmitter != NULL) + { + xParEmitterEmitCustom(passet->parEmitter, dt, &passet->emit); + } + } + frag = next; + } +} + +void zFrag_ProjectileCollData(zFrag* frag) +{ + xCollis colls; + + frag->info.projectile.tColl = 1e38f; + frag->info.projectile.path.initPos.y -= frag->info.projectile.model->Data->boundingSphere.radius * frag->info.projectile.parentScale; + xParabolaHitsEnv(&frag->info.projectile.path, globals.sceneCur->env, &colls); + + if ((colls.flags & 1) != 0) + { + frag->info.projectile.tColl = frag->info.projectile.path.initVel.x; + xVec3Copy(&frag->info.projectile.N, &colls.norm); + } + else + { + frag->info.projectile.tColl = 1e38f; + } + frag->info.projectile.path.initPos.y += frag->info.projectile.model->Data->boundingSphere.radius * frag->info.projectile.parentScale; +} + +void zFrag_DeleteProjectile(zFrag* frag) +{ + xVec3 finalVel; + zShrapnelAsset* child = frag->info.projectile.fasset->child; + + if (child != NULL && child->initCB != NULL) + { + xParabolaEvalVel(&frag->info.projectile.path, &finalVel, frag->info.projectile.t); + child->initCB(child, frag->info.projectile.model, &finalVel, NULL); + } + + if (frag->info.projectile.model != NULL) + { + xModelInstanceFree(frag->info.projectile.model); + } + + zFrag_Free(frag); +} + +void zFrag_ProjectileManager(F32 dt) +{ + xVec3 tanVel; + xVec3 oldPos; + xMat3x3 spin; + xVec3 back; + xVec3 newAxis; + F32 percent; + xVec3 uVar1; + + zFrag* frag = sProjectileList.next; + + while (frag != NULL) + { + zFrag* next = frag->next; + + frag->lifetime -= dt; + frag->alivetime += dt; + + if (frag->lifetime < 0.0f) + { + zFrag_DeleteProjectile(frag); + } + else + { + frag->info.projectile.t = frag->info.projectile.t + dt; + S32 killed = FALSE; + + if ((frag->info.projectile.fasset->flags & 1) != 0) + { + if (frag->info.projectile.t > frag->info.projectile.tColl) + { + frag->info.projectile.numBounces++; + + if (frag->info.projectile.fasset->maxBounces >= 0 && + frag->info.projectile.numBounces > frag->info.projectile.fasset->maxBounces) + { + xVec3Init(&frag->info.projectile.path.initVel, 0.0f, 0.0f, 0.0f); + zFrag_DeleteProjectile(frag); + killed = TRUE; + } + else + { + xParabolaRecenter(&frag->info.projectile.path, frag->info.projectile.tColl); + + percent = xVec3Dot(&frag->info.projectile.N, &frag->info.projectile.path.initVel); + xVec3AddScaled(&frag->info.projectile.path.initVel, &frag->info.projectile.N, + -(1.0f + frag->info.projectile.fasset->bounce) * percent); + xVec3AddScaled(&frag->info.projectile.path.initPos, &frag->info.projectile.path.initVel, + frag->info.projectile.t - frag->info.projectile.tColl); + frag->info.projectile.path.minTime = 0.0f; + frag->info.projectile.path.maxTime = frag->lifetime; + + if ((frag->info.projectile.fasset->flags & 0x20) == 0) + { + xVec3Cross(&frag->info.projectile.axis, &frag->info.projectile.N, &frag->info.projectile.path.initVel); + xVec3Normalize(&frag->info.projectile.axis, &frag->info.projectile.axis); + xVec3Copy(&tanVel, &frag->info.projectile.path.initVel); + xVec3AddScaled(&tanVel, &frag->info.projectile.N, percent * frag->info.projectile.fasset->bounce); + percent = xVec3Length(&tanVel); + + frag->info.projectile.angVel = (percent / (frag->info.projectile.model->Data->boundingSphere.radius * + frag->info.projectile.parentScale)); + } + zFrag_ProjectileCollData(frag); + frag->info.projectile.t = 0.0f; + + } + } + else if (frag->info.projectile.t > frag->info.projectile.path.maxTime) + { + frag->info.projectile.path.minTime = frag->info.projectile.path.maxTime; + frag->info.projectile.path.maxTime += 1.0f; + zFrag_ProjectileCollData(frag); + } + } + + if (!killed) + { + zFragProjectileAsset* proj = frag->info.projectile.fasset; + F32 minScale = proj->minScale; + + if (minScale != proj->maxScale || proj->scaleCurve != NULL) + { + F32 totalTime = frag->alivetime / (frag->lifetime + frag->alivetime); + F32 newScale = totalTime * (proj->maxScale - minScale) + minScale; + + if (proj->scaleCurve != NULL) + { + if ((proj->flags & 4) != 0) + { + newScale *= xCurveAssetEvaluate(proj->scaleCurve, totalTime); + } + else + { + newScale *= xCurveAssetEvaluate(proj->scaleCurve, frag->alivetime); + } + } + frag->info.projectile.scale = newScale; + } + + xVec3Copy(&oldPos, (xVec3*)&frag->info.projectile.model->Mat->pos); + xVec3Copy((xVec3*)&frag->info.projectile.model->Mat->pos, &frag->info.projectile.path.initPos); + xVec3AddScaled((xVec3*)&frag->info.projectile.model->Mat->pos, &frag->info.projectile.path.initVel, frag->info.projectile.t); + frag->info.projectile.model->Mat->pos.y -= + frag->info.projectile.t * ((0.5f * frag->info.projectile.path.gravity) * frag->info.projectile.t); + + if ((frag->info.projectile.fasset->flags & 0x20) != 0) + { + xVec3Sub(&back, (xVec3*)&frag->info.projectile.model->Mat->pos, &oldPos); + percent = xVec3Length2(&back); + + if (percent > 1e-5f) + { + percent = xsqrt(percent); + xVec3SMul((xVec3*)&frag->info.projectile.axis, &back, 1.0f / percent); + } + + xVec3Inv(&newAxis, (xVec3*)&frag->info.projectile.axis); + xMat3x3LookVec((xMat3x3*)frag->info.projectile.model->Mat, &newAxis); + } + else + { + xMat3x3Rot(&spin, &frag->info.projectile.axis, dt * frag->info.projectile.angVel); + xMat3x3Mul((xMat3x3*)frag->info.projectile.model->Mat, (xMat3x3*)frag->info.projectile.model->Mat, &spin); + } + + if ((frag->info.projectile.fasset->flags & 2) != 0) + { + xParabolaEvalVel(&frag->info.projectile.path, &uVar1, frag->info.projectile.t); + + U32 numBubbles = 2.0f * xVec3LengthFast(&uVar1); + if (numBubbles < 1) + { + numBubbles = 1; + } + + zFX_SpawnBubbleTrail((xVec3*)&frag->info.projectile.model->Mat->pos, numBubbles); + } + } + } + frag = next; + } +} + +void zFrag_DefaultLightningUpdate(zFrag* frag, F32 param_2) +{ + xVec3 start, end; + zFragLightningAsset* lasset = frag->info.lightning.fasset; + + sLightningAddInfo.start = &start; + sLightningAddInfo.end = &end; + + zFragLoc_InitVec(&lasset->start, sLightningAddInfo.start, frag->parent[0]); + zFragLoc_InitVec(&lasset->end, sLightningAddInfo.end, frag->parent[1]); + + frag->info.lightning.lightning = zLightningAdd(&sLightningAddInfo); + + if (frag->prev != NULL) + { + frag->prev->next = frag->next; + } + + if (frag->next != NULL) + { + frag->next->prev = frag->prev; + } + + frag->next = sLightningList.next; + frag->prev = &sLightningList; + + if (frag->prev != NULL) + { + frag->prev->next = frag; + } + + if (frag->next != NULL) + { + frag->next->prev = frag; + } +} + +// equivalent +void zFrag_LightningManager(F32 dt) +{ + xVec3 start; + xVec3 end; + zFrag* frag = sLightningList.next; + + while (frag != NULL) + { + zFrag* next = frag->next; + zLightning* inst = frag->info.lightning.lightning; + zFragLightningAsset* lasset = frag->info.lightning.fasset; + + frag->lifetime -= dt; + frag->alivetime += dt; + + if (frag->lifetime < 0.0f) + { + zLightningKill(inst); + zFrag_Free(frag); + } + else + { + if ((lasset->start.type & eFragLocBoneUpdated) != 0 || (lasset->end.type & eFragLocBoneUpdated) != 0) + { + if ((lasset->start.type & eFragLocBoneUpdated) != 0) + { + zFragLoc_InitVec(&lasset->start, &start, frag->parent[0]); + } + else + { + xVec3Copy(&start, (xVec3*)((U8*)inst + 0x8)); + } + + if ((lasset->end.type & eFragLocBoneUpdated) != 0) + { + zFragLoc_InitVec(&lasset->end, &end, frag->parent[1]); + } + else + { + xVec3Copy(&end, (xVec3*)((U8*)inst + 0x14)); + } + zLightningModifyEndpoints(inst, &start, &end); + } + } + frag = next; + } +} + +void zFrag_DefaultSoundUpdate(zFrag* frag, F32 param_2) +{ + zFragSoundAsset* sasset = frag->info.sound.fasset; + + if (sasset->delay > 0.0001f) + { + zFragLoc_InitVec(&sasset->source, &frag->info.sound.location, frag->parent[0]); + } + + frag->info.sound.soundID = xSndPlay3D(sasset->assetID, 0.77f * sasset->volume, 0.0f, 0, 0, + &frag->info.sound.location, sasset->innerRadius, sasset->outerRadius, SND_CAT_GAME, 0.0f); + + if (frag->prev != NULL) + { + frag->prev->next = frag->next; + } + + if (frag->next != NULL) + { + frag->next->prev = frag->prev; + } + + frag->next = sSoundList.next; + frag->prev = &sSoundList; + + if (frag->prev != NULL) + { + frag->prev->next = frag; + } + + if (frag->next != NULL) + { + frag->next->prev = frag; + } +} + +void zFrag_SoundManager(F32 dt) +{ + zFrag* frag = sSoundList.next; + + while (frag != NULL) + { + zFrag* next = frag->next; + + frag->lifetime -= dt; + frag->alivetime += dt; + + if (frag->lifetime < 0.0f) + { + if (frag->info.sound.soundID != 0) + { + xSndStop(frag->info.sound.soundID); + } + zFrag_Free(frag); + } + frag = next; + } +} + +void zFrag_ProjectileRenderer() +{ + // TODO +} + +static void zShrapnel_DestructObjInit(zShrapnelAsset* shrap, xModelInstance* parent, xVec3* initVel, void(*cb)(zFrag*, zFragAsset*)) +{ + // TODO +} + +static void zShrapnel_BB03FloorInit(zShrapnelAsset* shrap, xModelInstance* parent, xVec3* initVel, void(*cb)(zFrag*, zFragAsset*)) +{ + // TODO +} + +static void BB03FloorChildCB(zFrag* frag, zFragAsset* fasset) +{ + // TODO +} + +static void zShrapnel_BB03FloorChildInit(zShrapnelAsset* shrap, xModelInstance* parent, xVec3* initVel, void(*cb)(zFrag*, zFragAsset*)) +{ + zShrapnel_DefaultInit(shrap, parent, initVel, BB03FloorChildCB); +} + +static void zShrapnel_GlobalRobotInit(zShrapnelAsset* shrap, xModelInstance* parent, xVec3* initVel, void(*cb)(zFrag*, zFragAsset*)) +{ + // TODO +} + +static void zShrapnel_SpongebobInit(zShrapnelAsset* shrap, xModelInstance* parent, xVec3* initVel, void(*cb)(zFrag*, zFragAsset*)) +{ + // TODO +} diff --git a/src/SB/Game/zShrapnel.h b/src/SB/Game/zShrapnel.h index dd9a53be8..afdc81ec1 100644 --- a/src/SB/Game/zShrapnel.h +++ b/src/SB/Game/zShrapnel.h @@ -214,11 +214,50 @@ struct zShrapnelAsset void (*initCB)(zShrapnelAsset*, xModelInstance*, xVec3*, void (*)(zFrag*, zFragAsset*)); }; +struct zShrapnelInitTable +{ + char* name; + void (*initCB)(zShrapnelAsset*, xModelInstance*, xVec3*, void(*)(zFrag*, zFragAsset*)); + U32 ID; +}; + +struct zShrapnelParentList +{ + U32 parentID; + xModelInstance* parentModel; +}; + struct zScene; -void zShrapnel_SceneInit(zScene*); +zFrag* zFrag_Alloc(zFragType type); +void zFrag_Free(zFrag* frag); +void zShrapnel_GameInit(); +void zShrapnel_ProjectileSceneInit(zFragProjectileAsset* asset); +void zShrapnel_ParticleSceneInit(zFragParticleAsset* asset); +void zShrapnel_SetShrapnelAssetInitCB(zShrapnelAsset* sasset); void zShrapnel_Update(F32 dt); void zShrapnel_Reset(); void zShrapnel_Render(); +void zShrapnel_CinematicInit(zShrapnelAsset* shrap, RpAtomic* cinModel, RwMatrixTag* animMat, xVec3* initVel, void(*cb)(zFrag*, zFragAsset*)); +void zFragLoc_Setup(zFragLocation* loc, xModelInstance* parent); +void zFragLoc_InitDir(zFragLocation* loc, xVec3* vec, xModelInstance* parent); +void zFrag_DefaultInit(zFrag* frag, zFragAsset* fasset); +void zFrag_DefaultParticleUpdate(zFrag* frag, F32 param_2); +void zFrag_ParticleManager(F32 dt); +void zFrag_ProjectileCollData(zFrag* frag); +void zFrag_DeleteProjectile(zFrag* frag); +void zFrag_ProjectileManager(F32 dt); +void zFrag_DefaultLightningUpdate(zFrag* frag, F32 param_2); +void zFrag_LightningManager(F32 dt); +void zFrag_DefaultSoundUpdate(zFrag* frag, F32 param_2); +void zFrag_SoundManager(F32 dt); +void zFrag_ProjectileRenderer(); + +void zShrapnel_SceneInit(zScene*); +void zFragLoc_InitMat(zFragLocation*, xMat4x3*, xModelInstance*); +void zFragLoc_InitVec(zFragLocation*, xVec3*, xModelInstance*); +void zShrapnel_DefaultInit(zShrapnelAsset* shrap, xModelInstance* parent, xVec3* initVel, void(*cb)(zFrag*, zFragAsset*)); +void zFrag_ProjectileSetupPath(zFrag* frag, zFragProjectileAsset* passet); +void zFrag_DefaultProjectileUpdate(zFrag* frag, F32 param_2); #endif diff --git a/src/SB/Game/zVar.h b/src/SB/Game/zVar.h index cdf421deb..7d75f30a4 100644 --- a/src/SB/Game/zVar.h +++ b/src/SB/Game/zVar.h @@ -48,6 +48,7 @@ struct var_type extern S32 bad_card_needed; +void var_init(); void zVarNewGame(); void zVarInit(zVarEntry* table); U32 zVarEntryCB_VibrationOn(void* arg);