From ea32b1bc6d94acd33de9c2e2a6ba7e6c217ea4d0 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Wed, 4 May 2011 18:40:33 +1200 Subject: [PATCH] remove a bunch of trait lookups for PlayerResources --- OpenRA.Game/Traits/Player/PlayerResources.cs | 25 +++++++++++--------- OpenRA.Mods.RA/Player/ProductionQueue.cs | 13 +++++----- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/OpenRA.Game/Traits/Player/PlayerResources.cs b/OpenRA.Game/Traits/Player/PlayerResources.cs index 863d2c228e..a5dac670ed 100644 --- a/OpenRA.Game/Traits/Player/PlayerResources.cs +++ b/OpenRA.Game/Traits/Player/PlayerResources.cs @@ -22,37 +22,40 @@ namespace OpenRA.Traits public object Create(ActorInitializer init) { return new PlayerResources(init.self, this); } } - public class DebugResourceCashInfo : ITraitInfo + public class DebugResourceCashInfo : ITraitInfo, Requires { public object Create(ActorInitializer init) { return new DebugResourceCash(init.self); } } + public class DebugResourceCash : ISync { - readonly Actor self; - public DebugResourceCash(Actor self){this.self = self;} - [Sync] public int foo { get { return self.Trait().Cash; } } + readonly PlayerResources pr; + public DebugResourceCash(Actor self) { pr = self.Trait(); } + [Sync] public int foo { get { return pr.Cash; } } } - public class DebugResourceOreInfo : ITraitInfo + public class DebugResourceOreInfo : ITraitInfo, Requires { public object Create(ActorInitializer init) { return new DebugResourceOre(init.self); } } + public class DebugResourceOre : ISync { - readonly Actor self; - public DebugResourceOre(Actor self){this.self = self;} - [Sync] public int foo { get { return self.Trait().Ore; } } + readonly PlayerResources pr; + public DebugResourceOre(Actor self) { pr = self.Trait(); } + [Sync] public int foo { get { return pr.Ore; } } } public class DebugResourceOreCapacityInfo : ITraitInfo { public object Create(ActorInitializer init) { return new DebugResourceOreCapacity(init.self); } } + public class DebugResourceOreCapacity : ISync { - readonly Actor self; - public DebugResourceOreCapacity(Actor self){this.self = self;} - [Sync] public int foo { get { return self.Trait().OreCapacity; } } + readonly PlayerResources pr; + public DebugResourceOreCapacity(Actor self) { pr = self.Trait(); } + [Sync] public int foo { get { return pr.OreCapacity; } } } public class PlayerResources : ITick, ISync diff --git a/OpenRA.Mods.RA/Player/ProductionQueue.cs b/OpenRA.Mods.RA/Player/ProductionQueue.cs index f85e5f79da..a1738d989c 100755 --- a/OpenRA.Mods.RA/Player/ProductionQueue.cs +++ b/OpenRA.Mods.RA/Player/ProductionQueue.cs @@ -36,7 +36,7 @@ namespace OpenRA.Mods.RA public readonly Actor self; public ProductionQueueInfo Info; PowerManager PlayerPower; - PlayerResources PlayerResources; + PlayerResources playerResources; string Race; // A list of things we are currently building @@ -62,7 +62,7 @@ namespace OpenRA.Mods.RA { this.self = self; this.Info = info; - PlayerResources = playerActor.Trait(); + playerResources = playerActor.Trait(); PlayerPower = playerActor.Trait(); Race = self.Owner.Country.Race; @@ -72,7 +72,7 @@ namespace OpenRA.Mods.RA public void OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner) { PlayerPower = newOwner.PlayerActor.Trait(); - PlayerResources = newOwner.PlayerActor.Trait(); + playerResources = newOwner.PlayerActor.Trait(); Queue.Clear(); // Produceable contains the tech from the original owner - this is desired so we don't clear it. @@ -160,11 +160,11 @@ namespace OpenRA.Mods.RA { while( Queue.Count > 0 && !BuildableItems().Any(b => b.Name == Queue[ 0 ].Item) ) { - self.Owner.PlayerActor.Trait().GiveCash(Queue[0].TotalCost - Queue[0].RemainingCost); // refund what's been paid so far. + playerResources.GiveCash(Queue[0].TotalCost - Queue[0].RemainingCost); // refund what's been paid so far. FinishProduction(); } if( Queue.Count > 0 ) - Queue[ 0 ].Tick( PlayerResources, PlayerPower ); + Queue[ 0 ].Tick( playerResources, PlayerPower ); } public void ResolveOrder( Actor self, Order order ) @@ -256,8 +256,7 @@ namespace OpenRA.Mods.RA else if (lastIndex == 0) { var item = Queue[0]; - self.Owner.PlayerActor.Trait().GiveCash( - item.TotalCost - item.RemainingCost); // refund what has been paid + playerResources.GiveCash(item.TotalCost - item.RemainingCost); // refund what has been paid FinishProduction(); } }