Changes to reduce allocations in the main loop.
Targeted some methods that generated allocated a lot of memory in the main game loop: - Actor.Render - Changed LINQ calls into equivalent loops. No allocation for delegates. - Animation.Render - Returned an array rather than a yield expression. The array uses less memory than the complier generated enumerable. - FrozenActor and FrozenUnderFog - Materialize the footprint into an array: The enumerable is not-trivial to evaluate is and evaluated many times inside the Tick function. The memory needed is minimal. Changed LINQ into equivalent loops to prevent delegate allocation. Should result in overall much faster calls. - Widget.GetEventBounds - Changed LINQ calls into equivalent loops. - MobileInfo.CanEnterCell - Changed LINQ calls into equivalent loops. Don't materialize list of blocking actors every time, instead enumerate them and only when they need to be checked. - FrozenUnderFog.TickRender - Generate the renderables lazily and also remove a no-op Select call.
This commit is contained in:
@@ -22,7 +22,7 @@ namespace OpenRA.Traits
|
||||
|
||||
public class FrozenActor
|
||||
{
|
||||
public readonly IEnumerable<CPos> Footprint;
|
||||
public readonly CPos[] Footprint;
|
||||
public readonly WPos CenterPosition;
|
||||
public readonly Rectangle Bounds;
|
||||
readonly Actor actor;
|
||||
@@ -41,7 +41,7 @@ namespace OpenRA.Traits
|
||||
public FrozenActor(Actor self, IEnumerable<CPos> footprint)
|
||||
{
|
||||
actor = self;
|
||||
Footprint = footprint;
|
||||
Footprint = footprint.ToArray();
|
||||
CenterPosition = self.CenterPosition;
|
||||
Bounds = self.Bounds.Value;
|
||||
}
|
||||
@@ -54,7 +54,13 @@ namespace OpenRA.Traits
|
||||
int flashTicks;
|
||||
public void Tick(World world, Shroud shroud)
|
||||
{
|
||||
Visible = !Footprint.Any(c => shroud.IsVisible(c));
|
||||
Visible = false;
|
||||
foreach (var pos in Footprint)
|
||||
if (shroud.IsVisible(pos))
|
||||
{
|
||||
Visible = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (flashTicks > 0)
|
||||
flashTicks--;
|
||||
|
||||
Reference in New Issue
Block a user