Fix precision mismatch in ResyncInterpolationWithGameClock#4971
Merged
Conversation
Lpsd
added a commit
to Lpsd/mtasa-blue
that referenced
this pull request
Jun 22, 2026
…tauto#4971) #### Summary Fix the final edge case of multitheftauto#4803 where blending from any non-fog weather into FOGGY_SF caused building lights and night windows to flicker every game-clock second. The root cause was a precision mismatch between the constant used in `CWeatherSA::ResyncInterpolationWithGameClock` and the one the engine's `CWeather::Update` loads from its binary data section. #### Motivation Three prior PRs (multitheftauto#4882, multitheftauto#4901, multitheftauto#4906) fixed most flicker cases by re-applying MTA's weather before `CWeather::Update` and adjusting `InterpolationValue` precision. However the interpolation formula still used a 64-bit double literal (`0.016666668`) while the engine loads a 32-bit float (`0x3C888889` = `0.016666668f`). The double literal is slightly larger, making MTA's `InterpolationValue` exceed the engine's `v0` and triggering the wrap branch that corrupts `Foggyness`. This only manifested visibly for FOGGY_SF because the `Foggyness` delta between non-fog and fog weathers is so large (~0 to ~1.0). #### Test plan 1. Join a server, set time to night (22:00), position near buildings with visible night windows (e.g. San Fierro -2597 -156 4). 2. Run `setWeatherBlended(9)` from any non-fog weather (e.g. 5 SUNNY_SF). 3. Observe building lights and night windows during the 1-hour blend. 4. Expected: no per-second flicker, smooth fog transition. 5. Repeat with fast game clock to compress the blend and stress-test. #### Checklist * [x] Your code should follow the [coding guidelines](https://wiki.multitheftauto.com/index.php?title=Coding_guidelines). * [x] Smaller pull requests are easier to review. If your pull request is beefy, your pull request should be reviewable commit-by-commit.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix the final edge case of #4803 where blending from any non-fog weather into FOGGY_SF caused building lights and night windows to flicker every game-clock second.
The root cause was a precision mismatch between the constant used in
CWeatherSA::ResyncInterpolationWithGameClockand the one the engine'sCWeather::Updateloads from its binary data section.Motivation
Three prior PRs (#4882, #4901, #4906) fixed most flicker cases by re-applying MTA's weather before
CWeather::Updateand adjustingInterpolationValueprecision.However the interpolation formula still used a 64-bit double literal (
0.016666668) while the engine loads a 32-bit float (0x3C888889=0.016666668f). The double literal is slightly larger, making MTA'sInterpolationValueexceed the engine'sv0and triggering the wrap branch that corruptsFoggyness. This only manifested visibly for FOGGY_SF because theFoggynessdelta between non-fog and fog weathers is so large (~0 to ~1.0).Test plan
setWeatherBlended(9)from any non-fog weather (e.g. 5 SUNNY_SF).Checklist