From 36d2c146b09de7e4dc772e46d83810d3f28076ce Mon Sep 17 00:00:00 2001 From: ALEXTANG <574809918@qq.com> Date: Fri, 4 Aug 2023 01:41:31 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E4=BF=AE=E5=A4=8D=E4=BA=86MongoDB?= =?UTF-8?q?=E5=9C=A82.18.0=E4=BB=A5=E5=90=8E=E9=9C=80=E8=A6=81=E8=87=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E6=B3=A8=E5=86=8CObjectSerializer=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E3=80=82=202=E3=80=81Addressable=E7=9A=84Add?= =?UTF-8?q?Addressable=E6=8E=A5=E5=8F=A3=E5=A2=9E=E5=8A=A0isLock=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E3=80=81=E7=94=A8=E6=9D=A5=E5=86=B3=E5=AE=9A=E6=98=AF?= =?UTF-8?q?=E5=90=A6=E9=9C=80=E8=A6=81=E6=B7=BB=E5=8A=A0=E6=90=BA=E7=A8=8B?= =?UTF-8?q?=E9=94=81=E3=80=82=20=203=E3=80=81=E4=BF=AE=E5=A4=8D=E4=BA=86AP?= =?UTF-8?q?ackInfo=E5=9B=A0=E4=B8=BA=E7=BD=91=E7=BB=9C=E5=A4=9A=E7=BA=BF?= =?UTF-8?q?=E7=A8=8B=E7=9A=84=E5=8E=9F=E5=9B=A0=E5=AF=BC=E8=87=B4=E7=BA=BF?= =?UTF-8?q?=E7=A8=8B=E5=AE=89=E5=85=A8=E7=9A=84=E9=97=AE=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1、修复了MongoDB在2.18.0以后需要自定义注册ObjectSerializer的问题。 2、Addressable的AddAddressable接口增加isLock参数、用来决定是否需要添加携程锁。 3、修复了APackInfo因为网络多线程的原因导致线程安全的问题。 --- .../DotNet/Core/Assembly/AssemblyManager.cs | 8 +++ .../GameScripts/DotNet/Core/CoreErrorCode.cs | 1 + Assets/GameScripts/DotNet/Core/Define.cs | 1 + .../GameScripts/DotNet/Core/Entitas/Entity.cs | 50 +++++++++++++++++-- .../DotNet/Core/Entitas/EntityReference.cs | 30 +++++++++++ .../Core/Entitas/EntityReference.cs.meta | 3 ++ .../Interface/Supported/ISupportedTransfer.cs | 8 +++ .../Supported/ISupportedTransfer.cs.meta | 3 ++ .../DotNet/Core/Entitas/Scene/Scene.cs | 10 ++-- .../Core/Exporter/Excel/Base/Dictionary.meta | 3 ++ .../Base/Dictionary/IntDictionaryConfig.cs | 31 ++++++++++++ .../Dictionary/IntDictionaryConfig.cs.meta | 3 ++ .../Base/Dictionary/StringDictionaryConfig.cs | 32 ++++++++++++ .../Dictionary/StringDictionaryConfig.cs.meta | 3 ++ .../Core/Exporter/Excel/ExcelExporter.cs | 28 +++++++++++ .../Exporter/ProtoBuf/ProtoBufExporter.cs | 2 + .../DotNet/Core/Helper/Mongo/MongoHelper.cs | 5 +- .../Session/SessionIdleCheckerComponent.cs | 2 +- .../Message/Addressable/AddressableHelper.cs | 5 +- .../Addressable/AddressableManageComponent.cs | 20 +++++++- .../AddressableMessageComponent.cs | 4 +- .../Handler/I_AddressableAddHandler.cs | 2 +- .../Scheduler/ANetworkMessageScheduler.cs | 2 +- .../Message/Protocols/CoreMessageProtocols.cs | 2 + .../Scheduler/ClientMessageScheduler.cs | 2 +- .../Scheduler/InnerMessageScheduler.cs | 2 +- .../Scheduler/OuterMessageScheduler.cs | 2 +- .../Network/PacketParser/InnerPacketParser.cs | 13 ++++- .../Core/SingleCollection/SingleCollection.cs | 2 +- 29 files changed, 253 insertions(+), 26 deletions(-) create mode 100644 Assets/GameScripts/DotNet/Core/Entitas/EntityReference.cs create mode 100644 Assets/GameScripts/DotNet/Core/Entitas/EntityReference.cs.meta create mode 100644 Assets/GameScripts/DotNet/Core/Entitas/Interface/Supported/ISupportedTransfer.cs create mode 100644 Assets/GameScripts/DotNet/Core/Entitas/Interface/Supported/ISupportedTransfer.cs.meta create mode 100644 Assets/GameScripts/DotNet/Core/Exporter/Excel/Base/Dictionary.meta create mode 100644 Assets/GameScripts/DotNet/Core/Exporter/Excel/Base/Dictionary/IntDictionaryConfig.cs create mode 100644 Assets/GameScripts/DotNet/Core/Exporter/Excel/Base/Dictionary/IntDictionaryConfig.cs.meta create mode 100644 Assets/GameScripts/DotNet/Core/Exporter/Excel/Base/Dictionary/StringDictionaryConfig.cs create mode 100644 Assets/GameScripts/DotNet/Core/Exporter/Excel/Base/Dictionary/StringDictionaryConfig.cs.meta diff --git a/Assets/GameScripts/DotNet/Core/Assembly/AssemblyManager.cs b/Assets/GameScripts/DotNet/Core/Assembly/AssemblyManager.cs index 6db25d36..cf91f258 100644 --- a/Assets/GameScripts/DotNet/Core/Assembly/AssemblyManager.cs +++ b/Assets/GameScripts/DotNet/Core/Assembly/AssemblyManager.cs @@ -63,6 +63,14 @@ namespace TEngine.Core LoadAssembly(assemblyName, assembly); } + + public static IEnumerable ForEachAssemblyName() + { + foreach (var (key, _) in AssemblyList) + { + yield return key; + } + } public static IEnumerable ForEach() { diff --git a/Assets/GameScripts/DotNet/Core/CoreErrorCode.cs b/Assets/GameScripts/DotNet/Core/CoreErrorCode.cs index 0febebbb..18edc3f1 100644 --- a/Assets/GameScripts/DotNet/Core/CoreErrorCode.cs +++ b/Assets/GameScripts/DotNet/Core/CoreErrorCode.cs @@ -7,5 +7,6 @@ namespace TEngine.Core public const uint ErrRouteTimeout = 100000004; // 发送Route消息超时 public const uint Error_NotFindEntity = 100000008; // 没有找到Entity public const uint Error_CopyTimeout = 100000009; // CopyTimeout不能小于或等于0 + public const uint Error_Transfer = 100000010;// 传送发生了错误 } } \ No newline at end of file diff --git a/Assets/GameScripts/DotNet/Core/Define.cs b/Assets/GameScripts/DotNet/Core/Define.cs index 99eb8d11..9bb0b606 100644 --- a/Assets/GameScripts/DotNet/Core/Define.cs +++ b/Assets/GameScripts/DotNet/Core/Define.cs @@ -79,6 +79,7 @@ public static class Define public static readonly HashSet ColTypeSet = new HashSet() { "", "0", "bool", "byte", "short", "ushort", "int", "uint", "long", "ulong", "float", "string", "AttrConfig", + "IntDictionaryConfig", "StringDictionaryConfig", "short[]", "int[]", "long[]", "float[]", "string[]" }; /// diff --git a/Assets/GameScripts/DotNet/Core/Entitas/Entity.cs b/Assets/GameScripts/DotNet/Core/Entitas/Entity.cs index 0d976beb..fae76067 100644 --- a/Assets/GameScripts/DotNet/Core/Entitas/Entity.cs +++ b/Assets/GameScripts/DotNet/Core/Entitas/Entity.cs @@ -13,6 +13,7 @@ using Newtonsoft.Json; // ReSharper disable SuspiciousTypeConversion.Global // ReSharper disable InconsistentNaming +// ReSharper disable ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract namespace TEngine { @@ -401,11 +402,54 @@ namespace TEngine } #endregion + +#if TENGINE_NET + #region ForEach + public IEnumerable ForEachSingleCollection + { + get + { + foreach (var (_, treeEntity) in _tree) + { + if (treeEntity is not ISupportedSingleCollection) + { + continue; + } + yield return treeEntity; + } + } + } + public IEnumerable ForEachTransfer + { + get + { + if (_tree != null) + { + foreach (var (_, treeEntity) in _tree) + { + if (treeEntity is ISupportedSingleCollection || treeEntity is ISupportedTransfer) + { + yield return treeEntity; + } + } + } + if (_multiDb != null) + { + foreach (var treeEntity in _multiDb) + { + if (treeEntity is not ISupportedTransfer) + { + continue; + } + yield return treeEntity; + } + } + } + } + #endregion +#endif #region GetComponent - - public DictionaryPool GetTree => _tree; - public T GetComponent() where T : Entity, new() { return GetComponent(typeof(T)) as T; diff --git a/Assets/GameScripts/DotNet/Core/Entitas/EntityReference.cs b/Assets/GameScripts/DotNet/Core/Entitas/EntityReference.cs new file mode 100644 index 00000000..3a479a62 --- /dev/null +++ b/Assets/GameScripts/DotNet/Core/Entitas/EntityReference.cs @@ -0,0 +1,30 @@ +// ReSharper disable ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract +namespace TEngine +{ + public readonly struct EntityReference where T : Entity + { + private readonly T _entity; + private readonly long _runTimeId; + + private EntityReference(T t) + { + _entity = t; + _runTimeId = t.RuntimeId; + } + + public static implicit operator EntityReference(T t) + { + return new EntityReference(t); + } + + public static implicit operator T(EntityReference v) + { + if (v._entity == null) + { + return null; + } + + return v._entity.RuntimeId != v._runTimeId ? null : v._entity; + } + } +} \ No newline at end of file diff --git a/Assets/GameScripts/DotNet/Core/Entitas/EntityReference.cs.meta b/Assets/GameScripts/DotNet/Core/Entitas/EntityReference.cs.meta new file mode 100644 index 00000000..1c2a8b9c --- /dev/null +++ b/Assets/GameScripts/DotNet/Core/Entitas/EntityReference.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: c827c6f914b64f5d9eb0a1f29cc2c018 +timeCreated: 1691083017 \ No newline at end of file diff --git a/Assets/GameScripts/DotNet/Core/Entitas/Interface/Supported/ISupportedTransfer.cs b/Assets/GameScripts/DotNet/Core/Entitas/Interface/Supported/ISupportedTransfer.cs new file mode 100644 index 00000000..2de2175b --- /dev/null +++ b/Assets/GameScripts/DotNet/Core/Entitas/Interface/Supported/ISupportedTransfer.cs @@ -0,0 +1,8 @@ +#if TENGINE_NET +namespace TEngine; + +/// +/// Entity支持传送。 +/// +public interface ISupportedTransfer { } +#endif \ No newline at end of file diff --git a/Assets/GameScripts/DotNet/Core/Entitas/Interface/Supported/ISupportedTransfer.cs.meta b/Assets/GameScripts/DotNet/Core/Entitas/Interface/Supported/ISupportedTransfer.cs.meta new file mode 100644 index 00000000..aef658b7 --- /dev/null +++ b/Assets/GameScripts/DotNet/Core/Entitas/Interface/Supported/ISupportedTransfer.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 06770f37cdfc480fb0c270ea93a10d26 +timeCreated: 1691083054 \ No newline at end of file diff --git a/Assets/GameScripts/DotNet/Core/Entitas/Scene/Scene.cs b/Assets/GameScripts/DotNet/Core/Entitas/Scene/Scene.cs index 3db147d1..b052e715 100644 --- a/Assets/GameScripts/DotNet/Core/Entitas/Scene/Scene.cs +++ b/Assets/GameScripts/DotNet/Core/Entitas/Scene/Scene.cs @@ -91,7 +91,7 @@ namespace TEngine } #else /// - /// 创建一个Scene、但这个Scene是在某个Scene下面的Scene。 + /// 创建一个Scene。 /// /// /// @@ -101,24 +101,24 @@ namespace TEngine public static async FTask Create(Scene scene, int sceneType, int sceneSubType) where T : Scene, new() { var newScene = Create(scene); - newScene.Scene = scene; + newScene.Scene = newScene; newScene.Parent = scene; newScene.SceneType = sceneType; newScene.SceneSubType = sceneSubType; newScene.Server = scene.Server; newScene.LocationId = scene.Server.Id; - if (scene.World !=null) + if (scene.World != null) { newScene.World = scene.World; } if (sceneType > 0) { - await EventSystem.Instance.PublishAsync(new OnCreateScene(scene)); + await EventSystem.Instance.PublishAsync(new OnCreateScene(newScene)); } - Scenes.Add(scene); + Scenes.Add(newScene); return newScene; } diff --git a/Assets/GameScripts/DotNet/Core/Exporter/Excel/Base/Dictionary.meta b/Assets/GameScripts/DotNet/Core/Exporter/Excel/Base/Dictionary.meta new file mode 100644 index 00000000..5a7c1f41 --- /dev/null +++ b/Assets/GameScripts/DotNet/Core/Exporter/Excel/Base/Dictionary.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 2da9efac32374cb1a88c500e7ed43344 +timeCreated: 1691084274 \ No newline at end of file diff --git a/Assets/GameScripts/DotNet/Core/Exporter/Excel/Base/Dictionary/IntDictionaryConfig.cs b/Assets/GameScripts/DotNet/Core/Exporter/Excel/Base/Dictionary/IntDictionaryConfig.cs new file mode 100644 index 00000000..55a5a9e0 --- /dev/null +++ b/Assets/GameScripts/DotNet/Core/Exporter/Excel/Base/Dictionary/IntDictionaryConfig.cs @@ -0,0 +1,31 @@ +using ProtoBuf; + +namespace TEngine.Core +{ + [ProtoContract] + public class IntDictionaryConfig + { + [ProtoMember(1, IsRequired = true)] + public Dictionary Dic; + + public int this[int key] => GetValue(key); + + public bool TryGetValue(int key, out int value) + { + value = default; + + if (!Dic.ContainsKey(key)) + { + return false; + } + + value = Dic[key]; + return true; + } + + private int GetValue(int key) + { + return Dic.TryGetValue(key, out var value) ? value : default; + } + } +} \ No newline at end of file diff --git a/Assets/GameScripts/DotNet/Core/Exporter/Excel/Base/Dictionary/IntDictionaryConfig.cs.meta b/Assets/GameScripts/DotNet/Core/Exporter/Excel/Base/Dictionary/IntDictionaryConfig.cs.meta new file mode 100644 index 00000000..4cb0b234 --- /dev/null +++ b/Assets/GameScripts/DotNet/Core/Exporter/Excel/Base/Dictionary/IntDictionaryConfig.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 34b41344fd6e462bae371207cdf8a5cd +timeCreated: 1691084286 \ No newline at end of file diff --git a/Assets/GameScripts/DotNet/Core/Exporter/Excel/Base/Dictionary/StringDictionaryConfig.cs b/Assets/GameScripts/DotNet/Core/Exporter/Excel/Base/Dictionary/StringDictionaryConfig.cs new file mode 100644 index 00000000..5f72da38 --- /dev/null +++ b/Assets/GameScripts/DotNet/Core/Exporter/Excel/Base/Dictionary/StringDictionaryConfig.cs @@ -0,0 +1,32 @@ +using System.Collections.Generic; +using ProtoBuf; + +namespace TEngine.Core +{ + [ProtoContract] + public sealed class StringDictionaryConfig + { + [ProtoMember(1, IsRequired = true)] + public Dictionary Dic; + + public string this[int key] => GetValue(key); + + public bool TryGetValue(int key, out string value) + { + value = default; + + if (!Dic.ContainsKey(key)) + { + return false; + } + + value = Dic[key]; + return true; + } + + private string GetValue(int key) + { + return Dic.TryGetValue(key, out var value) ? value : default; + } + } +} \ No newline at end of file diff --git a/Assets/GameScripts/DotNet/Core/Exporter/Excel/Base/Dictionary/StringDictionaryConfig.cs.meta b/Assets/GameScripts/DotNet/Core/Exporter/Excel/Base/Dictionary/StringDictionaryConfig.cs.meta new file mode 100644 index 00000000..00d53c76 --- /dev/null +++ b/Assets/GameScripts/DotNet/Core/Exporter/Excel/Base/Dictionary/StringDictionaryConfig.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: a26ad73832de4b3e986ddb58426bcced +timeCreated: 1691084294 \ No newline at end of file diff --git a/Assets/GameScripts/DotNet/Core/Exporter/Excel/ExcelExporter.cs b/Assets/GameScripts/DotNet/Core/Exporter/Excel/ExcelExporter.cs index d25fc203..a8afe812 100644 --- a/Assets/GameScripts/DotNet/Core/Exporter/Excel/ExcelExporter.cs +++ b/Assets/GameScripts/DotNet/Core/Exporter/Excel/ExcelExporter.cs @@ -735,6 +735,34 @@ public sealed class ExcelExporter return; } + case "IntDictionaryConfig": + { + if (value.Trim() == "" || value.Trim() == "{}") + { + propertyInfo.SetValue(config, null); + return; + } + + var attr = new IntDictionaryConfig {Dic = JsonConvert.DeserializeObject>(value)}; + + propertyInfo.SetValue(config, attr); + + return; + } + case "StringDictionaryConfig": + { + if (value.Trim() == "" || value.Trim() == "{}") + { + propertyInfo.SetValue(config, null); + return; + } + + var attr = new StringDictionaryConfig {Dic = JsonConvert.DeserializeObject>(value)}; + + propertyInfo.SetValue(config, attr); + + return; + } default: throw new NotSupportedException($"不支持此类型: {type}"); } diff --git a/Assets/GameScripts/DotNet/Core/Exporter/ProtoBuf/ProtoBufExporter.cs b/Assets/GameScripts/DotNet/Core/Exporter/ProtoBuf/ProtoBufExporter.cs index 37401411..6c1e7085 100644 --- a/Assets/GameScripts/DotNet/Core/Exporter/ProtoBuf/ProtoBufExporter.cs +++ b/Assets/GameScripts/DotNet/Core/Exporter/ProtoBuf/ProtoBufExporter.cs @@ -424,7 +424,9 @@ public sealed class ProtoBufExporter "int32[]" => "int[] { }", "int64[]" => "long[] { }", "int32" => "int", + "uint32" => "uint", "int64" => "long", + "uint64" => "ulong", _ => type }; } diff --git a/Assets/GameScripts/DotNet/Core/Helper/Mongo/MongoHelper.cs b/Assets/GameScripts/DotNet/Core/Helper/Mongo/MongoHelper.cs index f136e246..9925a21d 100644 --- a/Assets/GameScripts/DotNet/Core/Helper/Mongo/MongoHelper.cs +++ b/Assets/GameScripts/DotNet/Core/Helper/Mongo/MongoHelper.cs @@ -179,9 +179,8 @@ public sealed class MongoHelper : Singleton public void SerializeTo(T t, MemoryStream stream) { - var bytes = t.ToBson(); - - stream.Write(bytes, 0, bytes.Length); + using var writer = new BsonBinaryWriter(stream, BsonBinaryWriterSettings.Defaults); + BsonSerializer.Serialize(writer, typeof(T), t); } public T Clone(T t) diff --git a/Assets/GameScripts/DotNet/Core/Modules/Session/SessionIdleCheckerComponent.cs b/Assets/GameScripts/DotNet/Core/Modules/Session/SessionIdleCheckerComponent.cs index 0d59ec77..edf1d0b3 100644 --- a/Assets/GameScripts/DotNet/Core/Modules/Session/SessionIdleCheckerComponent.cs +++ b/Assets/GameScripts/DotNet/Core/Modules/Session/SessionIdleCheckerComponent.cs @@ -51,7 +51,7 @@ public class SessionIdleCheckerComponent: Entity return; } - Log.Warning($"session timeout id:{Id}"); + Log.Warning($"session timeout id:{Id} timeNow:{timeNow} _session.LastReceiveTime:{_session.LastReceiveTime} _timeOut:{_timeOut}"); _session.Dispose(); } } diff --git a/Assets/GameScripts/DotNet/Core/Network/Message/Addressable/AddressableHelper.cs b/Assets/GameScripts/DotNet/Core/Network/Message/Addressable/AddressableHelper.cs index 31d8a46f..d1f843b3 100644 --- a/Assets/GameScripts/DotNet/Core/Network/Message/Addressable/AddressableHelper.cs +++ b/Assets/GameScripts/DotNet/Core/Network/Message/Addressable/AddressableHelper.cs @@ -19,15 +19,14 @@ namespace TEngine.Core.Network } } - public static async FTask AddAddressable(Scene scene, long addressableId, long routeId) + public static async FTask AddAddressable(Scene scene, long addressableId, long routeId, bool isLock = true) { var addressableScene = AddressableScenes[(int)addressableId % AddressableScenes.Count]; var response = await MessageHelper.CallInnerRoute(scene, addressableScene.EntityId, new I_AddressableAdd_Request { - AddressableId = addressableId, RouteId = routeId + AddressableId = addressableId, RouteId = routeId, IsLock = isLock }); - if (response.ErrorCode != 0) { Log.Error($"AddAddressable error is {response.ErrorCode}"); diff --git a/Assets/GameScripts/DotNet/Core/Network/Message/Addressable/AddressableManageComponent.cs b/Assets/GameScripts/DotNet/Core/Network/Message/Addressable/AddressableManageComponent.cs index 24df1693..124499b8 100644 --- a/Assets/GameScripts/DotNet/Core/Network/Message/Addressable/AddressableManageComponent.cs +++ b/Assets/GameScripts/DotNet/Core/Network/Message/Addressable/AddressableManageComponent.cs @@ -8,13 +8,28 @@ namespace TEngine.Core.Network private readonly Dictionary _locks = new(); private readonly CoroutineLockQueueType _addressableLock = new CoroutineLockQueueType("AddressableLock"); - public async FTask Add(long addressableId, long routeId) + public async FTask Add(long addressableId, long routeId, bool isLock) { - using (await _addressableLock.Lock(addressableId)) + WaitCoroutineLock waitCoroutineLock = null; + + try { + if (isLock) + { + waitCoroutineLock = await _addressableLock.Lock(addressableId); + } + _addressable[addressableId] = routeId; Log.Debug($"AddressableManageComponent Add addressableId:{addressableId} routeId:{routeId}"); } + catch (Exception e) + { + Log.Error(e); + } + finally + { + waitCoroutineLock?.Dispose(); + } } public async FTask Get(long addressableId) @@ -31,6 +46,7 @@ namespace TEngine.Core.Network using (await _addressableLock.Lock(addressableId)) { _addressable.Remove(addressableId); + Log.Debug($"Addressable Remove addressableId: {addressableId} _addressable:{_addressable.Count}"); } } diff --git a/Assets/GameScripts/DotNet/Core/Network/Message/Addressable/AddressableMessageComponent.cs b/Assets/GameScripts/DotNet/Core/Network/Message/Addressable/AddressableMessageComponent.cs index 0cb4bb85..d18761e9 100644 --- a/Assets/GameScripts/DotNet/Core/Network/Message/Addressable/AddressableMessageComponent.cs +++ b/Assets/GameScripts/DotNet/Core/Network/Message/Addressable/AddressableMessageComponent.cs @@ -19,7 +19,7 @@ namespace TEngine.Core.Network base.Dispose(); } - public FTask Register() + public FTask Register(bool isLock = true) { if (Parent == null) { @@ -36,7 +36,7 @@ namespace TEngine.Core.Network #if TENGINE_DEVELOP Log.Debug($"AddressableMessageComponent Register addressableId:{AddressableId} RouteId:{Parent.RuntimeId}"); #endif - return AddressableHelper.AddAddressable(Scene, AddressableId, Parent.RuntimeId); + return AddressableHelper.AddAddressable(Scene, AddressableId, Parent.RuntimeId, isLock); } public FTask Lock() diff --git a/Assets/GameScripts/DotNet/Core/Network/Message/Addressable/Handler/I_AddressableAddHandler.cs b/Assets/GameScripts/DotNet/Core/Network/Message/Addressable/Handler/I_AddressableAddHandler.cs index 2edd4a5d..03bde8af 100644 --- a/Assets/GameScripts/DotNet/Core/Network/Message/Addressable/Handler/I_AddressableAddHandler.cs +++ b/Assets/GameScripts/DotNet/Core/Network/Message/Addressable/Handler/I_AddressableAddHandler.cs @@ -5,7 +5,7 @@ public sealed class I_AddressableAddHandler : RouteRPC().Add(request.AddressableId, request.RouteId); + await scene.GetComponent().Add(request.AddressableId, request.RouteId, request.IsLock); } } #endif \ No newline at end of file diff --git a/Assets/GameScripts/DotNet/Core/Network/Message/Interface/Scheduler/ANetworkMessageScheduler.cs b/Assets/GameScripts/DotNet/Core/Network/Message/Interface/Scheduler/ANetworkMessageScheduler.cs index 8cd2a056..e7a4586b 100644 --- a/Assets/GameScripts/DotNet/Core/Network/Message/Interface/Scheduler/ANetworkMessageScheduler.cs +++ b/Assets/GameScripts/DotNet/Core/Network/Message/Interface/Scheduler/ANetworkMessageScheduler.cs @@ -78,7 +78,7 @@ namespace TEngine.Core.Network { if (DisposePackInfo) { - packInfo.Dispose(); + NetworkThread.Instance.SynchronizationContext.Post(packInfo.Dispose); } } } diff --git a/Assets/GameScripts/DotNet/Core/Network/Message/Protocols/CoreMessageProtocols.cs b/Assets/GameScripts/DotNet/Core/Network/Message/Protocols/CoreMessageProtocols.cs index c6ae78d0..9c488e5d 100644 --- a/Assets/GameScripts/DotNet/Core/Network/Message/Protocols/CoreMessageProtocols.cs +++ b/Assets/GameScripts/DotNet/Core/Network/Message/Protocols/CoreMessageProtocols.cs @@ -63,6 +63,8 @@ namespace TEngine public long AddressableId { get; set; } [ProtoMember(2)] public long RouteId { get; set; } + [ProtoMember(3)] + public bool IsLock { get; set; } } [ProtoContract] public partial class I_AddressableAdd_Response : AProto, IRouteResponse diff --git a/Assets/GameScripts/DotNet/Core/Network/Message/Scheduler/ClientMessageScheduler.cs b/Assets/GameScripts/DotNet/Core/Network/Message/Scheduler/ClientMessageScheduler.cs index 78d022b7..4ffd9b30 100644 --- a/Assets/GameScripts/DotNet/Core/Network/Message/Scheduler/ClientMessageScheduler.cs +++ b/Assets/GameScripts/DotNet/Core/Network/Message/Scheduler/ClientMessageScheduler.cs @@ -46,7 +46,7 @@ namespace TEngine.Core.Network } finally { - packInfo.Dispose(); + NetworkThread.Instance.SynchronizationContext.Post(packInfo.Dispose); } await FTask.CompletedTask; diff --git a/Assets/GameScripts/DotNet/Core/Network/Message/Scheduler/InnerMessageScheduler.cs b/Assets/GameScripts/DotNet/Core/Network/Message/Scheduler/InnerMessageScheduler.cs index 1cde77dd..d040a77e 100644 --- a/Assets/GameScripts/DotNet/Core/Network/Message/Scheduler/InnerMessageScheduler.cs +++ b/Assets/GameScripts/DotNet/Core/Network/Message/Scheduler/InnerMessageScheduler.cs @@ -103,7 +103,7 @@ namespace TEngine.Core.Network } finally { - packInfo.Dispose(); + NetworkThread.Instance.SynchronizationContext.Post(packInfo.Dispose); } } diff --git a/Assets/GameScripts/DotNet/Core/Network/Message/Scheduler/OuterMessageScheduler.cs b/Assets/GameScripts/DotNet/Core/Network/Message/Scheduler/OuterMessageScheduler.cs index 76ea1c39..af991df9 100644 --- a/Assets/GameScripts/DotNet/Core/Network/Message/Scheduler/OuterMessageScheduler.cs +++ b/Assets/GameScripts/DotNet/Core/Network/Message/Scheduler/OuterMessageScheduler.cs @@ -120,7 +120,7 @@ namespace TEngine.Core.Network } finally { - packInfo.Dispose(); + NetworkThread.Instance.SynchronizationContext.Post(packInfo.Dispose); } throw new NotSupportedException($"Received unsupported message protocolCode:{packInfo.ProtocolCode} messageType:{messageType}"); diff --git a/Assets/GameScripts/DotNet/Core/Network/PacketParser/InnerPacketParser.cs b/Assets/GameScripts/DotNet/Core/Network/PacketParser/InnerPacketParser.cs index 63a243d3..a291783a 100644 --- a/Assets/GameScripts/DotNet/Core/Network/PacketParser/InnerPacketParser.cs +++ b/Assets/GameScripts/DotNet/Core/Network/PacketParser/InnerPacketParser.cs @@ -1,6 +1,8 @@ #if TENGINE_NET using System.Buffers; using TEngine.DataStructure; +using MongoDB.Bson.Serialization; +using MongoDB.Bson.Serialization.Serializers; // ReSharper disable ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract namespace TEngine.Core.Network; @@ -199,7 +201,16 @@ public sealed class InnerPacketParser : APacketParser { if (message is IBsonMessage) { - MongoHelper.Instance.SerializeTo(message, memoryStream); + try + { + + MongoHelper.Instance.SerializeTo(message, memoryStream); + } + catch (Exception e) + { + Log.Fatal(e); + throw; + } } else { diff --git a/Assets/GameScripts/DotNet/Core/SingleCollection/SingleCollection.cs b/Assets/GameScripts/DotNet/Core/SingleCollection/SingleCollection.cs index 5f2bf935..c159dacd 100644 --- a/Assets/GameScripts/DotNet/Core/SingleCollection/SingleCollection.cs +++ b/Assets/GameScripts/DotNet/Core/SingleCollection/SingleCollection.cs @@ -92,7 +92,7 @@ public class SingleCollection : Singleton using var collections = ListPool.Create(); - foreach (var (_, treeEntity) in entity.GetTree) + foreach (var treeEntity in entity.ForEachSingleCollection) { if (treeEntity is not ISupportedSingleCollection) {