SmartlyDressedGames / Unturned-3.x-Community

Community portion of the Unturned-3.x repo. If you have access to the source code you can find it here:
https://github.com/SmartlyDressedGames/Unturned-3.x/
83 stars 17 forks source link

Remove vanilla use of FindBarricadeByRootTransform #4435

Closed rube200 closed 1 week ago

rube200 commented 3 weeks ago

For a long time unturned have these two events:

BarricadeManager.onDamageBarricadeRequested
StructureManager.onDamageStructureRequested

But those events pass transform instead of Drop. Example:

public delegate void DamageBarricadeRequestHandler(
    CSteamID instigatorSteamID,
    Transform barricadeTransform,
    ref ushort pendingTotalDamage,
    ref bool shouldAllow,
    EDamageOrigin damageOrigin);

The problem is any plugin using these methods need to call FindBarricadeByRootTransform/FindStructureByRootTransform, making server with alot of barricade hitting the performance a bit, but the thing is in the event caller already resolve this and have the data. image

Is it possible to edit the original or make a v2? I know editing the original may lead to breaking changes but i think in next update it will be since you are working with vehicles related code.

TLDR: make a v2 of BarricadeManager.onDamageBarricadeRequested and StructureManager.onDamageStructureRequested passing BarricadeDrop/StructureDrop instead of Transform.

rube200 commented 3 weeks ago
DanielWillett commented 3 weeks ago

Maybe consider using a struct or class for the arguments so you can add more later.

SDGNelson commented 3 weeks ago

Vanilla should probably be using FindBarricadeByRootFast. This isn't something I really want to touch at the moment because there are soo many items in need of rewrite there, but for the next update I will change vanilla's use of FindBarricadeByRootTransform so with plugins it at least cuts it in half.

rube200 commented 3 weeks ago

This is not my main point but if it helps performance seems good. The point is vanilla calls for that method and since plugins receive transform they need to call it again. (Doubling the calls to it). Even worst if server have multiple plugin that use that event, it would be 1 vanilla + 1 per plugin