Skip to content

Fix precision mismatch in ResyncInterpolationWithGameClock#4971

Merged
Lpsd merged 1 commit into
multitheftauto:masterfrom
Lpsd:flicker-fog-fix
Jun 21, 2026
Merged

Fix precision mismatch in ResyncInterpolationWithGameClock#4971
Lpsd merged 1 commit into
multitheftauto:masterfrom
Lpsd:flicker-fog-fix

Conversation

@Lpsd

@Lpsd Lpsd commented Jun 21, 2026

Copy link
Copy Markdown
Member

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::ResyncInterpolationWithGameClock and the one the engine's CWeather::Update loads from its binary data section.

Motivation

Three prior PRs (#4882, #4901, #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

  • Your code should follow the coding guidelines.
  • Smaller pull requests are easier to review. If your pull request is beefy, your pull request should be reviewable commit-by-commit.

@Lpsd Lpsd merged commit 160d6b1 into multitheftauto:master Jun 21, 2026
10 checks passed
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.
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.

1 participant