From c52e38c1c5956637dad04d80b6dd7cbed8b1b36f Mon Sep 17 00:00:00 2001 From: robojumper Date: Sat, 13 Sep 2025 11:48:25 +0200 Subject: [PATCH] Review feedback, cleanup --- include/d/col/bg/d_bg_pc.h | 23 +++++++++++++ include/d/snd/d_snd_anim_sound.h | 2 +- include/d/snd/d_snd_id_mappers.h | 25 --------------- include/d/snd/d_snd_source_e_spark.h | 3 +- include/d/snd/d_snd_state_mgr.h | 4 +-- include/egg/audio/eggAudioSystem.h | 3 ++ include/toBeSorted/d_emitter.h | 12 ++++++- src/d/col/bg/d_bg_s.cpp | 21 ++++++------ src/d/d_stage_mgr.cpp | 2 +- src/d/snd/d_snd_anim_sound.cpp | 6 ++-- src/d/snd/d_snd_id_mappers.cpp | 3 +- src/d/snd/d_snd_source.cpp | 3 +- src/d/snd/d_snd_state_mgr.cpp | 22 ++++++------- src/egg/audio/eggAudioSystem.cpp | 4 +-- src/toBeSorted/d_emitter.cpp | 48 ++++++++++++++-------------- 15 files changed, 98 insertions(+), 83 deletions(-) diff --git a/include/d/col/bg/d_bg_pc.h b/include/d/col/bg/d_bg_pc.h index 23a60965..e3b05ced 100644 --- a/include/d/col/bg/d_bg_pc.h +++ b/include/d/col/bg/d_bg_pc.h @@ -27,6 +27,29 @@ enum dBgPc_ECode { /* 0x80000000 */ CODE_UNUSED_8000_0000 = 0x80000000, }; +enum dBgPc_PolyAttr0_e { + POLY_ATT_0_NONE = 0, + POLY_ATT_0_TUTI = 1, + POLY_ATT_0_ROCK = 2, + POLY_ATT_0_SAND = 3, + POLY_ATT_0_GRASS = 4, + POLY_ATT_0_TREE = 5, + POLY_ATT_0_LAVA = 6, + POLY_ATT_0_WATER = 7, + POLY_ATT_0_STONE = 8, + POLY_ATT_0_LOTUS = 9, + POLY_ATT_0_METAL = 10, + POLY_ATT_0_NUMA = 11, + POLY_ATT_0_TUTA = 12, + POLY_ATT_0_LIFE = 13, + POLY_ATT_0_CARPET = 14, + POLY_ATT_0_QSAND = 15, + POLY_ATT_0_WOOD = 16, + POLY_ATT_0_DEATH = 17, + + POLY_ATT_0_MAX = 18, +}; + enum dBgPc_Attribute { POLY_ATTR_NORMAL = 0, POLY_ATTR_SLOPE = 1, diff --git a/include/d/snd/d_snd_anim_sound.h b/include/d/snd/d_snd_anim_sound.h index 07721f76..a1686e17 100644 --- a/include/d/snd/d_snd_anim_sound.h +++ b/include/d/snd/d_snd_anim_sound.h @@ -29,7 +29,7 @@ private: /* 0x00 */ nw4r::snd::AnimSound mSound; /* 0x90 */ const void *mpData; - /* 0x94 */ f32 field_0x94; + /* 0x94 */ f32 mRate; // TODO - is this actually used? /* 0x98 */ f32 field_0x98; /* 0x9C */ bool mNeedFrameReset; /* 0xA0 */ nw4r::snd::AnimSound::PlayDirection mDirection; diff --git a/include/d/snd/d_snd_id_mappers.h b/include/d/snd/d_snd_id_mappers.h index 69f482da..f8889468 100644 --- a/include/d/snd/d_snd_id_mappers.h +++ b/include/d/snd/d_snd_id_mappers.h @@ -8,31 +8,6 @@ u32 getGrpId(dSndSourceGroup_c *pGroup); u32 getBnkSeId(dSndSourceGroup_c *pGroup); u32 getSeId(dSndSourceGroup_c *pGroup); -// TODO move somewhere else, or maybe remove entirely -// could plausibly belong in d/col/bg -enum dSndMaterial_e { - SND_MAT_NONE = 0, - SND_MAT_TUTI = 1, - SND_MAT_ROCK = 2, - SND_MAT_SAND = 3, - SND_MAT_GRASS = 4, - SND_MAT_TREE = 5, - SND_MAT_LAVA = 6, - SND_MAT_WATER = 7, - SND_MAT_STONE = 8, - SND_MAT_LOTUS = 9, - SND_MAT_METAL = 10, - SND_MAT_NUMA = 11, - SND_MAT_TUTA = 12, - SND_MAT_LIFE = 13, - SND_MAT_CARPET = 14, - SND_MAT_QSAND = 15, - SND_MAT_WOOD = 16, - SND_MAT_DEATH = 17, - - SND_MAT_MAX = 18, -}; - const char *getHitEffectName(u32 polyAttr0); #endif diff --git a/include/d/snd/d_snd_source_e_spark.h b/include/d/snd/d_snd_source_e_spark.h index f1d03573..295f3ff4 100644 --- a/include/d/snd/d_snd_source_e_spark.h +++ b/include/d/snd/d_snd_source_e_spark.h @@ -8,7 +8,8 @@ public: dSndSourceESpark_c(s32 sourceType, dAcBase_c *ac, const char *name, dSndSourceGroup_c *pOwnerGroup) : dSoundSource_c(sourceType, ac, name, pOwnerGroup) {} - // okay + // TODO - this one doesn't actually have an AnimSound. Maybe the name is wrong, + // maybe something else is weird virtual bool hasAnimSound() override { return true; } diff --git a/include/d/snd/d_snd_state_mgr.h b/include/d/snd/d_snd_state_mgr.h index 37f0ad57..ce3058ef 100644 --- a/include/d/snd/d_snd_state_mgr.h +++ b/include/d/snd/d_snd_state_mgr.h @@ -319,7 +319,7 @@ private: /* 0x054 */ u32 mStageTypeFlags; /* 0x058 */ s32 mLayer; /* 0x05C */ s32 mRoomId; - /* 0x060 */ UNKWORD field_0x060; + /* 0x060 */ s32 mCheckRoomIdCooldown; /* 0x064 */ bool field_0x064; /* 0x065 */ bool field_0x065; /* 0x066 */ bool mHasChangedTgSndAreaFlags; @@ -367,7 +367,7 @@ private: /* 0x498 */ f32 mFxSend3DNext; /* 0x49C */ f32 mFxSend3D; /* 0x4A0 */ f32 mFxSend3DTarget; - /* 0x4A4 */ u32 field_0x4A4; + /* 0x4A4 */ u32 mPrevStageGroup; /* 0x4A8 */ u8 field_0x4A8; /* 0x4A9 */ bool mNeedsGroupsReload; }; diff --git a/include/egg/audio/eggAudioSystem.h b/include/egg/audio/eggAudioSystem.h index 80f4ea73..8ab47824 100644 --- a/include/egg/audio/eggAudioSystem.h +++ b/include/egg/audio/eggAudioSystem.h @@ -10,8 +10,11 @@ public: AudioSystem(); ~AudioSystem(); + // TODO - this seems to use milliseconds as the unit, but + // calling code seems to pass frame counts... void reset(s32 ms); void recoverReset(); + // TODO - see reset void shutdown(s32 ms); void calc(); diff --git a/include/toBeSorted/d_emitter.h b/include/toBeSorted/d_emitter.h index 9fdf9800..f0976a13 100644 --- a/include/toBeSorted/d_emitter.h +++ b/include/toBeSorted/d_emitter.h @@ -433,6 +433,16 @@ public: static s32 getGroupId(u16); static bool shouldBePaused(dBase_c *owner); + enum GroundEffect_e { + GROUND_0, + GROUND_1, + GROUND_2, + GROUND_3, + GROUND_4, + GROUND_5, + GROUND_6, + }; + enum Fx_e { TsuboA, TsuboB, @@ -500,7 +510,7 @@ private: u16 effectResourceId, const mMtx_c &transform, const GXColor *c1, const GXColor *c2, s32 idx1, s32 idx2 ); - static s32 polyAttrsToGroundEffectIdx(s32 polyAttr0, s32 polyAttr1); + static GroundEffect_e polyAttrsToGroundEffectIdx(s32 polyAttr0, s32 polyAttr1); static mHeapAllocator_c *ms_allocator; static dMassObjEmitter_c *sMassObjEmitters; diff --git a/src/d/col/bg/d_bg_s.cpp b/src/d/col/bg/d_bg_s.cpp index d6fd0242..7f96c7c3 100644 --- a/src/d/col/bg/d_bg_s.cpp +++ b/src/d/col/bg/d_bg_s.cpp @@ -1,6 +1,7 @@ #include "d/col/bg/d_bg_s.h" #include "common.h" +#include "d/col/bg/d_bg_pc.h" #include "d/col/bg/d_bg_s_acch.h" #include "d/col/bg/d_bg_s_gnd_chk.h" #include "d/col/bg/d_bg_s_lin_chk.h" @@ -557,10 +558,10 @@ s32 dBgS::GetWallCode(cBgS_PolyInfo const &info) { int dBgS::GetPolyAtt0(cBgS_PolyInfo const &info) { if (!ChkPolySafe(info)) { - return 0; + return POLY_ATT_0_NONE; } - if (GetSpecialCode(info) == 7 /* LAVA */) { - return 6; + if (GetSpecialCode(info) == POLY_ATTR_LAVA) { + return POLY_ATT_0_LAVA; } return mChkElem[info.GetBgIndex()].mpBgW->GetPolyAtt0Material(info); } @@ -577,10 +578,10 @@ int dBgS::GetMapCode(int att0, int att1, bool bAlt) { if (bAlt && dScGame_c::currentSpawnInfo.getTrial() == SpawnInfo::TRIAL) { return 0x1E; } - if (att0 == 4 && att1 == 1) { + if (att0 == POLY_ATT_0_GRASS && att1 == 1) { return 0x13; } - if (att0 == 5) { + if (att0 == POLY_ATT_0_TREE) { if (att1 == 1) { return 0x14; } @@ -588,10 +589,10 @@ int dBgS::GetMapCode(int att0, int att1, bool bAlt) { return 0x15; } } else { - if ((att0 == 8) && (att1 == 1)) { + if ((att0 == POLY_ATT_0_STONE) && (att1 == 1)) { return 0x16; } - if (att0 == 10) { + if (att0 == POLY_ATT_0_METAL) { if (att1 == 1) { return 0x17; } @@ -601,11 +602,11 @@ int dBgS::GetMapCode(int att0, int att1, bool bAlt) { } } - if ((att0 == 0xc) && (att1 == 1)) { + if ((att0 == POLY_ATT_0_TUTA) && (att1 == 1)) { return 0x19; } - if (att0 == 0xd) { + if (att0 == POLY_ATT_0_LIFE) { if (att1 == 1) { return 0x1a; } @@ -616,7 +617,7 @@ int dBgS::GetMapCode(int att0, int att1, bool bAlt) { return 0x1C; } } else { - if (att0 != 0xf) { + if (att0 != POLY_ATT_0_QSAND) { return att0; } if (att1 == 1) { diff --git a/src/d/d_stage_mgr.cpp b/src/d/d_stage_mgr.cpp index c3f7f005..e6bfc03e 100644 --- a/src/d/d_stage_mgr.cpp +++ b/src/d/d_stage_mgr.cpp @@ -153,7 +153,7 @@ void dStageMgr_c::finalizeState_ReadLayerObjectRes() { void *jpc = OarcManager::GetInstance()->getSubEntryData(name, "dat/jparticle.jpc"); if (jpc != nullptr) { void *jpn = OarcManager::GetInstance()->getData(name, "dat/jparticle.jpn"); - dParticle::mgr_c::GetInstance()->createResource(dHeap::work2Heap.heap, true, jpc, jpn); + dParticle::mgr_c::GetInstance()->createResource(dHeap::work2Heap.heap, 1, jpc, jpn); } } } diff --git a/src/d/snd/d_snd_anim_sound.cpp b/src/d/snd/d_snd_anim_sound.cpp index e5983268..f3638966 100644 --- a/src/d/snd/d_snd_anim_sound.cpp +++ b/src/d/snd/d_snd_anim_sound.cpp @@ -6,11 +6,11 @@ #include dSndAnimSound_c::dSndAnimSound_c(dSoundSource_c *source) - : mSound(*source), mpData(nullptr), field_0x94(1.0f), field_0x98(INFINITY), mNeedFrameReset(false) {} + : mSound(*source), mpData(nullptr), mRate(1.0f), field_0x98(INFINITY), mNeedFrameReset(false) {} void dSndAnimSound_c::setData(const void *data, const char *name) { mDirection = nw4r::snd::AnimSound::FORWARD; - field_0x94 = 1.0f; + mRate = 1.0f; if (data == mpData) { return; } @@ -49,7 +49,7 @@ void dSndAnimSound_c::setRate(f32 rate) { } else { mDirection = nw4r::snd::AnimSound::FORWARD; } - field_0x94 = rate; + mRate = rate; } void dSndAnimSound_c::resetFrame(f32 frame) { diff --git a/src/d/snd/d_snd_id_mappers.cpp b/src/d/snd/d_snd_id_mappers.cpp index 029701ba..6d699350 100644 --- a/src/d/snd/d_snd_id_mappers.cpp +++ b/src/d/snd/d_snd_id_mappers.cpp @@ -1,6 +1,7 @@ #include "d/snd/d_snd_id_mappers.h" #include "common.h" +#include "d/col/bg/d_bg_pc.h" #include "d/snd/d_snd_mgr.h" #include "d/snd/d_snd_player_mgr.h" #include "d/snd/d_snd_source_enums.h" @@ -144,7 +145,7 @@ const char *sSndHitEffects[] = { #pragma pop const char *getHitEffectName(u32 polyAttr0) { - if (polyAttr0 >= 1 && polyAttr0 < SND_MAT_MAX) { + if (polyAttr0 >= 1 && polyAttr0 < POLY_ATT_0_MAX) { polyAttr0 -= 1; return sSndHitEffects[polyAttr0]; } diff --git a/src/d/snd/d_snd_source.cpp b/src/d/snd/d_snd_source.cpp index 7d0540ac..2ed4fa23 100644 --- a/src/d/snd/d_snd_source.cpp +++ b/src/d/snd/d_snd_source.cpp @@ -2,6 +2,7 @@ #include "common.h" #include "d/a/d_a_base.h" +#include "d/col/bg/d_bg_pc.h" #include "d/snd/d_snd_3d_actor.h" #include "d/snd/d_snd_3d_manager.h" #include "d/snd/d_snd_anim_sound.h" @@ -1206,7 +1207,7 @@ u32 dSoundSource_c::modifySoundId(u32 baseSoundId, dSoundSource_c *source) { u32 dSoundSource_c::specializeBgHitSoundId(u32 soundId, u32 polyAttr0, u32 polyAttr1) { if (checkUserParamMask(soundId, 0x100)) { - if (polyAttr0 >= SND_MAT_NONE + 1 && polyAttr0 <= SND_MAT_MAX - 1) { + if (polyAttr0 >= POLY_ATT_0_NONE + 1 && polyAttr0 <= POLY_ATT_0_MAX - 1) { const char *baseLabel = dSndMgr_c::getSoundLabelString(soundId); SizedString<64> label; label.sprintf("%s_%s_%d", baseLabel, getHitEffectName(polyAttr0), polyAttr1); diff --git a/src/d/snd/d_snd_state_mgr.cpp b/src/d/snd/d_snd_state_mgr.cpp index 90eaaa6e..89a74d33 100644 --- a/src/d/snd/d_snd_state_mgr.cpp +++ b/src/d/snd/d_snd_state_mgr.cpp @@ -41,7 +41,7 @@ dSndStateMgr_c::dSndStateMgr_c() mStageTypeFlags(0), mLayer(0), mRoomId(-1), - field_0x060(0), + mCheckRoomIdCooldown(0), field_0x064(false), field_0x065(false), mHasChangedTgSndAreaFlags(false), @@ -81,7 +81,7 @@ dSndStateMgr_c::dSndStateMgr_c() mFxSend3DNext(-1.0f), mFxSend3D(0.02f), mFxSend3DTarget(0.02f), - field_0x4A4(-1), + mPrevStageGroup(-1), field_0x4A8(0), mNeedsGroupsReload(false) {} @@ -318,7 +318,7 @@ void dSndStateMgr_c::loadStageSound(bool force) { u32 id = -1; int round = 1; - bool b1 = false; + bool canReuseStageState = false; SizedString<64> label; if (info->unk4 == mStageId) { @@ -332,8 +332,8 @@ void dSndStateMgr_c::loadStageSound(bool force) { for (; round > 0; round--) { id = dSndMgr_c::GetInstance()->getArchive()->ConvertLabelStringToGroupId(label); - if (field_0x4A4 == id && field_0x4A4 != -1) { - b1 = true; + if (mPrevStageGroup == id && mPrevStageGroup != -1) { + canReuseStageState = true; break; } @@ -344,7 +344,7 @@ void dSndStateMgr_c::loadStageSound(bool force) { dSndPlayerMgr_c::GetInstance()->popToState0(); } if (dSndMgr_c::GetInstance()->loadGroup(id, nullptr, 0)) { - field_0x4A4 = id; + mPrevStageGroup = id; dSndPlayerMgr_c::GetInstance()->saveState2(); break; } @@ -357,7 +357,7 @@ void dSndStateMgr_c::loadStageSound(bool force) { } } - if (b1) { + if (canReuseStageState) { dSndPlayerMgr_c::GetInstance()->popToState2(); } else if (id == -1) { if (bHasState1) { @@ -366,7 +366,7 @@ void dSndStateMgr_c::loadStageSound(bool force) { dSndPlayerMgr_c::GetInstance()->popToState0(); } dSndPlayerMgr_c::GetInstance()->saveState2(); - field_0x4A4 = -1; + mPrevStageGroup = -1; } if (!demo && (field_0x03C != 2 || field_0x065)) { @@ -862,11 +862,11 @@ void dSndStateMgr_c::setStbEventName(const char *eventName) { void dSndStateMgr_c::calcRoomId() { if (checkFlag0x10(FLAG0x10_0x04)) { - if (field_0x060 > 0) { - field_0x060--; + if (mCheckRoomIdCooldown > 0) { + mCheckRoomIdCooldown--; } else { if (mRoomId == -1) { - field_0x060 = 30; + mCheckRoomIdCooldown = 30; } s32 newRoom = dSndSourceMgr_c::GetInstance()->getPlayerSourceRoomId(); if (mRoomId != newRoom) { diff --git a/src/egg/audio/eggAudioSystem.cpp b/src/egg/audio/eggAudioSystem.cpp index 4bc05c1d..844853ab 100644 --- a/src/egg/audio/eggAudioSystem.cpp +++ b/src/egg/audio/eggAudioSystem.cpp @@ -19,7 +19,7 @@ AudioSystem::~AudioSystem() {} void AudioSystem::reset(s32 ms) { if (mShutdownStatus == 0 && mResetStatus == 0) { mSavedMasterVolume = nw4r::snd::SoundSystem::GetMasterVolume(); - nw4r::snd::SoundSystem::SetMasterVolume(0.0f, ms * 16.666667f); + nw4r::snd::SoundSystem::SetMasterVolume(0.0f, ms * (1.0f / 60.f * 1000.0f)); mResetStatus = 1; } } @@ -34,7 +34,7 @@ void AudioSystem::recoverReset() { void AudioSystem::shutdown(s32 ms) { if (mShutdownStatus == 0) { mShutdownStatus = 1; - nw4r::snd::SoundSystem::SetMasterVolume(0.0f, ms * 16.666667f); + nw4r::snd::SoundSystem::SetMasterVolume(0.0f, ms * (1.0f / 60.f * 1000.0f)); } } diff --git a/src/toBeSorted/d_emitter.cpp b/src/toBeSorted/d_emitter.cpp index 64079684..ba4fcfd2 100644 --- a/src/toBeSorted/d_emitter.cpp +++ b/src/toBeSorted/d_emitter.cpp @@ -907,7 +907,9 @@ bool dJEffManager_c::createEffManagers() { } } - ms_allocator->createFrmHeapToCurrent(-1, dHeap::work1Heap.heap, "dJEffManager_c::ms_allocator", 0x20, mHeap::OPT_NONE); + ms_allocator->createFrmHeapToCurrent( + -1, dHeap::work1Heap.heap, "dJEffManager_c::ms_allocator", 0x20, mHeap::OPT_NONE + ); for (s32 idx = 0; idx < 2; idx++) { sFogProcs[idx].create(idx, sInts[idx], -1, ms_allocator); } @@ -1179,27 +1181,25 @@ bool EffectsStruct::createEffect( return hasEmitters(); } -// TODO: Document PolyAttrs -s32 dJEffManager_c::polyAttrsToGroundEffectIdx(s32 polyAttr0, s32 polyAttr1) { - if (polyAttr0 == 0 || (polyAttr0 == 4 && polyAttr1 == 1) || (polyAttr0 == 9) || - (polyAttr0 == 10 && polyAttr1 == 1) || (polyAttr0 == 12) || (polyAttr0 == 17 && polyAttr1 != 1) || - (polyAttr0 == 13 && (polyAttr1 == 1 || polyAttr1 == 3)) || polyAttr0 == 18) { - return 6; - } else if (polyAttr0 == 17) { - return 5; - } else if (polyAttr0 == 6) { - return 2; - } else if (polyAttr0 == 4) { - return 1; - } else if (polyAttr0 == 3 || polyAttr0 == 15) { - return 3; +// TODO: Document polyAttr1 and GROUND enum +dJEffManager_c::GroundEffect_e dJEffManager_c::polyAttrsToGroundEffectIdx(s32 polyAttr0, s32 polyAttr1) { + if (polyAttr0 == POLY_ATT_0_NONE || (polyAttr0 == POLY_ATT_0_GRASS && polyAttr1 == 1) || (polyAttr0 == POLY_ATT_0_LOTUS) || + (polyAttr0 == POLY_ATT_0_METAL && polyAttr1 == 1) || (polyAttr0 == POLY_ATT_0_TUTA) || (polyAttr0 == POLY_ATT_0_DEATH && polyAttr1 != 1) || + (polyAttr0 == POLY_ATT_0_LIFE && (polyAttr1 == 1 || polyAttr1 == 3)) || polyAttr0 == POLY_ATT_0_MAX) { + return GROUND_6; + } else if (polyAttr0 == POLY_ATT_0_DEATH) { + return GROUND_5; + } else if (polyAttr0 == POLY_ATT_0_LAVA) { + return GROUND_2; + } else if (polyAttr0 == POLY_ATT_0_GRASS) { + return GROUND_1; + } else if (polyAttr0 == POLY_ATT_0_SAND || polyAttr0 == POLY_ATT_0_QSAND) { + return GROUND_3; + } else if (polyAttr0 == POLY_ATT_0_NUMA) { + return GROUND_4; + } else { + return GROUND_0; } - // ??? - s32 result = 0; - if (polyAttr0 == 11) { - result = 4; - } - return result; } dEmitterBase_c *dJEffManager_c::spawnGroundEffect( @@ -1218,11 +1218,11 @@ dEmitterBase_c *dJEffManager_c::spawnGroundEffect( return nullptr; } - s32 idx = polyAttrsToGroundEffectIdx(polyAttr0, polyAttr1); - if (idx == 6) { + GroundEffect_e idx = polyAttrsToGroundEffectIdx(polyAttr0, polyAttr1); + if (idx == GROUND_6) { return nullptr; } - if (idx == 2 && unk == 0) { + if (idx == GROUND_2 && unk == 0) { scale *= 1.5f; } mMtx_c mtx;