Tweaks for map generator performance.

The map generator is already performant, but we can remove a few rough edges from infrastructure it interacts with.

- Add TypeDictionary constructor to clone from an existing copy. The map editor infrastructure relies heavily on cloning ActorReferences and the underlying dictionaries. A dedicated clone method avoids reflection overhead for CreateTypeContainer on a fresh instance.
- Use ThrowIndexOutOfRangeException helper. This allows the Index method to be inlined.
- Reuse lists in FloodFill. This avoids allocating and resizing new lists on each loop when we can reuse the existing capacity.
- Manage CellEntryChanged at the layer rather than individual previews. We only need to attach/detach from the delegate once at the layer, rather than many times as previews are added and removed.
This commit is contained in:
RoosterDragon
2025-11-24 19:10:39 +00:00
committed by Gustas Kažukauskas
parent 3ea5b08848
commit a546ca2f92
10 changed files with 62 additions and 49 deletions

View File

@@ -345,11 +345,12 @@ namespace OpenRA.Mods.Common.MapGenerator
Func<int2, P, P?> filler,
ImmutableArray<int2> spread) where P : struct
{
var current = new List<(int2 XY, P Prop)>();
var next = seeds.ToList();
while (next.Count != 0)
{
var current = next;
next = [];
(next, current) = (current, next);
next.Clear();
foreach (var (source, prop) in current)
{
var newProp = filler(source, prop);