mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-07 16:45:10 +00:00
合理化Address协议逻辑
合理化Address协议逻辑
This commit is contained in:
@@ -35,9 +35,9 @@ namespace TEngine.DataStructure
|
||||
if (layer <= rLevel)
|
||||
{
|
||||
var currentRight = cur.Right;
|
||||
cur.Right = new SkipTableNode<TValue>(sortKey, viceKey, key, value,
|
||||
layer == 1 ? cur.Index + 1 : 0, cur, cur.Right, null);
|
||||
|
||||
|
||||
cur.Right = new SkipTableNode<TValue>(sortKey, viceKey, key, value, layer == 1 ? cur.Index + 1 : 0, cur, cur.Right, null);
|
||||
|
||||
if (currentRight != null)
|
||||
{
|
||||
currentRight.Left = cur.Right;
|
||||
|
@@ -528,6 +528,7 @@ namespace TEngine
|
||||
|
||||
try
|
||||
{
|
||||
Scene = scene;
|
||||
#if TENGINE_NET
|
||||
RuntimeId = IdFactory.NextEntityId(scene.RouteId);
|
||||
#else
|
||||
@@ -546,7 +547,6 @@ namespace TEngine
|
||||
foreach (var entity in _treeDb)
|
||||
{
|
||||
entity.Parent = this;
|
||||
entity.Scene = scene;
|
||||
entity.Deserialize(scene, resetId);
|
||||
_tree.Add(entity.GetType(), entity);
|
||||
}
|
||||
@@ -558,7 +558,6 @@ namespace TEngine
|
||||
foreach (var entity in _multiDb)
|
||||
{
|
||||
entity.Parent = this;
|
||||
entity.Scene = scene;
|
||||
entity.Deserialize(scene, resetId);
|
||||
_multi.Add(entity.Id, (ISupportedMultiEntity)entity);
|
||||
}
|
||||
|
@@ -217,7 +217,7 @@ namespace TEngine
|
||||
|
||||
StringBuilder infoBuilder = GetFormatString(type, logString);
|
||||
|
||||
if (type == LogLevel.ERROR || type == LogLevel.WARNING || type == LogLevel.EXCEPTION)
|
||||
if (type == LogLevel.ERROR || type == LogLevel.EXCEPTION)
|
||||
{
|
||||
StackFrame[] sf = new StackTrace().GetFrames();
|
||||
for (int i = 0; i < sf.Length; i++)
|
||||
|
@@ -26,6 +26,7 @@ namespace TEngine.Logic
|
||||
{
|
||||
_session = (Session)Parent;
|
||||
_selfRunTimeId = RuntimeId;
|
||||
RepeatedSend().Coroutine();
|
||||
_timerId = TimerScheduler.Instance.Unity.RepeatedTimer(interval, () => RepeatedSend().Coroutine());
|
||||
}
|
||||
|
||||
@@ -57,6 +58,7 @@ namespace TEngine.Logic
|
||||
var responseTime = TimeHelper.Now;
|
||||
Ping = (int)(responseTime - requestTime) / 2;
|
||||
TimeHelper.TimeDiff = pingResponse.Now + Ping - responseTime;
|
||||
Log.Info("----------- HeartBeat -----------");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,50 +1,26 @@
|
||||
#pragma warning disable CS8603
|
||||
#pragma warning disable CS8600
|
||||
#if TENGINE_NET
|
||||
namespace TEngine.Core.Network;
|
||||
|
||||
public sealed class AddressableRouteComponentAwakeSystem : AwakeSystem<AddressableRouteComponent>
|
||||
{
|
||||
protected override void Awake(AddressableRouteComponent self)
|
||||
{
|
||||
self.Awake();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 可寻址消息组件、挂载了这个组件可以接收和发送Addressable消息
|
||||
/// </summary>
|
||||
public sealed class AddressableRouteComponent : Entity
|
||||
{
|
||||
private long _parentId;
|
||||
private long _addressableRouteId;
|
||||
private long _routeId;
|
||||
private long _addressableId;
|
||||
|
||||
public static readonly CoroutineLockQueueType AddressableRouteMessageLock = new CoroutineLockQueueType("AddressableRouteMessageLock");
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
_parentId = 0;
|
||||
_addressableRouteId = 0;
|
||||
_routeId = 0;
|
||||
_addressableId = 0;
|
||||
base.Dispose();
|
||||
}
|
||||
|
||||
public void Awake()
|
||||
{
|
||||
if (Parent == null)
|
||||
{
|
||||
throw new Exception("AddressableRouteComponent must be mounted under a component");
|
||||
}
|
||||
|
||||
if (Parent.RuntimeId == 0)
|
||||
{
|
||||
throw new Exception("AddressableRouteComponent.Parent.RuntimeId is null");
|
||||
}
|
||||
|
||||
_parentId = Parent.Id;
|
||||
}
|
||||
|
||||
public void SetAddressableRouteId(long addressableRouteId)
|
||||
public void SetAddressableId(long addressableId)
|
||||
{
|
||||
_addressableRouteId = addressableRouteId;
|
||||
_addressableId = addressableId;
|
||||
}
|
||||
|
||||
public void Send(IAddressableRouteMessage message)
|
||||
@@ -68,21 +44,21 @@ public sealed class AddressableRouteComponent : Entity
|
||||
var runtimeId = RuntimeId;
|
||||
IResponse iRouteResponse = null;
|
||||
|
||||
using (await AddressableRouteMessageLock.Lock(_parentId, "AddressableRouteComponent Call MemoryStream"))
|
||||
using (await AddressableRouteMessageLock.Lock(_addressableId, "AddressableRouteComponent Call MemoryStream"))
|
||||
{
|
||||
while (!IsDisposed)
|
||||
{
|
||||
if (_addressableRouteId == 0)
|
||||
if (_routeId == 0)
|
||||
{
|
||||
_addressableRouteId = await AddressableHelper.GetAddressableRouteId(Scene, _parentId);
|
||||
_routeId = await AddressableHelper.GetAddressableRouteId(Scene, _addressableId);
|
||||
}
|
||||
|
||||
if (_addressableRouteId == 0)
|
||||
if (_routeId == 0)
|
||||
{
|
||||
return MessageDispatcherSystem.Instance.CreateResponse(requestType, CoreErrorCode.ErrNotFoundRoute);
|
||||
}
|
||||
|
||||
iRouteResponse = await MessageHelper.CallInnerRoute(Scene, _addressableRouteId, routeTypeOpCode, requestType, request);
|
||||
iRouteResponse = await MessageHelper.CallInnerRoute(Scene, _routeId, routeTypeOpCode, requestType, request);
|
||||
|
||||
if (runtimeId != RuntimeId)
|
||||
{
|
||||
@@ -99,7 +75,7 @@ public sealed class AddressableRouteComponent : Entity
|
||||
{
|
||||
if (++failCount > 20)
|
||||
{
|
||||
Log.Error($"AddressableComponent.Call failCount > 20 route send message fail, routeId: {_addressableRouteId} AddressableRouteComponent:{Id}");
|
||||
Log.Error($"AddressableComponent.Call failCount > 20 route send message fail, routeId: {_routeId} AddressableRouteComponent:{Id}");
|
||||
return iRouteResponse;
|
||||
}
|
||||
|
||||
@@ -110,7 +86,7 @@ public sealed class AddressableRouteComponent : Entity
|
||||
iRouteResponse.ErrorCode = CoreErrorCode.ErrRouteTimeout;
|
||||
}
|
||||
|
||||
_addressableRouteId = 0;
|
||||
_routeId = 0;
|
||||
continue;
|
||||
}
|
||||
default:
|
||||
@@ -134,21 +110,21 @@ public sealed class AddressableRouteComponent : Entity
|
||||
var failCount = 0;
|
||||
var runtimeId = RuntimeId;
|
||||
|
||||
using (await AddressableRouteMessageLock.Lock(_parentId,"AddressableRouteComponent Call"))
|
||||
using (await AddressableRouteMessageLock.Lock(_addressableId,"AddressableRouteComponent Call"))
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (_addressableRouteId == 0)
|
||||
if (_routeId == 0)
|
||||
{
|
||||
_addressableRouteId = await AddressableHelper.GetAddressableRouteId(Scene, _parentId);
|
||||
_routeId = await AddressableHelper.GetAddressableRouteId(Scene, _addressableId);
|
||||
}
|
||||
|
||||
if (_addressableRouteId == 0)
|
||||
if (_routeId == 0)
|
||||
{
|
||||
return MessageDispatcherSystem.Instance.CreateResponse(request, CoreErrorCode.ErrNotFoundRoute);
|
||||
}
|
||||
|
||||
var iRouteResponse = await MessageHelper.CallInnerRoute(Scene, _addressableRouteId, request);
|
||||
var iRouteResponse = await MessageHelper.CallInnerRoute(Scene, _routeId, request);
|
||||
|
||||
if (runtimeId != RuntimeId)
|
||||
{
|
||||
@@ -161,7 +137,7 @@ public sealed class AddressableRouteComponent : Entity
|
||||
{
|
||||
if (++failCount > 20)
|
||||
{
|
||||
Log.Error($"AddressableRouteComponent.Call failCount > 20 route send message fail, routeId: {_addressableRouteId} AddressableRouteComponent:{Id}");
|
||||
Log.Error($"AddressableRouteComponent.Call failCount > 20 route send message fail, routeId: {_routeId} AddressableRouteComponent:{Id}");
|
||||
return iRouteResponse;
|
||||
}
|
||||
|
||||
@@ -172,7 +148,7 @@ public sealed class AddressableRouteComponent : Entity
|
||||
iRouteResponse.ErrorCode = CoreErrorCode.ErrRouteTimeout;
|
||||
}
|
||||
|
||||
_addressableRouteId = 0;
|
||||
_routeId = 0;
|
||||
continue;
|
||||
}
|
||||
case CoreErrorCode.ErrRouteTimeout:
|
||||
|
@@ -144,7 +144,7 @@ namespace TEngine.Core.Network
|
||||
scene = entity.Scene;
|
||||
}
|
||||
|
||||
Log.Error($"SceneWorld:{session.Scene.World.Id} SceneRouteId:{scene.RouteId} SceneType:{scene.SceneInfo.SceneType} EntityId {tEntity.Id} : Error {e}");
|
||||
Log.Error($"SceneWorld:{session.Scene.World?.Id} SceneRouteId:{scene.RouteId} SceneType:{scene.SceneInfo.SceneType} EntityId {tEntity.Id} : Error {e}");
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
@@ -75,7 +75,7 @@ namespace TEngine.Demo
|
||||
private void OnConnectComplete()
|
||||
{
|
||||
IsConnect = true;
|
||||
Scene.Session.AddComponent<SessionHeartbeatComponent>().Start(15);
|
||||
Scene.Session.AddComponent<SessionHeartbeatComponent>().Start(15000);
|
||||
LogDebug("已连接到服务器");
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user