diff --git a/src/SB/Core/gc/iAnim.h b/src/SB/Core/gc/iAnim.h index 8763ea9fa..594f67a05 100644 --- a/src/SB/Core/gc/iAnim.h +++ b/src/SB/Core/gc/iAnim.h @@ -6,6 +6,7 @@ extern U8* giAnimScratch; void iAnimInit(); +F32 iAnimDuration(void* RawData); U32 iAnimBoneCount(void* RawData); void iAnimBlend(F32 BlendFactor, F32 BlendRecip, U16* BlendTimeOffset, F32* BoneTable, U32 BoneCount, xVec3* Tran1, xQuat* Quat1, xVec3* Tran2, xQuat* Quat2, diff --git a/src/SB/Core/x/xEnt.h b/src/SB/Core/x/xEnt.h index ac0400baf..b52eefc52 100644 --- a/src/SB/Core/x/xEnt.h +++ b/src/SB/Core/x/xEnt.h @@ -3,6 +3,7 @@ #include #include +#include #include "xBase.h" #include "xMath3.h" @@ -40,7 +41,7 @@ struct xEntAsset : xBaseAsset F32 greenMult; F32 blueMult; F32 seeThru; - + // Offset: 0x48 F32 seeThruSpeed; U32 modelInfoID; diff --git a/src/SB/Core/x/xShadow.cpp b/src/SB/Core/x/xShadow.cpp index 879ad5702..455668da4 100644 --- a/src/SB/Core/x/xShadow.cpp +++ b/src/SB/Core/x/xShadow.cpp @@ -269,4 +269,4 @@ void xShadowManager_Remove(xEnt* ent) a++; } } -} \ No newline at end of file +} diff --git a/src/SB/Game/zEntDestructObj.cpp b/src/SB/Game/zEntDestructObj.cpp index 9f32296e8..d87d66313 100644 --- a/src/SB/Game/zEntDestructObj.cpp +++ b/src/SB/Game/zEntDestructObj.cpp @@ -6,27 +6,30 @@ namespace { static void SwapModel(zEntDestructObj* ent, xModelInstance* modelInst) { - xSFXAsset *sfxDestroy; - xModelInstance *collModel; - xModelInstance *camcollModel; - xModelInstance *entModel; + xSFXAsset* sfxDestroy; + xModelInstance* collModel; + xModelInstance* camcollModel; + xModelInstance* entModel; entModel = ent->model; - if (entModel != modelInst) { + if (entModel != modelInst) + { collModel = ent->collModel; - if ((collModel != NULL) && (collModel != entModel)) { + if ((collModel != NULL) && (collModel != entModel)) + { xModelInstanceFree(collModel); ent->collModel = NULL; } camcollModel = ent->camcollModel; - if ((camcollModel != NULL) && (camcollModel != (xModelInstance *) ent->model)) { + if ((camcollModel != NULL) && (camcollModel != (xModelInstance*)ent->model)) + { xModelInstanceFree(camcollModel); ent->camcollModel = NULL; } RwMatrixCopyMacro(modelInst->Mat, ent->model->Mat); - + modelInst->Flags &= 0xBBFC; modelInst->Flags |= (u16) (ent->model->Flags & 0x4403); ent->model = modelInst; @@ -34,12 +37,14 @@ namespace zCollGeom_EntSetup((xEnt *) ent); sfxDestroy = ent->sfx_destroy; - if (sfxDestroy != NULL) { - xSndPlay3D(sfxDestroy->soundAssetID, (f32) sfxDestroy->volume, 0.0f, 0x80U, 0U, &sfxDestroy->pos, 0.0f, (sound_category) SND_CAT_GAME, 0.0f); + if (sfxDestroy != NULL) + { + xSndPlay3D(sfxDestroy->soundAssetID, (f32)sfxDestroy->volume, 0.0f, 0x80U, 0U, + &sfxDestroy->pos, 0.0f, (sound_category)SND_CAT_GAME, 0.0f); } } } -} +} // namespace void zEntDestructObj_FindFX() { @@ -48,19 +53,19 @@ void zEntDestructObj_FindFX() sEmitWeb = zParEmitterFind("PzREMIT_DOBJ_WEB"); sEmitFire = zParEmitterFind("PAREMIT_FIRE"); sEmitSmoke = zParEmitterFind("PAREMIT_FIRESMOKE"); - sShrapDefault = (zParEmitter*) xSTFindAsset(xStrHash("destruct_obj_shrapnel"), NULL); + sShrapDefault = (zParEmitter*)xSTFindAsset(xStrHash("destruct_obj_shrapnel"), NULL); } void zEntDestructObj_Init(void* ent, void* asset) { - zEntDestructObj_Init((zEntDestructObj*) ent, (xEntAsset*) asset); + zEntDestructObj_Init((zEntDestructObj*)ent, (xEntAsset*)asset); } void zEntDestructObj_Init(zEntDestructObj* ent, xEntAsset* asset) { - zEntDestructObjAsset *dObjAsset; - xModelInstance *hitModelInst; - xModelInstance *destroyModelInst; + zEntDestructObjAsset* dObjAsset; + xModelInstance* hitModelInst; + xModelInstance* destroyModelInst; u32 shrapnelDestroyId; u32 shrapnelHitId; u32 sfxDestroyId; @@ -68,121 +73,156 @@ void zEntDestructObj_Init(zEntDestructObj* ent, xEntAsset* asset) u32 hitModelId; u32 destroyModelId; U8 boundType; - xModelInstance *destroyModel; - xModelInstance *hitModel; + xModelInstance* destroyModel; + xModelInstance* hitModel; + + zEntInit((zEnt*)ent, asset, 0x44535452U); - zEntInit((zEnt*) ent, asset, 0x44535452U); + dObjAsset = (zEntDestructObjAsset*)(asset + 0x1); - dObjAsset = (zEntDestructObjAsset*) (asset + 0x1); - ent->dasset = dObjAsset; ent->healthCnt = dObjAsset->health; shrapnelDestroyId = dObjAsset->shrapnelID_destroy; - if (shrapnelDestroyId != NULL) { - ent->shrapnel_destroy = (zShrapnelAsset*) xSTFindAsset(shrapnelDestroyId, NULL); - } else { + if (shrapnelDestroyId != NULL) + { + ent->shrapnel_destroy = (zShrapnelAsset*)xSTFindAsset(shrapnelDestroyId, NULL); + } + else + { ent->shrapnel_destroy = NULL; } - if ((zShrapnelAsset*) ent->shrapnel_destroy == NULL) { - ent->shrapnel_destroy = (zShrapnelAsset*) xSTFindAsset(xStrHash("destruct_obj_shrapnel"), NULL); + if ((zShrapnelAsset*)ent->shrapnel_destroy == NULL) + { + ent->shrapnel_destroy = + (zShrapnelAsset*)xSTFindAsset(xStrHash("destruct_obj_shrapnel"), NULL); } shrapnelHitId = dObjAsset->shrapnelID_hit; - if (shrapnelHitId != NULL) { - ent->shrapnel_hit = (zShrapnelAsset*) xSTFindAsset(shrapnelHitId, NULL); - } else { + if (shrapnelHitId != NULL) + { + ent->shrapnel_hit = (zShrapnelAsset*)xSTFindAsset(shrapnelHitId, NULL); + } + else + { ent->shrapnel_hit = NULL; } - if (ent->shrapnel_hit == NULL) { - ent->shrapnel_hit = (zShrapnelAsset*) xSTFindAsset(xStrHash("destruct_obj_shrapnel"), NULL); + if (ent->shrapnel_hit == NULL) + { + ent->shrapnel_hit = (zShrapnelAsset*)xSTFindAsset(xStrHash("destruct_obj_shrapnel"), NULL); } sfxDestroyId = dObjAsset->sfx_destroy; - if (sfxDestroyId != NULL) { - ent->sfx_destroy = (xSFXAsset*) xSTFindAsset(sfxDestroyId, NULL); - } else { + if (sfxDestroyId != NULL) + { + ent->sfx_destroy = (xSFXAsset*)xSTFindAsset(sfxDestroyId, NULL); + } + else + { ent->sfx_destroy = NULL; } sfxHitId = dObjAsset->sfx_hit; - if (sfxHitId != 0) { - ent->sfx_hit = (xSFXAsset*) xSTFindAsset(sfxHitId, NULL); - } else { + if (sfxHitId != 0) + { + ent->sfx_hit = (xSFXAsset*)xSTFindAsset(sfxHitId, NULL); + } + else + { ent->sfx_hit = NULL; } ent->penby |= 0x10; ent->state = DOBJ_STATE_INIT; - if (ent->dasset->collType & XENT_COLLTYPE_STAT) { + if (ent->dasset->collType & XENT_COLLTYPE_STAT) + { ent->chkby |= 0x18; - } else { + } + else + { ent->chkby = 0; } ent->chkby |= XENT_COLLTYPE_DYN; - ent->move = (xEntMoveCallback) zEntDestructObj_Move; - ent->eventFunc = (xBaseEventCB) zEntDestructObjEventCB; - ent->update = (xEntUpdateCallback) zEntDestructObj_Update; + ent->move = (xEntMoveCallback)zEntDestructObj_Move; + ent->eventFunc = (xBaseEventCB)zEntDestructObjEventCB; + ent->update = (xEntUpdateCallback)zEntDestructObj_Update; - if (ent->linkCount != NULL) { + if (ent->linkCount != NULL) + { // TODO: This compiles correctly but must be some other data structure, char* as a placeholder to make it work - ent->link = (xLinkAsset*)((char*) ent->asset + 0x8c); - } else { + ent->link = (xLinkAsset*)((char*)ent->asset + 0x8c); + } + else + { ent->link = NULL; } - ent->eventFunc = (xBaseEventCB) zEntDestructObjEventCB; + ent->eventFunc = (xBaseEventCB)zEntDestructObjEventCB; ent->throw_target = FALSE; boundType = ent->bound.type; - if (boundType == XBOUND_TYPE_SPHERE) { - if (ent->bound.sph.r <= 2.0f) { + if (boundType == XBOUND_TYPE_SPHERE) + { + if (ent->bound.sph.r <= 2.0f) + { ent->throw_target = TRUE; } - } else if (boundType == XBOUND_TYPE_CYL) { - if (ent->bound.cyl.r <= 2.0f) { + } + else if (boundType == XBOUND_TYPE_CYL) + { + if (ent->bound.cyl.r <= 2.0f) + { ent->throw_target = TRUE; - } - } else { - if (ent->bound.box.box.upper.x - ent->bound.box.box.lower.x <= 4.0f) { - if (ent->bound.box.box.upper.z - ent->bound.box.box.lower.z <= 4.0f) { + } + } + else + { + if (ent->bound.box.box.upper.x - ent->bound.box.box.lower.x <= 4.0f) + { + if (ent->bound.box.box.upper.z - ent->bound.box.box.lower.z <= 4.0f) + { ent->throw_target = TRUE; } } } - if (!(ent->dasset->dflags & 0x800)) { + if (!(ent->dasset->dflags & 0x800)) + { ent->throw_target = FALSE; } ent->base_model = ent->model; ent->hit_model = NULL; hitModelId = dObjAsset->hitModelId; - if (hitModelId != NULL) { - hitModelInst = (xModelInstance*) xSTFindAsset(hitModelId, NULL); - if (hitModelInst != NULL) { - ent->hit_model = xEntLoadModel(NULL, (RpAtomic*) hitModelInst); + if (hitModelId != NULL) + { + hitModelInst = (xModelInstance*)xSTFindAsset(hitModelId, NULL); + if (hitModelInst != NULL) + { + ent->hit_model = xEntLoadModel(NULL, (RpAtomic*)hitModelInst); RwMatrixCopyMacro(ent->hit_model->Mat, ent->model->Mat); hitModel = ent->hit_model; - hitModel->Flags = (U16) hitModel->Flags & 0xFBFF; + hitModel->Flags = (U16)hitModel->Flags & 0xFBFF; } } ent->destroy_model = NULL; destroyModelId = dObjAsset->destroyModelId; - if (destroyModelId != NULL) { - destroyModelInst = (xModelInstance*) xSTFindAsset(destroyModelId, NULL); - if (destroyModelInst != NULL) { - ent->destroy_model = xEntLoadModel(NULL, (RpAtomic*) destroyModelInst); + if (destroyModelId != NULL) + { + destroyModelInst = (xModelInstance*)xSTFindAsset(destroyModelId, NULL); + if (destroyModelInst != NULL) + { + ent->destroy_model = xEntLoadModel(NULL, (RpAtomic*)destroyModelInst); RwMatrixCopyMacro(ent->destroy_model->Mat, ent->model->Mat); destroyModel = ent->destroy_model; - destroyModel->Flags = (U16) destroyModel->Flags & 0xFBFF; + destroyModel->Flags = (U16)destroyModel->Flags & 0xFBFF; } } - xEntReset((xEnt*) ent); + xEntReset((xEnt*)ent); ent->destroy_notify = NULL; ent->notify_context = NULL; } @@ -198,29 +238,34 @@ void zEntDestructObj_Update(zEntDestructObj* ent, xScene* scene, F32 dt) f32 fxTimer; f32 respawnTimer; - xEntUpdate((xEnt *) ent, scene, dt); - if ((u32) ent->healthCnt > 1U) { + xEntUpdate((xEnt*)ent, scene, dt); + if ((u32)ent->healthCnt > 1U) + { ent->state = DOBJ_STATE_INIT; } - if ((xParEmitter *) ent->fx_emitter != NULL) { + if ((xParEmitter*)ent->fx_emitter != NULL) + { fxTimer = ent->fx_timer; - if (fxTimer > 0.0f) { + if (fxTimer > 0.0f) + { ent->fx_timer = fxTimer - dt; parEmitterCustomFlags = 0x100; emitterCustomSettings.custom_flags = parEmitterCustomFlags; - emitterCustomSettings.pos = *xEntGetCenter((xEnt *) ent); + emitterCustomSettings.pos = *xEntGetCenter((xEnt*)ent); xParEmitterEmitCustom(ent->fx_emitter, dt, &emitterCustomSettings); } } respawnTimer = ent->respawn_timer; - if (respawnTimer) { + if (respawnTimer) + { ent->respawn_timer = respawnTimer - dt; - if (ent->respawn_timer < 0.0f) { + if (ent->respawn_timer < 0.0f) + { zEntDestructObj_Reset(ent, globals.sceneCur); } } @@ -228,13 +273,18 @@ void zEntDestructObj_Update(zEntDestructObj* ent, xScene* scene, F32 dt) void zEntDestructObj_Hit(zEntDestructObj* ent, unsigned int mask) { - if (ent->dasset->dflags & mask) { - if (mask & 0x8000) { - zEntPlayer_SNDPlayStreamRandom(0U, 0x10U, (_tagePlayerStreamSnd) 0x1A, (_tagePlayerStreamSnd) 0x1C, 0.1f); - zEntPlayer_SNDPlayStreamRandom(0x10U, 0x23U, (_tagePlayerStreamSnd) 0x1A, (_tagePlayerStreamSnd) 0x1D, 0.1f); - zEntPlayer_SNDPlayStreamRandom(0x24U, 0x64U, (_tagePlayerStreamSnd) 0x1A, (_tagePlayerStreamSnd) 0x1E, 0.1f); + if (ent->dasset->dflags & mask) + { + if (mask & 0x8000) + { + zEntPlayer_SNDPlayStreamRandom(0U, 0x10U, (_tagePlayerStreamSnd)0x1A, + (_tagePlayerStreamSnd)0x1C, 0.1f); + zEntPlayer_SNDPlayStreamRandom(0x10U, 0x23U, (_tagePlayerStreamSnd)0x1A, + (_tagePlayerStreamSnd)0x1D, 0.1f); + zEntPlayer_SNDPlayStreamRandom(0x24U, 0x64U, (_tagePlayerStreamSnd)0x1A, + (_tagePlayerStreamSnd)0x1E, 0.1f); } - zEntEvent((xBase *) ent, 0x3AU); + zEntEvent((xBase*)ent, 0x3AU); } } @@ -243,46 +293,52 @@ U32 zEntDestructObj_GetHit(zEntDestructObj* ent, unsigned int mask) s32 hitMask; hitMask = ent->dasset->dflags & mask; - return (u32) (-hitMask | hitMask) >> 0x1FU; + return (u32)(-hitMask | hitMask) >> 0x1FU; } void zEntDestructObj_Save(zEntDestructObj* ent, xSerial* s) { - zEntSave((zEnt*) ent, s); + zEntSave((zEnt*)ent, s); s->Write(ent->state); } void zEntDestructObj_Load(zEntDestructObj* ent, xSerial* s) { - zEntLoad((zEnt*) ent, s); + zEntLoad((zEnt*)ent, s); s->Read(&ent->state); } void zEntDestructObj_Setup(zEntDestructObj* ent) { - zEntSetup((zEnt*) ent); + zEntSetup((zEnt*)ent); } void zEntDestructObj_Reset(zEntDestructObj* ent, xScene* scene) { - xEntReset((xEnt *) ent); - - if (ent->flags & 2) { + xEntReset((xEnt*)ent); + + if (ent->flags & 2) + { ent->pflags &= 4; - } else { + } + else + { ent->pflags = 0; } - + ent->healthCnt = ent->dasset->health; ent->penby |= 0x18; - - if (ent->dasset->collType & 2) { + + if (ent->dasset->collType & 2) + { ent->chkby |= 0x18; - } else { + } + else + { ent->chkby = 0; } - - ent->bupdate(ent, (xVec3*) &ent->model->Mat->pos); + + ent->bupdate(ent, (xVec3*)&ent->model->Mat->pos); ent->chkby = ent->chkby | 4; ent->fx_timer = 0.0f; ent->respawn_timer = 0.0f; @@ -301,181 +357,208 @@ U32 zEntDestructObj_isDestroyed(zEntDestructObj* ent) void zEntDestructObj_DestroyFX(zEntDestructObj* ent) { xVec3 entDistanceFromPlayer; - xSFXAsset *sfxAsset; + xSFXAsset* sfxAsset; _tagSDRumbleType sdrRumbleType; - u8 fxType; + u8 fxType; sfxAsset = ent->sfx_destroy; - if (sfxAsset != NULL) { - xSndPlay3D(sfxAsset->soundAssetID, (F32) sfxAsset->volume, (F32) 0.0f, (U32) 0x80, (U32) 0x0, &sfxAsset->pos, (F32) 0.0f, (sound_category) 0, (F32) 0.0f); + if (sfxAsset != NULL) + { + xSndPlay3D(sfxAsset->soundAssetID, (F32)sfxAsset->volume, (F32)0.0f, (U32)0x80, (U32)0x0, + &sfxAsset->pos, (F32)0.0f, (sound_category)0, (F32)0.0f); } sdrRumbleType = SDR_Total; ent->fx_timer = 0.33f; fxType = ent->dasset->fxType; - switch (fxType) { - case 0: - ent->fx_emitter = NULL; - break; - case 1: - sdrRumbleType = SDR_DustDestroyedObj; - ent->fx_emitter = sEmitDust; - break; - case 2: - sdrRumbleType = SDR_XploDestroyedObj; - ent->fx_emitter = sEmitXplo; - break; - case 3: - sdrRumbleType = SDR_WebDestroyed; - ent->fx_emitter = sEmitWeb; - break; - } - - if (sdrRumbleType != SDR_Total) { - xVec3Sub(&entDistanceFromPlayer, xEntGetPos((xEnt *) ent), xEntGetPos(&globals.player.ent)); - - if (xVec3Dot(&entDistanceFromPlayer, &entDistanceFromPlayer) <= 25.0f) { - zRumbleStart((S32) globals.currentActivePad, sdrRumbleType); + switch (fxType) + { + case 0: + ent->fx_emitter = NULL; + break; + case 1: + sdrRumbleType = SDR_DustDestroyedObj; + ent->fx_emitter = sEmitDust; + break; + case 2: + sdrRumbleType = SDR_XploDestroyedObj; + ent->fx_emitter = sEmitXplo; + break; + case 3: + sdrRumbleType = SDR_WebDestroyed; + ent->fx_emitter = sEmitWeb; + break; + } + + if (sdrRumbleType != SDR_Total) + { + xVec3Sub(&entDistanceFromPlayer, xEntGetPos((xEnt*)ent), xEntGetPos(&globals.player.ent)); + + if (xVec3Dot(&entDistanceFromPlayer, &entDistanceFromPlayer) <= 25.0f) + { + zRumbleStart((S32)globals.currentActivePad, sdrRumbleType); } } } S32 zEntDestructObjEventCB(xBase* from, xBase* to, U32 toEvent, const F32* toParam, xBase* baseUnk3) { - zEntDestructObj* toDobj = (zEntDestructObj*) to; + zEntDestructObj* toDobj = (zEntDestructObj*)to; F32 sp8; // Shrapnel Asset callbacks //void (*temp_r12) (zShrapnelAsset*, xModelInstance*, xVec3*, void*); - void (*temp_r12_2) (zEntDestructObj&, void*); - void (*temp_r12_3) (zShrapnelAsset*, xModelInstance*, xVec3*, void (*)(zFrag*, zFragAsset*)); + void (*temp_r12_2)(zEntDestructObj&, void*); + void (*temp_r12_3)(zShrapnelAsset*, xModelInstance*, xVec3*, void (*)(zFrag*, zFragAsset*)); F32 temp_f1; U32 temp_r3_2; - zShrapnelAsset *shrapnelDestroyAsset; - xEnt *temp_r4_2; - xModelInstance *temp_r4; - xModelInstance *temp_r4_3; + zShrapnelAsset* shrapnelDestroyAsset; + xEnt* temp_r4_2; + xModelInstance* temp_r4; + xModelInstance* temp_r4_3; - switch ((en_xEventTags) toEvent) { + switch ((en_xEventTags)toEvent) + { case eEventFastVisible: case eEventVisible: - xEntShow((xEnt *) to); - if ((toParam != NULL) && ((s32) (0.5f + toParam[0]) == 0x4D)) { + xEntShow((xEnt*)to); + if ((toParam != NULL) && ((s32)(0.5f + toParam[0]) == 0x4D)) + { zFXPopOn(*toDobj, toParam[1], toParam[2]); } break; case eEventFastInvisible: case eEventInvisible: - xEntHide((xEnt *) to); - if ((toParam != NULL) && ((s32) (0.5f + toParam[0]) == 0x4D)) { + xEntHide((xEnt*)to); + if ((toParam != NULL) && ((s32)(0.5f + toParam[0]) == 0x4D)) + { zFXPopOff(*toDobj, toParam[1], toParam[2]); } break; case eEventCollisionOn: toDobj->chkby |= 0x18; - toDobj->bupdate((xEnt*) to, (xVec3*) &toDobj->model->Mat->pos); + toDobj->bupdate((xEnt*)to, (xVec3*)&toDobj->model->Mat->pos); break; case eEventCollisionOff: toDobj->chkby &= 0xE7; break; case eEventCollision_Visible_On: toDobj->chkby |= 0x18; - xEntShow((xEnt *) to); - toDobj->bupdate((xEnt*) to, (xVec3*) &toDobj->model->Mat->pos); - if ((toParam != NULL) && ((s32) (0.5f + toParam[0]) == 0x4D)) { + xEntShow((xEnt*)to); + toDobj->bupdate((xEnt*)to, (xVec3*)&toDobj->model->Mat->pos); + if ((toParam != NULL) && ((s32)(0.5f + toParam[0]) == 0x4D)) + { zFXPopOn(*toDobj, toParam[1], toParam[2]); } break; case eEventCollision_Visible_Off: toDobj->chkby &= 0xE7; - xEntHide((xEnt *) to); - if ((toParam != NULL) && ((s32) (0.5f + toParam[0]) == 0x4D)) { + xEntHide((xEnt*)to); + if ((toParam != NULL) && ((s32)(0.5f + toParam[0]) == 0x4D)) + { zFXPopOff(*toDobj, toParam[1], toParam[2]); } break; case eEventCameraCollideOn: - zCollGeom_CamEnable((xEnt *) to); + zCollGeom_CamEnable((xEnt*)to); break; case eEventCameraCollideOff: - zCollGeom_CamDisable((xEnt *) to); + zCollGeom_CamDisable((xEnt*)to); break; case eEventTeleportPlayer: temp_r4 = toDobj->destroy_model; - if (temp_r4 != NULL) { + if (temp_r4 != NULL) + { SwapModel(toDobj, temp_r4); - } else { + } + else + { toDobj->chkby &= 0xE7; - xEntHide((xEnt *) to); + xEntHide((xEnt*)to); } - zEntDestructObj_DestroyFX((zEntDestructObj *) to); + zEntDestructObj_DestroyFX((zEntDestructObj*)to); toDobj->state = DOBJ_STATE_DESTROYED; shrapnelDestroyAsset = toDobj->shrapnel_destroy; - if (shrapnelDestroyAsset != NULL) { + if (shrapnelDestroyAsset != NULL) + { //temp_r12 = shrapnelDestroyAsset->initCB; - if (shrapnelDestroyAsset->initCB != NULL) { + if (shrapnelDestroyAsset->initCB != NULL) + { shrapnelDestroyAsset->initCB(shrapnelDestroyAsset, toDobj->model, NULL, NULL); } } temp_r12_2 = toDobj->destroy_notify; - if (temp_r12_2 != NULL) { + if (temp_r12_2 != NULL) + { temp_r12_2(*toDobj, toDobj->notify_context); } temp_r4_2 = toDobj->driver; - if (temp_r4_2 != NULL) { - temp_r4_2->driving_count = (u8) (temp_r4_2->driving_count - 1); + if (temp_r4_2 != NULL) + { + temp_r4_2->driving_count = (u8)(temp_r4_2->driving_count - 1); toDobj->driver = NULL; } break; case eEventReset: - zEntDestructObj_Reset((zEntDestructObj *) to, globals.sceneCur); + zEntDestructObj_Reset((zEntDestructObj*)to, globals.sceneCur); break; default: - zEntAnimEvent((zEnt *) to, toEvent, toParam); + zEntAnimEvent((zEnt*)to, toEvent, toParam); break; case eEventHit: temp_r3_2 = toDobj->healthCnt; - if (temp_r3_2 != 0U) { + if (temp_r3_2 != 0U) + { toDobj->healthCnt = temp_r3_2 - 1; - if (toDobj->healthCnt != 0U) { + if (toDobj->healthCnt != 0U) + { temp_r4_3 = toDobj->hit_model; - if (temp_r4_3 != NULL) { + if (temp_r4_3 != NULL) + { SwapModel(toDobj, temp_r4_3); } } - if (toDobj->healthCnt == 0U) { + if (toDobj->healthCnt == 0U) + { zEntEvent(to, to, eEventDestroy); } } break; case eEventSetUpdateDistance: - if ((xUpdateCullMgr *) globals.updateMgr != NULL) { + if ((xUpdateCullMgr*)globals.updateMgr != NULL) + { temp_f1 = toParam[0]; - if (temp_f1 <= 0.0f) { + if (temp_f1 <= 0.0f) + { xUpdateCull_SetCB(globals.updateMgr, to, xUpdateCull_AlwaysTrueCB, NULL); - } else { + } + else + { sp8 = temp_f1 * temp_f1; xUpdateCull_SetCB(globals.updateMgr, to, xUpdateCull_DistanceSquaredCB, &sp8); } } break; case eEventHit_BubbleBounce: - zEntDestructObj_Hit((zEntDestructObj *) to, 0x2000U); + zEntDestructObj_Hit((zEntDestructObj*)to, 0x2000U); break; case eEventHit_BubbleBash: - zEntDestructObj_Hit((zEntDestructObj *) to, 0x4000U); + zEntDestructObj_Hit((zEntDestructObj*)to, 0x4000U); break; case eEventHit_PatrickSlam: - zEntDestructObj_Hit((zEntDestructObj *) to, 0x400U); + zEntDestructObj_Hit((zEntDestructObj*)to, 0x400U); break; case eEventHit_Throw: - zEntDestructObj_Hit((zEntDestructObj *) to, 0x800U); + zEntDestructObj_Hit((zEntDestructObj*)to, 0x800U); break; case eEventLaunchShrapnel: - zShrapnelAsset* shrapnelAsset = (zShrapnelAsset*) baseUnk3; - if (baseUnk3 != NULL) { + zShrapnelAsset* shrapnelAsset = (zShrapnelAsset*)baseUnk3; + if (baseUnk3 != NULL) + { temp_r12_3 = shrapnelAsset->initCB; - if (temp_r12_3 != NULL) { + if (temp_r12_3 != NULL) + { temp_r12_3(shrapnelAsset, toDobj->model, NULL, NULL); } } diff --git a/src/SB/Game/zEntSimpleObj.cpp b/src/SB/Game/zEntSimpleObj.cpp index 6ae70c887..136ad9c31 100644 --- a/src/SB/Game/zEntSimpleObj.cpp +++ b/src/SB/Game/zEntSimpleObj.cpp @@ -2,21 +2,727 @@ #include +static xSphere* sMgrList; +static S32 sMgrCount; +static u32 sSimpleCustomCount; +static xEnt** sSimpleCustomList; + +void zEntSimpleObj_MgrInit(zEntSimpleObj** entList, U32 entCount) +{ + f32 sp14; + RpClump* sp10; + s32 spC; + s32 sp8; + RpAtomic* temp_r24; + RwMatrixTag* temp_r4_2; + f32 temp_f1; + f32 temp_f1_2; + f32 temp_f1_3; + f32 temp_f1_4; + f32 temp_f1_5; + f32 temp_f2; + f32 temp_f3; + f32 var_f0; + f32 var_f0_2; + f32 var_f0_3; + f32 var_f0_4; + f32 var_f2; + s32 temp_r0; + s32 temp_r0_2; + s32 temp_r0_3; + s32 temp_r10; + s32 temp_r11; + xEnt* temp_r28; + s32 temp_r5; + s32 temp_r6; + s32 temp_r6_4; + s32 temp_r7; + s32 temp_r8; + s32 temp_r9; + s32 var_ctr_2; + s32 var_r3; + s32 var_r6; + u32 temp_r31; + u32 temp_r6_3; + u32 var_ctr; + u32 var_r25; + u32 var_r26; + u32 var_r28; + u32 var_r30_2; + u32 var_r4; + u8 temp_r4; + void* temp_r3_3; + xSphere* var_r25_2; + zEntSimpleObj** temp_r27; + zEntSimpleObj** var_r29; + zEntSimpleObj** var_r29_2; + zEntSimpleObj** var_r30; + zEntSimpleObj* temp_r3; + zEntSimpleObj* temp_r3_2; + zEntSimpleObj* temp_r6_2; + + sMgrCount = 0; + sMgrList = NULL; + sSimpleCustomCount = 0; + sSimpleCustomList = NULL; + if (entCount != 0) + { + var_r26 = 0; + temp_r27 = (zEntSimpleObj**)RwMalloc(entCount * 4); + var_r25 = 0; + temp_r31 = xStrHash("trailer_hitch\0xEntAutoEventSimple"); + var_r30 = entList; + var_r29 = temp_r27; + var_r28 = 0U; + while (var_r28 < entCount) + { + temp_r3 = *var_r30; + temp_r6 = temp_r3->sflags; + if (!(temp_r6 & 0x10)) + { + if ((temp_r3->update != (xEntUpdateCallback)zEntSimpleObj_Update) || + (temp_r3->render != zEntSimpleObj_Render) || + (temp_r3->eventFunc != (xBaseEventCB)zEntSimpleObjEventCB) || + (temp_r3->move != NULL) || + (temp_r4 = temp_r3->moreFlags, (((temp_r4 & 8) == 0) == 0)) || + (temp_r4 & 0x20) || (temp_r3->miscflags & 1) || (temp_r3->atbl != NULL) || + (temp_r6 & 4) || (temp_r6 & 8) || (temp_r31 == temp_r3->asset->modelInfoID) || + (temp_r3->baseType == eBaseTypeTrackPhysics) || (temp_r3->driver != NULL)) + { + temp_r0 = (entCount - 1) - var_r25; + var_r25 += 1; + *(temp_r27 + (temp_r0 * 4)) = temp_r3; + temp_r6_2 = *var_r30; + if ((temp_r6_2->driver != NULL) && (temp_r6_2->move == NULL)) + { + temp_r6_2->move = zEntSimpleObj_Move; + temp_r3_2 = *var_r30; + temp_r3_2->pflags |= 1; + (*var_r30)->frame = (xEntFrame*)xMemAlloc(gActiveHeap, 0xE4U, 0); + } + } + else + { + var_r26 += 1; + temp_r3->baseFlags |= 0x80; + *var_r29 = *var_r30; + var_r29 += 4; + } + } + var_r30 += 4; + var_r28 += 1; + } + + if (var_r25 != 0) + { + sSimpleCustomCount = var_r25; + sSimpleCustomList = (xEnt**)xMemAlloc(gActiveHeap, var_r25 * 4, 0); + var_r4 = 0; + if (var_r25 > 0U) + { + temp_r6_3 = var_r25 - 8; + if (var_r25 > 8U) + { + var_r3 = 0; + temp_r0_2 = entCount - 1; + var_ctr = (u32)(temp_r6_3 + 7) >> 3U; + if (temp_r6_3 > 0U) + { + do + { + *(sSimpleCustomList + var_r3) = + *(temp_r27 + ((temp_r0_2 - var_r4) * 4)); + *(sSimpleCustomList + (var_r3 + 4)) = + *(temp_r27 + ((temp_r0_2 - (var_r4 + 1)) * 4)); + *(sSimpleCustomList + (var_r3 + 8)) = + *(temp_r27 + ((temp_r0_2 - (var_r4 + 2)) * 4)); + temp_r10 = (temp_r0_2 - (var_r4 + 5)) * 4; + temp_r8 = (temp_r0_2 - (var_r4 + 6)) * 4; + temp_r11 = var_r3 + 0x10; + temp_r9 = var_r3 + 0x14; + *(sSimpleCustomList + (var_r3 + 0xC)) = + *(temp_r27 + ((temp_r0_2 - (var_r4 + 3)) * 4)); + temp_r7 = var_r3 + 0x18; + temp_r5 = var_r3 + 0x1C; + temp_r6_4 = (temp_r0_2 - (var_r4 + 7)) * 4; + temp_r28 = *(temp_r27 + ((temp_r0_2 - (var_r4 + 4)) * 4)); + var_r3 += 0x20; + var_r4 += 8; + *(sSimpleCustomList + temp_r11) = temp_r28; + *(sSimpleCustomList + temp_r9) = *(temp_r27 + temp_r10); + *(sSimpleCustomList + temp_r7) = *(temp_r27 + temp_r8); + *(sSimpleCustomList + temp_r5) = *(temp_r27 + temp_r6_4); + var_ctr -= 1; + } while (var_ctr != 0); + } + } + var_r6 = var_r4 * 4; + var_ctr_2 = var_r25 - var_r4; + if (var_r4 < var_r25) + { + do + { + temp_r0_3 = ((entCount - 1) - var_r4) * 4; + var_r4 += 1; + *(sSimpleCustomList + var_r6) = *(temp_r27 + temp_r0_3); + var_r6 += 4; + var_ctr_2 -= 1; + } while (var_ctr_2 != 0); + } + } + } + else + { + sSimpleCustomCount = 0; + sSimpleCustomList = NULL; + } + if (var_r26 == 0) + { + RwFree(temp_r27); + return; + } + sMgrCount = var_r26; + sMgrList = (xSphere*)xMemAlloc(gActiveHeap, var_r26 << 6, 0x40); + var_r29_2 = temp_r27; + var_r30_2 = 0U; + var_r25_2 = sMgrList; + // while (var_r30_2 < var_r26) + // { + // temp_r24 = (*var_r29_2)->model->Data; + // sp8 = temp_r24->boundingSphere.center.x; + // spC = temp_r24->worldBoundingSphere.center.x; + // sp10 = temp_r24->clump; + // sp14 = temp_r24->inClumpLink; + // temp_r24->unk28 *= 1.1f; + // iModelCull(temp_r24, (*var_r29_2)->model->Mat); + // RwSphereAssign(&temp_r24->boundingSphere, (RwSphere*)&sp8); + // var_r25_2->unk0 = temp_r24->worldBoundingSphere.center.x; + // var_r25_2->unk4 = temp_r24->worldBoundingSphere.center.y; + // var_r25_2->unk8 = temp_r24->worldBoundingSphere.center.z; + // var_r25_2->unkC = temp_r24->worldBoundingSphere.radius; + // temp_r3_3 = zLOD_Get(*var_r29_2); + // if (temp_r3_3 != NULL) + // { + // temp_r4_2 = (*var_r29_2)->model->Mat; + // temp_f2 = temp_r4_2->right.x; + // temp_f1 = temp_r4_2->right.y; + // temp_f3 = temp_r4_2->right.z; + // var_f2 = (temp_f3 * temp_f3) + ((temp_f2 * temp_f2) + (temp_f1 * temp_f1)); + // if (var_f2 < 0.0001f) + // { + // var_f2 = 1.0f; + // } + // temp_f1_2 = temp_r3_3->unk14; + // if (temp_f1_2 != 0.0f) + // { + // var_f0 = temp_f1_2 * var_f2; + // } + // else + // { + // var_f0 = 1e38f; + // } + // var_r25_2->unk10 = var_f0; + // temp_f1_3 = temp_r3_3->unk18; + // if (temp_f1_3 != 0.0f) + // { + // var_f0_2 = temp_f1_3 * var_f2; + // } + // else + // { + // var_f0_2 = 1e38f; + // } + // var_r25_2->unk14 = var_f0_2; + // temp_f1_4 = temp_r3_3->unk1C; + // if (temp_f1_4 != 0.0f) + // { + // var_f0_3 = temp_f1_4 * var_f2; + // } + // else + // { + // var_f0_3 = 1e38f; + // } + // var_r25_2->unk18 = var_f0_3; + // temp_f1_5 = temp_r3_3->unk4; + // if (temp_f1_5 != 0.0f) + // { + // var_f0_4 = temp_f1_5 * var_f2; + // } + // else + // { + // var_f0_4 = 1e38f; + // } + // var_r25_2->unk1C = var_f0_4; + // var_r25_2->unk24 = temp_r3_3->unk0; + // var_r25_2->unk28 = temp_r3_3->unk8; + // var_r25_2->unk2C = temp_r3_3->unkC; + // var_r25_2->unk30 = temp_r3_3->unk10; + // if ((u32)var_r25_2->unk28 == 0U) + // { + // var_r25_2->unk10 = 1e38f; + // } + // if ((u32)var_r25_2->unk2C == 0U) + // { + // var_r25_2->unk14 = 1e38f; + // } + // if ((u32)var_r25_2->unk30 == 0U) + // { + // var_r25_2->unk18 = 1e38f; + // } + // } + // else + // { + // var_r25_2->unk10 = 1e38f; + // var_r25_2->unk14 = 1e38f; + // var_r25_2->unk18 = 1e38f; + // var_r25_2->unk1C = 1e38f; + // var_r25_2->unk24 = (*var_r29_2)->unk24->unk34; + // var_r25_2->unk28 = 0U; + // var_r25_2->unk2C = 0U; + // var_r25_2->unk30 = 0U; + // } + // var_r25_2->unk20 = (s16)(*var_r29_2)->unk18; + // var_r25_2->unk34 = (*var_r29_2)->unk24->unk4C; + // var_r25_2->unk38 = *var_r29_2; + // var_r25_2->unk22 = 0xFF; + // xEntUpdate(*var_r29_2, globals.sceneCur, 0.0f); + // var_r25_2 += 0x40; + // var_r29_2 += 4; + // var_r30_2 += 1; + // } + RwFree(temp_r27); + } +} + +void zEntSimpleObj_MgrUpdateRender(RpWorld* world, F32 dt) +{ + s32 sp1C; + s32 sp18; + s32 sp14; + f32 spC; + xVec3 sp8; + f32 temp_f0; + f32 temp_f1; + f32 temp_f2; + f32 temp_f30; + f32 temp_f3; + f32 temp_f4; + u32 var_r30; + u8 var_r27; + xModelInstance* var_r3; + xModelInstance* var_r3_2; + xEnt* temp_r28; + xModelInstance* temp_r3; + xModelInstance* temp_r5; + xQuat* temp_r26; + xSphere* var_r29; + xVec3* temp_r25; + + var_r29 = sMgrList; + for (var_r30 = 0; var_r30 < (u32)sMgrCount; var_r30++) + { + temp_r28 = (xEnt*)&var_r29[3].center.z; + if (xEntIsVisible(temp_r28) != 0U) + { + temp_f2 = globals.camera.mat.at.x - *((F32*)var_r29 + 0x0); + temp_f4 = globals.camera.mat.at.y - *((F32*)var_r29 + 0x1); + temp_f3 = globals.camera.mat.at.z - *((F32*)var_r29 + 0x2); + temp_f30 = (temp_f3 * temp_f3) + ((temp_f2 * temp_f2) + (temp_f4 * temp_f4)); + if (!(temp_f30 > *((F32*)var_r29 + 0x7)) && (iModelSphereCull((xSphere*)var_r29) == 0)) + { + var_r27 = 0; + if (temp_f30 > *((F32*)var_r29 + 0x4)) + { + var_r27 = 1; + if (temp_f30 > *((F32*)var_r29 + 0x5)) + { + var_r27 = 2; + if (temp_f30 > *((F32*)var_r29 + 0x6)) + { + var_r27 = 3; + } + } + } + temp_r5 = temp_r28->model; + temp_r5->Flags &= 0xFBFF; + *((U8*)var_r29 + 0x22) = var_r27; + temp_r5->Bucket = (xModelBucket**)var_r29 + (((var_r27 * 4) & 0x3FC) + 0x24); + temp_r5->Data = (*temp_r5->Bucket)->OriginalData; + if (var_r27 == 0) + { + var_r3 = temp_r5->Next; + while (var_r3 != NULL) + { + var_r3->Flags = (u16)(var_r3->Flags & 0xFBFF); + var_r3 = var_r3->Next; + } + } + else + { + var_r3_2 = temp_r5->Next; + while (var_r3_2 != NULL) + { + var_r3_2->Flags = (u16)(var_r3_2->Flags | 0x400); + var_r3_2 = var_r3_2->Next; + } + } + if ((((zEntSimpleObj*)temp_r28)->anim != NULL) && (zGameIsPaused() == 0)) + { + temp_f1 = iAnimDuration(((zEntSimpleObj*)temp_r28)); + ((zEntSimpleObj*)temp_r28)->animTime += dt; + temp_f0 = ((zEntSimpleObj*)temp_r28)->animTime; + if (temp_f0 >= temp_f1) + { + ((zEntSimpleObj*)temp_r28)->animTime = temp_f0 - temp_f1; + } + temp_r26 = (xQuat*)giAnimScratch; + temp_r25 = (xVec3*)temp_r26 + 0x410; + iAnimEval(((zEntSimpleObj*)temp_r28)->anim, + ((zEntSimpleObj*)temp_r28)->animTime, 0U, temp_r25, temp_r26); + temp_r3 = temp_r28->model; + iModelAnimMatrices(temp_r3->Data, temp_r26, temp_r25, + (RwMatrixTag*)&temp_r3->Mat); + } + xLightKit_Enable(temp_r28->lightKit, globals.currWorld); + zEntSimpleObj_Render(temp_r28); + if ((var_r27 == 0) && (xrand() < 0x55U)) + { + xVec3Copy(&sp8, (xVec3*)&temp_r28->model->Mat->pos); + spC += (0.25f * xurand()) + 0.25f; + zFX_SpawnBubbleTrail(&sp8, (xrand() & 7) + 1, &temp_r28->asset->pos, NULL); + } + } + } + var_r29 += 0x40; + } +} + +void zEntSimpleObj_MgrCustomUpdate(zScene* s, F32 dt) +{ + s32 var_r31; + u32 var_r30; + xEnt* temp_r3; + + var_r31 = 0; + var_r30 = 0U; + + while (var_r30 < (u32)sSimpleCustomCount) + { + temp_r3 = sSimpleCustomList[var_r31]; + if (!(temp_r3->baseFlags & 0x40)) + { + temp_r3->update(temp_r3, s, dt); + } + var_r31 += 1; + var_r30 += 1; + } +} + +void zEntSimpleObj_MgrCustomRender() +{ + s32 var_r30; + u32 var_r29; + xEnt* temp_r3; + + var_r30 = 0; + var_r29 = 0U; + + while (var_r29 < (u32)sSimpleCustomCount) + { + xLightKit_Enable(sSimpleCustomList[var_r30]->lightKit, globals.currWorld); + temp_r3 = sSimpleCustomList[var_r30]; + temp_r3->render(temp_r3); + var_r30 += 1; + var_r29 += 1; + } +} + +void zEntTrackPhysics_Init(void* ent, void* asset) +{ + zEntSimpleObj_Init((zEntSimpleObj*)ent, (xEntAsset*)asset, 1); +} + +void zEntSimpleObj_Init(void* ent, void* asset) +{ + zEntSimpleObj_Init((zEntSimpleObj*)ent, (xEntAsset*)asset, 0); +} + +void zEntSimpleObj_Render(xEnt* ent) +{ + if (ent->model == NULL || xEntIsVisible(ent) == FALSE) + { + return; + } + + xModelRender(ent->model); +} + +void zEntSimpleObj_Init(zEntSimpleObj* ent, xEntAsset* asset, bool arg2) +{ + U32 sp8; + RpAtomic* temp_r28; + void* temp_r3_5; + void* var_r31; + U32 temp_r3_4; + U32 temp_r3_6; + xModelInstance* temp_r3; + xAnimPlay* temp_r3_2; + xAnimPlay* temp_r3_3; + xAnimTable* temp_r4; + xSimpleObjAsset* temp_r0; + + zEntInit((zEnt*)ent, asset, 0x53494D50U); + + if (arg2 != 0) + { + ent->baseType = 0x3F; + } + + if (arg2 != 0) + { + temp_r0 = (xSimpleObjAsset*)(asset + 1); + } + else + { + temp_r0 = (xSimpleObjAsset*)(asset + 1); + } + + ent->sasset = temp_r0; + ent->sflags = 0; + ent->pflags = 0; + ent->penby |= 0x10; + if (ent->sasset->collType & XENT_COLLTYPE_STAT) + { + ent->chkby = 0x18; + } + else + { + ent->chkby = 0; + } + ent->move = NULL; + ent->update = (xEntUpdateCallback)zEntSimpleObj_Update; + ent->eventFunc = (xBaseEventCB)zEntSimpleObjEventCB; + ent->render = zEntSimpleObj_Render; + if ((u8)ent->linkCount != 0) + { + if (arg2 != 0) + { + ent->link = (xLinkAsset*)((char*)ent->asset + 0x9C); + } + else + { + ent->link = (xLinkAsset*)((char*)ent->asset + 0x60); + } + } + else + { + ent->link = NULL; + } + ent->eventFunc = (xBaseEventCB)zEntSimpleObjEventCB; + temp_r28 = (RpAtomic*)xSTFindAsset(asset->modelInfoID, &sp8); + var_r31 = NULL; + if (!(ent->miscflags & 1) && (ent->asset->modelInfoID != 0U) && + (temp_r3 = ent->model, ((temp_r3 == NULL) == 0)) && + (temp_r3_2 = temp_r3->Anim, ((temp_r3_2 == NULL) == 0)) && + (temp_r4 = temp_r3_2->Table, ((temp_r4 == NULL) == 0)) && + (strcmp(&"trailer_hitch\0xEntAutoEventSimple"[0xE], temp_r4->Name) == 0)) + { + temp_r3_3 = ent->model->Anim; + xAnimPlaySetState(temp_r3_3->Single, temp_r3_3->Table->StateList, 0.0f); + ent->miscflags |= 1; + } + else + { + temp_r3_4 = asset->animListID; + if ((temp_r3_4 != 0) && (ent->atbl == NULL)) + { + var_r31 = xSTFindAsset(temp_r3_4, &sp8); + if ((var_r31 != NULL) && + ((temp_r3_6 = iAnimBoneCount(var_r31), ((temp_r3_6 == 0U) != 0)) || + (temp_r3_6 != iModelNumBones(temp_r28)))) + { + var_r31 = NULL; + } + } + } + ent->anim = var_r31; + ent->animTime = 0.0f; + zEntReset((zEnt*)ent); +} + void zEntSimpleObj_Move(xEnt*, xScene*, F32, xEntFrame*) { } -void zEntSimpleObj_Setup(zEntSimpleObj *arg0) +void zEntSimpleObj_Setup(zEntSimpleObj* arg0) { - zEntSetup((zEnt *) arg0); + zEntSetup((zEnt*)arg0); } -void zEntSimpleObj_Save(zEntSimpleObj *arg0, xSerial *arg1) +void zEntSimpleObj_Save(zEntSimpleObj* arg0, xSerial* arg1) { - zEntSave((zEnt *) arg0, arg1); + zEntSave((zEnt*)arg0, arg1); } -void zEntSimpleObj_Load(zEntSimpleObj *arg0, xSerial *arg1) +void zEntSimpleObj_Load(zEntSimpleObj* arg0, xSerial* arg1) { - zEntLoad((zEnt *) arg0, arg1); + zEntLoad((zEnt*)arg0, arg1); +} + +void zEntSimpleObj_Update(zEntSimpleObj* ent, xScene* scene, float dt) +{ + void* temp_r3; + f32 temp_f0; + f32 temp_f1; + xModelInstance* temp_r3_2; + xModelInstance* temp_r4; + xQuat* temp_r31; + xVec3* temp_r30; + + xEntUpdate((xEnt*)ent, scene, dt); + temp_r3 = ent->anim; + if (temp_r3 != NULL) + { + temp_r4 = ent->model; + if ((temp_r4 != NULL) && !(temp_r4->Flags & 0x400)) + { + temp_f1 = iAnimDuration(temp_r3); + ent->animTime += dt; + temp_f0 = ent->animTime; + if (temp_f0 >= temp_f1) + { + ent->animTime = temp_f0 - temp_f1; + } + temp_r31 = (xQuat*)giAnimScratch; + temp_r30 = (xVec3*)((char*)temp_r31 + 0x410); + iAnimEval(ent->anim, ent->animTime, 0U, temp_r30, temp_r31); + temp_r3_2 = ent->model; + iModelAnimMatrices(temp_r3_2->Data, temp_r31, temp_r30, temp_r3_2->Mat + 0x1); + } + } +} + +void zEntSimpleObj_Reset(zEntSimpleObj* ent, xScene* scene) +{ + xEntBoundUpdateCallback temp_r12; + + zEntReset((zEnt*)ent); + ent->animTime = 0.0f; + ent->chkby &= 0xE3; + if (ent->sasset->collType & 2) + { + ent->chkby |= 0x18; + } + temp_r12 = ent->bupdate; + if (temp_r12 != NULL) + { + temp_r12(ent, (xVec3*)&ent->model->Mat->pos); + return; + } + xEntDefaultBoundUpdate((xEnt*)ent, (xVec3*)&ent->model->Mat->pos); +} + +s32 zEntSimpleObjEventCB(xBase* from, xBase* to, U32 toEvent, const F32* toParam, xBase* base3) +{ + zEntSimpleObj* toSimpleObj = (zEntSimpleObj*)to; + + switch (toEvent) + { + case eEventFastVisible: + case eEventVisible: + xEntShow((xEnt*)to); + if ((toParam != NULL) && ((S32)(0.5f + toParam[0]) == 0x4D)) + { + zFXPopOn((xEnt&)*to, toParam[1], toParam[2]); + } + break; + case eEventFastInvisible: + case eEventInvisible: + xEntHide((xEnt*)to); + if ((toParam != NULL) && ((S32)(0.5f + toParam[0]) == 0x4D)) + { + zFXPopOff((xEnt&)*to, toParam[1], toParam[2]); + } + break; + case eEventCollision_Visible_On: + xEntShow((xEnt*)to); + if ((toParam != NULL) && ((S32)(0.5f + toParam[0]) == 0x4D)) + { + zFXPopOn((xEnt&)*to, toParam[1], toParam[2]); + } + /* fallthrough */ + case eEventCollisionOn: + toSimpleObj->chkby = 0x18; + if (toSimpleObj->bupdate != NULL) + { + toSimpleObj->bupdate((xEnt*)to, (xVec3*)&toSimpleObj->model->Mat->pos); + } + else + { + xEntDefaultBoundUpdate((xEnt*)to, (xVec3*)&toSimpleObj->model->Mat->pos); + } + break; + case eEventCollision_Visible_Off: + xEntHide((xEnt*)to); + if ((toParam != NULL) && ((S32)(0.5f + toParam[0]) == 0x4D)) + { + zFXPopOff((xEnt&)*to, toParam[1], toParam[2]); + } + /* fallthrough */ + case eEventCollisionOff: + toSimpleObj->chkby = 0; + if (toSimpleObj->bupdate != NULL) + { + toSimpleObj->bupdate((xEnt*)to, (xVec3*)&toSimpleObj->model->Mat->pos); + } + else + { + xEntDefaultBoundUpdate((xEnt*)to, (xVec3*)&toSimpleObj->model->Mat->pos); + } + break; + case eEventCameraCollideOn: + zCollGeom_CamEnable((xEnt*)to); + break; + case eEventCameraCollideOff: + zCollGeom_CamDisable((xEnt*)to); + break; + case eEventReset: + zEntSimpleObj_Reset((zEntSimpleObj*)to, globals.sceneCur); + break; + case eEventAnimPlay: + case eEventAnimPlayLoop: + case eEventAnimStop: + case eEventAnimPause: + case eEventAnimResume: + case eEventAnimTogglePause: + case eEventAnimPlayRandom: + case eEventAnimPlayMaybe: + zEntAnimEvent((zEnt*)to, toEvent, toParam); + break; + case eEventSetSkyDome: + xSkyDome_AddEntity((xEnt*)to, (s32)toParam[0], (s32)toParam[1]); + break; + case eEventSetGoo: + zGooAdd((xEnt*)to, toParam[0], (s32)toParam[1]); + break; + case eEventGooSetWarb: + zFXGooEventSetWarb((xEnt*)to, toParam); + break; + case eEventGooSetFreezeDuration: + zFXGooEventSetFreezeDuration((xEnt*)to, toParam[0]); + break; + case eEventGooMelt: + zFXGooEventMelt((xEnt*)to); + break; + case eEventLaunchShrapnel: + zShrapnelAsset* shrapnel = (zShrapnelAsset*)base3; + if (shrapnel != NULL && shrapnel->initCB != NULL) + { + shrapnel->initCB(shrapnel, toSimpleObj->model, NULL, NULL); + } + break; + case eEventDestroy: + xEntHide((xEnt*)to); + break; + } + return 1; } diff --git a/src/SB/Game/zEntSimpleObj.h b/src/SB/Game/zEntSimpleObj.h index ab9465a87..dd4d4fbe2 100644 --- a/src/SB/Game/zEntSimpleObj.h +++ b/src/SB/Game/zEntSimpleObj.h @@ -2,6 +2,21 @@ #define ZENTSIMPLEOBJ_H #include "zEnt.h" +#include "xShadow.h" +#include "xString.h" +#include "xstransvc.h" +#include "iAnim.h" +#include "iModel.h" +#include "zFX.h" +#include "xEnt.h" +#include "zCollGeom.h" +#include "zGlobals.h" +#include "xSkyDome.h" +#include "zGoo.h" +#include "zShrapnel.h" +#include "xMath.h" +#include "zGame.h" +#include "zLOD.h" struct xSimpleObjAsset { @@ -13,7 +28,7 @@ struct xSimpleObjAsset struct zEntSimpleObj : zEnt { - xSimpleObjAsset* sasset; + xSimpleObjAsset* sasset; // 0xD4 U32 sflags; void* anim; F32 animTime; @@ -21,14 +36,22 @@ struct zEntSimpleObj : zEnt struct zScene; +extern void iModelAnimMatrices(RpAtomic*, xQuat*, xVec3*, RwMatrixTag*); + void zEntSimpleObj_MgrInit(zEntSimpleObj** entList, U32 entCount); -void zEntSimpleObj_MgrUpdateRender(RpWorld*, F32 dt); +void zEntSimpleObj_MgrUpdateRender(RpWorld* world, F32 dt); void zEntSimpleObj_MgrCustomUpdate(zScene* s, F32 dt); void zEntSimpleObj_MgrCustomRender(); void zEntTrackPhysics_Init(void* ent, void* asset); void zEntSimpleObj_Init(void* ent, void* asset); +void zEntSimpleObj_Render(xEnt* ent); +void zEntSimpleObj_Init(zEntSimpleObj* ent, xEntAsset* asset, bool arg2); +void zEntSimpleObj_Move(xEnt*, xScene*, F32, xEntFrame*); void zEntSimpleObj_Setup(zEntSimpleObj* ent); +void zEntSimpleObj_Update(zEntSimpleObj* ent, xScene* scene, F32 dt); void zEntSimpleObj_Save(zEntSimpleObj* ent, xSerial* s); void zEntSimpleObj_Load(zEntSimpleObj* ent, xSerial* s); +void zEntSimpleObj_Reset(zEntSimpleObj* ent, xScene* scene); +s32 zEntSimpleObjEventCB(xBase* from, xBase* to, U32 toEvent, const F32* toParam, xBase* base3); #endif diff --git a/src/SB/Game/zFX.h b/src/SB/Game/zFX.h index 48cd687f6..6087e813b 100644 --- a/src/SB/Game/zFX.h +++ b/src/SB/Game/zFX.h @@ -138,6 +138,10 @@ void zFXGoo_SceneEnter(); void zFXGoo_SceneReset(); void zFXGoo_SceneExit(); +void zFXGooEventSetWarb(xEnt* obj, const F32* param); +void zFXGooEventSetFreezeDuration(xEnt* obj, const F32 param); +void zFXGooEventMelt(xEnt* obj); + void zFXGooUpdate(F32 dt); void zFXUpdate(F32 dt); @@ -165,6 +169,7 @@ void xMat3x3RMulVec(xVec3* result, const xMat3x3* mat, const xVec3* vec); xFXRing* zFXMuscleArmWave(const xVec3* pos); +void zFX_SpawnBubbleTrail(const xVec3* pos, unsigned int num, const xVec3* pos_rnd, const xVec3* vel_rnd); void zFX_SpawnBubbleMenuTrail(const xVec3* pos, U32 num, const xVec3* pos_rnd, const xVec3* vel_rnd);