Skip to content

Conversation

@DemiAutomatic
Copy link

Pull Request: Optimize Doorlock Nearby Door Processing

Description

This PR optimizes the door processing loop in ox_doorlock to improve performance for scenarios with many nearby doors.

Changes Made

  • Merged the nearby door update thread and ClosestDoor calculation/UI thread into a single thread to eliminate shared state issues and reduce thread overhead.
  • Moved GetAspectRatio(true) calculation to the drawing thread, as it’s only needed when rendering sprites.
  • Removed global nearbyDoors and nearbyDoorsCount, computing values locally to simplify state management.
  • Maintained all existing functionality (e.g., entity updates, UI, sound playback) with no regressions.

Related Issues

Testing

  • Tested in a server with 311 doors in a single location.
  • Verified ClosestDoor selection matches previous behavior (closest door within maxDistance is correctly identified).
  • Confirmed UI (text/sprite) and sound playback trigger correctly for lock/unlock events.

Performance Impact

  • Thread merging eliminates minor async inconsistencies and reduces Lua thread overhead.
  • loop runtime reduced by ~90% in dense areas (measured with Resmon).

Screenshots/Video

BEFORE:
https://github.com/user-attachments/assets/4dbda7a0-9c15-442e-923b-05fedf8a467a

AFTER:
https://github.com/user-attachments/assets/54cecbe6-ce8a-4582-b308-24106c65d086

Additional Notes

  • on line 93 i added a hard 50 unit distance for the door processing, this greatly reduced the cpu time due to all the math involved in this section. not sure if you would like a more graceful way of handling this or even just add it as a config option. 50 units is pretty generous and not sure why you would need to interact with a door more than 50 meters away. another option could be just locking the math behind a distance check if this is problematic.
  • added the lock/unlock to a lib keybind

@jellyton255
Copy link

Might be good to add validation for the hard unit distance in the creator UI so it's not possible to set the interact distance greater than the specified hard limit.

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.

2 participants