RenderBeforeWorld/RenderAfterWorld split. still need to sort out which behavior belongs where.

This commit is contained in:
Chris Forbes
2010-07-26 18:19:39 +12:00
parent 9cf8ac0c3d
commit 69d30ac71b
17 changed files with 59 additions and 31 deletions

View File

@@ -98,6 +98,13 @@ namespace OpenRA.Graphics
Game.Renderer.Device.EnableScissor(bounds.Left, bounds.Top, bounds.Width, bounds.Height); Game.Renderer.Device.EnableScissor(bounds.Left, bounds.Top, bounds.Width, bounds.Height);
terrainRenderer.Draw(Game.viewport); terrainRenderer.Draw(Game.viewport);
if (Game.controller.orderGenerator != null)
Game.controller.orderGenerator.RenderBeforeWorld(world);
Game.Renderer.SpriteRenderer.Flush();
Game.Renderer.LineRenderer.Flush();
foreach (var image in worldSprites) foreach (var image in worldSprites)
Game.Renderer.SpriteRenderer.DrawSprite(image.Sprite, image.Pos, image.Palette); Game.Renderer.SpriteRenderer.DrawSprite(image.Sprite, image.Pos, image.Palette);
uiOverlay.Draw(world); uiOverlay.Draw(world);
@@ -105,7 +112,7 @@ namespace OpenRA.Graphics
DrawBandBox(); DrawBandBox();
if (Game.controller.orderGenerator != null) if (Game.controller.orderGenerator != null)
Game.controller.orderGenerator.Render(world); Game.controller.orderGenerator.RenderAfterWorld(world);
if (world.LocalPlayer != null) if (world.LocalPlayer != null)
world.LocalPlayer.Shroud.Draw(); world.LocalPlayer.Shroud.Draw();

View File

@@ -40,7 +40,8 @@ namespace OpenRA.Orders
} }
public virtual void Tick(World world) { } public virtual void Tick(World world) { }
public void Render(World world) { } public void RenderAfterWorld(World world) { }
public void RenderBeforeWorld(World world) { }
public string GetCursor(World world, int2 xy, MouseInput mi) { return world.Map.IsInMap(xy) ? cursor : "generic-blocked"; } public string GetCursor(World world, int2 xy, MouseInput mi) { return world.Map.IsInMap(xy) ? cursor : "generic-blocked"; }
} }

View File

@@ -14,9 +14,10 @@ namespace OpenRA
{ {
public interface IOrderGenerator public interface IOrderGenerator
{ {
IEnumerable<Order> Order( World world, int2 xy, MouseInput mi ); IEnumerable<Order> Order(World world, int2 xy, MouseInput mi);
void Tick( World world ); void Tick(World world);
void Render( World world ); void RenderBeforeWorld(World world);
string GetCursor( World world, int2 xy, MouseInput mi ); void RenderAfterWorld(World world);
string GetCursor(World world, int2 xy, MouseInput mi);
} }
} }

View File

@@ -61,11 +61,13 @@ namespace OpenRA.Orders
Game.controller.CancelInputMode(); Game.controller.CancelInputMode();
} }
public void Render( World world ) public void RenderAfterWorld( World world )
{ {
world.WorldRenderer.uiOverlay.DrawBuildingGrid( world, Building, BuildingInfo ); world.WorldRenderer.uiOverlay.DrawBuildingGrid( world, Building, BuildingInfo );
} }
public void RenderBeforeWorld(World world) { }
public string GetCursor(World world, int2 xy, MouseInput mi) { return "default"; } public string GetCursor(World world, int2 xy, MouseInput mi) { return "default"; }
} }
} }

View File

@@ -35,13 +35,18 @@ namespace OpenRA.Orders
public void Tick( World world ) {} public void Tick( World world ) {}
public void Render( World world ) public void RenderBeforeWorld(World world)
{ {
foreach (var a in Game.controller.selection.Actors) foreach (var a in Game.controller.selection.Actors)
{ foreach (var t in a.traits.WithInterface<IPreRenderSelection>())
foreach (var t in a.traits.WithInterface<IRenderSelection>()) t.RenderBeforeWorld(a);
t.Render(a); }
}
public void RenderAfterWorld( World world )
{
foreach (var a in Game.controller.selection.Actors)
foreach (var t in a.traits.WithInterface<IPostRenderSelection>())
t.RenderAfterWorld(a);
} }
public string GetCursor( World world, int2 xy, MouseInput mi ) public string GetCursor( World world, int2 xy, MouseInput mi )

View File

