mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-27 02:36:14 +00:00
提交
This commit is contained in:
@@ -77,7 +77,7 @@ namespace Plugins.JNGame.Network
|
||||
private void Onbinary(WebSocket websocket, byte[] data)
|
||||
{
|
||||
|
||||
NSystem.Log($"[JNSocket] Onbinary");
|
||||
// NSystem.Log($"[JNSocket] Onbinary");
|
||||
Dispatch(NDataUtil.Parse(data));
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9606b3aa4a2d4390890ae975ea7567d3
|
||||
timeCreated: 1707030980
|
@@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Plugins.JNGame.Util;
|
||||
|
||||
namespace Plugins.JNGame.Sync.Frame.game.Time
|
||||
{
|
||||
|
||||
|
||||
public class JNFrameTimeHandler
|
||||
{
|
||||
public int ID;
|
||||
public Action Handler;
|
||||
public int Timeout;
|
||||
}
|
||||
|
||||
//帧同步定时器
|
||||
public class JNFrameTime : Singleton<JNFrameTime>
|
||||
{
|
||||
|
||||
private int _id = 0;
|
||||
private List<JNFrameTimeHandler> _handlers = new();
|
||||
|
||||
//设置定时器
|
||||
public int SetTimeout(Action handler,int timeout = 0)
|
||||
{
|
||||
var funHandler = new JNFrameTimeHandler()
|
||||
{
|
||||
ID = this._id++,
|
||||
Handler = handler,
|
||||
Timeout = timeout
|
||||
};
|
||||
this._handlers.Add(funHandler);
|
||||
return funHandler.ID;
|
||||
}
|
||||
|
||||
public void Update(int dt)
|
||||
{
|
||||
|
||||
this._handlers.ToList().ForEach(action =>
|
||||
{
|
||||
action.Timeout -= dt;
|
||||
if (action.Timeout <= 0)
|
||||
{
|
||||
action.Handler();
|
||||
this._handlers.Remove(action);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d96b5b6d30384c7482ce18479c06ebfb
|
||||
timeCreated: 1707030984
|
@@ -7,6 +7,7 @@ using Cysharp.Threading.Tasks;
|
||||
using Google.Protobuf;
|
||||
using Plugins.JNGame.Sync.Frame.Entity;
|
||||
using Plugins.JNGame.Sync.Frame.game;
|
||||
using Plugins.JNGame.Sync.Frame.game.Time;
|
||||
using Plugins.JNGame.System;
|
||||
using Plugins.JNGame.Util;
|
||||
using UnityEngine;
|
||||
@@ -33,7 +34,7 @@ namespace Plugins.JNGame.Sync.Frame
|
||||
//大于多少帧进行快速追帧
|
||||
private int _nMaxFrameLoopBan = 18;
|
||||
//将服务器帧数进行平分
|
||||
private int _nDivideFrame = 3;
|
||||
private int _nDivideFrame = 2;
|
||||
|
||||
public int NSyncTime => _nSyncTime;
|
||||
public int NMaxFrameBan => _nMaxFrameBan;
|
||||
@@ -85,6 +86,10 @@ namespace Plugins.JNGame.Sync.Frame
|
||||
int dtTotal = 0;
|
||||
//输入更新
|
||||
int dtInputTotal = 0;
|
||||
|
||||
//是否在追帧
|
||||
private Boolean _isLoop = false;
|
||||
public bool IsLoop => _isLoop;
|
||||
|
||||
public JNTime Time => (new JNTime(this));
|
||||
|
||||
@@ -122,7 +127,10 @@ namespace Plugins.JNGame.Sync.Frame
|
||||
this.dtInputTotal = 0;
|
||||
this._isRequestServerData = false;
|
||||
|
||||
Physics.SyncTransforms();
|
||||
//清除定时器
|
||||
SingletonUtil<JNFrameTime>.Clean();
|
||||
|
||||
// Physics.SyncTransforms();
|
||||
EventDispatcher.Event.Dispatch(JNSyncFrameEvent.CREATE);
|
||||
|
||||
}
|
||||
@@ -140,6 +148,7 @@ namespace Plugins.JNGame.Sync.Frame
|
||||
|
||||
if(nSyncTime > 0){
|
||||
while(nSyncTime != 0 && this.dtTotal > nSyncTime){
|
||||
this._isLoop = false;
|
||||
this.OnUpdate();
|
||||
this.dtTotal -= nSyncTime;
|
||||
nSyncTime = this.DyTime();
|
||||
@@ -147,7 +156,9 @@ namespace Plugins.JNGame.Sync.Frame
|
||||
}else{
|
||||
//追帧运行 保持前端 15 帧 刷新
|
||||
long endTime = (new DateTimeOffset(DateTime.UtcNow).ToUnixTimeMilliseconds()) + 66;
|
||||
while(this.DyTime() == 0 && (new DateTimeOffset(DateTime.UtcNow).ToUnixTimeMilliseconds()) < endTime){
|
||||
while(this.DyTime() == 0 && (new DateTimeOffset(DateTime.UtcNow).ToUnixTimeMilliseconds()) < endTime)
|
||||
{
|
||||
this._isLoop = true;
|
||||
this.OnUpdate();
|
||||
}
|
||||
dtTotal = 0;
|
||||
@@ -211,7 +222,7 @@ namespace Plugins.JNGame.Sync.Frame
|
||||
inputs[message.NId] = message;
|
||||
}
|
||||
|
||||
Debug.Log(inputs.Count);
|
||||
// Debug.Log(inputs.Count);
|
||||
|
||||
//运行之前帧
|
||||
this._nSyncActors.ToList().ForEach(child =>
|
||||
@@ -243,9 +254,11 @@ namespace Plugins.JNGame.Sync.Frame
|
||||
}
|
||||
});
|
||||
|
||||
//执行下一帧物理
|
||||
Physics.Simulate((float)dt / 1000);
|
||||
Physics.SyncTransforms();
|
||||
//执行定时器
|
||||
SingletonUtil<JNFrameTime>.Instance.Update(dt);
|
||||
// //执行下一帧物理
|
||||
// Physics.Simulate((float)dt / 1000);
|
||||
// Physics.SyncTransforms();
|
||||
|
||||
|
||||
}
|
||||
|
@@ -15,7 +15,8 @@
|
||||
|
||||
public static void Clean()
|
||||
{
|
||||
Singleton<T>.ins.Clean();
|
||||
if(Singleton<T>.ins != null)
|
||||
Singleton<T>.ins.Clean();
|
||||
Singleton<T>.ins = null;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user