Skip to content

Commit

Permalink
Merge pull request OpenRA#7281 from RoosterDragon/cache-render-traits
Browse files Browse the repository at this point in the history
Cache render related TraitsImplementing calls in Actor.
  • Loading branch information
chrisforbes committed Jan 8, 2015
2 parents 40c9d0a + dc4d522 commit 0a493df
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions OpenRA.Game/Actor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ public WRot Orientation
}
}

readonly IEnumerable<IRenderModifier> traitsImplementingRenderModifier;
readonly IEnumerable<IRender> traitsImplementingRender;

internal Actor(World world, string name, TypeDictionary initDict)
{
var init = new ActorInitializer(this, initDict);
Expand Down Expand Up @@ -104,6 +107,9 @@ internal Actor(World world, string name, TypeDictionary initDict)

return new Rectangle(offset.X, offset.Y, size.X, size.Y);
});

traitsImplementingRenderModifier = TraitsImplementing<IRenderModifier>();
traitsImplementingRender = TraitsImplementing<IRender>();
}

public void Tick()
Expand All @@ -119,14 +125,14 @@ public void Tick()
public IEnumerable<IRenderable> Render(WorldRenderer wr)
{
var renderables = Renderables(wr);
foreach (var modifier in TraitsImplementing<IRenderModifier>())
foreach (var modifier in traitsImplementingRenderModifier)
renderables = modifier.ModifyRender(this, wr, renderables);
return renderables;
}

IEnumerable<IRenderable> Renderables(WorldRenderer wr)
{
foreach (var render in TraitsImplementing<IRender>())
foreach (var render in traitsImplementingRender)
foreach (var renderable in render.Render(this, wr))
yield return renderable;
}
Expand Down

0 comments on commit 0a493df

Please sign in to comment.