WorldRenderer, replace foreach ActorsWithTraits with ApplyToActorsWithTrait. #18798.
This commit is contained in:
@@ -151,14 +151,14 @@ namespace OpenRA.Graphics
|
||||
// PERF: Avoid LINQ.
|
||||
void GenerateOverlayRenderables()
|
||||
{
|
||||
foreach (var a in World.ActorsWithTrait<IRenderAboveShroud>())
|
||||
World.ApplyToActorsWithTrait<IRenderAboveShroud>((actor, trait) =>
|
||||
{
|
||||
if (!a.Actor.IsInWorld || a.Actor.Disposed || (a.Trait.SpatiallyPartitionable && !onScreenActors.Contains(a.Actor)))
|
||||
continue;
|
||||
if (!actor.IsInWorld || actor.Disposed || (trait.SpatiallyPartitionable && !onScreenActors.Contains(actor)))
|
||||
return;
|
||||
|
||||
foreach (var renderable in a.Trait.RenderAboveShroud(a.Actor, this))
|
||||
foreach (var renderable in trait.RenderAboveShroud(actor, this))
|
||||
preparedOverlayRenderables.Add(renderable.PrepareRender(this));
|
||||
}
|
||||
});
|
||||
|
||||
foreach (var a in World.Selection.Actors)
|
||||
{
|
||||
@@ -193,14 +193,14 @@ namespace OpenRA.Graphics
|
||||
// PERF: Avoid LINQ.
|
||||
void GenerateAnnotationRenderables()
|
||||
{
|
||||
foreach (var a in World.ActorsWithTrait<IRenderAnnotations>())
|
||||
World.ApplyToActorsWithTrait<IRenderAnnotations>((actor, trait) =>
|
||||
{
|
||||
if (!a.Actor.IsInWorld || a.Actor.Disposed || (a.Trait.SpatiallyPartitionable && !onScreenActors.Contains(a.Actor)))
|
||||
continue;
|
||||
if (!actor.IsInWorld || actor.Disposed || (trait.SpatiallyPartitionable && !onScreenActors.Contains(actor)))
|
||||
return;
|
||||
|
||||
foreach (var renderAnnotation in a.Trait.RenderAnnotations(a.Actor, this))
|
||||
foreach (var renderAnnotation in trait.RenderAnnotations(actor, this))
|
||||
preparedAnnotationRenderables.Add(renderAnnotation.PrepareRender(this));
|
||||
}
|
||||
});
|
||||
|
||||
foreach (var a in World.Selection.Actors)
|
||||
{
|
||||
@@ -272,15 +272,16 @@ namespace OpenRA.Graphics
|
||||
if (enableDepthBuffer)
|
||||
Game.Renderer.ClearDepthBuffer();
|
||||
|
||||
foreach (var a in World.ActorsWithTrait<IRenderAboveWorld>())
|
||||
if (a.Actor.IsInWorld && !a.Actor.Disposed)
|
||||
a.Trait.RenderAboveWorld(a.Actor, this);
|
||||
World.ApplyToActorsWithTrait<IRenderAboveWorld>((actor, trait) =>
|
||||
{
|
||||
if (actor.IsInWorld && !actor.Disposed)
|
||||
trait.RenderAboveWorld(actor, this);
|
||||
});
|
||||
|
||||
if (enableDepthBuffer)
|
||||
Game.Renderer.ClearDepthBuffer();
|
||||
|
||||
foreach (var a in World.ActorsWithTrait<IRenderShroud>())
|
||||
a.Trait.RenderShroud(this);
|
||||
World.ApplyToActorsWithTrait<IRenderShroud>((actor, trait) => trait.RenderShroud(this));
|
||||
|
||||
if (enableDepthBuffer)
|
||||
Game.Renderer.Context.DisableDepthBuffer();
|
||||
|
||||
@@ -427,7 +427,7 @@ namespace OpenRA
|
||||
foreach (var a in actors.Values)
|
||||
a.Tick();
|
||||
|
||||
ApplyToActorsWithTraitTimed<ITick>((Actor actor, ITick trait) => trait.Tick(actor), "Trait");
|
||||
ApplyToActorsWithTraitTimed<ITick>((actor, trait) => trait.Tick(actor), "Trait");
|
||||
|
||||
effects.DoTimed(e => e.Tick(this), "Effect");
|
||||
}
|
||||
@@ -439,7 +439,7 @@ namespace OpenRA
|
||||
// For things that want to update their render state once per tick, ignoring pause state
|
||||
public void TickRender(WorldRenderer wr)
|
||||
{
|
||||
ApplyToActorsWithTraitTimed<ITickRender>((Actor actor, ITickRender trait) => trait.TickRender(wr, actor), "Render");
|
||||
ApplyToActorsWithTraitTimed<ITickRender>((actor, trait) => trait.TickRender(wr, actor), "Render");
|
||||
ScreenMap.TickRender();
|
||||
}
|
||||
|
||||
@@ -503,6 +503,11 @@ namespace OpenRA
|
||||
TraitDict.ApplyToActorsWithTraitTimed<T>(action, text);
|
||||
}
|
||||
|
||||
public void ApplyToActorsWithTrait<T>(Action<Actor, T> action)
|
||||
{
|
||||
TraitDict.ApplyToActorsWithTrait<T>(action);
|
||||
}
|
||||
|
||||
public IEnumerable<Actor> ActorsHavingTrait<T>()
|
||||
{
|
||||
return TraitDict.ActorsHavingTrait<T>();
|
||||
|
||||
Reference in New Issue
Block a user