mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
[+] 接入ET8服务端
[+] 接入ET8服务端
This commit is contained in:
75
Assets/GameScripts/DotNet/Core/Fiber/TimeInfo.cs
Normal file
75
Assets/GameScripts/DotNet/Core/Fiber/TimeInfo.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
using System;
|
||||
|
||||
namespace ET
|
||||
{
|
||||
public class TimeInfo
|
||||
{
|
||||
private int timeZone;
|
||||
|
||||
public int TimeZone
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.timeZone;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.timeZone = value;
|
||||
dt = dt1970.AddHours(TimeZone);
|
||||
}
|
||||
}
|
||||
|
||||
private DateTime dt1970;
|
||||
private DateTime dt;
|
||||
|
||||
public long ServerMinusClientTime { private get; set; }
|
||||
|
||||
public long FrameTime;
|
||||
|
||||
public TimeInfo()
|
||||
{
|
||||
this.dt1970 = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
|
||||
this.dt = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
|
||||
this.FrameTime = this.ClientNow();
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
this.FrameTime = this.ClientNow();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据时间戳获取时间
|
||||
/// </summary>
|
||||
public DateTime ToDateTime(long timeStamp)
|
||||
{
|
||||
return dt.AddTicks(timeStamp * 10000);
|
||||
}
|
||||
|
||||
// 线程安全
|
||||
public long ClientNow()
|
||||
{
|
||||
return (DateTime.UtcNow.Ticks - this.dt1970.Ticks) / 10000;
|
||||
}
|
||||
|
||||
public long ServerNow()
|
||||
{
|
||||
return ClientNow() + this.ServerMinusClientTime;
|
||||
}
|
||||
|
||||
public long ClientFrameTime()
|
||||
{
|
||||
return this.FrameTime;
|
||||
}
|
||||
|
||||
public long ServerFrameTime()
|
||||
{
|
||||
return this.FrameTime + this.ServerMinusClientTime;
|
||||
}
|
||||
|
||||
public long Transition(DateTime d)
|
||||
{
|
||||
return (d.Ticks - dt.Ticks) / 10000;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user