Skip to content

Move entity model streaming and polling to worker threads - #5303

Open
iManGaaX wants to merge 2 commits into
multitheftauto:masterfrom
iManGaaX:patch-3
Open

Move entity model streaming and polling to worker threads#5303
iManGaaX wants to merge 2 commits into
multitheftauto:masterfrom
iManGaaX:patch-3

Conversation

@iManGaaX

@iManGaaX iManGaaX commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Refactored CClientModelRequestManager to process model streaming requests asynchronously via worker threads.
  • Implemented a dual-mutex architecture utilizing m_Mutex for container safety and m_ModelInfoMutex to serialize game engine and RenderWare calls.
  • Added a thread-safe cancellation mechanism (bCancelled) ensuring all memory cleanup and engine callbacks remain strictly on the main thread inside DoPulse()

Motivation

  • Eliminates severe frame drops and game stuttering (FPS stutters) caused by synchronous disk I/O and heavy model loading operations on the main thread.

Test plan

  1. Compiled the MTA client source code locally.
  2. Conducted stress tests by rapidly spawning and destroying custom entities and models to simulate heavy streaming loads.
  3. Verified stable frame rates, smooth movement, and complete absence of use-after-free crashes or deadlocks during dynamic request cancellations.

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.

Added worker thread management for model requests, including start and stop functionality. Enhanced request handling with improved cancellation checks and background processing.
Added atomic flags for background processing and cancellation in SClientModelRequest.
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