diff --git a/Assets/GameScripts/DotNet/Core/Entitas/Entity.cs b/Assets/GameScripts/DotNet/Core/Entitas/Entity.cs index 0b05f7f0..0d976beb 100644 --- a/Assets/GameScripts/DotNet/Core/Entitas/Entity.cs +++ b/Assets/GameScripts/DotNet/Core/Entitas/Entity.cs @@ -194,14 +194,14 @@ namespace TEngine public static T Create(Scene scene, bool isRunEvent = true) where T : Entity, new() { - var entity = Create(scene.RouteId, isRunEvent); + var entity = Create(scene.LocationId, isRunEvent); entity.Scene = scene; return entity; } public static T Create(Scene scene, long id, bool isRunEvent = true) where T : Entity, new() { - var entity = Create(id, scene.RouteId, isRunEvent); + var entity = Create(id, scene.LocationId, isRunEvent); entity.Scene = scene; return entity; } @@ -235,12 +235,12 @@ namespace TEngine return entity; } - private static T Create(long id, uint routeId, bool isRunEvent = true) where T : Entity, new() + protected static T Create(long id, uint locationId, bool isRunEvent = true) where T : Entity, new() { - return Create(id, IdFactory.NextEntityId(routeId), isRunEvent); + return Create(id, IdFactory.NextEntityId(locationId), isRunEvent); } - private static T Create(long id, long runtimeId, bool isRunEvent = true) where T : Entity, new() + protected static T Create(long id, long runtimeId, bool isRunEvent = true) where T : Entity, new() { var entity = Rent(typeof(T)); entity.Id = id; @@ -264,13 +264,6 @@ namespace TEngine return entity; } - protected static Scene CreateScene(long id, bool isRunEvent = true) - { - var entity = Create(id, id, isRunEvent); - entity.Scene = entity; - return entity; - } - #endregion #region Members @@ -293,12 +286,12 @@ namespace TEngine [BsonIgnore] [JsonIgnore] [IgnoreDataMember] - public Scene Scene { get; private set; } + public Scene Scene { get; protected set; } [BsonIgnore] [JsonIgnore] [IgnoreDataMember] - public Entity Parent { get; private set; } + public Entity Parent { get; protected set; } [BsonElement("t")] [BsonIgnoreIfNull] @@ -321,7 +314,7 @@ namespace TEngine public T AddComponent() where T : Entity, new() { - var entity = Create(Id, Scene.RouteId, false); + var entity = Create(Id, Scene.LocationId, false); AddComponent(entity); EntitiesSystem.Instance.Awake(entity); EntitiesSystem.Instance.StartUpdate(entity); @@ -330,7 +323,7 @@ namespace TEngine public T AddComponent(long id) where T : Entity, new() { - var entity = Create(id, Scene.RouteId, false); + var entity = Create(id, Scene.LocationId, false); AddComponent(entity); EntitiesSystem.Instance.Awake(entity); EntitiesSystem.Instance.StartUpdate(entity); @@ -538,7 +531,7 @@ namespace TEngine { Scene = scene; #if TENGINE_NET - RuntimeId = IdFactory.NextEntityId(scene.RouteId); + RuntimeId = IdFactory.NextEntityId(scene.LocationId); #else RuntimeId = IdFactory.NextRunTimeId(); #endif diff --git a/Assets/GameScripts/DotNet/Core/Entitas/Scene/Scene.cs b/Assets/GameScripts/DotNet/Core/Entitas/Scene/Scene.cs index b39d28f1..72d6fdb9 100644 --- a/Assets/GameScripts/DotNet/Core/Entitas/Scene/Scene.cs +++ b/Assets/GameScripts/DotNet/Core/Entitas/Scene/Scene.cs @@ -12,16 +12,15 @@ namespace TEngine public sealed class Scene : Entity, INotSupportedPool { public string Name { get; private set; } - public uint RouteId { get; private set; } + public uint LocationId { get; private set; } #if TENGINE_UNITY public Session Session { get; private set; } public SceneConfigInfo SceneInfo { get; private set; } #endif #if TENGINE_NET + public string SceneType { get; private set; } public World World { get; private set; } public Server Server { get; private set; } - public uint SceneConfigId { get; private set; } - public SceneConfigInfo SceneInfo => ConfigTableManage.SceneConfig(SceneConfigId); #endif public static readonly List Scenes = new List(); @@ -33,11 +32,11 @@ namespace TEngine } Name = null; - RouteId = 0; + this.LocationId = 0; #if TENGINE_NET World = null; Server = null; - SceneConfigId = 0; + SceneType = null; #endif #if TENGINE_UNITY SceneInfo = null; @@ -61,8 +60,10 @@ namespace TEngine #if TENGINE_UNITY public static Scene Create(string name) { - var runTimeId = IdFactory.NextRunTimeId(); - var scene = CreateScene(runTimeId); + var sceneId = IdFactory.NextRunTimeId(); + var scene = Create(sceneId, sceneId); + scene.Scene = scene; + scene.Parent = scene; scene.Name = name; Scenes.Add(scene); return scene; @@ -77,41 +78,81 @@ namespace TEngine } #else /// - /// 创建一个Scene + /// 创建一个Scene、但这个Scene是在某个Scene下面的Scene + /// + /// + /// + /// + /// + public static async FTask Create(Scene scene, string sceneType, string sceneName) + { + var newScene = Create(scene); + newScene.Scene = scene; + newScene.Parent = scene; + newScene.Name = sceneName; + newScene.SceneType = sceneType; + newScene.Server = scene.Server; + newScene.LocationId = scene.Server.Id; + + if (scene.World !=null) + { + newScene.World = scene.World; + } + + if (!string.IsNullOrEmpty(sceneType)) + { + await EventSystem.Instance.PublishAsync(new OnCreateScene(scene)); + } + + Scenes.Add(scene); + return scene; + } + + /// + /// 创建一个Scene。 /// /// + /// + /// + /// + /// + /// /// - /// - /// - /// + /// /// - public static async FTask Create(Server server, string outerBindIp, SceneConfigInfo sceneInfo, Action onSetNetworkComplete = null, bool runEvent = true) + public static async FTask Create(Server server, string sceneType, string sceneName, long sceneId =0, uint worldId =0, string networkProtocol = null, string outerBindIp = null, int outerPort = 0) { - var scene = CreateScene(sceneInfo.EntityId); - sceneInfo.Scene = scene; - scene.Name = sceneInfo.Name; - scene.RouteId = sceneInfo.RouteId; + if (sceneId == 0) + { + sceneId = new EntityIdStruct(server.Id, 0, 0); + } + + var scene = Create(sceneId, sceneId); + scene.Scene = scene; + scene.Parent = scene; + scene.Name = sceneName; + scene.SceneType = sceneType; scene.Server = server; - scene.SceneConfigId = sceneInfo.Id; + scene.LocationId = server.Id; - if (sceneInfo.WorldId != 0) + if (worldId != 0) { // 有可能不需要数据库、所以这里默认0的情况下就不创建数据库了 - scene.World = World.Create(sceneInfo.WorldId); + scene.World = World.Create(worldId); } - if (!string.IsNullOrEmpty(sceneInfo.NetworkProtocol) && !string.IsNullOrEmpty(outerBindIp) && sceneInfo.OuterPort != 0) + if (!string.IsNullOrEmpty(networkProtocol) && !string.IsNullOrEmpty(outerBindIp) && outerPort != 0) { // 设置Scene的网络、目前只支持KCP和TCP - var networkProtocolType = Enum.Parse(sceneInfo.NetworkProtocol); + var networkProtocolType = Enum.Parse(networkProtocol); var serverNetworkComponent = scene.AddComponent(); - var address = NetworkHelper.ToIPEndPoint($"{outerBindIp}:{sceneInfo.OuterPort}"); + var address = NetworkHelper.ToIPEndPoint($"{outerBindIp}:{outerPort}"); serverNetworkComponent.Initialize(networkProtocolType, NetworkTarget.Outer, address); } - if (runEvent && sceneInfo.SceneType != null) + if (!string.IsNullOrEmpty(sceneType)) { - switch (sceneInfo.SceneType) + switch (sceneType) { case "Addressable": { @@ -121,7 +162,7 @@ namespace TEngine default: { // 没有SceneType目前只有代码创建的Scene才会这样、目前只有Server的Scene是这样 - await EventSystem.Instance.PublishAsync(new OnCreateScene(sceneInfo, onSetNetworkComplete)); + await EventSystem.Instance.PublishAsync(new OnCreateScene(scene)); break; } } @@ -131,42 +172,14 @@ namespace TEngine return scene; } - /// - /// 一般用于创建临时Scene、如果不是必要不建议使用这个接口 - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - public static async FTask Create(string name, Server server, long entityId, uint sceneConfigId = 0, string networkProtocol = null, string outerBindIp = null, int outerPort = 0, Action onSetNetworkComplete = null, bool runEvent = true) - { - var sceneInfo = new SceneConfigInfo() - { - Name = name, - EntityId = entityId, - Id = sceneConfigId, - NetworkProtocol = networkProtocol, - OuterPort = outerPort, - WorldId = ((EntityIdStruct)entityId).WordId - }; - - return await Create(server, outerBindIp, sceneInfo, onSetNetworkComplete, runEvent); - } - - public static List GetSceneInfoByRouteId(uint routeId) + public static List GetSceneInfoByServerConfigId(uint serverConfigId) { var list = new List(); var allSceneConfig = ConfigTableManage.AllSceneConfig(); foreach (var sceneConfigInfo in allSceneConfig) { - if (sceneConfigInfo.RouteId != routeId) + if (sceneConfigInfo.ServerConfigId != serverConfigId) { continue; } diff --git a/Assets/GameScripts/DotNet/Core/Entitas/Scene/SceneEvent.cs b/Assets/GameScripts/DotNet/Core/Entitas/Scene/SceneEvent.cs index 03f27b3a..20e7566c 100644 --- a/Assets/GameScripts/DotNet/Core/Entitas/Scene/SceneEvent.cs +++ b/Assets/GameScripts/DotNet/Core/Entitas/Scene/SceneEvent.cs @@ -5,13 +5,11 @@ namespace TEngine { public struct OnCreateScene { - public readonly SceneConfigInfo SceneInfo; - public readonly Action OnSetNetworkComplete; + public readonly Scene Scene; - public OnCreateScene(SceneConfigInfo sceneInfo, Action onSetNetworkComplete) + public OnCreateScene(Scene scene) { - SceneInfo = sceneInfo; - OnSetNetworkComplete = onSetNetworkComplete; + Scene = scene; } } } diff --git a/Assets/GameScripts/DotNet/Core/Exporter/Excel/ServerConfigTableManage.cs b/Assets/GameScripts/DotNet/Core/Exporter/Excel/ServerConfigTableManage.cs index c8b7c2ea..00d8b9d6 100644 --- a/Assets/GameScripts/DotNet/Core/Exporter/Excel/ServerConfigTableManage.cs +++ b/Assets/GameScripts/DotNet/Core/Exporter/Excel/ServerConfigTableManage.cs @@ -33,8 +33,6 @@ namespace TEngine.Core { var configFile = GetConfigPath(dataConfig); var bytes = File.ReadAllBytes(configFile); - // var data = (AProto) ProtoBufHelper.FromBytes(typeof(T), bytes, 0, bytes.Length); - // var data = ProtoBufHelper.FromBytes(bytes, 0, bytes.Length); var data = (T)ProtoBufHelper.FromBytes(typeof(T), bytes, 0, bytes.Length); data.AfterDeserialization(); ConfigDic[dataConfig] = data; diff --git a/Assets/GameScripts/DotNet/Core/IdFactory/EntityIdStruct.cs b/Assets/GameScripts/DotNet/Core/IdFactory/EntityIdStruct.cs index 976f20d0..a70153fb 100644 --- a/Assets/GameScripts/DotNet/Core/IdFactory/EntityIdStruct.cs +++ b/Assets/GameScripts/DotNet/Core/IdFactory/EntityIdStruct.cs @@ -14,26 +14,26 @@ namespace TEngine.Core public uint Time{ get; private set; } public uint Sequence{ get; private set; } - public uint RouteId { get; private set; } + public uint LocationId { get; private set; } - public ushort AppId => (ushort)(RouteId >> 10 & RouteIdStruct.MaskAppId); - public ushort WordId=> (ushort)(RouteId & RouteIdStruct.MaskWordId); + public ushort AppId => (ushort)(this.LocationId >> 10 & RouteIdStruct.MaskAppId); + public ushort WordId=> (ushort)(this.LocationId & RouteIdStruct.MaskWordId); public const int MaskRouteId = 0x3FFFF; public const int MaskSequence = 0xFFFF; - public EntityIdStruct(uint routeId, uint time, uint sequence) + public EntityIdStruct(uint locationId, uint time, uint sequence) { Time = time; Sequence = sequence; - RouteId = routeId; + LocationId = locationId; } public static implicit operator long(EntityIdStruct entityIdStruct) { ulong result = 0; result |= entityIdStruct.Sequence; - result |= (ulong)entityIdStruct.RouteId << 16; + result |= (ulong)entityIdStruct.LocationId << 16; result |= (ulong)entityIdStruct.Time << 34; return (long)result; } @@ -46,7 +46,7 @@ namespace TEngine.Core Sequence = (uint) (result & MaskSequence) }; result >>= 16; - idStruct.RouteId = (uint) (result & 0x3FFFF); + idStruct.LocationId = (uint) (result & 0x3FFFF); result >>= 18; idStruct.Time = (uint) result; return idStruct; diff --git a/Assets/GameScripts/DotNet/Core/IdFactory/IdFactory.cs b/Assets/GameScripts/DotNet/Core/IdFactory/IdFactory.cs index 504f19bc..d0f75865 100644 --- a/Assets/GameScripts/DotNet/Core/IdFactory/IdFactory.cs +++ b/Assets/GameScripts/DotNet/Core/IdFactory/IdFactory.cs @@ -32,7 +32,7 @@ namespace TEngine.Core return new RuntimeIdStruct(_lastRunTimeIdTime, _lastRunTimeIdSequence); } - public static long NextEntityId(uint routeId) + public static long NextEntityId(uint locationId) { var time = (uint)((TimeHelper.Now - Epoch2023) / 1000); @@ -47,7 +47,7 @@ namespace TEngine.Core _lastEntityIdSequence = 0; } - return new EntityIdStruct(routeId, _lastEntityIdTime, _lastEntityIdSequence); + return new EntityIdStruct(locationId, _lastEntityIdTime, _lastEntityIdSequence); } public static uint GetRouteId(long entityId) diff --git a/Assets/GameScripts/DotNet/Core/Network/Base/Server/SceneConfigInfo.cs b/Assets/GameScripts/DotNet/Core/Network/Base/Server/SceneConfigInfo.cs index 80fbed2d..3da40038 100644 --- a/Assets/GameScripts/DotNet/Core/Network/Base/Server/SceneConfigInfo.cs +++ b/Assets/GameScripts/DotNet/Core/Network/Base/Server/SceneConfigInfo.cs @@ -2,16 +2,14 @@ namespace TEngine { public class SceneConfigInfo { - public Scene Scene; - public long EntityId; - public uint Id; - public string SceneType; public string Name; - public string NetworkProtocol; - public uint RouteId; + public long EntityId; + public string SceneType; + public uint ServerConfigId; public uint WorldId; public int OuterPort; + public string NetworkProtocol; } } diff --git a/Assets/GameScripts/DotNet/Core/Network/Base/Server/Server.cs b/Assets/GameScripts/DotNet/Core/Network/Base/Server/Server.cs index b246a9aa..19f1d951 100644 --- a/Assets/GameScripts/DotNet/Core/Network/Base/Server/Server.cs +++ b/Assets/GameScripts/DotNet/Core/Network/Base/Server/Server.cs @@ -103,13 +103,13 @@ namespace TEngine private static readonly Dictionary Servers = new Dictionary(); - public static async FTask Create(uint routeId) + public static async FTask Create(uint serverConfigId) { - var serverConfigInfo = ConfigTableManage.ServerConfig(routeId); + var serverConfigInfo = ConfigTableManage.ServerConfig(serverConfigId); if (serverConfigInfo == null) { - Log.Error($"not found server by Id:{routeId}"); + Log.Error($"not found server by Id:{serverConfigId}"); return; } @@ -121,14 +121,14 @@ namespace TEngine return; } - var sceneInfos = Scene.GetSceneInfoByRouteId(routeId); - await Create(routeId, machineConfigInfo.InnerBindIP, serverConfigInfo.InnerPort, machineConfigInfo.OuterBindIP, sceneInfos); - // Log.Info($"ServerId:{routeId} is start complete"); + var sceneInfos = Scene.GetSceneInfoByServerConfigId(serverConfigId); + await Create(serverConfigId, machineConfigInfo.InnerBindIP, serverConfigInfo.InnerPort, machineConfigInfo.OuterBindIP, sceneInfos); + // Log.Info($"ServerId:{serverConfigId} is start complete"); } - public static async FTask Create(uint routeId, string innerBindIp, int innerPort, string outerBindIp, List sceneInfos) + public static async FTask Create(uint serverConfigId, string innerBindIp, int innerPort, string outerBindIp, List sceneInfos) { - if (Servers.TryGetValue(routeId, out var server)) + if (Servers.TryGetValue(serverConfigId, out var server)) { return server; } @@ -137,10 +137,10 @@ namespace TEngine server = new Server { - Id = routeId + Id = serverConfigId }; - server.Scene = await Scene.Create($"ServerScene{routeId}", server, new EntityIdStruct(routeId, 0, 0)); + server.Scene = await Scene.Create(server,null,$"ServerScene{serverConfigId}"); // 创建网络、Server下的网络只能是内部网络、外部网络是在Scene中定义 @@ -155,16 +155,17 @@ namespace TEngine foreach (var sceneConfig in sceneInfos) { - await Scene.Create(server, outerBindIp, sceneConfig); + await Scene.Create(server, sceneConfig.SceneType, sceneConfig.Name, sceneConfig.EntityId, + sceneConfig.WorldId, sceneConfig.NetworkProtocol, outerBindIp, sceneConfig.OuterPort); } - Servers.Add(routeId, server); + Servers.Add(serverConfigId, server); return server; } - public static Server Get(uint routeId) + public static Server Get(uint serverConfigId) { - return Servers.TryGetValue(routeId, out var server) ? server : null; + return Servers.TryGetValue(serverConfigId, out var server) ? server : null; } #endregion diff --git a/Assets/GameScripts/DotNet/Core/Network/Message/Interface/Handler/IRouteMessageHandler.cs b/Assets/GameScripts/DotNet/Core/Network/Message/Interface/Handler/IRouteMessageHandler.cs index bb362cdf..edfc26ce 100644 --- a/Assets/GameScripts/DotNet/Core/Network/Message/Interface/Handler/IRouteMessageHandler.cs +++ b/Assets/GameScripts/DotNet/Core/Network/Message/Interface/Handler/IRouteMessageHandler.cs @@ -41,7 +41,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} ServerConfigId:{scene.Server?.Id} SceneType:{scene.SceneType} EntityId {tEntity.Id} : Error {e}"); } } @@ -100,7 +100,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} ServerConfigId:{scene.Server?.Id} SceneType:{scene.SceneType} EntityId {tEntity.Id} : Error {e}"); response.ErrorCode = CoreErrorCode.ErrRpcFail; } finally @@ -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} ServerConfigId:{scene.Server?.Id} SceneType:{scene.SceneType} EntityId {tEntity.Id} : Error {e}"); } finally { @@ -207,7 +207,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} ServerConfigId:{scene.Server?.Id} SceneType:{scene.SceneType} EntityId {tEntity.Id} : Error {e}"); response.ErrorCode = CoreErrorCode.ErrRpcFail; } finally diff --git a/Assets/GameScripts/DotNet/Core/Network/Message/MessageHelper.cs b/Assets/GameScripts/DotNet/Core/Network/Message/MessageHelper.cs index 51fda256..809dfa82 100644 --- a/Assets/GameScripts/DotNet/Core/Network/Message/MessageHelper.cs +++ b/Assets/GameScripts/DotNet/Core/Network/Message/MessageHelper.cs @@ -35,7 +35,7 @@ public static class MessageHelper } EntityIdStruct entityIdStruct = entityId; - var session = scene.Server.GetSession(entityIdStruct.RouteId); + var session = scene.Server.GetSession(entityIdStruct.LocationId); session.Send(message, 0, entityId); } @@ -48,7 +48,7 @@ public static class MessageHelper } EntityIdStruct entityIdStruct = entityId; - var session = scene.Server.GetSession(entityIdStruct.RouteId); + var session = scene.Server.GetSession(entityIdStruct.LocationId); session.Send(message, 0, routeTypeOpCode, entityId); } @@ -81,7 +81,7 @@ public static class MessageHelper EntityIdStruct entityIdStruct = entityId; var rpcId = ++_rpcId; - var session = scene.Server.GetSession(entityIdStruct.RouteId); + var session = scene.Server.GetSession(entityIdStruct.LocationId); var requestCallback = FTask.Create(false); RequestCallback.Add(rpcId, MessageSender.Create(rpcId, requestType, requestCallback)); session.Send(request, rpcId, routeTypeOpCode, entityId); @@ -98,7 +98,7 @@ public static class MessageHelper EntityIdStruct entityIdStruct = entityId; var rpcId = ++_rpcId; - var session = scene.Server.GetSession(entityIdStruct.RouteId); + var session = scene.Server.GetSession(entityIdStruct.LocationId); var requestCallback = FTask.Create(false); RequestCallback.Add(rpcId, MessageSender.Create(rpcId, request, requestCallback)); session.Send(request, rpcId, entityId); diff --git a/DotNet/Config/Binary/SceneConfigData.bytes b/DotNet/Config/Binary/SceneConfigData.bytes index 06edf031..9db43dca 100644 Binary files a/DotNet/Config/Binary/SceneConfigData.bytes and b/DotNet/Config/Binary/SceneConfigData.bytes differ diff --git a/DotNet/Config/Excel/Server/SceneConfig.xlsx b/DotNet/Config/Excel/Server/SceneConfig.xlsx index 01c7df48..7aed6363 100644 Binary files a/DotNet/Config/Excel/Server/SceneConfig.xlsx and b/DotNet/Config/Excel/Server/SceneConfig.xlsx differ diff --git a/DotNet/Config/Excel/Version.txt b/DotNet/Config/Excel/Version.txt index ec7fde68..a61a561f 100644 --- a/DotNet/Config/Excel/Version.txt +++ b/DotNet/Config/Excel/Version.txt @@ -1 +1 @@ -{"MachineConfig":1689771956715,"SceneConfig":1689619864417,"ServerConfig":1689620185714,"WorldConfig":1689267887552} \ No newline at end of file +{"MachineConfig":1690328264682,"SceneConfig":1690415187917,"ServerConfig":1690328264682,"WorldConfig":1690328264683} \ No newline at end of file diff --git a/DotNet/Config/Json/Server/SceneConfigData.Json b/DotNet/Config/Json/Server/SceneConfigData.Json index 8e087481..7aa3e0b3 100644 --- a/DotNet/Config/Json/Server/SceneConfigData.Json +++ b/DotNet/Config/Json/Server/SceneConfigData.Json @@ -1,7 +1,6 @@ {"List":[ -{"Id":1,"EntityId":17246978048,"RouteId":1024,"WorldId":0,"SceneType":"Gate","Name":"Gate","NetworkProtocol":"KCP","OuterPort":20000}, -{"Id":2,"EntityId":34493956096,"RouteId":2048,"WorldId":0,"SceneType":"Addressable","Name":"Addressable1","NetworkProtocol":null,"OuterPort":0}, -{"Id":4,"EntityId":68920803328,"RouteId":3072,"WorldId":0,"SceneType":"Map","Name":"Map1","NetworkProtocol":null,"OuterPort":0}, -{"Id":5,"EntityId":86167781376,"RouteId":4096,"WorldId":0,"SceneType":"Chat","Name":"Chat1","NetworkProtocol":null,"OuterPort":0}, -{"Id":6,"EntityId":103414759424,"RouteId":5120,"WorldId":0,"SceneType":"Gameplay","Name":"Gameplay1","NetworkProtocol":null,"OuterPort":0} +{"Id":1,"EntityId":17246978048,"ServerConfigId":1024,"WorldId":0,"SceneType":"Gate","Name":"Gate","NetworkProtocol":"KCP","OuterPort":20000}, +{"Id":2,"EntityId":34493956096,"ServerConfigId":2048,"WorldId":0,"SceneType":"Addressable","Name":"Addressable1","NetworkProtocol":null,"OuterPort":0}, +{"Id":4,"EntityId":68920803328,"ServerConfigId":3072,"WorldId":0,"SceneType":"Map","Name":"Map1","NetworkProtocol":null,"OuterPort":0}, +{"Id":5,"EntityId":86167781376,"ServerConfigId":4096,"WorldId":0,"SceneType":"Chat","Name":"Chat1","NetworkProtocol":null,"OuterPort":0} ]} diff --git a/DotNet/Logic/src/Generate/ConfigTable/Entity/SceneConfig.cs b/DotNet/Logic/src/Generate/ConfigTable/Entity/SceneConfig.cs index 8f64dcf4..9499190d 100644 --- a/DotNet/Logic/src/Generate/ConfigTable/Entity/SceneConfig.cs +++ b/DotNet/Logic/src/Generate/ConfigTable/Entity/SceneConfig.cs @@ -29,9 +29,9 @@ namespace TEngine public SceneConfig Get(uint id, bool check = true) { - if (this._configs.TryGetValue(id, out SceneConfig? config)) + if (_configs.ContainsKey(id)) { - return config; + return _configs[id]; } if (check) @@ -79,7 +79,7 @@ namespace TEngine [ProtoMember(2, IsRequired = true)] public long EntityId { get; set; } // 实体Id [ProtoMember(3, IsRequired = true)] - public uint RouteId { get; set; } // 路由Id + public uint ServerConfigId { get; set; } // 服务配置Id [ProtoMember(4, IsRequired = true)] public uint WorldId { get; set; } // 世界Id [ProtoMember(5, IsRequired = true)] diff --git a/DotNet/Logic/src/Generate/CustomExport/SceneType.cs b/DotNet/Logic/src/Generate/CustomExport/SceneType.cs index a0d59e7f..e4ccaa18 100644 --- a/DotNet/Logic/src/Generate/CustomExport/SceneType.cs +++ b/DotNet/Logic/src/Generate/CustomExport/SceneType.cs @@ -7,7 +7,6 @@ namespace TEngine public const int Addressable = 2; public const int Map = 3; public const int Chat = 4; - public const int Gameplay = 5; public static readonly Dictionary SceneDic = new Dictionary() { @@ -15,7 +14,6 @@ namespace TEngine { "Addressable", 2 }, { "Map", 3 }, { "Chat", 4 }, - { "Gameplay", 5 }, }; } } diff --git a/DotNet/Logic/src/Helper/AddressableSceneHelper.cs b/DotNet/Logic/src/Helper/AddressableSceneHelper.cs index ea3dddd1..9cb7b3a6 100644 --- a/DotNet/Logic/src/Helper/AddressableSceneHelper.cs +++ b/DotNet/Logic/src/Helper/AddressableSceneHelper.cs @@ -10,7 +10,7 @@ public static class AddressableSceneHelper var sceneEntityId = 0L; foreach (var sceneConfig in SceneConfigData.Instance.List) { - if (sceneConfig.RouteId == 3072) + if (sceneConfig.ServerConfigId == 3072) { sceneEntityId = sceneConfig.EntityId; break; diff --git a/DotNet/Logic/src/Helper/ConfigTableSystem.cs b/DotNet/Logic/src/Helper/ConfigTableSystem.cs index f149060a..9ccb9d11 100644 --- a/DotNet/Logic/src/Helper/ConfigTableSystem.cs +++ b/DotNet/Logic/src/Helper/ConfigTableSystem.cs @@ -74,7 +74,7 @@ public static class ConfigTableSystem SceneType = sceneConfig.SceneType, Name = sceneConfig.Name, NetworkProtocol = sceneConfig.NetworkProtocol, - RouteId = sceneConfig.RouteId, + ServerConfigId = sceneConfig.ServerConfigId, WorldId = sceneConfig.WorldId, OuterPort = sceneConfig.OuterPort }; @@ -126,7 +126,7 @@ public static class ConfigTableSystem SceneType = sceneConfig.SceneType, Name = sceneConfig.Name, NetworkProtocol = sceneConfig.NetworkProtocol, - RouteId = sceneConfig.RouteId, + ServerConfigId = sceneConfig.ServerConfigId, WorldId = sceneConfig.WorldId, OuterPort = sceneConfig.OuterPort }); diff --git a/DotNet/Logic/src/OnCreateScene.cs b/DotNet/Logic/src/OnCreateScene.cs index 21ed8d95..25458261 100644 --- a/DotNet/Logic/src/OnCreateScene.cs +++ b/DotNet/Logic/src/OnCreateScene.cs @@ -22,21 +22,15 @@ public enum SceneType: long /// Addressable = 1 << 2, - /// - /// 场景GamePlay - /// 游戏玩法服。 - /// - Gameplay = 1 << 3, - /// /// 游戏场景服。 /// - Map = 1 << 4, + Map = 1 << 3, /// /// 游戏聊天服。 /// - Chat = 1 << 5, + Chat = 1 << 4, } /// @@ -51,24 +45,16 @@ public class OnCreateScene : AsyncEventSystem // OnCreateScene这个事件就是给开发者使用的 // 比如Address协议这里、我就是做了一个管理Address地址的一个组件挂在到Address这个Scene下面了 // 比如Map下你需要一些自定义组件、你也可以在这里操作 - var sceneConfigInfo = self.SceneInfo; - - switch (sceneConfigInfo.SceneType.Parse()) + var scene = self.Scene; + switch (scene.SceneType.Parse()) { - case SceneType.Addressable: - { - sceneConfigInfo.Scene.AddComponent(); - break; - } case SceneType.Gate: { - sceneConfigInfo.Scene.AddComponent(); + self.Scene.AddComponent(); break; } - case SceneType.Gameplay: - break; } - Log.Info($"scene create: {self.SceneInfo.SceneType} {self.SceneInfo.Name} SceneId:{self.SceneInfo.Id} ServerId:{self.SceneInfo.RouteId} WorldId:{self.SceneInfo.WorldId}"); + Log.Info($"scene create: {self.Scene.SceneType} {self.Scene.Name} SceneId:{self.Scene.Id} LocationId:{self.Scene.LocationId} WorldId:{self.Scene.World?.Id}"); await FTask.CompletedTask; }