This commit is contained in:
Chris Forbes
2009-11-04 20:40:48 +13:00
parent f84d756570
commit db89136adf
4 changed files with 53 additions and 1 deletions

View File

@@ -82,6 +82,8 @@ namespace OpenRa.Game
PlaySound("intro.aud", false);
skipMakeAnims = false;
sw = new Stopwatch();
}
static void LoadMapBuildings( IniFile mapfile )
@@ -139,6 +141,10 @@ namespace OpenRa.Game
const int oreFrequency = 1;
static int oreTicks = oreFrequency;
public static int RenderFrame = 0;
public static double RenderTime = 0.0;
public static double TickTime = 0.0;
public static Stopwatch sw;
public static void Tick()
{
@@ -146,6 +152,7 @@ namespace OpenRa.Game
int dt = t - lastTime;
if( dt >= timestep )
{
sw.Reset();
lastTime += timestep;
if( orderManager.Tick() )
@@ -163,11 +170,15 @@ namespace OpenRa.Game
foreach( var player in players.Values )
player.Tick();
}
TickTime = sw.ElapsedTime();
}
sw.Reset();
++RenderFrame;
viewport.cursor = controller.ChooseCursor();
viewport.DrawRegions();
RenderTime = sw.ElapsedTime();
}
public static bool IsCellBuildable(int2 a, UnitMovementType umt)

View File

@@ -99,7 +99,10 @@ namespace OpenRa.Game.Graphics
lineRenderer.Flush();
renderer.DrawText(string.Format("RenderFrame {0} Tick {1}", Game.RenderFrame, Game.orderManager.FrameNumber), new int2(5, 5), Color.White);
renderer.DrawText(string.Format("RenderFrame {0} ({2:F1} ms) Tick {1} ({3:F1} ms)",
Game.RenderFrame, Game.orderManager.FrameNumber,
Game.RenderTime * 1000,
Game.TickTime * 1000), new int2(5, 5), Color.White);
}
const float conditionYellow = 0.5f; /* todo: get these from gamerules */

View File

@@ -76,6 +76,7 @@
<ItemGroup>
<Compile Include="GameRules\TechTree.cs" />
<Compile Include="OrderManager.cs" />
<Compile Include="Stopwatch.cs" />
<Compile Include="Traits\AcceptsOre.cs" />
<Compile Include="Traits\Activities\Activity.cs" />
<Compile Include="Traits\Activities\DeliverOre.cs" />

37
OpenRa.Game/Stopwatch.cs Normal file
View File

@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace OpenRa.Game
{
class Stopwatch
{
[DllImport("kernel32.dll")]
static extern bool QueryPerformanceCounter(out long value);
[DllImport("kernel32.dll")]
static extern bool QueryPerformanceFrequency(out long frequency);
long freq, start;
public Stopwatch()
{
QueryPerformanceFrequency(out freq);
QueryPerformanceCounter(out start);
}
public double ElapsedTime()
{
long current;
QueryPerformanceCounter(out current);
return (current - start) / (double)freq;
}
public void Reset()
{
QueryPerformanceCounter(out start);
}
}
}