Skip to content

feat: Clean deterministic math fixes for review (v2.2-clean)#3

Open
Okladnoj wants to merge 4 commits into
okji/feat/deterministic-math-v2from
okji/feat/deterministic-math-v2.2-clean
Open

feat: Clean deterministic math fixes for review (v2.2-clean)#3
Okladnoj wants to merge 4 commits into
okji/feat/deterministic-math-v2from
okji/feat/deterministic-math-v2.2-clean

Conversation

@Okladnoj

Copy link
Copy Markdown
Owner

This PR merges the clean deterministic math fixes (without debug instrumentation) to the okji/feat/deterministic-math-v2 branch for team review.

Key Changes:

  • Math Determinism: Prevented MSVC x87 FPU desyncs by routing WWMath::Atan and WWMath::Atan2 double overloads to their single-precision gm_atan*f variants. This forces 24-bit precision and avoids the 53-bit vs 24-bit divergence between ARM64 and x86.
  • Retail Compatibility: Removed retail CRC conditional logic from SpecialPowerModule.
  • Config: Toggled RETAIL_COMPATIBLE_CRC back to 0.

Note: There might be more controversial fixes ahead (like patching DumbProjectileBehavior NaN casts and PartitionManager radius math), so this PR serves as a stable checkpoint for the team to review.

Okladnoj added 4 commits July 12, 2026 21:56
… check

isPlayerConnected expects a Network slot index, but was receiving a PlayerList index. Added proper mapping to avoid spurious mismatches at low CRC intervals.
…rModule

Hardcode m_availableOnFrame to 0 to simplify initialization and ensure deterministic behavior regardless of the CRC macro.
// TheSuperHackers @bugfix Caball009 14/06/2026 Check if player is still connected,
// to avoid spurious mismatches at low CRC intervals, e.g. every frame.
if (!TheNetwork->isPlayerConnected(it->first))
// @fix 08/07/2026 okladnoj: it->first is the PlayerList index, but isPlayerConnected expects Network slot index!

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ConnectionManager::getPlayerName returns an empty string once the connection is quitting (same condition isPlayerConnected checks), so for the player who just disconnected, the loop finds nothing, slotIndex stays -1, and the stale CRC gets included again. 2796 was fixing this. Maybe do the mapping at cache time? The map could be keyed by slot and this loop calls isPlayerConnected(it->first) unchanged. That also avoids the duplicate-display-name

{

#if RETAIL_COMPATIBLE_CRC

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hit this bug on my fork too (Strategy Center battle plans never become ready with CRC=0). I'm not sure about removing the 0xFFFFFFFF init though, could hit a null issue. What worked for me was to keep the init and charge any power still at 0xFFFFFFFF in Player::onStructureConstructionComplete. This fixes the never-ready issue without reopening the crash that Mauller fixed.

{
#if USE_DETERMINISTIC_MATH
return gm_atan(x);
return (double) gm_atanf((float)x);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This matches what I found on my fork. IMHO the long term fix is GameMath compiling the double kernels pure SSE2, or win64 with no x87 at all. This should work as is though

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Outside of VC6 even 32bit builds from MSVC use SSE2 unless that is specifically disabled in TSH? This basically violates the implied contract of the double math variants and you might as well just remove them or rename them so they can be used specifically where required. IMO, we should just support FLT_EVAL_METHOD == 0 from the float.h header and anything else just accept it will desync.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants