Utilized NetIds to get drops for structures and barricades rather than find by root.#2
Utilized NetIds to get drops for structures and barricades rather than find by root.#2Jdance-Media wants to merge 2 commits into
Conversation
… down on number of ticks required by 48%.
- StructureHelper.ForceDropStructure: dropReplicatedStructure goes through ClaimBlock(2u) (StructureManager.cs:445), so drop is at counter-1 (transform at counter), not counter-2. The previous value pointed to either an unassigned slot or the previous block, returning null or an unrelated object. - BarricadeHelper.FindBarricadeDrop: 'return null' inside the foreach exited the whole loop on the first non-registered transform. Changed to 'continue' so other results in the radius still get checked. - RaycastHelper.GetBarricadeTransform(Vector3) / RaycastHelper.GetStructureTransform(Vector3): same foreach early-exit bug, also changed to 'continue'. Added drop != null check before returning so an invalid type cast falls through to the next match. - TransformBase.UpdatePosition: was calling GetTransformNetId(Transform) twice on the same Transform. Single lookup, then try BarricadeDrop cast; if null, try StructureDrop cast on the same netId. - StructureHelper: deleted the commented-out FindStructureDropByPosition block (no callers in repo, dead code).
|
Hey, thanks for the PR, sorry I'm only getting to this now lol. I pushed a fix commit (6b61e29) directly to your branch with a few small things I noticed while going through it: 1. StructureHelper.ForceDropStructure: dropReplicatedStructure internally calls // StructureManager.cs:434
public static bool dropReplicatedStructure(Structure structure, Vector3 point, Quaternion rotation, ulong owner, ulong group)
{
...
NetId netId = NetIdRegistry.ClaimBlock(2u); // line 445
...
}And ClaimBlock returns // NetIdRegistry.cs:28
public static NetId ClaimBlock(uint size)
{
NetId result = new NetId(counter + 1);
counter += size;
return result;
}So if old counter was N: drop gets N+1, transform gets N+2, new counter = N+2. Drop is at 2. BarricadeHelper.FindBarricadeDrop: foreach early-exited on first miss The 3. TransformBase.UpdatePosition: double GetTransformNetId on same Transform Was calling it twice on the same // BarricadeDrop.cs:77
internal void AssignNetId(NetId netId)
{
_netId = netId;
NetIdRegistry.Assign(netId, this); // drop @ netId
NetIdRegistry.AssignTransform(netId + 1u, _model); // transform @ netId+1
if (_interactable != null)
{
_interactable.AssignNetId(netId + 2u); // interactable @ netId+2
}
}
// StructureDrop.cs:62
internal void AssignNetId(NetId netId)
{
_netId = netId;
NetIdRegistry.Assign(netId, this);
NetIdRegistry.AssignTransform(netId + 1u, _model);
}So 4. Deleted the commented-out FindStructureDropByPosition block Nothing was referencing it. Going to run it on a test server to double check everything's good, then merge. Thanks again! |
|
Whoops, I appreciate the fixes. You understand the concept though. 🤣 It will speed things up though. |
Earlier I discovered that
BarricadeDrop.FindByRootFastutilizesGetComponentin order to obtain the BarricadeDrop. Nelson likes to return transforms for new plants and finding barricades in a radius, so this is called fairly often.By utilizing the NetIdRegistry and therefore its built-in dictionaries, you save 31.64 - 48% in tick speed in comparison to the FindByRootFast way. I've tested this alongside RBMKBlaze in relation to a plugin on LC and it gives a noticeable improvement.
This is the new standard and improved way to get
BarricadeDropfrom a Transform. Tons of plugins use the old FindBarricadeByRootTransform way and it can be incredibly problematic.