mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
合理化Address协议逻辑
合理化Address协议逻辑
This commit is contained in:
@@ -17,7 +17,7 @@ namespace TEngine
|
||||
public uint OpCode() { return InnerOpcode.I_G2M_LoginAddressRequest; }
|
||||
public long RouteTypeOpCode() { return CoreRouteType.Route; }
|
||||
[ProtoMember(1)]
|
||||
public long AddressId { get; set; }
|
||||
public long AddressableId { get; set; }
|
||||
[ProtoMember(2)]
|
||||
public long GateRouteId { get; set; }
|
||||
}
|
||||
@@ -27,5 +27,7 @@ namespace TEngine
|
||||
public uint OpCode() { return InnerOpcode.I_M2G_LoginAddressResponse; }
|
||||
[ProtoMember(91, IsRequired = true)]
|
||||
public uint ErrorCode { get; set; }
|
||||
[ProtoMember(1)]
|
||||
public long AddressableId { get; set; }
|
||||
}
|
||||
}
|
||||
|
@@ -24,14 +24,14 @@ public class H_C2G_LoginAddressRequestHandler : MessageRPC<H_C2G_LoginAddressReq
|
||||
// 1、首选分配一个可用、负载比较低的服务器给这个Unit、我这里就在ServerConfig.xsl表里拿一个MAP了、但实际开发过程可能比这个要复杂
|
||||
// 我这里就简单些一个做为演示、其实这些逻辑开发者完全可以自己封装一个接口来做。
|
||||
// 在ServerConfig.xsl里找到MAP的进程、看到ID是3072通过这个Id在SceneConfig.xsl里找到对应的Scene的EntityId
|
||||
var sceneEntityId = Helper.AddressableSceneHelper.GetSceneEntityIdByRouteId(3072);
|
||||
var sceneEntityId = Helper.AddressableSceneHelper.GetSceneEntityId();
|
||||
|
||||
// 2、在InnerMessage里定义一个协议、用于Gate跟Map通讯的协议I_G2M_LoginAddress
|
||||
var loginAddressResponse = (I_M2G_LoginAddressResponse)await MessageHelper.CallInnerRoute(session.Scene,
|
||||
sceneEntityId,
|
||||
new I_G2M_LoginAddressRequest()
|
||||
{
|
||||
AddressId = session.Id,
|
||||
AddressableId = session.Id,
|
||||
GateRouteId = session.RuntimeId,
|
||||
});
|
||||
if (loginAddressResponse.ErrorCode != 0)
|
||||
@@ -40,7 +40,7 @@ public class H_C2G_LoginAddressRequestHandler : MessageRPC<H_C2G_LoginAddressReq
|
||||
return;
|
||||
}
|
||||
// 3、可寻址消息组件、挂载了这个组件可以接收和发送Addressable消息
|
||||
session.AddComponent<AddressableRouteComponent>();
|
||||
session.AddComponent<AddressableRouteComponent>().SetAddressableId(loginAddressResponse.AddressableId);
|
||||
}
|
||||
}
|
||||
#endif
|
@@ -36,10 +36,10 @@ namespace TEngine.Logic
|
||||
// 一般这个信息是数据库里拿到或者其他服务器给传递过来了、这里主要演示怎么注册Address、所以这些步骤这里就不做了
|
||||
// 这里我就模拟一个假的Unit数据使用
|
||||
// 1、首先创建一个Unit
|
||||
var unit = AddressManage.Add(scene, request.AddressId, request.GateRouteId);
|
||||
var unit = AddressManage.Add(scene, request.AddressableId, request.GateRouteId);
|
||||
// 2、挂在AddressableMessageComponent组件、让这个Unit支持Address、并且会自动注册到网格中
|
||||
await unit.AddComponent<AddressableMessageComponent>().Register();
|
||||
await FTask.CompletedTask;
|
||||
response.AddressableId = unit.Id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -33,10 +33,10 @@ public static class AddressableSceneHelper
|
||||
return sceneEntityId;
|
||||
}
|
||||
|
||||
public static long GetSceneEntityIdByRouteId(uint routeId)
|
||||
public static long GetSceneEntityIdBySceneId(uint sceneId)
|
||||
{
|
||||
var sceneEntityId = 0L;
|
||||
var sceneConfig = SceneConfigData.Instance.Get(routeId);
|
||||
var sceneConfig = SceneConfigData.Instance.Get(sceneId);
|
||||
sceneEntityId = sceneConfig.EntityId;
|
||||
return sceneEntityId;
|
||||
}
|
||||
|
35
DotNet/Logic/src/Helper/GameTickWatcher.cs
Normal file
35
DotNet/Logic/src/Helper/GameTickWatcher.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
namespace TEngine.Helper;
|
||||
|
||||
public class GameTickWatcher
|
||||
{
|
||||
private long m_startTick = 0;
|
||||
|
||||
public GameTickWatcher()
|
||||
{
|
||||
Refresh();
|
||||
}
|
||||
|
||||
public void Refresh()
|
||||
{
|
||||
m_startTick = DateTime.Now.Ticks;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 计算用时。
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public float ElapseTime()
|
||||
{
|
||||
long endTick = DateTime.Now.Ticks;
|
||||
return (endTick - m_startTick) / 10000f / 1000.0f;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 计算用时。
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public void LogElapseTime(string tag)
|
||||
{
|
||||
Console.WriteLine($"计算用时:{tag} 耗时 {this.ElapseTime()}");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user