diff --git a/Assets/IGSoft_Resources/Scripts/Unity.meta b/Assets/IGSoft_Resources/Scripts/Unity.meta deleted file mode 100644 index 4d33f00..0000000 --- a/Assets/IGSoft_Resources/Scripts/Unity.meta +++ /dev/null @@ -1,9 +0,0 @@ -fileFormatVersion: 2 -guid: 7e5ff68c3b5d95f438f5809bfcc54a1f -folderAsset: yes -timeCreated: 1456727630 -licenseType: Free -DefaultImporter: - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/IGSoft_Resources/Scripts/User.meta b/Assets/IGSoft_Resources/Scripts/User.meta deleted file mode 100644 index 8a2c2cb..0000000 --- a/Assets/IGSoft_Resources/Scripts/User.meta +++ /dev/null @@ -1,9 +0,0 @@ -fileFormatVersion: 2 -guid: c16fdabf3f6c3ae44b2f7455be0154f3 -folderAsset: yes -timeCreated: 1456727630 -licenseType: Free -DefaultImporter: - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/IGSoft_Resources/Projects/[Resources]/[Sprite]/UserSprite/_MaterialsUser.meta b/Assets/kbengine_unity3d_plugins-0.8.10.meta similarity index 67% rename from Assets/IGSoft_Resources/Projects/[Resources]/[Sprite]/UserSprite/_MaterialsUser.meta rename to Assets/kbengine_unity3d_plugins-0.8.10.meta index 88fb2f5..2a1252a 100644 --- a/Assets/IGSoft_Resources/Projects/[Resources]/[Sprite]/UserSprite/_MaterialsUser.meta +++ b/Assets/kbengine_unity3d_plugins-0.8.10.meta @@ -1,7 +1,7 @@ fileFormatVersion: 2 -guid: 0370eba3b40023041b3557ccd930d10f +guid: ec8772ad87c0d4948bd0a369aef3d97d folderAsset: yes -timeCreated: 1456727631 +timeCreated: 1467109502 licenseType: Free DefaultImporter: userData: diff --git a/Assets/kbengine_unity3d_plugins-0.8.2/Bundle.cs b/Assets/kbengine_unity3d_plugins-0.8.10/Bundle.cs similarity index 80% rename from Assets/kbengine_unity3d_plugins-0.8.2/Bundle.cs rename to Assets/kbengine_unity3d_plugins-0.8.10/Bundle.cs index c280c82..af9cac8 100644 --- a/Assets/kbengine_unity3d_plugins-0.8.2/Bundle.cs +++ b/Assets/kbengine_unity3d_plugins-0.8.10/Bundle.cs @@ -10,9 +10,9 @@ 由于每个数据包都有最大上限, 向Bundle中写入大量数据将会在内部产生多个MemoryStream 在send时会全部发送出去 */ - public class Bundle + public class Bundle : ObjectPool { - public MemoryStream stream = new MemoryStream(); + public MemoryStream stream = MemoryStream.createObject(); public List streamList = new List(); public int numMessage = 0; public int messageLength = 0; @@ -62,7 +62,7 @@ public void fini(bool issend) writeMsgLength(); streamList.Add(stream); - stream = new MemoryStream(); + stream = MemoryStream.createObject(); } if(issend) @@ -90,9 +90,21 @@ public void send(NetworkInterface networkInterface) { Dbg.ERROR_MSG("Bundle::send: networkInterface invalid!"); } - + + // 把不用的MemoryStream放回缓冲池,以减少垃圾回收的消耗 + for (int i = 0; i < streamList.Count; ++i) + { + streamList[i].reclaimObject(); + } streamList.Clear(); stream.clear(); + + // 我们认为,发送完成,就视为这个bundle不再使用了, + // 所以我们会把它放回对象池,以减少垃圾回收带来的消耗, + // 如果需要继续使用,应该重新Bundle.createObject(), + // 如果外面不重新createObject()而直接使用,就可能会出现莫名的问题, + // 仅以此备注,警示使用者。 + Bundle.reclaimObject(this); } public void checkStream(int v) @@ -100,7 +112,7 @@ public void checkStream(int v) if(v > stream.space()) { streamList.Add(stream); - stream = new MemoryStream(); + stream = MemoryStream.createObject(); ++ _curMsgStreamIndex; } diff --git a/Assets/kbengine_unity3d_plugins-0.8.2/Bundle.cs.meta b/Assets/kbengine_unity3d_plugins-0.8.10/Bundle.cs.meta similarity index 76% rename from Assets/kbengine_unity3d_plugins-0.8.2/Bundle.cs.meta rename to Assets/kbengine_unity3d_plugins-0.8.10/Bundle.cs.meta index ae7effc..003772a 100644 --- a/Assets/kbengine_unity3d_plugins-0.8.2/Bundle.cs.meta +++ b/Assets/kbengine_unity3d_plugins-0.8.10/Bundle.cs.meta @@ -1,6 +1,6 @@ fileFormatVersion: 2 -guid: 48f3036988468184b8efaf35ce284557 -timeCreated: 1457687535 +guid: 5af16cf5e36c06a4283ad9a73f525f4a +timeCreated: 1467109502 licenseType: Free MonoImporter: serializedVersion: 2 diff --git a/Assets/kbengine_unity3d_plugins-0.8.2/DataTypes.cs b/Assets/kbengine_unity3d_plugins-0.8.10/DataTypes.cs similarity index 100% rename from Assets/kbengine_unity3d_plugins-0.8.2/DataTypes.cs rename to Assets/kbengine_unity3d_plugins-0.8.10/DataTypes.cs diff --git a/Assets/kbengine_unity3d_plugins-0.8.2/DataTypes.cs.meta b/Assets/kbengine_unity3d_plugins-0.8.10/DataTypes.cs.meta similarity index 76% rename from Assets/kbengine_unity3d_plugins-0.8.2/DataTypes.cs.meta rename to Assets/kbengine_unity3d_plugins-0.8.10/DataTypes.cs.meta index 31f3e00..e76a068 100644 --- a/Assets/kbengine_unity3d_plugins-0.8.2/DataTypes.cs.meta +++ b/Assets/kbengine_unity3d_plugins-0.8.10/DataTypes.cs.meta @@ -1,6 +1,6 @@ fileFormatVersion: 2 -guid: 42d44eca9ae950a4d80af9224d32e58c -timeCreated: 1457687535 +guid: 5b0c9b59df8d96f4884f3092e7315142 +timeCreated: 1467109502 licenseType: Free MonoImporter: serializedVersion: 2 diff --git a/Assets/kbengine_unity3d_plugins-0.8.2/Dbg.cs b/Assets/kbengine_unity3d_plugins-0.8.10/Dbg.cs similarity index 100% rename from Assets/kbengine_unity3d_plugins-0.8.2/Dbg.cs rename to Assets/kbengine_unity3d_plugins-0.8.10/Dbg.cs diff --git a/Assets/kbengine_unity3d_plugins-0.8.2/Dbg.cs.meta b/Assets/kbengine_unity3d_plugins-0.8.10/Dbg.cs.meta similarity index 76% rename from Assets/kbengine_unity3d_plugins-0.8.2/Dbg.cs.meta rename to Assets/kbengine_unity3d_plugins-0.8.10/Dbg.cs.meta index 7d6d32b..e0d8831 100644 --- a/Assets/kbengine_unity3d_plugins-0.8.2/Dbg.cs.meta +++ b/Assets/kbengine_unity3d_plugins-0.8.10/Dbg.cs.meta @@ -1,6 +1,6 @@ fileFormatVersion: 2 -guid: 9339075fd7b0c1d4584c7b7bb35e335d -timeCreated: 1457687535 +guid: d9121e33053991949839602d89fab31b +timeCreated: 1467109503 licenseType: Free MonoImporter: serializedVersion: 2 diff --git a/Assets/kbengine_unity3d_plugins-0.8.2/Entity.cs b/Assets/kbengine_unity3d_plugins-0.8.10/Entity.cs similarity index 89% rename from Assets/kbengine_unity3d_plugins-0.8.2/Entity.cs rename to Assets/kbengine_unity3d_plugins-0.8.10/Entity.cs index 9955a6d..49e9e1a 100644 --- a/Assets/kbengine_unity3d_plugins-0.8.2/Entity.cs +++ b/Assets/kbengine_unity3d_plugins-0.8.10/Entity.cs @@ -11,6 +11,11 @@ */ public class Entity { + // 当前玩家最后一次同步到服务端的位置与朝向 + // 这两个属性是给引擎KBEngine.cs用的,别的地方不要修改 + public Vector3 _entityLastLocalPos = new Vector3(0f, 0f, 0f); + public Vector3 _entityLastLocalDir = new Vector3(0f, 0f, 0f); + public Int32 id = 0; public string className = ""; public Vector3 position = new Vector3(0.0f, 0.0f, 0.0f); @@ -26,6 +31,12 @@ public class Entity // enterworld之后设置为true public bool inWorld = false; + + /// + /// 对于玩家自身来说,它表示是否自己被其它玩家控制了; + /// 对于其它entity来说,表示我本机是否控制了这个entity + /// + public bool isControlled = false; // __init__调用之后设置为true public bool inited = false; @@ -368,6 +379,19 @@ public virtual void set_direction(object old) if(inWorld) Event.fireOut("set_direction", new object[]{this}); } + + /// + /// This callback method is called when the local entity control by the client has been enabled or disabled. + /// See the Entity.controlledBy() method in the CellApp server code for more infomation. + /// + /// + /// 对于玩家自身来说,它表示是否自己被其它玩家控制了; + /// 对于其它entity来说,表示我本机是否控制了这个entity + /// + public virtual void onControlled(bool isControlled_) + { + + } } } diff --git a/Assets/kbengine_unity3d_plugins-0.8.2/Entity.cs.meta b/Assets/kbengine_unity3d_plugins-0.8.10/Entity.cs.meta similarity index 76% rename from Assets/kbengine_unity3d_plugins-0.8.2/Entity.cs.meta rename to Assets/kbengine_unity3d_plugins-0.8.10/Entity.cs.meta index 26c34c9..acfb915 100644 --- a/Assets/kbengine_unity3d_plugins-0.8.2/Entity.cs.meta +++ b/Assets/kbengine_unity3d_plugins-0.8.10/Entity.cs.meta @@ -1,6 +1,6 @@ fileFormatVersion: 2 -guid: 37a383ea5349c1742b74d6f4a664fe24 -timeCreated: 1457687535 +guid: 3982b44b53653174eb98da7657707198 +timeCreated: 1467109502 licenseType: Free MonoImporter: serializedVersion: 2 diff --git a/Assets/kbengine_unity3d_plugins-0.8.2/EntityDef.cs b/Assets/kbengine_unity3d_plugins-0.8.10/EntityDef.cs similarity index 98% rename from Assets/kbengine_unity3d_plugins-0.8.2/EntityDef.cs rename to Assets/kbengine_unity3d_plugins-0.8.10/EntityDef.cs index 11088ee..a56cc17 100644 --- a/Assets/kbengine_unity3d_plugins-0.8.2/EntityDef.cs +++ b/Assets/kbengine_unity3d_plugins-0.8.10/EntityDef.cs @@ -12,7 +12,7 @@ public class EntityDef { // 所有的数据类型 - public static Dictionary datatype2id = new Dictionary(); + public static Dictionary datatype2id = new Dictionary(); public static Dictionary datatypes = new Dictionary(); public static Dictionary id2datatypes = new Dictionary(); diff --git a/Assets/kbengine_unity3d_plugins-0.8.2/EntityDef.cs.meta b/Assets/kbengine_unity3d_plugins-0.8.10/EntityDef.cs.meta similarity index 76% rename from Assets/kbengine_unity3d_plugins-0.8.2/EntityDef.cs.meta rename to Assets/kbengine_unity3d_plugins-0.8.10/EntityDef.cs.meta index 44ebd2b..5245dde 100644 --- a/Assets/kbengine_unity3d_plugins-0.8.2/EntityDef.cs.meta +++ b/Assets/kbengine_unity3d_plugins-0.8.10/EntityDef.cs.meta @@ -1,6 +1,6 @@ fileFormatVersion: 2 -guid: 2e02167a5ee6b5143a827d5bf40272b1 -timeCreated: 1457687535 +guid: 302f32438869b694fa6f13b51fc7e20b +timeCreated: 1467109502 licenseType: Free MonoImporter: serializedVersion: 2 diff --git a/Assets/kbengine_unity3d_plugins-0.8.2/Event.cs b/Assets/kbengine_unity3d_plugins-0.8.10/Event.cs similarity index 94% rename from Assets/kbengine_unity3d_plugins-0.8.2/Event.cs rename to Assets/kbengine_unity3d_plugins-0.8.10/Event.cs index 1745eb7..78eb608 100644 --- a/Assets/kbengine_unity3d_plugins-0.8.2/Event.cs +++ b/Assets/kbengine_unity3d_plugins-0.8.10/Event.cs @@ -218,17 +218,17 @@ private static bool deregister(Dictionary> events, object obj { monitor_Enter(events); - foreach(KeyValuePair> e in events) + var iter = events.GetEnumerator(); + while (iter.MoveNext()) { - List lst = e.Value; -__RESTART_REMOVE: - for(int i=0; i lst = iter.Current.Value; + // 从后往前遍历,以避免中途删除的问题 + for (int i = lst.Count - 1; i >= 0; i--) { - if(obj == lst[i].obj) + if (obj == lst[i].obj) { //Dbg.DEBUG_MSG("Event::deregister: event(" + e.Key + ":" + lst[i].funcname + ")!"); lst.RemoveAt(i); - goto __RESTART_REMOVE; } } } @@ -298,9 +298,10 @@ public static void processOutEvents() if(firedEvents_out.Count > 0) { - foreach(EventObj evt in firedEvents_out) + var iter = firedEvents_out.GetEnumerator(); + while (iter.MoveNext()) { - doingEvents_out.AddLast(evt); + doingEvents_out.AddLast(iter.Current); } firedEvents_out.Clear(); @@ -338,9 +339,10 @@ public static void processInEvents() if(firedEvents_in.Count > 0) { - foreach(EventObj evt in firedEvents_in) + var iter = firedEvents_in.GetEnumerator(); + while (iter.MoveNext()) { - doingEvents_in.AddLast(evt); + doingEvents_in.AddLast(iter.Current); } firedEvents_in.Clear(); diff --git a/Assets/kbengine_unity3d_plugins-0.8.2/Event.cs.meta b/Assets/kbengine_unity3d_plugins-0.8.10/Event.cs.meta similarity index 76% rename from Assets/kbengine_unity3d_plugins-0.8.2/Event.cs.meta rename to Assets/kbengine_unity3d_plugins-0.8.10/Event.cs.meta index 9a4fe50..41344fc 100644 --- a/Assets/kbengine_unity3d_plugins-0.8.2/Event.cs.meta +++ b/Assets/kbengine_unity3d_plugins-0.8.10/Event.cs.meta @@ -1,6 +1,6 @@ fileFormatVersion: 2 -guid: 4b70ad44e61ce52439475613e98d951f -timeCreated: 1457687535 +guid: 7479add2f6ea5ee4daba91acebdda71a +timeCreated: 1467109502 licenseType: Free MonoImporter: serializedVersion: 2 diff --git a/Assets/kbengine_unity3d_plugins-0.8.2/KBEMain.cs b/Assets/kbengine_unity3d_plugins-0.8.10/KBEMain.cs similarity index 100% rename from Assets/kbengine_unity3d_plugins-0.8.2/KBEMain.cs rename to Assets/kbengine_unity3d_plugins-0.8.10/KBEMain.cs diff --git a/Assets/kbengine_unity3d_plugins-0.8.2/KBEMain.cs.meta b/Assets/kbengine_unity3d_plugins-0.8.10/KBEMain.cs.meta similarity index 76% rename from Assets/kbengine_unity3d_plugins-0.8.2/KBEMain.cs.meta rename to Assets/kbengine_unity3d_plugins-0.8.10/KBEMain.cs.meta index b477023..f888795 100644 --- a/Assets/kbengine_unity3d_plugins-0.8.2/KBEMain.cs.meta +++ b/Assets/kbengine_unity3d_plugins-0.8.10/KBEMain.cs.meta @@ -1,6 +1,6 @@ fileFormatVersion: 2 -guid: ea037b323227240468abc3c8abb2db08 -timeCreated: 1457687542 +guid: ec4739357af29a74aba0ed4e97d54757 +timeCreated: 1467109503 licenseType: Free MonoImporter: serializedVersion: 2 diff --git a/Assets/kbengine_unity3d_plugins-0.8.2/KBEngine.cs b/Assets/kbengine_unity3d_plugins-0.8.10/KBEngine.cs similarity index 91% rename from Assets/kbengine_unity3d_plugins-0.8.2/KBEngine.cs rename to Assets/kbengine_unity3d_plugins-0.8.10/KBEngine.cs index c3dcc5c..6a3e60a 100644 --- a/Assets/kbengine_unity3d_plugins-0.8.2/KBEngine.cs +++ b/Assets/kbengine_unity3d_plugins-0.8.10/KBEngine.cs @@ -86,7 +86,7 @@ public enum CLIENT_TYPE // 服务端与客户端的版本号以及协议MD5 public string serverVersion = ""; - public string clientVersion = "0.8.0"; + public string clientVersion = "0.8.10"; public string serverScriptVersion = ""; public string clientScriptVersion = "0.1.0"; public string serverProtocolMD5 = ""; @@ -100,10 +100,10 @@ public enum CLIENT_TYPE public UInt64 entity_uuid = 0; public Int32 entity_id = 0; public string entity_type = ""; + + private List _controlledEntities = new List(); - // 当前玩家最后一次同步到服务端的位置与朝向与服务端最后一次同步过来的位置 - private Vector3 _entityLastLocalPos = new Vector3(0f, 0f, 0f); - private Vector3 _entityLastLocalDir = new Vector3(0f, 0f, 0f); + // 当前服务端最后一次同步过来的玩家位置 private Vector3 _entityServerPos = new Vector3(0f, 0f, 0f); // space的数据,具体看API手册关于spaceData @@ -259,7 +259,9 @@ public virtual void reset() spaceResPath = ""; isLoadedGeometry = false; - _networkInterface.reset(); + if (_networkInterface != null) + _networkInterface.reset(); + _networkInterface = new NetworkInterface(); _spacedatas.Clear(); @@ -277,7 +279,8 @@ public static bool validEmail(string strEmail) public virtual void process() { // 处理网络 - _networkInterface.process(); + if (_networkInterface != null) + _networkInterface.process(); // 处理外层抛入的事件 Event.processInEvents(); @@ -308,7 +311,7 @@ public void _closeNetwork(NetworkInterface networkInterface) */ public void sendTick() { - if(!_networkInterface.valid()) + if(_networkInterface == null || !_networkInterface.valid()) return; if(!loginappMessageImported_ && !baseappMessageImported_) @@ -331,7 +334,7 @@ public void sendTick() { if(Loginapp_onClientActiveTickMsg != null) { - Bundle bundle = new Bundle(); + Bundle bundle = Bundle.createObject(); bundle.newMessage(Message.messages["Loginapp_onClientActiveTick"]); bundle.send(_networkInterface); } @@ -340,7 +343,7 @@ public void sendTick() { if(Baseapp_onClientActiveTickMsg != null) { - Bundle bundle = new Bundle(); + Bundle bundle = Bundle.createObject(); bundle.newMessage(Message.messages["Baseapp_onClientActiveTick"]); bundle.send(_networkInterface); } @@ -355,7 +358,7 @@ public void sendTick() */ public void hello() { - Bundle bundle = new Bundle(); + Bundle bundle = Bundle.createObject(); if(currserver == "loginapp") bundle.newMessage(Message.messages["Loginapp_hello"]); else @@ -491,7 +494,7 @@ public void login_loginapp(bool noconnect) else { Dbg.DEBUG_MSG("KBEngine::login_loginapp(): send login! username=" + username); - Bundle bundle = new Bundle(); + Bundle bundle = Bundle.createObject(); bundle.newMessage(Message.messages["Loginapp_login"]); bundle.writeInt8((sbyte)_args.clientType); bundle.writeBlob(KBEngineApp.app._clientdatas); @@ -521,7 +524,7 @@ private void onLogin_loginapp() { if(!loginappMessageImported_) { - var bundle = new Bundle(); + var bundle = Bundle.createObject(); bundle.newMessage(Message.messages["Loginapp_importClientMessages"]); bundle.send(_networkInterface); Dbg.DEBUG_MSG("KBEngine::onLogin_loginapp: send importClientMessages ..."); @@ -548,7 +551,7 @@ public void login_baseapp(bool noconnect) } else { - Bundle bundle = new Bundle(); + Bundle bundle = Bundle.createObject(); bundle.newMessage(Message.messages["Baseapp_loginBaseapp"]); bundle.writeString(username); bundle.writeString(password); @@ -576,7 +579,7 @@ private void onLogin_baseapp() { if(!baseappMessageImported_) { - var bundle = new Bundle(); + var bundle = Bundle.createObject(); bundle.newMessage(Message.messages["Baseapp_importClientMessages"]); bundle.send(_networkInterface); Dbg.DEBUG_MSG("KBEngine::onLogin_baseapp: send importClientMessages ..."); @@ -609,7 +612,7 @@ private void onReConnectTo_baseapp_callback(string ip, int port, bool success, o Dbg.DEBUG_MSG(string.Format("KBEngine::relogin_baseapp(): connect {0}:{1} is successfully!", ip, port)); - Bundle bundle = new Bundle(); + Bundle bundle = Bundle.createObject(); bundle.newMessage(Message.messages["Baseapp_reLoginBaseapp"]); bundle.writeString(username); bundle.writeString(password); @@ -626,24 +629,28 @@ public bool importMessagesFromMemoryStream(byte[] loginapp_clientMessages, byte[ resetMessages(); loadingLocalMessages_ = true; - MemoryStream stream = new MemoryStream(); + MemoryStream stream = MemoryStream.createObject(); stream.append(loginapp_clientMessages, (UInt32)0, (UInt32)loginapp_clientMessages.Length); currserver = "loginapp"; onImportClientMessages(stream); + stream.reclaimObject(); - stream = new MemoryStream(); + stream = MemoryStream.createObject(); stream.append(baseapp_clientMessages, (UInt32)0, (UInt32)baseapp_clientMessages.Length); currserver = "baseapp"; onImportClientMessages(stream); currserver = "loginapp"; + stream.reclaimObject(); - stream = new MemoryStream(); + stream = MemoryStream.createObject(); stream.append(serverErrorsDescr, (UInt32)0, (UInt32)serverErrorsDescr.Length); onImportServerErrorsDescr(stream); - - stream = new MemoryStream(); + stream.reclaimObject(); + + stream = MemoryStream.createObject(); stream.append(entitydefMessages, (UInt32)0, (UInt32)entitydefMessages.Length); onImportClientEntityDef(stream); + stream.reclaimObject(); loadingLocalMessages_ = false; loginappMessageImported_ = true; @@ -670,7 +677,7 @@ private void onImportClientMessagesCompleted() { Dbg.DEBUG_MSG("KBEngine::onImportClientMessagesCompleted(): send importServerErrorsDescr!"); isImportServerErrorsDescr_ = true; - Bundle bundle = new Bundle(); + Bundle bundle = Bundle.createObject(); bundle.newMessage(Message.messages["Loginapp_importServerErrorsDescr"]); bundle.send(_networkInterface); } @@ -702,7 +709,7 @@ private void onImportClientMessagesCompleted() if(!entitydefImported_ && !loadingLocalMessages_) { Dbg.DEBUG_MSG("KBEngine::onImportClientMessagesCompleted: send importEntityDef(" + entitydefImported_ + ") ..."); - Bundle bundle = new Bundle(); + Bundle bundle = Bundle.createObject(); bundle.newMessage(Message.messages["Baseapp_importClientEntityDef"]); bundle.send(_networkInterface); Event.fireOut("Baseapp_importClientEntityDef", new object[]{}); @@ -1054,7 +1061,11 @@ public void onImportClientMessages(MemoryStream stream) MessageID msgid = stream.readUint16(); Int16 msglen = stream.readInt16(); - + + if (msgid == 1033) + { + int a = 0; + } string msgname = stream.readString(); sbyte argstype = stream.readInt8(); Byte argsize = stream.readUint8(); @@ -1131,7 +1142,7 @@ public void onOpenLoginapp_resetpassword() if(!loginappMessageImported_) { - Bundle bundle = new Bundle(); + Bundle bundle = Bundle.createObject(); bundle.newMessage(Message.messages["Loginapp_importClientMessages"]); bundle.send(_networkInterface); Dbg.DEBUG_MSG("KBEngine::onOpenLoginapp_resetpassword: send importClientMessages ..."); @@ -1163,7 +1174,7 @@ public void resetpassword_loginapp(bool noconnect) } else { - Bundle bundle = new Bundle(); + Bundle bundle = Bundle.createObject(); bundle.newMessage(Message.messages["Loginapp_reqAccountResetPassword"]); bundle.writeString(username); bundle.send(_networkInterface); @@ -1197,8 +1208,8 @@ public void Client_onReqAccountResetPasswordCB(UInt16 failcode) 绑定Email,通过baseapp */ public void bindAccountEmail(string emailAddress) - { - Bundle bundle = new Bundle(); + { + Bundle bundle = Bundle.createObject(); bundle.newMessage(Message.messages["Baseapp_reqAccountBindEmail"]); bundle.writeInt32(entity_id); bundle.writeString(password); @@ -1222,7 +1233,7 @@ public void Client_onReqAccountBindEmailCB(UInt16 failcode) */ public void newPassword(string old_password, string new_password) { - Bundle bundle = new Bundle(); + Bundle bundle = Bundle.createObject(); bundle.newMessage(Message.messages["Baseapp_reqAccountNewPassword"]); bundle.writeInt32(entity_id); bundle.writeString(old_password); @@ -1262,7 +1273,7 @@ public void createAccount_loginapp(bool noconnect) } else { - Bundle bundle = new Bundle(); + Bundle bundle = Bundle.createObject(); bundle.newMessage(Message.messages["Loginapp_reqCreateAccount"]); bundle.writeString(username); bundle.writeString(password); @@ -1279,7 +1290,7 @@ public void onOpenLoginapp_createAccount() if(!loginappMessageImported_) { - Bundle bundle = new Bundle(); + Bundle bundle = Bundle.createObject(); bundle.newMessage(Message.messages["Loginapp_importClientMessages"]); bundle.send(_networkInterface); Dbg.DEBUG_MSG("KBEngine::onOpenLoginapp_createAccount: send importClientMessages ..."); @@ -1412,6 +1423,7 @@ public void Client_onCreatedProxies(UInt64 rndUUID, Int32 eid, string entityType { Client_onUpdatePropertys(entityMessage); _bufferedCreateEntityMessage.Remove(eid); + entityMessage.reclaimObject(); } entity.__init__(); @@ -1445,12 +1457,6 @@ public Int32 getAoiEntityIDFromStream(MemoryStream stream) if(_entityIDAliasIDList.Count > 255) { id = stream.readInt32(); - - // 如果为0且客户端上一步是重登陆或者重连操作并且服务端entity在断线期间一直处于在线状态 - // 则可以忽略这个错误, 因为cellapp可能一直在向baseapp发送同步消息, 当客户端重连上时未等 - // 服务端初始化步骤开始则收到同步信息, 此时这里就会出错。 - if(_entityIDAliasIDList.Count == 0) - return 0; } else { @@ -1459,7 +1465,7 @@ public Int32 getAoiEntityIDFromStream(MemoryStream stream) // 如果为0且客户端上一步是重登陆或者重连操作并且服务端entity在断线期间一直处于在线状态 // 则可以忽略这个错误, 因为cellapp可能一直在向baseapp发送同步消息, 当客户端重连上时未等 // 服务端初始化步骤开始则收到同步信息, 此时这里就会出错。 - if(_entityIDAliasIDList.Count == 0) + if(_entityIDAliasIDList.Count <= aliasID) return 0; id = _entityIDAliasIDList[aliasID]; @@ -1498,8 +1504,8 @@ public void onUpdatePropertys_(Int32 eid, MemoryStream stream) Dbg.ERROR_MSG("KBEngine::Client_onUpdatePropertys: entity(" + eid + ") not found!"); return; } - - MemoryStream stream1 = new MemoryStream(); + + MemoryStream stream1 = MemoryStream.createObject(); stream1.wpos = stream.wpos; stream1.rpos = stream.rpos - 4; Array.Copy(stream.data(), stream1.data(), stream.data().Length); @@ -1670,6 +1676,7 @@ public void Client_onEntityEnterWorld(MemoryStream stream) Client_onUpdatePropertys(entityMessage); _bufferedCreateEntityMessage.Remove(eid); + entityMessage.reclaimObject(); entity.isOnGround = isOnGround > 0; entity.set_direction(entity.getDefinedProperty("direction")); @@ -1745,6 +1752,9 @@ public void Client_onEntityLeaveWorld(Int32 eid) } else { + if(_controlledEntities.Remove(entity)) + Event.fireOut("onLoseControlledEntity", new object[]{entity}); + entities.Remove(eid); entity.onDestroy(); _entityIDAliasIDList.Remove(eid); @@ -1813,6 +1823,47 @@ public void Client_onCreateAccountResult(MemoryStream stream) Dbg.DEBUG_MSG("KBEngine::Client_onCreateAccountResult: " + username + " create is successfully!"); } + /* + 告诉客户端:你当前负责(或取消)控制谁的位移同步 + */ + public void Client_onControlEntity(Int32 eid, sbyte isControlled) + { + Entity entity = null; + + if (!entities.TryGetValue(eid, out entity)) + { + Dbg.ERROR_MSG("KBEngine::Client_onControlEntity: entity(" + eid + ") not found!"); + return; + } + + var isCont = isControlled != 0; + if (isCont) + { + // 如果被控制者是玩家自己,那表示玩家自己被其它人控制了 + // 所以玩家自己不应该进入这个被控制列表 + if (player().id != entity.id) + { + _controlledEntities.Add(entity); + } + } + else + { + _controlledEntities.Remove(entity); + } + + entity.isControlled = isCont; + + try + { + entity.onControlled(isCont); + Event.fireOut("onControlled", new object[]{entity, isCont}); + } + catch (Exception e) + { + Dbg.ERROR_MSG(string.Format("KBEngine::Client_onControlEntity: entity id = '{0}', is controlled = '{1}', error = '{1}'", eid, isCont, e)); + } + } + /* 更新当前玩家的位置与朝向到服务端, 可以通过开关_syncPlayer关闭这个机制 */ @@ -1822,30 +1873,31 @@ public void updatePlayerToServer() { return; } - - TimeSpan span = DateTime.Now - _lastUpdateToServerTime; - - if(span.Milliseconds < 50) + + var now = DateTime.Now; + TimeSpan span = now - _lastUpdateToServerTime; + + if (span.Ticks < 1000000) return; Entity playerEntity = player(); - if(playerEntity == null || playerEntity.inWorld == false) + if (playerEntity == null || playerEntity.inWorld == false || playerEntity.isControlled) return; - - _lastUpdateToServerTime = System.DateTime.Now; + + _lastUpdateToServerTime = now - (span - TimeSpan.FromTicks(1000000)); Vector3 position = playerEntity.position; Vector3 direction = playerEntity.direction; - bool posHasChanged = Vector3.Distance(_entityLastLocalPos, position) > 0.001f; - bool dirHasChanged = Vector3.Distance(_entityLastLocalDir, direction) > 0.001f; + bool posHasChanged = Vector3.Distance(playerEntity._entityLastLocalPos, position) > 0.001f; + bool dirHasChanged = Vector3.Distance(playerEntity._entityLastLocalDir, direction) > 0.001f; if(posHasChanged || dirHasChanged) { - _entityLastLocalPos = position; - _entityLastLocalDir = direction; - - Bundle bundle = new Bundle(); + playerEntity._entityLastLocalPos = position; + playerEntity._entityLastLocalDir = direction; + + Bundle bundle = Bundle.createObject(); bundle.newMessage(Message.messages["Baseapp_onUpdateDataFromClient"]); bundle.writeFloat(position.x); bundle.writeFloat(position.y); @@ -1858,6 +1910,37 @@ public void updatePlayerToServer() bundle.writeUint32(spaceID); bundle.send(_networkInterface); } + + // 开始同步所有被控制了的entity的位置 + for (int i = 0; i < _controlledEntities.Count; ++i) + { + var entity = _controlledEntities[i]; + position = entity.position; + direction = entity.direction; + + posHasChanged = Vector3.Distance(entity._entityLastLocalPos, position) > 0.001f; + dirHasChanged = Vector3.Distance(entity._entityLastLocalDir, direction) > 0.001f; + + if (posHasChanged || dirHasChanged) + { + entity._entityLastLocalPos = position; + entity._entityLastLocalDir = direction; + + Bundle bundle = Bundle.createObject(); + bundle.newMessage(Message.messages["Baseapp_onUpdateDataFromClientForControlledEntity"]); + bundle.writeInt32(entity.id); + bundle.writeFloat(position.x); + bundle.writeFloat(position.y); + bundle.writeFloat(position.z); + + bundle.writeFloat((float)((double)direction.x / 360 * 6.283185307179586)); + bundle.writeFloat((float)((double)direction.y / 360 * 6.283185307179586)); + bundle.writeFloat((float)((double)direction.z / 360 * 6.283185307179586)); + bundle.writeUint8((Byte)(entity.isOnGround == true ? 1 : 0)); + bundle.writeUint32(spaceID); + bundle.send(_networkInterface); + } + } } /* @@ -1885,7 +1968,9 @@ public void clearSpace(bool isall) public void clearEntities(bool isall) { - if(!isall) + _controlledEntities.Clear(); + + if (!isall) { Entity entity = player(); @@ -1993,7 +2078,10 @@ public void Client_onEntityDestroyed(Int32 eid) entity.leaveWorld(); } - + + if(_controlledEntities.Remove(entity)) + Event.fireOut("onLoseControlledEntity", new object[]{entity}); + entities.Remove(eid); entity.onDestroy(); } @@ -2001,19 +2089,52 @@ public void Client_onEntityDestroyed(Int32 eid) /* 服务端更新玩家的基础位置, 客户端以这个基础位置加上便宜值计算出玩家周围实体的坐标 */ - public void Client_onUpdateBasePos(MemoryStream stream) + public void Client_onUpdateBasePos(float x, float y, float z) { - _entityServerPos.x = stream.readFloat(); - _entityServerPos.y = stream.readFloat(); - _entityServerPos.z = stream.readFloat(); + _entityServerPos.x = x; + _entityServerPos.y = y; + _entityServerPos.z = z; + + var entity = player(); + if (entity != null && entity.isControlled) + { + entity.position.Set(_entityServerPos.x, _entityServerPos.y, _entityServerPos.z); + Event.fireOut("updatePosition", new object[]{entity}); + entity.onUpdateVolatileData(); + } } - public void Client_onUpdateBasePosXZ(MemoryStream stream) + public void Client_onUpdateBasePosXZ(float x, float z) + { + _entityServerPos.x = x; + _entityServerPos.z = z; + + var entity = player(); + if (entity != null && entity.isControlled) + { + entity.position.x = _entityServerPos.x; + entity.position.z = _entityServerPos.z; + Event.fireOut("updatePosition", new object[]{entity}); + entity.onUpdateVolatileData(); + } + } + + public void Client_onUpdateBaseDir(MemoryStream stream) { - _entityServerPos.x = stream.readFloat(); - _entityServerPos.z = stream.readFloat(); + float yaw, pitch, roll; + yaw = stream.readFloat() * 360 / ((float)System.Math.PI * 2); + pitch = stream.readFloat() * 360 / ((float)System.Math.PI * 2); + roll = stream.readFloat() * 360 / ((float)System.Math.PI * 2); + + var entity = player(); + if (entity != null && entity.isControlled) + { + entity.direction.Set(roll, pitch, yaw); + Event.fireOut("set_direction", new object[]{entity}); + entity.onUpdateVolatileData(); + } } - + public void Client_onUpdateData(MemoryStream stream) { Int32 eid = getAoiEntityIDFromStream(stream); @@ -2065,8 +2186,8 @@ public void Client_onSetEntityPosAndDir(MemoryStream stream) entity.setDefinedProperty("position", position); entity.setDefinedProperty("direction", direction); - _entityLastLocalPos = entity.position; - _entityLastLocalDir = entity.direction; + entity._entityLastLocalPos = entity.position; + entity._entityLastLocalDir = entity.direction; entity.set_direction(old_direction); entity.set_position(old_position); diff --git a/Assets/kbengine_unity3d_plugins-0.8.2/KBEngine.cs.meta b/Assets/kbengine_unity3d_plugins-0.8.10/KBEngine.cs.meta similarity index 76% rename from Assets/kbengine_unity3d_plugins-0.8.2/KBEngine.cs.meta rename to Assets/kbengine_unity3d_plugins-0.8.10/KBEngine.cs.meta index b1a5301..c2a842b 100644 --- a/Assets/kbengine_unity3d_plugins-0.8.2/KBEngine.cs.meta +++ b/Assets/kbengine_unity3d_plugins-0.8.10/KBEngine.cs.meta @@ -1,6 +1,6 @@ fileFormatVersion: 2 -guid: b342c2db3bc85c24a93b21f472ad1bde -timeCreated: 1457687535 +guid: 648ca568278426b4da0e0e89d87f870b +timeCreated: 1467109502 licenseType: Free MonoImporter: serializedVersion: 2 diff --git a/Assets/kbengine_unity3d_plugins-0.8.2/KBEngineArgs.cs b/Assets/kbengine_unity3d_plugins-0.8.10/KBEngineArgs.cs similarity index 100% rename from Assets/kbengine_unity3d_plugins-0.8.2/KBEngineArgs.cs rename to Assets/kbengine_unity3d_plugins-0.8.10/KBEngineArgs.cs diff --git a/Assets/kbengine_unity3d_plugins-0.8.2/KBEngineArgs.cs.meta b/Assets/kbengine_unity3d_plugins-0.8.10/KBEngineArgs.cs.meta similarity index 76% rename from Assets/kbengine_unity3d_plugins-0.8.2/KBEngineArgs.cs.meta rename to Assets/kbengine_unity3d_plugins-0.8.10/KBEngineArgs.cs.meta index 088c86c..3e3234b 100644 --- a/Assets/kbengine_unity3d_plugins-0.8.2/KBEngineArgs.cs.meta +++ b/Assets/kbengine_unity3d_plugins-0.8.10/KBEngineArgs.cs.meta @@ -1,6 +1,6 @@ fileFormatVersion: 2 -guid: 613a4365727028c47b26f506dc5f7d1a -timeCreated: 1457687535 +guid: b8e6da6ff48b58e47bd2900b88de0e73 +timeCreated: 1467109503 licenseType: Free MonoImporter: serializedVersion: 2 diff --git a/Assets/kbengine_unity3d_plugins-0.8.2/Mailbox.cs b/Assets/kbengine_unity3d_plugins-0.8.10/Mailbox.cs similarity index 97% rename from Assets/kbengine_unity3d_plugins-0.8.2/Mailbox.cs rename to Assets/kbengine_unity3d_plugins-0.8.10/Mailbox.cs index 23136c3..c5a9319 100644 --- a/Assets/kbengine_unity3d_plugins-0.8.2/Mailbox.cs +++ b/Assets/kbengine_unity3d_plugins-0.8.10/Mailbox.cs @@ -52,7 +52,7 @@ bool isCell() public Bundle newMail() { if(bundle == null) - bundle = new Bundle(); + bundle = Bundle.createObject(); if(type == Mailbox.MAILBOX_TYPE.MAILBOX_TYPE_CELL) bundle.newMessage(Message.messages["Baseapp_onRemoteCallCellMethodFromClient"]); diff --git a/Assets/kbengine_unity3d_plugins-0.8.2/Mailbox.cs.meta b/Assets/kbengine_unity3d_plugins-0.8.10/Mailbox.cs.meta similarity index 76% rename from Assets/kbengine_unity3d_plugins-0.8.2/Mailbox.cs.meta rename to Assets/kbengine_unity3d_plugins-0.8.10/Mailbox.cs.meta index 2d2829d..f4ae64f 100644 --- a/Assets/kbengine_unity3d_plugins-0.8.2/Mailbox.cs.meta +++ b/Assets/kbengine_unity3d_plugins-0.8.10/Mailbox.cs.meta @@ -1,6 +1,6 @@ fileFormatVersion: 2 -guid: bc71c1d3fb1e93a4d844a0542ec0b8f2 -timeCreated: 1457687535 +guid: 8fb989870d426f24096ce3a0bdf0de65 +timeCreated: 1467109502 licenseType: Free MonoImporter: serializedVersion: 2 diff --git a/Assets/kbengine_unity3d_plugins-0.8.2/Math.cs b/Assets/kbengine_unity3d_plugins-0.8.10/Math.cs similarity index 100% rename from Assets/kbengine_unity3d_plugins-0.8.2/Math.cs rename to Assets/kbengine_unity3d_plugins-0.8.10/Math.cs diff --git a/Assets/kbengine_unity3d_plugins-0.8.2/Math.cs.meta b/Assets/kbengine_unity3d_plugins-0.8.10/Math.cs.meta similarity index 76% rename from Assets/kbengine_unity3d_plugins-0.8.2/Math.cs.meta rename to Assets/kbengine_unity3d_plugins-0.8.10/Math.cs.meta index fe1a21b..5649e3c 100644 --- a/Assets/kbengine_unity3d_plugins-0.8.2/Math.cs.meta +++ b/Assets/kbengine_unity3d_plugins-0.8.10/Math.cs.meta @@ -1,6 +1,6 @@ fileFormatVersion: 2 -guid: 20e4bbd76a25f9842a5500559cd64eed -timeCreated: 1457687535 +guid: 70193636bfe763044981fb2507286b5f +timeCreated: 1467109502 licenseType: Free MonoImporter: serializedVersion: 2 diff --git a/Assets/kbengine_unity3d_plugins-0.8.2/MemoryStream.cs b/Assets/kbengine_unity3d_plugins-0.8.10/MemoryStream.cs similarity index 97% rename from Assets/kbengine_unity3d_plugins-0.8.2/MemoryStream.cs rename to Assets/kbengine_unity3d_plugins-0.8.10/MemoryStream.cs index 1e2c029..e2db7bf 100644 --- a/Assets/kbengine_unity3d_plugins-0.8.2/MemoryStream.cs +++ b/Assets/kbengine_unity3d_plugins-0.8.10/MemoryStream.cs @@ -13,7 +13,7 @@ 二进制数据流模块 能够将一些基本类型序列化(writeXXX)成二进制流同时也提供了反序列化(readXXX)等操作 */ - public class MemoryStream + public class MemoryStream : ObjectPool { public const int BUFFER_MAX = 1460 * 4; @@ -36,7 +36,16 @@ struct PackFloatXType public Int32 iv; } - public byte[] data() + /// + /// 把自己放回缓冲池 + /// + public void reclaimObject() + { + clear(); + reclaimObject(this); + } + + public byte[] data() { return datas_; } diff --git a/Assets/kbengine_unity3d_plugins-0.8.2/MemoryStream.cs.meta b/Assets/kbengine_unity3d_plugins-0.8.10/MemoryStream.cs.meta similarity index 76% rename from Assets/kbengine_unity3d_plugins-0.8.2/MemoryStream.cs.meta rename to Assets/kbengine_unity3d_plugins-0.8.10/MemoryStream.cs.meta index bc00fb5..108175b 100644 --- a/Assets/kbengine_unity3d_plugins-0.8.2/MemoryStream.cs.meta +++ b/Assets/kbengine_unity3d_plugins-0.8.10/MemoryStream.cs.meta @@ -1,6 +1,6 @@ fileFormatVersion: 2 -guid: 4474c2ba3c8ae514d963b27cf04aebb4 -timeCreated: 1457687535 +guid: fd16637e260aa1446be1c3d29f0a5c6d +timeCreated: 1467109510 licenseType: Free MonoImporter: serializedVersion: 2 diff --git a/Assets/kbengine_unity3d_plugins-0.8.2/Message.cs b/Assets/kbengine_unity3d_plugins-0.8.10/Message.cs similarity index 100% rename from Assets/kbengine_unity3d_plugins-0.8.2/Message.cs rename to Assets/kbengine_unity3d_plugins-0.8.10/Message.cs diff --git a/Assets/kbengine_unity3d_plugins-0.8.2/Message.cs.meta b/Assets/kbengine_unity3d_plugins-0.8.10/Message.cs.meta similarity index 76% rename from Assets/kbengine_unity3d_plugins-0.8.2/Message.cs.meta rename to Assets/kbengine_unity3d_plugins-0.8.10/Message.cs.meta index a57f4f2..9b120a3 100644 --- a/Assets/kbengine_unity3d_plugins-0.8.2/Message.cs.meta +++ b/Assets/kbengine_unity3d_plugins-0.8.10/Message.cs.meta @@ -1,6 +1,6 @@ fileFormatVersion: 2 -guid: e5b09d8a22aae08468fd21eb00d3a138 -timeCreated: 1457687535 +guid: 81373a92609fb1c4bb0b71fe96888190 +timeCreated: 1467109502 licenseType: Free MonoImporter: serializedVersion: 2 diff --git a/Assets/kbengine_unity3d_plugins-0.8.2/MessageReader.cs b/Assets/kbengine_unity3d_plugins-0.8.10/MessageReader.cs similarity index 100% rename from Assets/kbengine_unity3d_plugins-0.8.2/MessageReader.cs rename to Assets/kbengine_unity3d_plugins-0.8.10/MessageReader.cs diff --git a/Assets/kbengine_unity3d_plugins-0.8.2/MessageReader.cs.meta b/Assets/kbengine_unity3d_plugins-0.8.10/MessageReader.cs.meta similarity index 76% rename from Assets/kbengine_unity3d_plugins-0.8.2/MessageReader.cs.meta rename to Assets/kbengine_unity3d_plugins-0.8.10/MessageReader.cs.meta index 5249226..a0ca5c7 100644 --- a/Assets/kbengine_unity3d_plugins-0.8.2/MessageReader.cs.meta +++ b/Assets/kbengine_unity3d_plugins-0.8.10/MessageReader.cs.meta @@ -1,6 +1,6 @@ fileFormatVersion: 2 -guid: e7c2355fb38d00d42bd65b749d440334 -timeCreated: 1457687535 +guid: 1d0f3b6fce19c884d9d0d25171830a49 +timeCreated: 1467109502 licenseType: Free MonoImporter: serializedVersion: 2 diff --git a/Assets/kbengine_unity3d_plugins-0.8.2/Method.cs b/Assets/kbengine_unity3d_plugins-0.8.10/Method.cs similarity index 100% rename from Assets/kbengine_unity3d_plugins-0.8.2/Method.cs rename to Assets/kbengine_unity3d_plugins-0.8.10/Method.cs diff --git a/Assets/kbengine_unity3d_plugins-0.8.2/Method.cs.meta b/Assets/kbengine_unity3d_plugins-0.8.10/Method.cs.meta similarity index 76% rename from Assets/kbengine_unity3d_plugins-0.8.2/Method.cs.meta rename to Assets/kbengine_unity3d_plugins-0.8.10/Method.cs.meta index a1a0bc0..53d0008 100644 --- a/Assets/kbengine_unity3d_plugins-0.8.2/Method.cs.meta +++ b/Assets/kbengine_unity3d_plugins-0.8.10/Method.cs.meta @@ -1,6 +1,6 @@ fileFormatVersion: 2 -guid: 1da177da9b90959459a53f55fb1990ea -timeCreated: 1457687535 +guid: 08c822ab46ec95f49964088e2c059f35 +timeCreated: 1467109502 licenseType: Free MonoImporter: serializedVersion: 2 diff --git a/Assets/kbengine_unity3d_plugins-0.8.2/NetworkInterface.cs b/Assets/kbengine_unity3d_plugins-0.8.10/NetworkInterface.cs similarity index 90% rename from Assets/kbengine_unity3d_plugins-0.8.2/NetworkInterface.cs rename to Assets/kbengine_unity3d_plugins-0.8.10/NetworkInterface.cs index c01fa4f..4b623d6 100644 --- a/Assets/kbengine_unity3d_plugins-0.8.2/NetworkInterface.cs +++ b/Assets/kbengine_unity3d_plugins-0.8.10/NetworkInterface.cs @@ -22,7 +22,7 @@ public class NetworkInterface public const int TCP_PACKET_MAX = 1460; public delegate void ConnectCallback(string ip, int port, bool success, object userData); - Socket _socket = null; + protected Socket _socket = null; PacketReceiver _packetReceiver = null; PacketSender _packetSender = null; @@ -47,6 +47,7 @@ public void reset() { if(valid()) { + Dbg.DEBUG_MSG(string.Format("NetworkInterface::reset(), close socket from '{0}'", _socket.RemoteEndPoint.ToString())); _socket.Close(0); } _socket = null; @@ -125,7 +126,9 @@ public void connectTo(string ip, int port, ConnectCallback callback, object user // Security.PrefetchSocketPolicy(ip, 843); _socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); - _socket.SetSocketOption (System.Net.Sockets.SocketOptionLevel.Socket, SocketOptionName.ReceiveBuffer, KBEngineApp.app.getInitArgs().getRecvBufferSize() * 2); + _socket.SetSocketOption(System.Net.Sockets.SocketOptionLevel.Socket, SocketOptionName.ReceiveBuffer, KBEngineApp.app.getInitArgs().getRecvBufferSize() * 2); + _socket.SetSocketOption(System.Net.Sockets.SocketOptionLevel.Socket, SocketOptionName.SendBuffer, KBEngineApp.app.getInitArgs().getSendBufferSize() * 2); + _socket.NoDelay = true; ConnectState state = new ConnectState(); state.connectIP = ip; diff --git a/Assets/kbengine_unity3d_plugins-0.8.2/NetworkInterface.cs.meta b/Assets/kbengine_unity3d_plugins-0.8.10/NetworkInterface.cs.meta similarity index 76% rename from Assets/kbengine_unity3d_plugins-0.8.2/NetworkInterface.cs.meta rename to Assets/kbengine_unity3d_plugins-0.8.10/NetworkInterface.cs.meta index 0f1fc80..fbde111 100644 --- a/Assets/kbengine_unity3d_plugins-0.8.2/NetworkInterface.cs.meta +++ b/Assets/kbengine_unity3d_plugins-0.8.10/NetworkInterface.cs.meta @@ -1,6 +1,6 @@ fileFormatVersion: 2 -guid: e16c07f8212c9f34585339f2619efb84 -timeCreated: 1457687535 +guid: 4e0ececa87075d6489b767e8422ca7ae +timeCreated: 1467109502 licenseType: Free MonoImporter: serializedVersion: 2 diff --git a/Assets/kbengine_unity3d_plugins-0.8.10/ObjectPool.cs b/Assets/kbengine_unity3d_plugins-0.8.10/ObjectPool.cs new file mode 100644 index 0000000..812ee3e --- /dev/null +++ b/Assets/kbengine_unity3d_plugins-0.8.10/ObjectPool.cs @@ -0,0 +1,44 @@ +using UnityEngine; +using System; +using System.Collections; +using System.Collections.Generic; +using System.Threading; + + +namespace KBEngine +{ + /// + /// 简单的对象池 + /// + /// 对象类型 + public class ObjectPool where T : new() + { + private static LinkedList _objects = new LinkedList(); + + public static T createObject() + { + lock (_objects) + { + if (_objects.First != null) + { + T v = _objects.First.Value; + _objects.RemoveFirst(); + return v; + } + else + { + return new T(); + } + } + } + + public static void reclaimObject(T item) + { + lock (_objects) + { + _objects.AddLast(item); + } + } + } + +} diff --git a/Assets/kbengine_unity3d_plugins-0.8.10/ObjectPool.cs.meta b/Assets/kbengine_unity3d_plugins-0.8.10/ObjectPool.cs.meta new file mode 100644 index 0000000..56e6399 --- /dev/null +++ b/Assets/kbengine_unity3d_plugins-0.8.10/ObjectPool.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 0b564dc91d03172458c396be263838f1 +timeCreated: 1467109502 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/kbengine_unity3d_plugins-0.8.2/PacketReceiver.cs b/Assets/kbengine_unity3d_plugins-0.8.10/PacketReceiver.cs similarity index 95% rename from Assets/kbengine_unity3d_plugins-0.8.2/PacketReceiver.cs rename to Assets/kbengine_unity3d_plugins-0.8.10/PacketReceiver.cs index 44fbee1..0c7228e 100644 --- a/Assets/kbengine_unity3d_plugins-0.8.2/PacketReceiver.cs +++ b/Assets/kbengine_unity3d_plugins-0.8.10/PacketReceiver.cs @@ -20,6 +20,7 @@ public class PacketReceiver { private MessageReader messageReader = null; private NetworkInterface _networkInterface = null; + AsyncCallback _asyncCallback = null; private byte[] _buffer; @@ -34,10 +35,16 @@ public PacketReceiver(NetworkInterface networkInterface) _init(networkInterface); } + ~PacketReceiver() + { + Dbg.DEBUG_MSG("PacketReceiver::~PacketReceiver(), destroyed!"); + } + void _init(NetworkInterface networkInterface) { _networkInterface = networkInterface; _buffer = new byte[KBEngineApp.app.getInitArgs().RECV_BUFFER_MAX]; + _asyncCallback = new AsyncCallback(_onRecv); messageReader = new MessageReader(); } @@ -114,7 +121,7 @@ public void startRecv() try { _networkInterface.sock().BeginReceive(_buffer, _wpos, space, 0, - new AsyncCallback(_onRecv), this); + _asyncCallback, this); } catch (Exception e) { diff --git a/Assets/kbengine_unity3d_plugins-0.8.2/PacketReceiver.cs.meta b/Assets/kbengine_unity3d_plugins-0.8.10/PacketReceiver.cs.meta similarity index 76% rename from Assets/kbengine_unity3d_plugins-0.8.2/PacketReceiver.cs.meta rename to Assets/kbengine_unity3d_plugins-0.8.10/PacketReceiver.cs.meta index aa39c95..0c0e732 100644 --- a/Assets/kbengine_unity3d_plugins-0.8.2/PacketReceiver.cs.meta +++ b/Assets/kbengine_unity3d_plugins-0.8.10/PacketReceiver.cs.meta @@ -1,6 +1,6 @@ fileFormatVersion: 2 -guid: 4cae353b8f7bfc541bfcf49ea68355db -timeCreated: 1457687535 +guid: 9a4206ba076e04040a841a518bf8cebd +timeCreated: 1467109502 licenseType: Free MonoImporter: serializedVersion: 2 diff --git a/Assets/kbengine_unity3d_plugins-0.8.2/PacketSender.cs b/Assets/kbengine_unity3d_plugins-0.8.10/PacketSender.cs similarity index 94% rename from Assets/kbengine_unity3d_plugins-0.8.2/PacketSender.cs rename to Assets/kbengine_unity3d_plugins-0.8.10/PacketSender.cs index d6165cf..9a6b59d 100644 --- a/Assets/kbengine_unity3d_plugins-0.8.2/PacketSender.cs +++ b/Assets/kbengine_unity3d_plugins-0.8.10/PacketSender.cs @@ -25,17 +25,24 @@ public class PacketSender int _sending = 0; private NetworkInterface _networkInterface = null; + AsyncCallback _asyncCallback = null; public PacketSender(NetworkInterface networkInterface) { _init(networkInterface); } + ~PacketSender() + { + Dbg.DEBUG_MSG("PacketSender::~PacketSender(), destroyed!"); + } + void _init(NetworkInterface networkInterface) { _networkInterface = networkInterface; _buffer = new byte[KBEngineApp.app.getInitArgs().SEND_BUFFER_MAX]; + _asyncCallback = new AsyncCallback(_onSent); _wpos = 0; _spos = 0; @@ -116,7 +123,7 @@ void _startSend() try { _networkInterface.sock().BeginSend(_buffer, _spos % _buffer.Length, sendSize, 0, - new AsyncCallback(_onSent), this); + _asyncCallback, this); } catch (Exception e) { diff --git a/Assets/kbengine_unity3d_plugins-0.8.2/PacketSender.cs.meta b/Assets/kbengine_unity3d_plugins-0.8.10/PacketSender.cs.meta similarity index 76% rename from Assets/kbengine_unity3d_plugins-0.8.2/PacketSender.cs.meta rename to Assets/kbengine_unity3d_plugins-0.8.10/PacketSender.cs.meta index fae0309..d29b4a9 100644 --- a/Assets/kbengine_unity3d_plugins-0.8.2/PacketSender.cs.meta +++ b/Assets/kbengine_unity3d_plugins-0.8.10/PacketSender.cs.meta @@ -1,6 +1,6 @@ fileFormatVersion: 2 -guid: 02b4a83384c414e4985c0be2095ceb69 -timeCreated: 1457687535 +guid: cd740bfc75138b44787a4577d32421b0 +timeCreated: 1467109503 licenseType: Free MonoImporter: serializedVersion: 2 diff --git a/Assets/kbengine_unity3d_plugins-0.8.2/PersistentInofs.cs b/Assets/kbengine_unity3d_plugins-0.8.10/PersistentInofs.cs similarity index 100% rename from Assets/kbengine_unity3d_plugins-0.8.2/PersistentInofs.cs rename to Assets/kbengine_unity3d_plugins-0.8.10/PersistentInofs.cs diff --git a/Assets/kbengine_unity3d_plugins-0.8.2/PersistentInofs.cs.meta b/Assets/kbengine_unity3d_plugins-0.8.10/PersistentInofs.cs.meta similarity index 76% rename from Assets/kbengine_unity3d_plugins-0.8.2/PersistentInofs.cs.meta rename to Assets/kbengine_unity3d_plugins-0.8.10/PersistentInofs.cs.meta index de1fd95..37f8c60 100644 --- a/Assets/kbengine_unity3d_plugins-0.8.2/PersistentInofs.cs.meta +++ b/Assets/kbengine_unity3d_plugins-0.8.10/PersistentInofs.cs.meta @@ -1,6 +1,6 @@ fileFormatVersion: 2 -guid: 3f7a37c05c25b794fa0984b63c31e53e -timeCreated: 1457687535 +guid: edbd7443209ecc64caa5100f6da0df66 +timeCreated: 1467109503 licenseType: Free MonoImporter: serializedVersion: 2 diff --git a/Assets/kbengine_unity3d_plugins-0.8.2/Profile.cs b/Assets/kbengine_unity3d_plugins-0.8.10/Profile.cs similarity index 100% rename from Assets/kbengine_unity3d_plugins-0.8.2/Profile.cs rename to Assets/kbengine_unity3d_plugins-0.8.10/Profile.cs diff --git a/Assets/kbengine_unity3d_plugins-0.8.2/Profile.cs.meta b/Assets/kbengine_unity3d_plugins-0.8.10/Profile.cs.meta similarity index 76% rename from Assets/kbengine_unity3d_plugins-0.8.2/Profile.cs.meta rename to Assets/kbengine_unity3d_plugins-0.8.10/Profile.cs.meta index d028392..4062849 100644 --- a/Assets/kbengine_unity3d_plugins-0.8.2/Profile.cs.meta +++ b/Assets/kbengine_unity3d_plugins-0.8.10/Profile.cs.meta @@ -1,6 +1,6 @@ fileFormatVersion: 2 -guid: 59df5d1e72be4b54497a2a46609bccb0 -timeCreated: 1457687535 +guid: 0e45016c06d7c4547b26fc5d39d41f90 +timeCreated: 1467109502 licenseType: Free MonoImporter: serializedVersion: 2 diff --git a/Assets/kbengine_unity3d_plugins-0.8.2/Property.cs b/Assets/kbengine_unity3d_plugins-0.8.10/Property.cs similarity index 100% rename from Assets/kbengine_unity3d_plugins-0.8.2/Property.cs rename to Assets/kbengine_unity3d_plugins-0.8.10/Property.cs diff --git a/Assets/kbengine_unity3d_plugins-0.8.2/Property.cs.meta b/Assets/kbengine_unity3d_plugins-0.8.10/Property.cs.meta similarity index 76% rename from Assets/kbengine_unity3d_plugins-0.8.2/Property.cs.meta rename to Assets/kbengine_unity3d_plugins-0.8.10/Property.cs.meta index 877c597..2eefc3d 100644 --- a/Assets/kbengine_unity3d_plugins-0.8.2/Property.cs.meta +++ b/Assets/kbengine_unity3d_plugins-0.8.10/Property.cs.meta @@ -1,6 +1,6 @@ fileFormatVersion: 2 -guid: 4ba2ebe99cce9d44e9f8f5ca07939728 -timeCreated: 1457687535 +guid: 76717f16453da554586b3662d50072d7 +timeCreated: 1467109502 licenseType: Free MonoImporter: serializedVersion: 2 diff --git a/Assets/kbengine_unity3d_plugins-0.8.2/README.md b/Assets/kbengine_unity3d_plugins-0.8.10/README.md similarity index 96% rename from Assets/kbengine_unity3d_plugins-0.8.2/README.md rename to Assets/kbengine_unity3d_plugins-0.8.10/README.md index e7fbd18..f68bdda 100644 --- a/Assets/kbengine_unity3d_plugins-0.8.2/README.md +++ b/Assets/kbengine_unity3d_plugins-0.8.10/README.md @@ -92,6 +92,21 @@ KBE-Plugin fire-out events(KBE => Unity): bytes: datas If you use third-party account system, the system may fill some of the third-party additional datas. + onControlled + Description: + Triggered when the entity is controlled or out of control. + + Event-datas: + Enity + bool: isControlled + + onLoseControlledEntity + Description: + Lose controlled entity. + + Event-datas: + Enity + set_position Description: Sets the current position of the entity. diff --git a/Assets/kbengine_unity3d_plugins-0.8.2/README.md.meta b/Assets/kbengine_unity3d_plugins-0.8.10/README.md.meta similarity index 64% rename from Assets/kbengine_unity3d_plugins-0.8.2/README.md.meta rename to Assets/kbengine_unity3d_plugins-0.8.10/README.md.meta index d073bcd..c234c13 100644 --- a/Assets/kbengine_unity3d_plugins-0.8.2/README.md.meta +++ b/Assets/kbengine_unity3d_plugins-0.8.10/README.md.meta @@ -1,6 +1,6 @@ fileFormatVersion: 2 -guid: c98964918aac78946902ce280152ebf9 -timeCreated: 1457687534 +guid: 355c8919d6c94f0479fe55d974dcdf0a +timeCreated: 1467109502 licenseType: Free DefaultImporter: userData: diff --git a/Assets/kbengine_unity3d_plugins-0.8.2/ScriptModule.cs b/Assets/kbengine_unity3d_plugins-0.8.10/ScriptModule.cs similarity index 100% rename from Assets/kbengine_unity3d_plugins-0.8.2/ScriptModule.cs rename to Assets/kbengine_unity3d_plugins-0.8.10/ScriptModule.cs diff --git a/Assets/kbengine_unity3d_plugins-0.8.2/ScriptModule.cs.meta b/Assets/kbengine_unity3d_plugins-0.8.10/ScriptModule.cs.meta similarity index 76% rename from Assets/kbengine_unity3d_plugins-0.8.2/ScriptModule.cs.meta rename to Assets/kbengine_unity3d_plugins-0.8.10/ScriptModule.cs.meta index cf0eb94..2ddcdb7 100644 --- a/Assets/kbengine_unity3d_plugins-0.8.2/ScriptModule.cs.meta +++ b/Assets/kbengine_unity3d_plugins-0.8.10/ScriptModule.cs.meta @@ -1,6 +1,6 @@ fileFormatVersion: 2 -guid: 2cd0a806f25b7ae4bbd0a8b8774d102b -timeCreated: 1457687535 +guid: 67f0df24eb2e2334eb4f752f9a57da10 +timeCreated: 1467109502 licenseType: Free MonoImporter: serializedVersion: 2 diff --git a/Assets/kbengine_unity3d_plugins-0.8.2.meta b/Assets/kbengine_unity3d_plugins-0.8.2.meta deleted file mode 100644 index 68e2f72..0000000 --- a/Assets/kbengine_unity3d_plugins-0.8.2.meta +++ /dev/null @@ -1,9 +0,0 @@ -fileFormatVersion: 2 -guid: aab3a75b2adc817448b5cb015c724015 -folderAsset: yes -timeCreated: 1457687534 -licenseType: Free -DefaultImporter: - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/world.unity b/Assets/world.unity index 652cb82..67b7ec8 100644 Binary files a/Assets/world.unity and b/Assets/world.unity differ diff --git a/ProjectSettings/ProjectSettings.asset b/ProjectSettings/ProjectSettings.asset index d54ebd9..2133d1c 100644 Binary files a/ProjectSettings/ProjectSettings.asset and b/ProjectSettings/ProjectSettings.asset differ