Skip to content

Commit f779129

Browse files
committed
up
1 parent 09c55dd commit f779129

File tree

5 files changed

+36
-25
lines changed

5 files changed

+36
-25
lines changed

Assets/Plugins/kbengine/kbengine_unity3d_plugins/EntityDef.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,6 +1166,7 @@ public static void initScriptModules()
11661166

11671167
//Dbg.DEBUG_MSG("EntityDef::initScriptModules: add(NPC), property(utype / 41005).");
11681168

1169+
pNPCModule.useMethodDescrAlias = true;
11691170
ScriptModule pGateModule = new ScriptModule("Gate");
11701171
EntityDef.moduledefs["Gate"] = pGateModule;
11711172
EntityDef.idmoduledefs[5] = pGateModule;
@@ -1302,6 +1303,7 @@ public static void initScriptModules()
13021303

13031304
//Dbg.DEBUG_MSG("EntityDef::initScriptModules: add(Gate), property(utype / 41005).");
13041305

1306+
pGateModule.useMethodDescrAlias = true;
13051307
}
13061308

13071309
public static void initDefTypes()

Assets/Plugins/kbengine/kbengine_unity3d_plugins/KBEMain.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class KBEMain : MonoBehaviour
1818
public string ip = "127.0.0.1";
1919
public int port = 20013;
2020
public KBEngineApp.CLIENT_TYPE clientType = KBEngineApp.CLIENT_TYPE.CLIENT_TYPE_MINI;
21-
public bool syncPlayer = true;
21+
public int syncPlayerMS = 100;
2222
public int threadUpdateHZ = 10;
2323
public int serverHeartbeatTick = 15;
2424
public int SEND_BUFFER_MAX = (int)KBEngine.NetworkInterface.TCP_PACKET_MAX;
@@ -54,7 +54,7 @@ public virtual void initKBEngine()
5454
args.ip = ip;
5555
args.port = port;
5656
args.clientType = clientType;
57-
args.syncPlayer = syncPlayer;
57+
args.syncPlayerMS = syncPlayerMS;
5858
args.threadUpdateHZ = threadUpdateHZ;
5959
args.serverHeartbeatTick = serverHeartbeatTick;
6060
args.useAliasEntityID = useAliasEntityID;

