Skip to content

Add vehicle suspension restoration and post-render handling#5011

Open
QueryOfficial wants to merge 2 commits into
multitheftauto:masterfrom
QueryOfficial:fix/privatize-suspension-lines-prerender
Open

Add vehicle suspension restoration and post-render handling#5011
QueryOfficial wants to merge 2 commits into
multitheftauto:masterfrom
QueryOfficial:fix/privatize-suspension-lines-prerender

Conversation

@QueryOfficial

Copy link
Copy Markdown
Contributor

Summary

Privatize suspension line data for CAutomobile::PreRender, mirroring the existing collision hook pattern, so wheel render height is per-vehicle instead of shared per model.

After the PreRender wheel block, re-apply cached wheel_*_dummy component positions so setVehicleComponentPosition Z offsets are not overwritten every frame.

Motivation

Fixes #5007 and #1652.

#5007: When suspension handling is modified (setVehicleHandling, hedit, etc.), wheels render at the wrong height as soon as another vehicle of the same model streams in or recalculates handling. Physics is correct because ProcessVehicleCollision already swaps in per-vehicle private suspension lines via CopyGlobalSuspensionLinesToPrivate, but PreRender still reads the shared per-model CColModel suspension lines (“last writer wins”).

#1652: setVehicleComponentPosition on wheel dummies (wheel_lf_dummy, etc.) applies X but not Z, because PreRender overwrites wheel dummy Z from suspension lines every frame.

This change:

  • Hooks CAutomobile::PreRender entry (0x6AAB50) to temporarily set the model’s suspension lines to the current vehicle’s private copy before wheel positioning runs.
  • Restores the original per-model pointer at the existing post-wheel PreRender hook (0x6ABCFD in HOOK_Vehicle_PreRender).
  • Registers a post-PreRender handler to re-apply script-set wheel dummy positions from CClientVehicle::m_ComponentData.

Test plan

  • Spawn vehicle A (e.g. Infernus 411), lower/raise suspension via setVehicleHandling — wheels and body should match.
  • Stream in vehicle B of the same model with default handling near A — A should still render with correct wheel height for all viewers (not just the owner).
  • Re-apply suspension on A — B should not break visually (no last-writer regression).
  • Repeat with a monster truck model if available.
  • Run setVehicleComponentPosition(veh, "wheel_lf_dummy", x+1, y, z+10) — both X and Z offsets should be visible and stable while driving.
  • Attach wheel.zip test resource from setVehicleComponentPosition does not work for Z axis on wheel dummies #1652 and confirm Z offset works.
  • Verify unmodified vehicles / default handling still look and collide normally.
  • Two clients: compare local owner vs remote observer for the same edited vehicle.

Environment tested: MTA:SA client (Windows), local + remote client scenario.

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.

#### Summary

Introduces a new handler for restoring vehicle suspension after the automobile pre-render phase. This includes the addition of `OnAutomobilePostPreRender` to manage suspension restoration and a corresponding static handler in `CClientGame`. The `CMultiplayerSA` class is updated to support this new functionality, ensuring that vehicle suspension data is correctly managed during rendering.

#### Test plan

1. Verify that vehicle suspension is restored correctly after pre-render.
2. Test the integration of the new handler with existing vehicle rendering processes.

#### Checklist

* [x] Code adheres to the coding guidelines.
* [x] Changes have been tested and verified.
#### Summary

Updated the formatting of static variable declarations for improved readability in the `CMultiplayerSA` class. The changes align with coding standards and enhance code clarity without altering functionality.

#### Checklist

* [x] Code adheres to the coding guidelines.
* [x] Changes have been tested and verified.
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.

Wheel render position uses suspension lines shared per model

1 participant