From 36c4a4b7757fad5a0f34e417bbb91eef51cd2c8b Mon Sep 17 00:00:00 2001 From: Aaron <87652897@qq.com> Date: Tue, 17 Oct 2017 16:50:12 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E4=B8=8A=E4=BC=A0=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E5=99=A8=E9=A2=91=E7=8E=87=E9=97=B4=E9=9A=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 完善上传服务器频率间隔 --- KBEngine.cs | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/KBEngine.cs b/KBEngine.cs index b2fff35..be5d105 100644 --- a/KBEngine.cs +++ b/KBEngine.cs @@ -29,6 +29,10 @@ public class KBEngineApp KBEngineArgs _args = null; + //上传服务器玩家位置信息间隔,单位毫秒 + private float updatePlayerToServerPeroid = 100.0f; + + private const int ONE_MS_TO_100_NS = 10000; // 客户端的类别 // http://www.kbengine.org/docs/programming/clientsdkprogramming.html // http://www.kbengine.org/cn/docs/programming/clientsdkprogramming.html @@ -158,6 +162,8 @@ public virtual bool initialize(KBEngineArgs args) { _args = args; + updatePlayerToServerPeroid = 1000f / args.threadUpdateHZ; + initNetwork(); // 注册事件 @@ -1923,14 +1929,15 @@ public void updatePlayerToServer() var now = DateTime.Now; TimeSpan span = now - _lastUpdateToServerTime; - if (span.Ticks < 1000000) - return; - - Entity playerEntity = player(); - if (playerEntity == null || playerEntity.inWorld == false || playerEntity.isControlled) - return; + if (span.Ticks < updatePlayerToServerPeroid * ONE_MS_TO_100_NS) + return; + + Entity playerEntity = player(); + if (playerEntity == null || playerEntity.inWorld == false || playerEntity.isControlled) + return; + + _lastUpdateToServerTime = now - (span - TimeSpan.FromTicks(Convert.ToInt64(updatePlayerToServerPeroid * ONE_MS_TO_100_NS))); - _lastUpdateToServerTime = now - (span - TimeSpan.FromTicks(1000000)); Vector3 position = playerEntity.position; Vector3 direction = playerEntity.direction;