Skip to content

Fix weather flicker 4803#4870

Merged
Lpsd merged 4 commits into
multitheftauto:masterfrom
Zephkek:fix/weather-flicker-4803
May 1, 2026
Merged

Fix weather flicker 4803#4870
Lpsd merged 4 commits into
multitheftauto:masterfrom
Zephkek:fix/weather-flicker-4803

Conversation

@Zephkek
Copy link
Copy Markdown
Contributor

@Zephkek Zephkek commented May 1, 2026

Summary

Re-apply MTA's blended weather state in PreWorldProcessHandler so it runs after the engine's CWeather::Update but before CTimeCycle::CalcColoursForPoint reads the weather globals for rendering.

Motivation

Fixes #4803. When setWeatherBlended/setTime are used (e.g. race resource restart/respawn), the sky and ambient lighting flicker for 1-2 frames in fullscreen.

The engine's CWeather::Update (at 0x53BFC2 in CGame::Process) detects a clock wrap when setTime jumps the game clock past its internal InterpolationValue. It then overwrites OldWeatherType/NewWeatherType with its own weather-list pick. CalcColoursForPoint (at 0x53C0DA) reads these wrong values and computes incorrect sky/ambient colors for that frame. MTA's CBlendedWeather::DoPulse previously only ran in DoPulses during Render2dStuff, which is after the frame was already rendered with the wrong state.

Fullscreen-only because exclusive mode bypasses DWM composition, so every frame including the glitch frames is presented directly. Windowed mode's DWM triple buffering absorbs them.

Test plan

  1. Join a server running the default race resource
  2. Set fullscreen (any mode)
  3. Use setWeatherBlended + setTime via script, then restart the race resource to respawn
  4. Observe no sky/lighting flicker on respawn

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.

Zephkek added 4 commits April 30, 2026 21:24
…rBlended/setTime

Re-apply MTA's blended weather state in PreWorldProcessHandler, which runs
after the engine's CWeather::Update() (0x53BFC2) but before
CTimeCycle::CalcColoursForPoint() (via sub_561760 at 0x53C0DA) reads the
weather globals for rendering.

Root cause: When setTime() jumps the clock past InterpolationValue, the
engine's CWeather::Update() detects a time wrap and overwrites
OldWeatherType (0xC81320) / NewWeatherType (0xC8131C) with its own
weather-list selection. MTA's CBlendedWeather::DoPulse() previously only
ran in DoPulses() during Render2dStuff -- AFTER CalcColoursForPoint had
already consumed the wrong values for that frame's sky/ambient/fog colors.

The existing DoPulse() call in DoPulses() is kept as the function is
idempotent and serves as a safety net for late-frame consistency.

Fullscreen-only because exclusive mode uses hardware page-flipping without
DWM composition, exposing every frame including the 2 glitch frames that
windowed mode's triple buffering absorbs.
@Zephkek Zephkek changed the title Fix/weather flicker 4803 Fix weather flicker 4803 May 1, 2026
@Lpsd Lpsd merged commit 57b07f4 into multitheftauto:master May 1, 2026
9 checks passed
Zephkek added a commit to Zephkek/mtasa-blue that referenced this pull request May 4, 2026
…te hook

Follow-up to multitheftauto#4870. PR4870 hooks at CWorld::Process (0x53C095) to
re-apply MTA's blended weather before CTimeCycle::CalcColoursForPoint
reads the weather globals at 0x53C0DA — that fixes sky/ambient. But
CWeather::Update itself runs earlier (0x53BFC2), and on the clock-wrap
branch it derives Rain, Foggyness, CloudCoverage, ExtraSunnyness,
SunGlare, HeatHaze, Sandstorm, WetRoads, Wind and Rainbow from a
freshly-picked weather pair. Those globals drive cloud, fog and
night-time building light rendering, so building lights still flickered
after multitheftauto#4870.

Add a HookInstallCall over the call site at 0x53BFC2 and route a new
PreWeatherUpdateHandler through CMultiplayerSA -> CClientGame, calling
CBlendedWeather::DoPulse before CWeather::Update. DoPulse re-applies
Old/New via Set and re-syncs InterpolationValue with the game clock, so
CWeather::Update takes the non-wrap branch and derives every weather
global from MTA's intended pair. The PreWorldProcessHandler hook from
multitheftauto#4870 is kept as a defensive idempotent re-apply.

CBlendedWeather::DoPulse now also calls
CWeather::ResyncInterpolationWithGameClock after Set so the
InterpolationValue used by CalcColoursForPoint matches the clock —
fixes residual flicker on glass/reflective materials that the sky-only
fix in multitheftauto#4870 left behind.
FileEX pushed a commit that referenced this pull request May 5, 2026
#### Summary

Follow-up to #4870. Move the weather re-apply earlier in
`CGame::Process` so the engine's clock-wrap branch in `CWeather::Update`
also runs against MTA's intended weather pair.

#### Motivation

#4870 fixed the sky/ambient flicker by re-applying MTA's weather in
`PreWorldProcessHandler` (`0x53C095`), ahead of
`CTimeCycle::CalcColoursForPoint` (`0x53C0DA`). Cloud cover, fog and
night-time building lights still pop for the same frames, because
`CWeather::Update` itself runs earlier (`0x53BFC2`) and on the wrap
branch derives `Rain`, `Foggyness`, `CloudCoverage`, `ExtraSunnyness`,
`SunGlare`, `HeatHaze`, `Sandstorm`, `WetRoads`, `Wind` and `Rainbow`
from its own freshly-picked pair before `PreWorldProcessHandler` gets a
chance to fix things.

This PR adds a `HookInstallCall` over the `call CWeather::Update` site
at `0x53BFC2` and a new `PreWeatherUpdateHandler` that runs
`CBlendedWeather::DoPulse` before the engine update. With
Old/New/`InterpolationValue` already aligned, `CWeather::Update` takes
the non-wrap branch and derives every weather global from MTA's pair.
The existing `PreWorldProcessHandler` re-apply from #4870 is kept as an
idempotent safety net for the colour-set path.

`CBlendedWeather::DoPulse` also calls
`CWeather::ResyncInterpolationWithGameClock` after `Set`, so
`InterpolationValue` matches the clock also fixes residual flicker on
glass/reflective materials that #4870 left behind.

#### Test plan

1. Join a server running the default race resource
2. Set fullscreen (any mode)
3. Use `setWeatherBlended` + `setTime` via script, then restart the race
resource to respawn
4. Observe no sky/lighting flicker on respawn
5. Repeat at night so building/streetlight glow and cloud cover are
visible they should not pop either

#### 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.
@FileEX FileEX added this to the 1.7 (Current) milestone May 5, 2026
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.

setWeatherBlended / setTime causing flickering

3 participants