Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
kebiao committed Jul 12, 2018
1 parent 09c55dd commit f779129
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 25 deletions.
2 changes: 2 additions & 0 deletions Assets/Plugins/kbengine/kbengine_unity3d_plugins/EntityDef.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1166,6 +1166,7 @@ public static void initScriptModules()

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

pNPCModule.useMethodDescrAlias = true;
ScriptModule pGateModule = new ScriptModule("Gate");
EntityDef.moduledefs["Gate"] = pGateModule;
EntityDef.idmoduledefs[5] = pGateModule;
Expand Down Expand Up @@ -1302,6 +1303,7 @@ public static void initScriptModules()

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

pGateModule.useMethodDescrAlias = true;
}

public static void initDefTypes()
Expand Down
4 changes: 2 additions & 2 deletions Assets/Plugins/kbengine/kbengine_unity3d_plugins/KBEMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class KBEMain : MonoBehaviour
public string ip = "127.0.0.1";
public int port = 20013;
public KBEngineApp.CLIENT_TYPE clientType = KBEngineApp.CLIENT_TYPE.CLIENT_TYPE_MINI;
public bool syncPlayer = true;
public int syncPlayerMS = 100;
public int threadUpdateHZ = 10;
public int serverHeartbeatTick = 15;
public int SEND_BUFFER_MAX = (int)KBEngine.NetworkInterface.TCP_PACKET_MAX;
Expand Down Expand Up @@ -54,7 +54,7 @@ public virtual void initKBEngine()
args.ip = ip;
args.port = port;
args.clientType = clientType;
args.syncPlayer = syncPlayer;
args.syncPlayerMS = syncPlayerMS;
args.threadUpdateHZ = threadUpdateHZ;
args.serverHeartbeatTick = serverHeartbeatTick;
args.useAliasEntityID = useAliasEntityID;
Expand Down
36 changes: 22 additions & 14 deletions Assets/Plugins/kbengine/kbengine_unity3d_plugins/KBEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
包括网络创建、持久化协议、entities的管理、以及引起对外可调用接口。
一些可以参考的地方:
http://www.kbengine.org/docs/programming/clientsdkprogramming.html
http://www.kbengine.org/docs/programming/kbe_message_format.html
http://kbengine.github.io/docs/programming/clientsdkprogramming.html
http://kbengine.github.io/docs/programming/kbe_message_format.html
http://www.kbengine.org/cn/docs/programming/clientsdkprogramming.html
http://www.kbengine.org/cn/docs/programming/kbe_message_format.html
http://kbengine.github.io/cn/docs/programming/clientsdkprogramming.html
http://kbengine.github.io/cn/docs/programming/kbe_message_format.html
*/
public class KBEngineApp
{
Expand All @@ -30,8 +30,8 @@ public class KBEngineApp
KBEngineArgs _args = null;

// 客户端的类别
// http://www.kbengine.org/docs/programming/clientsdkprogramming.html
// http://www.kbengine.org/cn/docs/programming/clientsdkprogramming.html
// http://kbengine.github.io/docs/programming/clientsdkprogramming.html
// http://kbengine.github.io/cn/docs/programming/clientsdkprogramming.html
public enum CLIENT_TYPE
{
// Mobile(Phone, Pad)
Expand Down Expand Up @@ -77,7 +77,7 @@ public enum CLIENT_TYPE

// 服务端与客户端的版本号以及协议MD5
public string serverVersion = "";
public string clientVersion = "1.1.9";
public string clientVersion = "1.1.10";
public string serverScriptVersion = "";
public string clientScriptVersion = "0.1.0";
public string serverProtocolMD5 = "4930E6C01028CE4D5B3CE228CA841378";
Expand Down Expand Up @@ -112,6 +112,10 @@ public enum CLIENT_TYPE
private System.DateTime _lastTickCBTime = System.DateTime.Now;
private System.DateTime _lastUpdateToServerTime = System.DateTime.Now;

//上传玩家信息到服务器间隔,单位毫秒
private float _updatePlayerToServerPeroid = 100.0f;
private const int _1MS_TO_100NS = 10000;

// 玩家当前所在空间的id, 以及空间对应的资源
public UInt32 spaceID = 0;
public string spaceResPath = "";
Expand All @@ -133,7 +137,8 @@ public KBEngineApp(KBEngineArgs args)
public virtual bool initialize(KBEngineArgs args)
{
_args = args;

_updatePlayerToServerPeroid = (float)_args.syncPlayerMS;

EntityDef.init();

initNetwork();
Expand Down Expand Up @@ -551,7 +556,10 @@ private void onLogin_baseapp()
一些移动类应用容易掉线,可以使用该功能快速的重新与服务端建立通信
*/
public void reloginBaseapp()
{
{
_lastTickTime = System.DateTime.Now;
_lastTickCBTime = System.DateTime.Now;

if(_networkInterface.valid())
return;

Expand Down Expand Up @@ -1274,26 +1282,26 @@ public void Client_onControlEntity(Int32 eid, sbyte isControlled)
}

/*
更新当前玩家的位置与朝向到服务端, 可以通过开关_syncPlayer关闭这个机制
更新当前玩家的位置与朝向到服务端, 可以通过开关_syncPlayerMS关闭这个机制
*/
public void updatePlayerToServer()
{
if(!_args.syncPlayer || spaceID == 0)
if(_updatePlayerToServerPeroid <= 0.01f || spaceID == 0)
{
return;
}

var now = DateTime.Now;
TimeSpan span = now - _lastUpdateToServerTime;

if (span.Ticks < 1000000)
return;
if (span.Ticks < _updatePlayerToServerPeroid * _1MS_TO_100NS)
return;

Entity playerEntity = player();
if (playerEntity == null || playerEntity.inWorld == false || playerEntity.isControlled)
return;

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

Vector3 position = playerEntity.position;
Vector3 direction = playerEntity.direction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ public class KBEngineArgs
public int port = 20013;

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

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

// 是否使用别名机制
// 这个参数的选择必须与kbengine_defs.xml::cellapp/aliasEntityID的参数保持一致
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,16 @@ public virtual Socket sock()

public void reset()
{
if(valid())
{
Dbg.DEBUG_MSG(string.Format("NetworkInterface::reset(), close socket from '{0}'", _socket.RemoteEndPoint.ToString()));
_socket.Close(0);
}
_socket = null;
_packetReceiver = null;
_packetSender = null;
connected = false;

if(_socket != null)
{
Dbg.DEBUG_MSG(string.Format("NetworkInterface::reset(), close socket from '{0}'", _socket.RemoteEndPoint.ToString()));
_socket.Close(0);
_socket = null;
}
}


Expand Down

0 comments on commit f779129

Please sign in to comment.