debug (timing) spam, and perf fixed on SupportPower
Build timing (un)hacked by chrisf
This commit is contained in:
@@ -28,7 +28,9 @@ namespace OpenRA.Support
|
||||
public static void Time( string message )
|
||||
{
|
||||
var time = sw.ElapsedTime();
|
||||
Log.Write( message, time - lastTime );
|
||||
var dt = time - lastTime;
|
||||
if( dt > 0.0001 )
|
||||
Log.Write( message, dt );
|
||||
lastTime = time;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.GameRules;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Support;
|
||||
|
||||
namespace OpenRA
|
||||
{
|
||||
@@ -92,5 +93,19 @@ namespace OpenRA
|
||||
var xs = ts.ToArray();
|
||||
return xs[r.Next(xs.Length)];
|
||||
}
|
||||
|
||||
public static void DoTimed<T>( this IEnumerable<T> e, Action<T> a, string text, double time )
|
||||
{
|
||||
var sw = new Stopwatch();
|
||||
|
||||
e.Do( x =>
|
||||
{
|
||||
var t = sw.ElapsedTime();
|
||||
a( x );
|
||||
var dt = sw.ElapsedTime() - t;
|
||||
if( dt > time )
|
||||
Log.Write( text, x, dt*1000 );
|
||||
} );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ namespace OpenRA.GameRules
|
||||
throw new InvalidOperationException( "Trait prerequisites not satisfied (or prerequisite loop)" );
|
||||
|
||||
var prereqs = PrerequisitesOf( t[ index ] );
|
||||
if( prereqs.Count == 0 || prereqs.All( n => ret.Any( x => x.GetType().IsSubclassOf( n ) ) ) )
|
||||
if( prereqs.Count == 0 || prereqs.All( n => ret.Any( x => x.GetType() == n || x.GetType().IsSubclassOf( n ) ) ) )
|
||||
{
|
||||
ret.Add( t[ index ] );
|
||||
t.RemoveAt( index );
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>TRACE;DEBUG;SANITY_CHECKS</DefineConstants>
|
||||
<DefineConstants>TRACE;DEBUG</DefineConstants>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
@@ -87,6 +87,7 @@
|
||||
<Compile Include="Traits\Attack\AttackLeap.cs" />
|
||||
<Compile Include="Traits\Player\ActorGroupProxy.cs" />
|
||||
<Compile Include="Traits\Player\PlayerResources.cs" />
|
||||
<Compile Include="Traits\Player\TechTreeCache.cs" />
|
||||
<Compile Include="Traits\RevealsShroud.cs" />
|
||||
<Compile Include="Traits\Player\ConquestVictoryConditions.cs" />
|
||||
<Compile Include="Traits\Modifiers\HiddenUnderFog.cs" />
|
||||
|
||||
69
OpenRA.Game/Traits/Player/TechTreeCache.cs
Executable file
69
OpenRA.Game/Traits/Player/TechTreeCache.cs
Executable 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();
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,19 +138,31 @@ namespace OpenRA
|
||||
|
||||
public void Tick()
|
||||
{
|
||||
foreach (var a in actors) a.Tick();
|
||||
Timer.Time("----World Tick");
|
||||
|
||||
Queries.WithTraitMultiple<ITick>().Do(x => x.Trait.Tick(x.Actor));
|
||||
actors.DoTimed( x => x.Tick(), "expensive actor tick: {0} ({1:0.000})", 0.001 );
|
||||
Timer.Time(" actors: {0:0.000}");
|
||||
|
||||
foreach (var e in effects) e.Tick( this );
|
||||
Queries.WithTraitMultiple<ITick>().DoTimed( x =>
|
||||
{
|
||||
x.Trait.Tick( x.Actor );
|
||||
Timer.Time( "trait tick \"{0}\": {{0}}".F( x.Trait.GetType().Name ) );
|
||||
}, "expensive trait tick: {0} ({1:0.000})", 0.001 );
|
||||
Timer.Time(" traits: {0:0.000}");
|
||||
|
||||
effects.DoTimed( e => e.Tick( this ), "expensive effect tick: {0} ({1:0.000})", 0.001 );
|
||||
Timer.Time(" effects: {0:0.000}");
|
||||
|
||||
Game.viewport.Tick();
|
||||
Timer.Time(" viewport: {0:0.000}");
|
||||
|
||||
var acts = frameEndActions;
|
||||
frameEndActions = new List<Action<World>>();
|
||||
foreach (var a in acts) a(this);
|
||||
Timer.Time(" frameEndActions: {0:0.000}");
|
||||
|
||||
WorldRenderer.Tick();
|
||||
Timer.Time(" worldrenderer: {0:0.000}");
|
||||
}
|
||||
|
||||
public IEnumerable<Actor> Actors { get { return actors; } }
|
||||
@@ -163,6 +175,8 @@ namespace OpenRA
|
||||
}
|
||||
|
||||
public int SyncHash()
|
||||
{
|
||||
//using (new PerfSample("synchash"))
|
||||
{
|
||||
int ret = 0;
|
||||
foreach (var a in Actors)
|
||||
@@ -170,6 +184,7 @@ namespace OpenRA
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
public class AllQueries
|
||||
{
|
||||
@@ -219,6 +234,11 @@ namespace OpenRA
|
||||
{
|
||||
public Actor Actor;
|
||||
public T Trait;
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "{0}->{1}".F( Actor.Info.Name, Trait.GetType().Name );
|
||||
}
|
||||
}
|
||||
|
||||
public class OwnedByCachedView : CachedView<Actor, Actor>
|
||||
|
||||
@@ -3,6 +3,7 @@ Player:
|
||||
BuildSpeed: .04
|
||||
LowPowerSlowdown: 3
|
||||
PlaceBuilding:
|
||||
TechTreeCache:
|
||||
GpsPower:
|
||||
Image: gpssicon
|
||||
OneShot: yes
|
||||
|
||||
Reference in New Issue
Block a user