From 770a066a4eb4182c4b994f22c4d876ae8dc4d242 Mon Sep 17 00:00:00 2001 From: 6emmes <27066734+6emmes@users.noreply.github.com> Date: Wed, 9 Oct 2024 21:08:25 +0200 Subject: [PATCH 1/5] changed rounding method (#884) --- src/game/common/rts/player.cpp | 2 +- src/w3d/math/gamemath.h | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/game/common/rts/player.cpp b/src/game/common/rts/player.cpp index 0a753ee5a..59b3503a9 100644 --- a/src/game/common/rts/player.cpp +++ b/src/game/common/rts/player.cpp @@ -2998,7 +2998,7 @@ void Player::Do_Bounty_For_Kill(const Object *killer, const Object *killed) { if (killer != nullptr && killed != nullptr && !killed->Get_Status(OBJECT_STATUS_UNDER_CONSTRUCTION)) { unsigned int amount = - GameMath::Fast_To_Int_Ceil(killed->Get_Template()->Calc_Cost_To_Build(this) * m_bountyCostToBuild); + GameMath::Fast_To_Int_Round(killed->Get_Template()->Calc_Cost_To_Build(this) * m_bountyCostToBuild); if (amount != 0) { Get_Money()->Deposit(amount, true); diff --git a/src/w3d/math/gamemath.h b/src/w3d/math/gamemath.h index a51ecc2b1..95c533fc0 100644 --- a/src/w3d/math/gamemath.h +++ b/src/w3d/math/gamemath.h @@ -378,6 +378,23 @@ inline int Fast_To_Int_Truncate(float val) #endif } +inline int Fast_To_Int_Round(float val) +{ + static const float _exactly_half = 0.5f; + + if (Fast_Is_Float_Positive(val)) { + val += _exactly_half; + } else { + val -= _exactly_half; + } + +#ifdef BUILD_WITH_GAMEMATH + return gm_lrintf(gm_truncf(val)); +#else + return lrintf(truncf(val)); // TODO reimplement based on fdlibm for cross platform reproducibility. +#endif +} + inline float Random_Float() { return float((float(rand() & 0xFFF)) / float(0xFFF)); From 5a0ac600968f86e162eb9770bff5d9d57e137035 Mon Sep 17 00:00:00 2001 From: 6emmes <27066734+6emmes@users.noreply.github.com> Date: Thu, 10 Oct 2024 20:22:12 +0200 Subject: [PATCH 2/5] changed rounding method (#884) --- src/game/common/rts/player.cpp | 2 +- src/w3d/math/gamemath.h | 17 ----------------- 2 files changed, 1 insertion(+), 18 deletions(-) diff --git a/src/game/common/rts/player.cpp b/src/game/common/rts/player.cpp index 59b3503a9..0f6b5f167 100644 --- a/src/game/common/rts/player.cpp +++ b/src/game/common/rts/player.cpp @@ -2998,7 +2998,7 @@ void Player::Do_Bounty_For_Kill(const Object *killer, const Object *killed) { if (killer != nullptr && killed != nullptr && !killed->Get_Status(OBJECT_STATUS_UNDER_CONSTRUCTION)) { unsigned int amount = - GameMath::Fast_To_Int_Round(killed->Get_Template()->Calc_Cost_To_Build(this) * m_bountyCostToBuild); + GameMath::Fast_To_Int_Floor(killed->Get_Template()->Calc_Cost_To_Build(this) * m_bountyCostToBuild); if (amount != 0) { Get_Money()->Deposit(amount, true); diff --git a/src/w3d/math/gamemath.h b/src/w3d/math/gamemath.h index 95c533fc0..a51ecc2b1 100644 --- a/src/w3d/math/gamemath.h +++ b/src/w3d/math/gamemath.h @@ -378,23 +378,6 @@ inline int Fast_To_Int_Truncate(float val) #endif } -inline int Fast_To_Int_Round(float val) -{ - static const float _exactly_half = 0.5f; - - if (Fast_Is_Float_Positive(val)) { - val += _exactly_half; - } else { - val -= _exactly_half; - } - -#ifdef BUILD_WITH_GAMEMATH - return gm_lrintf(gm_truncf(val)); -#else - return lrintf(truncf(val)); // TODO reimplement based on fdlibm for cross platform reproducibility. -#endif -} - inline float Random_Float() { return float((float(rand() & 0xFFF)) / float(0xFFF)); From ada64af8b11186c0b7427915faa6fc4293f0be75 Mon Sep 17 00:00:00 2001 From: 6emmes <27066734+6emmes@users.noreply.github.com> Date: Fri, 18 Oct 2024 23:43:19 +0200 Subject: [PATCH 3/5] Update drawable.cpp Fixed boolean expression --- src/game/client/drawable.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/game/client/drawable.cpp b/src/game/client/drawable.cpp index d3eaca162..1e53c0caf 100644 --- a/src/game/client/drawable.cpp +++ b/src/game/client/drawable.cpp @@ -3185,7 +3185,7 @@ void Drawable::Update_Drawable() (*modules)->Set_Terrain_Decal_Opacity(m_terrainDecalOpacity); } - if (m_terrainDecalFadeTarget2 < 0.0f || m_terrainDecalOpacity <= 0.0f) { + if (m_terrainDecalFadeTarget2 < 0.0f && m_terrainDecalOpacity <= 0.0f) { m_terrainDecalFadeTarget2 = 0.0f; m_terrainDecalOpacity = 0.0f; Set_Terrain_Decal(TERRAIN_DECAL_8); From e48c78ac0f52fee85345e83d815186df0055dbd8 Mon Sep 17 00:00:00 2001 From: 6emmes <27066734+6emmes@users.noreply.github.com> Date: Thu, 31 Oct 2024 12:11:16 +0100 Subject: [PATCH 4/5] revert rounding --- src/game/common/rts/player.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/game/common/rts/player.cpp b/src/game/common/rts/player.cpp index 0f6b5f167..0a753ee5a 100644 --- a/src/game/common/rts/player.cpp +++ b/src/game/common/rts/player.cpp @@ -2998,7 +2998,7 @@ void Player::Do_Bounty_For_Kill(const Object *killer, const Object *killed) { if (killer != nullptr && killed != nullptr && !killed->Get_Status(OBJECT_STATUS_UNDER_CONSTRUCTION)) { unsigned int amount = - GameMath::Fast_To_Int_Floor(killed->Get_Template()->Calc_Cost_To_Build(this) * m_bountyCostToBuild); + GameMath::Fast_To_Int_Ceil(killed->Get_Template()->Calc_Cost_To_Build(this) * m_bountyCostToBuild); if (amount != 0) { Get_Money()->Deposit(amount, true); From 7e8941d3264df5f77dcd2811890b1e9ebbf6395d Mon Sep 17 00:00:00 2001 From: 6emmes <27066734+6emmes@users.noreply.github.com> Date: Thu, 31 Oct 2024 12:11:36 +0100 Subject: [PATCH 5/5] added float error --- src/game/common/ini/ini.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/game/common/ini/ini.cpp b/src/game/common/ini/ini.cpp index f5332cb1a..9d971f1ef 100644 --- a/src/game/common/ini/ini.cpp +++ b/src/game/common/ini/ini.cpp @@ -481,7 +481,7 @@ float INI::Scan_PercentToReal(const char *token) int res = sscanf(token, "%f", &value); captainslog_relassert(res == 1, 0xDEAD0006, "Unable to parse percentage from token %s.", token); - return (value / 100.0f); + return (value * 0.01f); } float INI::Scan_Real(const char *token)