mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
[+] GameTickWacher
[+] GameTickWacher
This commit is contained in:
@@ -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()}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 7320165f7aa147a998a30fe2f7a5a5c2
|
||||||
|
timeCreated: 1681989139
|
@@ -2,9 +2,14 @@
|
|||||||
|
|
||||||
namespace GameBase
|
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;
|
private static T _instance;
|
||||||
|
|
||||||
public static T Instance
|
public static T Instance
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
@@ -19,4 +24,4 @@ namespace GameBase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user