Avoid some allocations during loading.

- In FieldLoader, cache boxed bools and some boxed ints.
- In FieldLoader, presize collections when parsing a List, HashSet or Dictionary.
- In FieldLoader, don't allocate a list of missing items until required.
- In FieldLoader, when a string value is passed, avoid wrapping this in a MiniYaml object by allowing both strings and yaml to be passed in the GetValue overload that does the real work.
- In Animation, avoid allocating no-op actions.
- In VxlReader, use EnsureCapcity to better size the Dictionary.
- In VxlReader change VxlElement to a struct.
- In Locomotor, presize TerrainSpeeds dictionary.
This commit is contained in:
RoosterDragon
2023-07-02 16:35:51 +01:00
committed by abcdefg30
parent be04d232c0
commit 58e8b123db
5 changed files with 55 additions and 29 deletions

View File

@@ -57,7 +57,7 @@ namespace OpenRA.Mods.Cnc.Graphics
sheetBuilder = CreateSheetBuilder();
}
Vertex[] GenerateSlicePlane(int su, int sv, Func<int, int, VxlElement> first, Func<int, int, VxlElement> second, Func<int, int, float3> coord)
Vertex[] GenerateSlicePlane(int su, int sv, Func<int, int, VxlElement?> first, Func<int, int, VxlElement?> second, Func<int, int, float3> coord)
{
var colors = new byte[su * sv];
var normals = new byte[su * sv];
@@ -68,8 +68,8 @@ namespace OpenRA.Mods.Cnc.Graphics
for (var u = 0; u < su; u++)
{
var voxel = first(u, v) ?? second(u, v);
colors[c] = voxel == null ? (byte)0 : voxel.Color;
normals[c] = voxel == null ? (byte)0 : voxel.Normal;
colors[c] = voxel == null ? (byte)0 : voxel.Value.Color;
normals[c] = voxel == null ? (byte)0 : voxel.Value.Normal;
c++;
}
}
@@ -99,7 +99,7 @@ namespace OpenRA.Mods.Cnc.Graphics
IEnumerable<Vertex[]> GenerateSlicePlanes(VxlLimb l)
{
VxlElement Get(int x, int y, int z)
VxlElement? Get(int x, int y, int z)
{
if (x < 0 || y < 0 || z < 0)
return null;