Let scripts remove, restore and edit the map's own occluders - #5379
Flashmyname wants to merge 6 commits into
Conversation
d52eb08 to
4fa051f
Compare
|
Updated along with #5378. local zones = engineGetOccluders()
engineSetOccluder(zones[1].id, 2400, 2400, 20, 60, 4, 40)
engineRestoreOccluder(zones[1].id) -- back to what the map loadedThe original entry stays as the IPL loader wrote it, so that is what a restore gives back. Only one resource can hold an edit, and when it stops the occluder goes back to normal. The test resource covers the whole API from commands now, listed in the description. |
GTA only loads occluders from the map files, so nothing built from scripted objects could hide what it covers. Boxes go through the game's own COcclusion::AddOne, a removal replays the rest over a snapshot of the map's entries, and a resource's boxes go with it when it stops.
Removing and re-adding a box gives its slot up in between, so the add can fail on a full array and the script ends up with a new id or no box at all. The entry is rewritten in place, with the rebuild a removal already does as the fallback.
4fa051f to
98a211a
Compare
98a211a to
ebe8daf
Compare
There was a problem hiding this comment.
Copilot review overview
🔵 Needs a closer look
Fixed-address native memory manipulation and occluder-list rebuilding require final human review and runtime validation.
Review effort: Balanced
Findings: 1
What changed in this PR
Adds Lua APIs for querying, editing, removing, and restoring GTA map occluders with resource-scoped cleanup.
Changes:
- Exposes occluder management APIs to Lua.
- Snapshots and safely rebuilds native occluder pools.
- Restores resource-owned changes during cleanup.
Commit messages should retain the motivation, implementation reasoning, and testing details.
| File | Description |
|---|---|
Client/sdk/game/CWorld.h |
Defines occluder data and world APIs. |
Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.h |
Declares Lua-facing functions. |
Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp |
Implements validation and Lua bindings. |
Client/mods/deathmatch/logic/CResource.cpp |
Cleans up resource-owned changes. |
Client/mods/deathmatch/logic/CClientGame.cpp |
Resets occluders on game initialization. |
Client/game_sa/CWorldSA.h |
Defines native pool structures and state. |
Client/game_sa/CWorldSA.cpp |
Implements capture, rebuild, editing, and restoration. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
The byte snapshot becomes one record per loaded entry with an id and the resources holding it out, so a rebuild can leave it out and its slot counts as free. Ids follow the client's IPL load order and are read through GetOccluders.
An edit is carried beside the loaded bytes and replaces the geometry until the resource that made it restores the occluder or stops, so a restore still hands back what the IPL loader wrote. One resource owns an edit at a time.
engineRemoveOccluder and engineSetOccluder already accept a map occluder id through the existing entry points; these four functions list the occluders with their ids and lift or apply removals by id and by radius. Ids follow the client's IPL load order, so a script reads them from engineGetOccluders rather than hardcoding them.
ebe8daf to
17b6d2b
Compare

Summary
The other half of #4079, on top of #5378. That one adds occluders, this one lets scripts remove, restore and edit the ones the map loads.
engineRemoveOccluderandengineSetOccludertake a map occluder id as well, andengineGetOccluderCapacitycounts a removed one as free.Neither a removal nor an edit touches the loaded entry, so a restore gives back the geometry the IPL loader wrote. Both end when the resource that asked for them stops.
Ids are per client and follow map load order, so read them from
engineGetOccludersinstead of hardcoding them.Motivation
On a stock install the map already uses 995 of the 1000 exterior slots, so #5378 has five to work with. The ones in use still cull the buildings the map shipped with, even where those have been removed.
Test plan
Test resource: occedit.zip
53 checks run on join and print to the server log. The commands cover the whole API:
Checklist