16
16
包括网络创建、持久化协议、entities的管理、以及引起对外可调用接口。
17
17
18
18
一些可以参考的地方:
19
- http://www. kbengine.org /docs/programming/clientsdkprogramming.html
20
- http://www. kbengine.org /docs/programming/kbe_message_format.html
19
+ http://kbengine.github.io /docs/programming/clientsdkprogramming.html
20
+ http://kbengine.github.io /docs/programming/kbe_message_format.html
21
21
22
- http://www. kbengine.org /cn/docs/programming/clientsdkprogramming.html
23
- http://www. kbengine.org /cn/docs/programming/kbe_message_format.html
22
+ http://kbengine.github.io /cn/docs/programming/clientsdkprogramming.html
23
+ http://kbengine.github.io /cn/docs/programming/kbe_message_format.html
24
24
*/
25
25
public class KBEngineApp
26
26
{
@@ -30,8 +30,8 @@ public class KBEngineApp
30
30
KBEngineArgs _args = null ;
31
31
32
32
// 客户端的类别
33
- // http://www. kbengine.org /docs/programming/clientsdkprogramming.html
34
- // http://www. kbengine.org /cn/docs/programming/clientsdkprogramming.html
33
+ // http://kbengine.github.io /docs/programming/clientsdkprogramming.html
34
+ // http://kbengine.github.io /cn/docs/programming/clientsdkprogramming.html
35
35
public enum CLIENT_TYPE
36
36
{
37
37
// Mobile(Phone, Pad)
@@ -77,7 +77,7 @@ public enum CLIENT_TYPE
77
77
78
78
// 服务端与客户端的版本号以及协议MD5
79
79
public string serverVersion = "" ;
80
- public string clientVersion = "1.1.9 " ;
80
+ public string clientVersion = "1.1.10 " ;
81
81
public string serverScriptVersion = "" ;
82
82
public string clientScriptVersion = "0.1.0" ;
83
83
public string serverProtocolMD5 = "4930E6C01028CE4D5B3CE228CA841378" ;
@@ -112,6 +112,10 @@ public enum CLIENT_TYPE
112
112
private System . DateTime _lastTickCBTime = System . DateTime . Now ;
113
113
private System . DateTime _lastUpdateToServerTime = System . DateTime . Now ;
114
114
115
+ //上传玩家信息到服务器间隔,单位毫秒
116
+ private float _updatePlayerToServerPeroid = 100.0f ;
117
+ private const int _1MS_TO_100NS = 10000 ;
118
+
115
119
// 玩家当前所在空间的id, 以及空间对应的资源
116
120
public UInt32 spaceID = 0 ;
117
121
public string spaceResPath = "" ;
@@ -133,7 +137,8 @@ public KBEngineApp(KBEngineArgs args)
133
137
public virtual bool initialize ( KBEngineArgs args )
134
138
{
135
139
_args = args ;
136
-
140
+ _updatePlayerToServerPeroid = ( float ) _args . syncPlayerMS ;
141
+
137
142
EntityDef . init ( ) ;
138
143
139
144
initNetwork ( ) ;
@@ -551,7 +556,10 @@ private void onLogin_baseapp()
551
556
一些移动类应用容易掉线,可以使用该功能快速的重新与服务端建立通信
552
557
*/
553
558
public void reloginBaseapp ( )
554
- {
559
+ {
560
+ _lastTickTime = System . DateTime . Now ;
561
+ _lastTickCBTime = System . DateTime . Now ;
562
+
555
563
if ( _networkInterface . valid ( ) )
556
564
return ;
557
565
@@ -1274,26 +1282,26 @@ public void Client_onControlEntity(Int32 eid, sbyte isControlled)
1274
1282
}
1275
1283
1276
1284
/*
1277
- 更新当前玩家的位置与朝向到服务端, 可以通过开关_syncPlayer关闭这个机制
1285
+ 更新当前玩家的位置与朝向到服务端, 可以通过开关_syncPlayerMS关闭这个机制
1278
1286
*/
1279
1287
public void updatePlayerToServer ( )
1280
1288
{
1281
- if ( ! _args . syncPlayer || spaceID == 0 )
1289
+ if ( _updatePlayerToServerPeroid <= 0.01f || spaceID == 0 )
1282
1290
{
1283
1291
return ;
1284
1292
}
1285
1293
1286
1294
var now = DateTime . Now ;
1287
1295
TimeSpan span = now - _lastUpdateToServerTime ;
1288
1296
1289
- if ( span . Ticks < 1000000 )
1290
- return ;
1297
+ if ( span . Ticks < _updatePlayerToServerPeroid * _1MS_TO_100NS )
1298
+ return ;
1291
1299
1292
1300
Entity playerEntity = player ( ) ;
1293
1301
if ( playerEntity == null || playerEntity . inWorld == false || playerEntity . isControlled )
1294
1302
return ;
1295
1303
1296
- _lastUpdateToServerTime = now - ( span - TimeSpan . FromTicks ( 1000000 ) ) ;
1304
+ _lastUpdateToServerTime = now - ( span - TimeSpan . FromTicks ( Convert . ToInt64 ( _updatePlayerToServerPeroid * _1MS_TO_100NS ) ) ) ;
1297
1305
1298
1306
Vector3 position = playerEntity . position ;
1299
1307
Vector3 direction = playerEntity . direction ;
0 commit comments