You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix#4803 building light flicker via pre-CWeather::Update hook
PR #4870 hooks at CWorld::Process (0x53C095) to re-apply MTA's blended
weather before CTimeCycle::CalcColoursForPoint reads the weather globals
at 0x53C0DA. That is in time for the sky/ambient colour set, but it is
too late for CWeather::Update itself: when setTime() jumps the game clock
past CWeather::InterpolationValue, CWeather::Update (called at 0x53BFC2,
earlier in CGame::Process) takes its clock-wrap branch and re-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
for the rest of the frame, so building lights still flickered after
PR #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 PR #4870 PreWorldProcessHandler
hook is kept as a defensive idempotent re-apply.
CBlendedWeather::DoPulse now also calls CWeather::ResyncInterpolation
WithGameClock after Set so the InterpolationValue used by CalcColoursFor
Point matches the clock — fixes glass/reflective material flicker
that the sky-only fix in #4870 left behind.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Re-apply MTA's blended weather state both **before**`CWeather::Update` and before `CTimeCycle::CalcColoursForPoint`, so neither the engine's clock-wrap branch nor the colour calculation ever observes a stale weather pair.
4
+
5
+
#### Motivation
6
+
7
+
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, and night-time building lights / cloud / fog also pop for the same frames.
8
+
9
+
The engine's `CWeather::Update` (called at `0x53BFC2` from `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 **and** uses that wrong pair to derive `Rain`, `Foggyness`, `CloudCoverage`, `ExtraSunnyness`, `SunGlare`, `HeatHaze`, `Sandstorm`, `WetRoads`, `Wind` and `Rainbow` for the frame. `CalcColoursForPoint` (at `0x53C0DA`) then reads `OldWeatherType`/`NewWeatherType`/`InterpolationValue` to compute the sky/ambient colour set.
10
+
11
+
MTA's `CBlendedWeather::DoPulse` previously only ran in `DoPulses` during `Render2dStuff`, which is after the frame was already rendered with the wrong state.
12
+
13
+
Two hooks are now used:
14
+
15
+
1.**`HOOK_CWeather_Update`** — replaces the `call CWeather::Update` site at `0x53BFC2`. Fires `PreWeatherUpdateHandler`*before* the engine's update, so MTA's `Set` + `ResyncInterpolationWithGameClock` re-sync `OldWeatherType`/`NewWeatherType`/`InterpolationValue` with the new clock. `CWeather::Update` then takes the non-wrap branch and derives `Rain`/`Foggyness`/`CloudCoverage`/etc. from MTA's intended pair. This is what fixes the **building light / cloud / fog flicker**.
16
+
2.**`PreWorldProcessHandler`** (the original hook from #4870, kept as a defensive idempotent re-apply) — runs at `CWorld::Process` (`0x53C095`), still ahead of `CalcColoursForPoint` at `0x53C0DA`, so the sky/ambient frame is also guaranteed to use MTA's weather pair even if the early hook is bypassed for any reason.
17
+
18
+
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.
19
+
20
+
#### Test plan
21
+
22
+
1. Join a server running the default race resource
23
+
2. Set fullscreen (any mode)
24
+
3. Use `setWeatherBlended` + `setTime` via script, then restart the race resource to respawn
25
+
4. Observe no sky/lighting flicker on respawn
26
+
5. Repeat at night-time so building/streetlight glow and cloud cover are visible — they should not pop either
27
+
28
+
#### Checklist
29
+
30
+
*[x] Your code should follow the [coding guidelines](https://wiki.multitheftauto.com/index.php?title=Coding_guidelines).
31
+
*[x] Smaller pull requests are easier to review. If your pull request is beefy, your pull request should be reviewable commit-by-commit.
0 commit comments