Skip to content

Commit

Permalink
* Leverage a better hash key (with less collisions) for the clear geo…
Browse files Browse the repository at this point in the history
…metry GUID mapping
  • Loading branch information
Sunrunner37 committed Jan 13, 2019
1 parent c0cb780 commit ceae5c6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
10 changes: 8 additions & 2 deletions NitroxPatcher/Patches/Base_ClearGeometry_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class Base_ClearGeometry_Patch : NitroxPatch
* them so that we can update the newly placed pieces with the proper id. The new
* pieces are added by Base.SpawnPiece (see that patch)
*/
public static Dictionary<Vector3, string> LastClearedCellsByPosition = new Dictionary<Vector3, string>();
public static Dictionary<string, string> GuidByObjectKey = new Dictionary<string, string>();

public static void Prefix(Base __instance)
{
Expand Down Expand Up @@ -48,14 +48,20 @@ public static void Prefix(Base __instance)
if(child.gameObject.GetComponent<UniqueIdentifier>() != null)
{
string guid = child.gameObject.GetComponent<UniqueIdentifier>().Id;
LastClearedCellsByPosition[child.position] = guid;
string key = getObjectKey(child.gameObject.name, child.position);
GuidByObjectKey[key] = guid;
}
}
}
}
}
}

public static string getObjectKey(string name, Vector3 postion)
{
return name + postion.ToString();
}

public override void Patch(HarmonyInstance harmony)
{
PatchPrefix(harmony, TARGET_METHOD);
Expand Down
6 changes: 4 additions & 2 deletions NitroxPatcher/Patches/Base_SpawnPiece_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ public static void Postfix(Base __instance, Transform __result)
}

string guid;

if (Base_ClearGeometry_Patch.LastClearedCellsByPosition.TryGetValue(__result.position, out guid))

string key = Base_ClearGeometry_Patch.getObjectKey(__result.name, __result.position);

if (Base_ClearGeometry_Patch.GuidByObjectKey.TryGetValue(key, out guid))
{
GuidHelper.SetNewGuid(__result.gameObject, guid);
}
Expand Down

0 comments on commit ceae5c6

Please sign in to comment.