mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-07 16:45:10 +00:00
1、修复了MongoDB在2.18.0以后需要自定义注册ObjectSerializer的问题。 2、Addressable的AddAddressable接口增加isLock参数、用来决定是否需要添加携程锁。 3、修复了APackInfo因为网络多线程的原因导致线程安全的问题。
1、修复了MongoDB在2.18.0以后需要自定义注册ObjectSerializer的问题。 2、Addressable的AddAddressable接口增加isLock参数、用来决定是否需要添加携程锁。 3、修复了APackInfo因为网络多线程的原因导致线程安全的问题。
This commit is contained in:
@@ -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}");
|
||||
|
@@ -8,13 +8,28 @@ namespace TEngine.Core.Network
|
||||
private readonly Dictionary<long, WaitCoroutineLock> _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<long> 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}");
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -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()
|
||||
|
@@ -5,7 +5,7 @@ public sealed class I_AddressableAddHandler : RouteRPC<Scene, I_AddressableAdd_R
|
||||
{
|
||||
protected override async FTask Run(Scene scene, I_AddressableAdd_Request request, I_AddressableAdd_Response response, Action reply)
|
||||
{
|
||||
await scene.GetComponent<AddressableManageComponent>().Add(request.AddressableId, request.RouteId);
|
||||
await scene.GetComponent<AddressableManageComponent>().Add(request.AddressableId, request.RouteId, request.IsLock);
|
||||
}
|
||||
}
|
||||
#endif
|
@@ -78,7 +78,7 @@ namespace TEngine.Core.Network
|
||||
{
|
||||
if (DisposePackInfo)
|
||||
{
|
||||
packInfo.Dispose();
|
||||
NetworkThread.Instance.SynchronizationContext.Post(packInfo.Dispose);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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
|
||||
|
@@ -46,7 +46,7 @@ namespace TEngine.Core.Network
|
||||
}
|
||||
finally
|
||||
{
|
||||
packInfo.Dispose();
|
||||
NetworkThread.Instance.SynchronizationContext.Post(packInfo.Dispose);
|
||||
}
|
||||
|
||||
await FTask.CompletedTask;
|
||||
|
@@ -103,7 +103,7 @@ namespace TEngine.Core.Network
|
||||
}
|
||||
finally
|
||||
{
|
||||
packInfo.Dispose();
|
||||
NetworkThread.Instance.SynchronizationContext.Post(packInfo.Dispose);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -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}");
|
||||
|
@@ -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
|
||||
{
|
||||
|
Reference in New Issue
Block a user