Skip to content

Commit ceae5c6

Browse files
committed
* Leverage a better hash key (with less collisions) for the clear geometry GUID mapping
1 parent c0cb780 commit ceae5c6

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

NitroxPatcher/Patches/Base_ClearGeometry_Patch.cs

+8-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class Base_ClearGeometry_Patch : NitroxPatch
1919
* them so that we can update the newly placed pieces with the proper id. The new
2020
* pieces are added by Base.SpawnPiece (see that patch)
2121
*/
22-
public static Dictionary<Vector3, string> LastClearedCellsByPosition = new Dictionary<Vector3, string>();
22+
public static Dictionary<string, string> GuidByObjectKey = new Dictionary<string, string>();
2323

2424
public static void Prefix(Base __instance)
2525
{
@@ -48,14 +48,20 @@ public static void Prefix(Base __instance)
4848
if(child.gameObject.GetComponent<UniqueIdentifier>() != null)
4949
{
5050
string guid = child.gameObject.GetComponent<UniqueIdentifier>().Id;
51-
LastClearedCellsByPosition[child.position] = guid;
51+
string key = getObjectKey(child.gameObject.name, child.position);
52+
GuidByObjectKey[key] = guid;
5253
}
5354
}
5455
}
5556
}
5657
}
5758
}
5859

60+
public static string getObjectKey(string name, Vector3 postion)
61+
{
62+
return name + postion.ToString();
63+
}
64+
5965
public override void Patch(HarmonyInstance harmony)
6066
{
6167
PatchPrefix(harmony, TARGET_METHOD);

NitroxPatcher/Patches/Base_SpawnPiece_Patch.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ public static void Postfix(Base __instance, Transform __result)
2525
}
2626

2727
string guid;
28-
29-
if (Base_ClearGeometry_Patch.LastClearedCellsByPosition.TryGetValue(__result.position, out guid))
28+
29+
string key = Base_ClearGeometry_Patch.getObjectKey(__result.name, __result.position);
30+
31+
if (Base_ClearGeometry_Patch.GuidByObjectKey.TryGetValue(key, out guid))
3032
{
3133
GuidHelper.SetNewGuid(__result.gameObject, guid);
3234
}

0 commit comments

Comments
 (0)