Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f765becf06 | |||
| 9acc18e1fa |
@@ -36,6 +36,25 @@ namespace GameDevLibrary.Helpers
|
|||||||
return stopwatch.ElapsedMilliseconds;
|
return stopwatch.ElapsedMilliseconds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static long RecordAndSaveToResults(string key, Action actionToRecord)
|
||||||
|
{
|
||||||
|
var stopwatch = new Stopwatch();
|
||||||
|
stopwatch.Start();
|
||||||
|
|
||||||
|
actionToRecord.Invoke();
|
||||||
|
|
||||||
|
stopwatch.Stop();
|
||||||
|
|
||||||
|
if (!_benchmarks.ContainsKey(key))
|
||||||
|
{
|
||||||
|
_benchmarks[key] = new List<long>();
|
||||||
|
}
|
||||||
|
|
||||||
|
_benchmarks[key].Add(stopwatch.ElapsedMilliseconds);
|
||||||
|
|
||||||
|
return stopwatch.ElapsedMilliseconds;
|
||||||
|
}
|
||||||
|
|
||||||
public static void Start(string key)
|
public static void Start(string key)
|
||||||
{
|
{
|
||||||
GetStopwatch(key).Restart();
|
GetStopwatch(key).Restart();
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace GameDevLibrary.Models
|
||||||
|
{
|
||||||
|
public abstract class InstancedObject<T> where T : class
|
||||||
|
{
|
||||||
|
public static T Instance { get; private set; }
|
||||||
|
|
||||||
|
protected InstancedObject()
|
||||||
|
{
|
||||||
|
if (Instance != null)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException($"An instance of {typeof(T).Name} already exists.");
|
||||||
|
}
|
||||||
|
|
||||||
|
Instance = this as T;
|
||||||
|
if (Instance == null)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException($"Failed to cast {GetType().Name} to {typeof(T).Name}.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
~InstancedObject()
|
||||||
|
{
|
||||||
|
if (Instance == this)
|
||||||
|
{
|
||||||
|
Instance = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user