@@ -19,7 +19,7 @@ namespace OpenRA.Traits
public virtual object Create(ActorInitializer init) { return new DrawLineToTarget(this); } public virtual object Create(ActorInitializer init) { return new DrawLineToTarget(this); }
} }
public class DrawLineToTarget :IRenderSelection public class DrawLineToTarget :IPostRenderSelection
{ {
DrawLineToTargetInfo Info; DrawLineToTargetInfo Info;
public DrawLineToTarget(DrawLineToTargetInfo info) public DrawLineToTarget(DrawLineToTargetInfo info)
@@ -44,7 +44,7 @@ namespace OpenRA.Traits
this.c = c; this.c = c;
} }
public void Render (Actor self) public void RenderAfterWorld (Actor self)
{ {
var force = Game.controller.GetModifiers().HasModifier(Modifiers.Alt); var force = Game.controller.GetModifiers().HasModifier(Modifiers.Alt);
if ((lifetime <= 0 || --lifetime <= 0) && !force) if ((lifetime <= 0 || --lifetime <= 0) && !force)

View File

@@ -23,13 +23,13 @@ namespace OpenRA.Traits
public readonly float Radius = 10; public readonly float Radius = 10;
} }
public class Selectable : IRenderSelection public class Selectable : IPostRenderSelection
{ {
// depends on the order of pips in TraitsInterfaces.cs! // depends on the order of pips in TraitsInterfaces.cs!
static readonly string[] pipStrings = { "pip-empty", "pip-green", "pip-yellow", "pip-red", "pip-gray" }; static readonly string[] pipStrings = { "pip-empty", "pip-green", "pip-yellow", "pip-red", "pip-gray" };
static readonly string[] tagStrings = { "", "tag-fake", "tag-primary" }; static readonly string[] tagStrings = { "", "tag-fake", "tag-primary" };
public void Render (Actor self) public void RenderAfterWorld (Actor self)
{ {
var bounds = self.GetBounds(true); var bounds = self.GetBounds(true);

View File

@@ -165,7 +165,8 @@ namespace OpenRA.Traits
public interface IBlocksBullets { } public interface IBlocksBullets { }
public interface IRenderSelection { void Render(Actor self); } public interface IPostRenderSelection { void RenderAfterWorld(Actor self); }
public interface IPreRenderSelection { void RenderBeforeWorld(Actor self); }
public struct Target // a target: either an actor, or a fixed location. public struct Target // a target: either an actor, or a fixed location.
{ {

View File

@@ -26,7 +26,7 @@ namespace OpenRA.Mods.RA
public readonly string[] RearmBuildings = { "fix" }; public readonly string[] RearmBuildings = { "fix" };
} }
class Minelayer : IIssueOrder, IResolveOrder, IOrderCursor, IRenderSelection class Minelayer : IIssueOrder, IResolveOrder, IOrderCursor, IPostRenderSelection
{ {
/* [Sync] when sync can cope with arrays! */ /* [Sync] when sync can cope with arrays! */
public int2[] minefield = null; public int2[] minefield = null;
@@ -120,7 +120,7 @@ namespace OpenRA.Mods.RA
} }
int2 lastMousePos; int2 lastMousePos;
public void Render(World world) public void RenderAfterWorld(World world)
{ {
var ml = minelayer.traits.Get<Minelayer>(); var ml = minelayer.traits.Get<Minelayer>();
var movement = minelayer.traits.Get<IMove>(); var movement = minelayer.traits.Get<IMove>();
@@ -130,10 +130,12 @@ namespace OpenRA.Mods.RA
Game.world.WorldRenderer.DrawLocus(Color.Cyan, minefield); Game.world.WorldRenderer.DrawLocus(Color.Cyan, minefield);
} }
public void RenderBeforeWorld(World world) { }
public string GetCursor(World world, int2 xy, MouseInput mi) { lastMousePos = xy; return "ability"; } /* todo */ public string GetCursor(World world, int2 xy, MouseInput mi) { lastMousePos = xy; return "ability"; } /* todo */
} }
public void Render(Actor self) public void RenderAfterWorld(Actor self)
{ {
if (self.Owner != self.World.LocalPlayer) if (self.Owner != self.World.LocalPlayer)
return; return;

View File

@@ -38,7 +38,8 @@ namespace OpenRA.Mods.RA.Orders
} }
public void Tick(World world) { } public void Tick(World world) { }
public void Render(World world) { } public void RenderAfterWorld(World world) { }
public void RenderBeforeWorld(World world) { }
public string GetCursor(World world, int2 xy, MouseInput mi) public string GetCursor(World world, int2 xy, MouseInput mi)
{ {

View File

@@ -53,7 +53,8 @@ namespace OpenRA.Mods.RA.Orders
.Any(); .Any();
} }
public void Render( World world ) {} public void RenderAfterWorld( World world ) {}
public void RenderBeforeWorld(World world) { }
public string GetCursor(World world, int2 xy, MouseInput mi) public string GetCursor(World world, int2 xy, MouseInput mi)
{ {

View File

@@ -41,7 +41,8 @@ namespace OpenRA.Mods.RA.Orders
} }
public void Tick( World world ) {} public void Tick( World world ) {}
public void Render( World world ) {} public void RenderAfterWorld( World world ) {}
public void RenderBeforeWorld(World world) { }
public string GetCursor(World world, int2 xy, MouseInput mi) public string GetCursor(World world, int2 xy, MouseInput mi)
{ {

View File

@@ -36,11 +36,13 @@ namespace OpenRA.Mods.RA.Orders
} }
public void Tick( World world ) { } public void Tick( World world ) { }
public void Render( World world ) public void RenderAfterWorld( World world )
{ {
world.WorldRenderer.DrawSelectionBox(self, Color.White); world.WorldRenderer.DrawSelectionBox(self, Color.White);
} }
public void RenderBeforeWorld(World world) { }
public string GetCursor(World world, int2 xy, MouseInput mi) public string GetCursor(World world, int2 xy, MouseInput mi)
{ {
if (!world.LocalPlayer.Shroud.IsExplored(xy)) if (!world.LocalPlayer.Shroud.IsExplored(xy))

View File

@@ -14,9 +14,9 @@ using OpenRA.Traits;
namespace OpenRA.Mods.RA namespace OpenRA.Mods.RA
{ {
class RenderDetectionCircleInfo : TraitInfo<RenderDetectionCircle> { } class RenderDetectionCircleInfo : TraitInfo<RenderDetectionCircle> { }
class RenderDetectionCircle : IRenderSelection class RenderDetectionCircle : IPostRenderSelection
{ {
public void Render(Actor self) public void RenderAfterWorld(Actor self)
{ {
if (self.Owner != self.World.LocalPlayer) if (self.Owner != self.World.LocalPlayer)
return; return;

View File

@@ -14,9 +14,9 @@ using OpenRA.Traits;
namespace OpenRA.Mods.RA namespace OpenRA.Mods.RA
{ {
class RenderRangeCircleInfo : TraitInfo<RenderRangeCircle> { } class RenderRangeCircleInfo : TraitInfo<RenderRangeCircle> { }
class RenderRangeCircle : IRenderSelection class RenderRangeCircle : IPostRenderSelection
{ {
public void Render(Actor self) public void RenderAfterWorld(Actor self)
{ {
if (self.Owner != self.World.LocalPlayer) if (self.Owner != self.World.LocalPlayer)
return; return;

View File

@@ -93,7 +93,8 @@ namespace OpenRA.Mods.RA
// TODO: Check if the selected unit is still alive // TODO: Check if the selected unit is still alive
} }
public void Render( World world ) { } public void RenderAfterWorld( World world ) { }
public void RenderBeforeWorld(World world) { }
public string GetCursor(World world, int2 xy, MouseInput mi) public string GetCursor(World world, int2 xy, MouseInput mi)
{ {
@@ -133,11 +134,13 @@ namespace OpenRA.Mods.RA
// TODO: Check if the selected unit is still alive // TODO: Check if the selected unit is still alive
} }
public void Render(World world) public void RenderAfterWorld(World world)
{ {
world.WorldRenderer.DrawSelectionBox(self, Color.Red); world.WorldRenderer.DrawSelectionBox(self, Color.Red);
} }
public void RenderBeforeWorld(World world) { }
public string GetCursor(World world, int2 xy, MouseInput mi) public string GetCursor(World world, int2 xy, MouseInput mi)
{ {
if (!world.LocalPlayer.Shroud.IsExplored(xy)) if (!world.LocalPlayer.Shroud.IsExplored(xy))

View File

@@ -95,7 +95,8 @@ namespace OpenRA.Mods.RA
Game.controller.CancelInputMode(); Game.controller.CancelInputMode();
} }
public void Render(World world) { } public void RenderAfterWorld(World world) { }
public void RenderBeforeWorld(World world) { }
public string GetCursor(World world, int2 xy, MouseInput mi) public string GetCursor(World world, int2 xy, MouseInput mi)
{ {