From 7f2969be639971386ffccdcbeeaf2d0817cf0bae Mon Sep 17 00:00:00 2001 From: Malkierian Date: Tue, 13 May 2025 16:03:31 -0700 Subject: [PATCH] Convert c-style casts to static_cast. --- soh/soh/Enhancements/ExtraTraps.cpp | 16 ++++++++-------- soh/soh/Enhancements/boss-rush/BossRush.cpp | 5 +++-- soh/soh/Enhancements/controls/Mouse.cpp | 10 +++++----- .../game-interactor/GameInteractor_RawAction.cpp | 4 ++-- .../Enhancements/randomizer/3drando/random.hpp | 10 +++++----- .../Enhancements/randomizer/hook_handlers.cpp | 11 ++++++----- 6 files changed, 29 insertions(+), 27 deletions(-) diff --git a/soh/soh/Enhancements/ExtraTraps.cpp b/soh/soh/Enhancements/ExtraTraps.cpp index 96ddea654..e88a8f1fe 100644 --- a/soh/soh/Enhancements/ExtraTraps.cpp +++ b/soh/soh/Enhancements/ExtraTraps.cpp @@ -61,8 +61,8 @@ std::vector getEnabledAddTraps() { }; static void RollRandomTrap(uint32_t seed) { - uint32_t finalSeed = - seed + (IS_RANDO ? Rando::Context::GetInstance()->GetSeed() : (uint32_t)gSaveContext.ship.stats.fileCreatedAt); + uint32_t finalSeed = seed + (IS_RANDO ? Rando::Context::GetInstance()->GetSeed() + : static_cast(gSaveContext.ship.stats.fileCreatedAt)); Random_Init(finalSeed); roll = RandomElement(getEnabledAddTraps()); @@ -126,12 +126,12 @@ static void OnPlayerUpdate() { Play_TriggerRespawn(gPlayState); break; case ADD_AMMO_TRAP: - AMMO(ITEM_STICK) = (int8_t)floor(AMMO(ITEM_STICK) * 0.5f); - AMMO(ITEM_NUT) = (int8_t)floor(AMMO(ITEM_NUT) * 0.5f); - AMMO(ITEM_SLINGSHOT) = (int8_t)floor(AMMO(ITEM_SLINGSHOT) * 0.5f); - AMMO(ITEM_BOW) = (int8_t)floor(AMMO(ITEM_BOW) * 0.5f); - AMMO(ITEM_BOMB) = (int8_t)floor(AMMO(ITEM_BOMB) * 0.5f); - AMMO(ITEM_BOMBCHU) = (int8_t)floor(AMMO(ITEM_BOMBCHU) * 0.5f); + AMMO(ITEM_STICK) = static_cast(floor(AMMO(ITEM_STICK) * 0.5f)); + AMMO(ITEM_NUT) = static_cast(floor(AMMO(ITEM_NUT) * 0.5f)); + AMMO(ITEM_SLINGSHOT) = static_cast(floor(AMMO(ITEM_SLINGSHOT) * 0.5f)); + AMMO(ITEM_BOW) = static_cast(floor(AMMO(ITEM_BOW) * 0.5f)); + AMMO(ITEM_BOMB) = static_cast(floor(AMMO(ITEM_BOMB) * 0.5f)); + AMMO(ITEM_BOMBCHU) = static_cast(floor(AMMO(ITEM_BOMBCHU) * 0.5f)); Audio_PlaySoundGeneral(NA_SE_VO_FR_SMILE_0, &gSfxDefaultPos, 4, &gSfxDefaultFreqAndVolScale, &gSfxDefaultFreqAndVolScale, &gSfxDefaultReverb); break; diff --git a/soh/soh/Enhancements/boss-rush/BossRush.cpp b/soh/soh/Enhancements/boss-rush/BossRush.cpp index cf7330aa8..979f0ad6a 100644 --- a/soh/soh/Enhancements/boss-rush/BossRush.cpp +++ b/soh/soh/Enhancements/boss-rush/BossRush.cpp @@ -111,7 +111,7 @@ const char* BossRush_GetSettingChoiceName(u8 optionIndex, u8 choiceIndex, u8 lan } u8 BossRush_GetSettingOptionsAmount(u8 optionIndex) { - return (u8)BossRushOptions[optionIndex].choices.size(); + return static_cast(BossRushOptions[optionIndex].choices.size()); } void BossRush_SpawnBlueWarps(PlayState* play) { @@ -311,7 +311,8 @@ void BossRush_HandleCompleteBoss(PlayState* play) { play->sceneNum == SCENE_GANON_BOSS) { gSaveContext.ship.stats.playTimer += 2; gSaveContext.ship.stats.gameComplete = 1; - gSaveContext.ship.stats.itemTimestamp[TIMESTAMP_BOSSRUSH_FINISH] = (uint32_t)GAMEPLAYSTAT_TOTAL_TIME; + gSaveContext.ship.stats.itemTimestamp[TIMESTAMP_BOSSRUSH_FINISH] = + static_cast(GAMEPLAYSTAT_TOTAL_TIME); } } diff --git a/soh/soh/Enhancements/controls/Mouse.cpp b/soh/soh/Enhancements/controls/Mouse.cpp index f01848bd9..4ad9d11d0 100644 --- a/soh/soh/Enhancements/controls/Mouse.cpp +++ b/soh/soh/Enhancements/controls/Mouse.cpp @@ -50,8 +50,8 @@ void Mouse_HandleFirstPerson(Player* player) { : 1; s8 invertYAxisMulti = CVarGetInteger(CVAR_SETTING("Controls.InvertAimingYAxis"), 1) ? 1 : -1; if (MOUSE_ENABLED) { - player->actor.focus.rot.y -= (int16_t)(mouseCoordRel.x * 6.0f * xAxisMulti * invertXAxisMulti); - player->actor.focus.rot.x += (int16_t)(mouseCoordRel.y * 6.0f * yAxisMulti * invertYAxisMulti); + player->actor.focus.rot.y -= static_cast(mouseCoordRel.x * 6.0f * xAxisMulti * invertXAxisMulti); + player->actor.focus.rot.x += static_cast(mouseCoordRel.y * 6.0f * yAxisMulti * invertYAxisMulti); } } @@ -59,7 +59,7 @@ void Mouse_RecenterCursor() { u32 width = GetWindow()->GetWidth(); u32 height = GetWindow()->GetHeight(); if (MOUSE_ENABLED) { - GetWindow()->SetMousePos({ (s32)(width / 2), (s32)(height / 2) }); + GetWindow()->SetMousePos({ static_cast(width / 2), static_cast(height / 2) }); } } @@ -67,8 +67,8 @@ void Mouse_HandleShield(f32* sp50, f32* sp54) { if (MOUSE_ENABLED) { s32 width = GetWindow()->GetWidth(); s32 height = GetWindow()->GetHeight(); - f32 xBound = 7200 / ((f32)width / 2); - f32 yBound = 6000 / ((f32)height / 2); + f32 xBound = 7200 / (width / 2.0f); + f32 yBound = 6000 / (height / 2.0f); *sp50 += (mouseCoord.x - (width / 2)) * xBound * (CVarGetInteger(CVAR_ENHANCEMENT("MirroredWorld"), 0) ? 1 : -1); *sp54 += (mouseCoord.y - (height / 2)) * yBound; diff --git a/soh/soh/Enhancements/game-interactor/GameInteractor_RawAction.cpp b/soh/soh/Enhancements/game-interactor/GameInteractor_RawAction.cpp index e44c44bc5..779b37981 100644 --- a/soh/soh/Enhancements/game-interactor/GameInteractor_RawAction.cpp +++ b/soh/soh/Enhancements/game-interactor/GameInteractor_RawAction.cpp @@ -112,7 +112,7 @@ void GameInteractor::RawAction::FreezePlayer() { void GameInteractor::RawAction::BurnPlayer() { Player* player = GET_PLAYER(gPlayState); for (int i = 0; i < 18; i++) { - player->bodyFlameTimers[i] = (uint8_t)Rand_S16Offset(0, 200); + player->bodyFlameTimers[i] = static_cast(Rand_S16Offset(0, 200)); } player->bodyIsBurning = true; func_80837C0C(gPlayState, player, 0, 0, 0, 0, 0); @@ -617,7 +617,7 @@ GameInteractionEffectQueryResult GameInteractor::RawAction::SpawnEnemyWithOffset } // Generate point in random angle with a radius. - float angle = (float)(RandomDouble() * 2 * M_PI); + float angle = static_cast(RandomDouble() * 2 * M_PI); float radius = 150; float posXOffset = radius * cos(angle); float posZOffset = radius * sin(angle); diff --git a/soh/soh/Enhancements/randomizer/3drando/random.hpp b/soh/soh/Enhancements/randomizer/3drando/random.hpp index a1be55cc5..2d9ffa6f1 100644 --- a/soh/soh/Enhancements/randomizer/3drando/random.hpp +++ b/soh/soh/Enhancements/randomizer/3drando/random.hpp @@ -21,17 +21,17 @@ template T RandomElement(std::vector& vector, bool erase) { return selected; } template auto& RandomElement(Container& container) { - return container[Random(0, (uint32_t)std::size(container))]; + return container[Random(0, static_cast(std::size(container)))]; } template const auto& RandomElement(const Container& container) { - return container[Random(0, (uint32_t)std::size(container))]; + return container[Random(0, static_cast(std::size(container)))]; } template const T RandomElementFromSet(const std::set& set) { if (set.size() == 1) { return *set.begin(); } - uint32_t rand = Random(0, (uint32_t)set.size()); + uint32_t rand = Random(0, static_cast(set.size())); auto it = set.begin(); for (uint32_t i = 0; i < rand; i++) { it++; @@ -44,11 +44,11 @@ template const T RandomElementFromSet(const std::set& set) { // RANDOTODO There's probably a more efficient way to do what this does. template void Shuffle(std::vector& vector) { for (size_t i = 0; i + 1 < vector.size(); i++) { - std::swap(vector[i], vector[Random((uint32_t)i, (uint32_t)vector.size())]); + std::swap(vector[i], vector[Random(static_cast(i), static_cast(vector.size()))]); } } template void Shuffle(std::array& arr) { for (size_t i = 0; i + 1 < arr.size(); i++) { - std::swap(arr[i], arr[Random((uint32_t)i, (uint32_t)arr.size())]); + std::swap(arr[i], arr[Random(static_cast(i), static_cast(arr.size()))]); } } diff --git a/soh/soh/Enhancements/randomizer/hook_handlers.cpp b/soh/soh/Enhancements/randomizer/hook_handlers.cpp index df0dbeaaf..9c0d1a5e3 100644 --- a/soh/soh/Enhancements/randomizer/hook_handlers.cpp +++ b/soh/soh/Enhancements/randomizer/hook_handlers.cpp @@ -328,7 +328,7 @@ void RandomizerOnPlayerUpdateForRCQueueHandler() { (getItemEntry.getItemCategory == ITEM_CATEGORY_JUNK || getItemEntry.getItemCategory == ITEM_CATEGORY_SKULLTULA_TOKEN || getItemEntry.getItemCategory == ITEM_CATEGORY_LESSER))))) { - Item_DropCollectible(gPlayState, &spawnPos, (int16_t)(ITEM00_SOH_GIVE_ITEM_ENTRY | 0x8000)); + Item_DropCollectible(gPlayState, &spawnPos, static_cast(ITEM00_SOH_GIVE_ITEM_ENTRY | 0x8000)); } } @@ -2157,7 +2157,7 @@ void RandomizerOnGameFrameUpdateHandler() { } if (Flags_GetRandomizerInf(RAND_INF_HAS_INFINITE_MAGIC_METER)) { - gSaveContext.magic = (int8_t)gSaveContext.magicCapacity; + gSaveContext.magic = static_cast(gSaveContext.magicCapacity); } if (Flags_GetRandomizerInf(RAND_INF_HAS_INFINITE_BOMBCHUS)) { @@ -2203,7 +2203,8 @@ void RandomizerOnActorUpdateHandler(void* refActor) { if (actor->id == ACTOR_OBJ_COMB) { ObjComb* combActor = reinterpret_cast(actor); combActor->actor.shape.rot.x = - (int16_t)Math_SinS(combActor->unk_1B2) * CLAMP_MIN(combActor->unk_1B0, 0) + combActor->actor.home.rot.x; + static_cast(Math_SinS(combActor->unk_1B2)) * CLAMP_MIN(combActor->unk_1B0, 0) + + combActor->actor.home.rot.x; } } @@ -2298,8 +2299,8 @@ void RandomizerOnSceneSpawnActorsHandler() { switch (gPlayState->sceneNum) { case SCENE_TEMPLE_OF_TIME: if (gPlayState->roomCtx.curRoom.num == 1) { - Actor_Spawn(&gPlayState->actorCtx, gPlayState, ACTOR_EN_XC, -104, -40, 2382, 0, (int16_t)0x8000, 0, - SHEIK_TYPE_RANDO, false); + Actor_Spawn(&gPlayState->actorCtx, gPlayState, ACTOR_EN_XC, -104, -40, 2382, 0, + static_cast(0x8000), 0, SHEIK_TYPE_RANDO, false); } break; case SCENE_INSIDE_GANONS_CASTLE: