[+] GameTickWacher

[+] GameTickWacher
This commit is contained in:
ALEXTANG
2023-04-20 19:34:01 +08:00
parent 385d789c96
commit 069c5b93e0
4 changed files with 50 additions and 2 deletions

View File

@@ -0,0 +1,40 @@
using TEngine;
namespace GameBase
{
/// <summary>
/// 用来在多线程下检测耗时。
/// </summary>
public struct GameTickWatcher
{
private long _startTick;
public GameTickWatcher()
{
_startTick = System.DateTime.Now.Ticks;
}
public void Refresh()
{
_startTick = System.DateTime.Now.Ticks;
}
/// <summary>
/// 获取用时。
/// </summary>
/// <returns></returns>
public float ElapseTime()
{
long endTick = System.DateTime.Now.Ticks;
return (float)((endTick - _startTick) / 10000) / 1000.0f;
}
/// <summary>
/// 输出用时。
/// </summary>
public void LogUsedTime()
{
Log.Info($"Used Time: {this.ElapseTime()}");
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 7320165f7aa147a998a30fe2f7a5a5c2
timeCreated: 1681989139

View File

@@ -2,9 +2,14 @@
namespace GameBase
{
public class Singleton<T> where T:new()
/// <summary>
/// 通用单例。
/// </summary>
/// <typeparam name="T">泛型T。</typeparam>
public class Singleton<T> where T : new()
{
private static T _instance;
public static T Instance
{
get
@@ -19,4 +24,4 @@ namespace GameBase
}
}
}
}
}