From 6676d5984774a5266932b53a95344f897f5fbf11 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Wed, 4 May 2011 11:20:41 +1200 Subject: [PATCH] Cache IOccupySpace and IHasLocation for some free perf --- OpenRA.Game/Actor.cs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/OpenRA.Game/Actor.cs b/OpenRA.Game/Actor.cs index 31c77b87fd..99742496ed 100755 --- a/OpenRA.Game/Actor.cs +++ b/OpenRA.Game/Actor.cs @@ -25,9 +25,24 @@ namespace OpenRA public readonly World World; public readonly uint ActorID; + + IOccupySpace OccupiesSpace; + IHasLocation HasLocation; - public int2 Location { get { return Trait().TopLeft; } } - public int2 CenterLocation { get { return Trait().PxPosition; } } + public int2 Location + { get { + if (OccupiesSpace == null) + OccupiesSpace = Trait(); + return OccupiesSpace.TopLeft; + }} + + public int2 CenterLocation + { get { + if (HasLocation == null) + HasLocation = Trait(); + return HasLocation.PxPosition; + }} + [Sync] public Player Owner;