Skip to content

Commit d8dbbb8

Browse files
authored
Merge pull request #16 from zjsjmvn/master
完善客户端上传服务器数据间隔
2 parents f516fcd + 36c4a4b commit d8dbbb8

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

KBEngine.cs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ public class KBEngineApp
2929

3030
KBEngineArgs _args = null;
3131

32+
//上传服务器玩家位置信息间隔,单位毫秒
33+
private float updatePlayerToServerPeroid = 100.0f;
34+
35+
private const int ONE_MS_TO_100_NS = 10000;
3236
// 客户端的类别
3337
// http://www.kbengine.org/docs/programming/clientsdkprogramming.html
3438
// http://www.kbengine.org/cn/docs/programming/clientsdkprogramming.html
@@ -158,6 +162,8 @@ public virtual bool initialize(KBEngineArgs args)
158162
{
159163
_args = args;
160164

165+
updatePlayerToServerPeroid = 1000f / args.threadUpdateHZ;
166+
161167
initNetwork();
162168

163169
// 注册事件
@@ -1923,14 +1929,15 @@ public void updatePlayerToServer()
19231929
var now = DateTime.Now;
19241930
TimeSpan span = now - _lastUpdateToServerTime;
19251931

1926-
if (span.Ticks < 1000000)
1927-
return;
1928-
1929-
Entity playerEntity = player();
1930-
if (playerEntity == null || playerEntity.inWorld == false || playerEntity.isControlled)
1931-
return;
1932+
if (span.Ticks < updatePlayerToServerPeroid * ONE_MS_TO_100_NS)
1933+
return;
1934+
1935+
Entity playerEntity = player();
1936+
if (playerEntity == null || playerEntity.inWorld == false || playerEntity.isControlled)
1937+
return;
1938+
1939+
_lastUpdateToServerTime = now - (span - TimeSpan.FromTicks(Convert.ToInt64(updatePlayerToServerPeroid * ONE_MS_TO_100_NS)));
19321940

1933-
_lastUpdateToServerTime = now - (span - TimeSpan.FromTicks(1000000));
19341941

19351942
Vector3 position = playerEntity.position;
19361943
Vector3 direction = playerEntity.direction;

0 commit comments

Comments
 (0)