Skip to content

Commit

Permalink
Avoid lag burst when a CE grenade explodes
Browse files Browse the repository at this point in the history
When a CE frag grenade explodes, it spawns a large number of "Fragment_GrenadeFrag" entities at the same time (mortar shells spawn "Fragment_Shell" instead)
Running "DefDatabase<ThingDef>.AllDefs.FirstOrDefault()" twice each time is very slow, causing a several-second RimWorld freeze.
Bailing out early on "Fragment_" prefixes seems to work around it, but please check if this would break anything else before accepting this PR, I don't have much of any experience in RimWorld modding.

Fixes #4.
  • Loading branch information
Maeyanie authored Feb 4, 2019
1 parent 4bad4eb commit 908ad35
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion Source/HarmonyPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,12 @@ public static bool WipeExistingThings(IntVec3 thingPos, Rot4 thingRot, Buildable
//GenSpawn
public static void InvisDoorsDontWipe(BuildableDef newEntDef, BuildableDef oldEntDef, ref bool __result)
{
if (newEntDef.defName.StartsWith("Fragment_") &&
oldEntDef.defName.StartsWith("Fragment_"))
{
return;
}

var oldTrueDef =
DefDatabase<ThingDef>.AllDefs.FirstOrDefault(predicate: x => x.defName == oldEntDef.defName);
var newTrueDef =
Expand Down Expand Up @@ -904,4 +910,4 @@ public static void GetHeronRegionType(ref RegionType __result, IntVec3 c, Map ma
}
}
}
}
}

0 comments on commit 908ad35

Please sign in to comment.