moved Log, Stopwatch to FileFormats. Added Support/Timer.

This commit is contained in:
Bob
2010-01-22 15:12:25 +13:00
parent cba37055e5
commit 8fd0e35d16
5 changed files with 75 additions and 2 deletions

View File

@@ -76,6 +76,9 @@
<Compile Include="ShpReader.cs" /> <Compile Include="ShpReader.cs" />
<Compile Include="ShroudPaletteRemap.cs" /> <Compile Include="ShroudPaletteRemap.cs" />
<Compile Include="SingleColorRemap.cs" /> <Compile Include="SingleColorRemap.cs" />
<Compile Include="Support\Log.cs" />
<Compile Include="Support\Stopwatch.cs" />
<Compile Include="Support\Timer.cs" />
<Compile Include="Terrain.cs" /> <Compile Include="Terrain.cs" />
<Compile Include="TileReference.cs" /> <Compile Include="TileReference.cs" />
<Compile Include="TileSet.cs" /> <Compile Include="TileSet.cs" />

View File

@@ -0,0 +1,19 @@
using System.IO;
namespace OpenRa
{
public static class Log
{
static StreamWriter writer = File.CreateText("log.txt");
static Log()
{
writer.AutoFlush = true;
}
public static void Write(string format, params object[] args)
{
writer.WriteLine(format, args);
}
}
}

View File

@@ -0,0 +1,33 @@
using System.Runtime.InteropServices;
namespace OpenRa.Support
{
public 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);
}
}
}

View File

@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace OpenRa.Support
{
public static class Timer
{
static Stopwatch sw = new Stopwatch();
static double lastTime = 0;
public static void Time( string message )
{
var time = sw.ElapsedTime();
Log.Write( message, time - lastTime );
lastTime = time;
}
}
}

View File

@@ -133,7 +133,6 @@
<Compile Include="SupportPowers\ISupportPowerImpl.cs" /> <Compile Include="SupportPowers\ISupportPowerImpl.cs" />
<Compile Include="SupportPowers\NullPower.cs" /> <Compile Include="SupportPowers\NullPower.cs" />
<Compile Include="Support\OpenAlInterop.cs" /> <Compile Include="Support\OpenAlInterop.cs" />
<Compile Include="Support\Stopwatch.cs" />
<Compile Include="Support\PerfHistory.cs" /> <Compile Include="Support\PerfHistory.cs" />
<Compile Include="Sync.cs" /> <Compile Include="Sync.cs" />
<Compile Include="Traits\AcceptsOre.cs" /> <Compile Include="Traits\AcceptsOre.cs" />
@@ -180,7 +179,6 @@
<Compile Include="Player.cs" /> <Compile Include="Player.cs" />
<Compile Include="Race.cs" /> <Compile Include="Race.cs" />
<Compile Include="Graphics\Sheet.cs" /> <Compile Include="Graphics\Sheet.cs" />
<Compile Include="Support\Log.cs" />
<Compile Include="PathFinder.cs" /> <Compile Include="PathFinder.cs" />
<Compile Include="Graphics\Sequence.cs" /> <Compile Include="Graphics\Sequence.cs" />
<Compile Include="Orders\Order.cs" /> <Compile Include="Orders\Order.cs" />