Assets/Plugins/kbengine/kbengine_unity3d_plugins/KBEngine.cs

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
包括网络创建、持久化协议、entities的管理、以及引起对外可调用接口。
1717
1818
一些可以参考的地方:
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
2121
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
2424
*/
2525
public class KBEngineApp
2626
{
@@ -30,8 +30,8 @@ public class KBEngineApp
3030
KBEngineArgs _args = null;
3131

3232
// 客户端的类别
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
3535
public enum CLIENT_TYPE
3636
{
3737
// Mobile(Phone, Pad)
@@ -77,7 +77,7 @@ public enum CLIENT_TYPE
7777

7878
// 服务端与客户端的版本号以及协议MD5
7979
public string serverVersion = "";
80-
public string clientVersion = "1.1.9";
80+
public string clientVersion = "1.1.10";
8181
public string serverScriptVersion = "";
8282
public string clientScriptVersion = "0.1.0";
8383
public string serverProtocolMD5 = "4930E6C01028CE4D5B3CE228CA841378";
@@ -112,6 +112,10 @@ public enum CLIENT_TYPE
112112
private System.DateTime _lastTickCBTime = System.DateTime.Now;
113113
private System.DateTime _lastUpdateToServerTime = System.DateTime.Now;
114114

115+
//上传玩家信息到服务器间隔,单位毫秒
116+
private float _updatePlayerToServerPeroid = 100.0f;
117+
private const int _1MS_TO_100NS = 10000;
118+
115119
// 玩家当前所在空间的id, 以及空间对应的资源
116120
public UInt32 spaceID = 0;
117121
public string spaceResPath = "";
@@ -133,7 +137,8 @@ public KBEngineApp(KBEngineArgs args)
133137
public virtual bool initialize(KBEngineArgs args)
134138
{
135139
_args = args;
136-
140+
_updatePlayerToServerPeroid = (float)_args.syncPlayerMS;
141+
137142
EntityDef.init();
138143

139144
initNetwork();
@@ -551,7 +556,10 @@ private void onLogin_baseapp()
551556
一些移动类应用容易掉线,可以使用该功能快速的重新与服务端建立通信
552557
*/
553558
public void reloginBaseapp()
554-
{
559+
{
560+
_lastTickTime = System.DateTime.Now;
561+
_lastTickCBTime = System.DateTime.Now;
562+
555563
if(_networkInterface.valid())
556564
return;
557565

@@ -1274,26 +1282,26 @@ public void Client_onControlEntity(Int32 eid, sbyte isControlled)
12741282
}
12751283

12761284
/*
1277-
更新当前玩家的位置与朝向到服务端, 可以通过开关_syncPlayer关闭这个机制
1285+
更新当前玩家的位置与朝向到服务端, 可以通过开关_syncPlayerMS关闭这个机制
12781286
*/
12791287
public void updatePlayerToServer()
12801288
{
1281-
if(!_args.syncPlayer || spaceID == 0)
1289+
if(_updatePlayerToServerPeroid <= 0.01f || spaceID == 0)
12821290
{
12831291
return;
12841292
}
12851293

12861294
var now = DateTime.Now;
12871295
TimeSpan span = now - _lastUpdateToServerTime;
12881296

1289-
if (span.Ticks < 1000000)
1290-
return;
1297+
if (span.Ticks < _updatePlayerToServerPeroid * _1MS_TO_100NS)
1298+
return;
12911299

12921300
Entity playerEntity = player();
12931301
if (playerEntity == null || playerEntity.inWorld == false || playerEntity.isControlled)
12941302
return;
12951303

1296-
_lastUpdateToServerTime = now - (span - TimeSpan.FromTicks(1000000));
1304+
_lastUpdateToServerTime = now - (span - TimeSpan.FromTicks(Convert.ToInt64(_updatePlayerToServerPeroid * _1MS_TO_100NS)));
12971305

12981306
Vector3 position = playerEntity.position;
12991307
Vector3 direction = playerEntity.direction;

Assets/Plugins/kbengine/kbengine_unity3d_plugins/KBEngineArgs.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ public class KBEngineArgs
1414
public int port = 20013;
1515

1616
// 客户端类型
17-
// Reference: http://www.kbengine.org/docs/programming/clientsdkprogramming.html, client types
17+
// Reference: http://kbengine.github.io/docs/programming/clientsdkprogramming.html, client types
1818
public KBEngineApp.CLIENT_TYPE clientType = KBEngineApp.CLIENT_TYPE.CLIENT_TYPE_MINI;
1919

2020
// Allow synchronization role position information to the server
21-
// 是否开启自动同步玩家信息到服务端,信息包括位置与方向
21+
// 是否开启自动同步玩家信息到服务端,信息包括位置与方向,毫秒
2222
// 非高实时类游戏不需要开放这个选项
23-
public bool syncPlayer = true;
23+
public int syncPlayerMS = 100;
2424

2525
// 是否使用别名机制
2626
// 这个参数的选择必须与kbengine_defs.xml::cellapp/aliasEntityID的参数保持一致

Assets/Plugins/kbengine/kbengine_unity3d_plugins/NetworkInterface.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,16 @@ public virtual Socket sock()
6060

6161
public void reset()
6262
{
63-
if(valid())
64-
{
65-
Dbg.DEBUG_MSG(string.Format("NetworkInterface::reset(), close socket from '{0}'", _socket.RemoteEndPoint.ToString()));
66-
_socket.Close(0);
67-
}
68-
_socket = null;
6963
_packetReceiver = null;
7064
_packetSender = null;
7165
connected = false;
66+
67+
if(_socket != null)
68+
{
69+
Dbg.DEBUG_MSG(string.Format("NetworkInterface::reset(), close socket from '{0}'", _socket.RemoteEndPoint.ToString()));
70+
_socket.Close(0);
71+
_socket = null;
72+
}
7273
}
7374

7475

0 commit comments

Comments
 (0)