Skip to content

Commit

Permalink
Finish matching zPendulum
Browse files Browse the repository at this point in the history
  • Loading branch information
tgsm authored and SquareMan committed Jul 3, 2024
1 parent 40b00ee commit 283c618
Show file tree
Hide file tree
Showing 3 changed files with 156 additions and 10 deletions.
2 changes: 1 addition & 1 deletion configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ def Rel(lib_name: str, objects: List[Object]) -> Dict[str, Any]:
Object(NonMatching, "SB/Game/zMusic.cpp"),
Object(Equivalent, "SB/Game/zParCmd.cpp"),
Object(Matching, "SB/Game/zParEmitter.cpp"),
Object(NonMatching, "SB/Game/zPendulum.cpp"),
Object(Matching, "SB/Game/zPendulum.cpp"),
Object(Matching, "SB/Game/zPickupTable.cpp"),
Object(NonMatching, "SB/Game/zPlatform.cpp"),
Object(Matching, "SB/Game/zPortal.cpp"),
Expand Down
162 changes: 154 additions & 8 deletions src/SB/Game/zPendulum.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#include "zPendulum.h"
#include "zGlobals.h"
#include "zCollGeom.h"
#include "zShrapnel.h"

#include "xEnt.h"
#include "xEntMotion.h"
#include "xMath.h"

#include <types.h>

Expand All @@ -9,28 +14,27 @@ void zPendulum_Init(void* pend, void* asset)
zPendulum_Init((_zPendulum*)pend, (xEntAsset*)asset);
}

#if 0
//WIP.
void zPendulum_Init(_zPendulum* pend, xEntAsset* asset)
{
zEntInit((zEnt*)pend, asset, 'PEND');
xEntMotionAsset* motionAsset = (xEntMotionAsset*)(asset + 1);
if (pend->linkCount != 0)
{
//TODO!!!
pend->link = (xLinkAsset*)(motionAsset + 1);
}
else
{
pend->link = NULL;
}
pend->update = zPendulum_Update;
pend->move = zPendulum_Move;
pend->update = (xEntUpdateCallback)zPendulum_Update;
pend->move = (xEntMoveCallback)zPendulum_Move;
pend->eventFunc = zPendulumEventCB;
pend->transl = zPendulumTranslate;

zEntReset((zEnt*)pend);
//zEntMotionInit(&pend->motion, (xEnt*)pend, (xEntMotionAsset*)asset->) TODO!!!
xEntMotionInit(&pend->motion, (xEnt*)pend, motionAsset);
}

#endif

void zPendulum_Save(_zPendulum* pend, xSerial* s)
{
zEntSave((zEnt*)pend, s);
Expand All @@ -46,6 +50,64 @@ void zPendulum_Setup(_zPendulum* pend, xScene* sc)
zEntSetup((zEnt*)pend);
}

void zPendulum_Reset(_zPendulum* pend, xScene* sc)
{
zEntReset((zEnt*)pend);
xEntMotionInit(&pend->motion, (xEnt*)pend, (xEntMotionAsset*)(pend->asset + 1));
xEntMotionReset(&pend->motion, sc);

xEntMotionAsset* asset = pend->motion.asset;
pend->lt = 0.0f;
pend->q1t = 1.0f - (asset->pen.phase / (2.0f * PI));
pend->q3t = 0.5f - (asset->pen.phase / (2.0f * PI));
if (pend->q1t <= 0.0f)
{
pend->q1t += 1.0f;
}
if (pend->q1t > 1.0f)
{
pend->q1t -= 1.0f;
}
if (pend->q3t <= 0.0f)
{
pend->q3t += 1.0f;
}
if (pend->q3t > 1.0f)
{
pend->q3t -= 1.0f;
}

pend->q1t *= asset->pen.period;
pend->q3t *= asset->pen.period;
}

