debug (timing) spam, and perf fixed on SupportPower

Build timing (un)hacked by chrisf
This commit is contained in:
Bob
2010-05-16 17:27:19 +12:00
committed by Chris Forbes
parent de9ec12c8c
commit 7deefc5246
8 changed files with 136 additions and 23 deletions

View File

@@ -0,0 +1,69 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenRA.GameRules;
using OpenRA.FileFormats;
namespace OpenRA.Traits
{
class TechTreeCacheInfo : TraitInfo<TechTreeCache> { }
class TechTreeCache : ITick
{
class Watcher
{
public readonly List<ActorInfo> prerequisites;
public readonly ITechTreeElement watcher;
bool hasPrerequisites;
public Watcher(List<ActorInfo> prerequisites, ITechTreeElement watcher)
{
this.prerequisites = prerequisites;
this.watcher = watcher;
this.hasPrerequisites = false;
}
public void Tick( Player owner, Cache<string, List<Actor>> buildings )
{
var effectivePrereq = prerequisites.Where( a => a.Traits.Get<BuildableInfo>().Owner.Contains( owner.Country.Race ) );
var nowHasPrerequisites = effectivePrereq.Any() &&
effectivePrereq.All( a => buildings[ a.Name ].Any( b => !b.traits.Get<Building>().Disabled ) );
if( nowHasPrerequisites && !hasPrerequisites )
watcher.Available();
if( !nowHasPrerequisites && hasPrerequisites )
watcher.Unavailable();
hasPrerequisites = nowHasPrerequisites;
}
}
readonly List<Watcher> watchers = new List<Watcher>();
public void Tick( Actor self )
{
var buildings = Rules.TechTree.GatherBuildings( self.Owner );
foreach( var w in watchers )
w.Tick( self.Owner, buildings );
}
public void Add( List<ActorInfo> prerequisites, ITechTreeElement tte )
{
watchers.Add( new Watcher( prerequisites, tte ) );
}
public void Remove( ITechTreeElement tte )
{
watchers.RemoveAll( x => x.watcher == tte );
}
}
interface ITechTreeElement
{
void Available();
void Unavailable();
}
}

View File

@@ -22,7 +22,7 @@ using System.Linq;
namespace OpenRA.Traits
{
public abstract class SupportPowerInfo : ITraitInfo
public abstract class SupportPowerInfo : ITraitInfo, ITraitPrerequisite<TechTreeCacheInfo>
{
public readonly bool RequiresPower = true;
public readonly bool OneShot = false;
@@ -46,7 +46,7 @@ namespace OpenRA.Traits
public SupportPowerInfo() { OrderName = GetType().Name + "Order"; }
}
public class SupportPower : ITick
public class SupportPower : ITick, ITechTreeElement
{
public readonly SupportPowerInfo Info;
public int RemainingTime { get; private set; }
@@ -64,6 +64,8 @@ namespace OpenRA.Traits
Info = info;
RemainingTime = TotalTime;
Owner = self.Owner;
self.traits.Get<TechTreeCache>().Add( Info.Prerequisites.Select( a => Rules.Info[ a.ToLowerInvariant() ] ).ToList(), this );
}
public void Tick(Actor self)
@@ -71,17 +73,8 @@ namespace OpenRA.Traits
if (Info.OneShot && IsUsed)
return;
var buildings = Rules.TechTree.GatherBuildings(self.Owner);
var effectivePrereq = Info.Prerequisites
.Select(a => a.ToLowerInvariant())
.Where(a => Rules.Info[a].Traits.Get<BuildableInfo>().Owner.Contains(self.Owner.Country.Race));
if (Info.GivenAuto)
{
IsAvailable = Info.TechLevel > -1
&& effectivePrereq.Any()
&& effectivePrereq.All(a => buildings[a].Count > 0);
}
IsAvailable = Info.TechLevel > -1 && hasPrerequisites;
if (IsAvailable && (!Info.RequiresPower || IsPowered()))
{
@@ -157,5 +150,17 @@ namespace OpenRA.Traits
Sound.PlayToPlayer(Owner, Info.SelectTargetSound);
OnActivate();
}
bool hasPrerequisites;
public void Available()
{
hasPrerequisites = true;
}
public void Unavailable()
{
hasPrerequisites = false;
}
}
}