void zPendulum_Update(_zPendulum* pend, xScene* sc, float32 dt)
{
float32 lt, t;

xEntUpdate((xEnt*)pend, sc, dt);

t = pend->motion.t;
lt = pend->lt;
xEntMotionPenData* pen = &pend->motion.asset->pen;

if (t < lt)
{
t += pen->period;
}

if (lt <= pend->q1t && t > pend->q1t)
{
zEntEvent((xBase*)pend, eEventSwoosh);
}
else if (lt <= pend->q3t && t > pend->q3t)
{
zEntEvent((xBase*)pend, eEventSwoosh);
}

pend->lt = pend->motion.t;
}

void zPendulum_Move(_zPendulum* pend, xScene* sc, float32 dt, xEntFrame* frame)
{
xEntMotionMove(&pend->motion, sc, dt, frame);
Expand All @@ -56,3 +118,87 @@ void zPendulumTranslate(xEnt* xent, xVec3* dpos, xMat4x3* dmat)
xEntDefaultTranslate(xent, dpos, dmat);
xEntMotionTranslate(&((_zPendulum*)xent)->motion, dpos, dmat);
}

int32 zPendulumEventCB(xBase* from, xBase* to, uint32 toEvent, const float32* toParam, xBase* b3)
{
_zPendulum* pend = (_zPendulum*)to;

switch (toEvent)
{
case eEventRun:
xEntMotionRun(&pend->motion);
break;
case eEventStop:
xEntMotionStop(&pend->motion);
break;
case eEventReset:
zPendulum_Reset(pend, globals.sceneCur);
break;
case eEventVisible:
case eEventFastVisible:
xEntShow((xEnt*)pend);
break;
case eEventInvisible:
case eEventFastInvisible:
xEntHide((xEnt*)pend);
break;
case eEventCollision_Visible_On:
xEntShow((xEnt*)pend);
case eEventCollisionOn:
pend->chkby = XENT_COLLTYPE_PLYR | XENT_COLLTYPE_NPC;
pend->bupdate(pend, (xVec3*)&pend->model->Mat->pos);
break;
case eEventCollision_Visible_Off:
xEntHide((xEnt*)pend);
case eEventCollisionOff:
pend->chkby = XENT_COLLTYPE_NONE;
break;
case eEventCameraCollideOn:
zCollGeom_CamEnable((xEnt*)pend);
break;
case eEventCameraCollideOff:
zCollGeom_CamDisable((xEnt*)pend);
break;
case eEventAnimPlay:
case eEventAnimPlayLoop:
case eEventAnimStop:
case eEventAnimPause:
case eEventAnimResume:
case eEventAnimTogglePause:
case eEventAnimPlayRandom:
case eEventAnimPlayMaybe:
zEntAnimEvent((zEnt*)pend, toEvent, toParam);
break;
case eEventSetUpdateDistance:
{
if (globals.updateMgr == NULL)
{
break;
}

if (*toParam <= 0.0f)
{
xUpdateCull_SetCB(globals.updateMgr, pend, xUpdateCull_AlwaysTrueCB, NULL);
}
else
{
float32 unk = SQR(*toParam);
xUpdateCull_SetCB(globals.updateMgr, pend, xUpdateCull_DistanceSquaredCB,
*(void**)&unk);
}

break;
}
case eEventLaunchShrapnel:
{
zShrapnelAsset* shrapnel = (zShrapnelAsset*)b3;
if (shrapnel != NULL && shrapnel->initCB != NULL)
{
shrapnel->initCB(shrapnel, pend->model, NULL, NULL);
}
break;
}
}

return 1;
}
2 changes: 1 addition & 1 deletion src/SB/Game/zPendulum.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void zPendulum_Reset(_zPendulum* pend, xScene* sc);
void zPendulum_Update(_zPendulum* pend, xScene* sc, float32 dt);
void zPendulum_Move(_zPendulum* pend, xScene* sc, float32 dt, xEntFrame* frame);
void zPendulumTranslate(xEnt* xent, xVec3* dpos, xMat4x3* dmat);
int32 zPendulumEventCB(xBase* to, uint32 toEvent, uint32 event, float32* toParam,
int32 zPendulumEventCB(xBase* from, xBase* to, uint32 event, const float32* toParam,
xBase* toParamWidget);

#endif

0 comments on commit 283c618

Please sign in to comment.