Преглед изворни кода

Actor消息之前使用InstanceId发送,现在改成ActorId,ActorId由三部分组成Process VProcess InstanceId

tanghai пре 2 година
родитељ
комит
713ba00888
75 измењених фајлова са 351 додато и 417 уклоњено
  1. 1 0
      DotNet/Loader/Init.cs
  2. 6 6
      Unity/Assets/Config/Proto/InnerMessage_S_20001.proto
  3. 2 2
      Unity/Assets/Config/Proto/LockStepInner_S_21001.proto
  4. 2 2
      Unity/Assets/Config/Proto/LockStepOuter_C_11001.proto
  5. 1 1
      Unity/Assets/Config/Proto/OuterMessage_C_10001.proto
  6. 7 0
      Unity/Assets/Scripts/Core/Helper/ByteHelper.cs
  7. 5 0
      Unity/Assets/Scripts/Core/VProcess/Module/Entity/Entity.cs
  8. 52 182
      Unity/Assets/Scripts/Core/VProcess/Module/IdGenerater/IdGenerater.cs
  9. 1 1
      Unity/Assets/Scripts/Core/VProcess/VProcess.cs
  10. 50 0
      Unity/Assets/Scripts/Core/World/ActorId.cs
  11. 3 0
      Unity/Assets/Scripts/Core/World/ActorId.cs.meta
  12. 3 0
      Unity/Assets/Scripts/Core/World/Module/IdGenerater.meta
  13. 22 0
      Unity/Assets/Scripts/Core/World/Module/IdGenerater/IdValueGenerater.cs
  14. 3 0
      Unity/Assets/Scripts/Core/World/Module/IdGenerater/IdValueGenerater.cs.meta
  15. 1 1
      Unity/Assets/Scripts/Core/World/Module/Network/AChannel.cs
  16. 1 1
      Unity/Assets/Scripts/Core/World/Module/Network/AService.cs
  17. 8 5
      Unity/Assets/Scripts/Core/World/Module/Network/KChannel.cs
  18. 1 1
      Unity/Assets/Scripts/Core/World/Module/Network/KService.cs
  19. 15 15
      Unity/Assets/Scripts/Core/World/Module/Network/NetServices.cs
  20. 7 4
      Unity/Assets/Scripts/Core/World/Module/Network/TChannel.cs
  21. 1 1
      Unity/Assets/Scripts/Core/World/Module/Network/TService.cs
  22. 1 10
      Unity/Assets/Scripts/Core/World/Module/Network/WChannel.cs
  23. 1 1
      Unity/Assets/Scripts/Core/World/Module/Network/WService.cs
  24. 4 5
      Unity/Assets/Scripts/Core/World/World.cs
  25. 1 1
      Unity/Assets/Scripts/Hotfix/Client/LockStep/G2C_ChangeSceneHandler.cs
  26. 1 1
      Unity/Assets/Scripts/Hotfix/Client/Module/Message/NetClientComponentSystem.cs
  27. 1 1
      Unity/Assets/Scripts/Hotfix/Server/Demo/EntryEvent2_InitServer.cs
  28. 1 1
      Unity/Assets/Scripts/Hotfix/Server/Demo/Helper/MessageHelper.cs
  29. 1 1
      Unity/Assets/Scripts/Hotfix/Server/Demo/Scenes/Gate/C2G_EnterMapHandler.cs
  30. 2 2
      Unity/Assets/Scripts/Hotfix/Server/Demo/Scenes/Gate/C2G_LoginGateHandler.cs
  31. 1 1
      Unity/Assets/Scripts/Hotfix/Server/Demo/Scenes/Map/Transfer/C2M_TransferMapHandler.cs
  32. 1 1
      Unity/Assets/Scripts/Hotfix/Server/Demo/Scenes/Map/Transfer/M2M_UnitTransferRequestHandler.cs
  33. 5 6
      Unity/Assets/Scripts/Hotfix/Server/Demo/Scenes/Map/Transfer/TransferHelper.cs
  34. 1 1
      Unity/Assets/Scripts/Hotfix/Server/Demo/Scenes/Realm/C2R_LoginHandler.cs
  35. 3 7
      Unity/Assets/Scripts/Hotfix/Server/Demo/Session/NetInnerComponentOnReadEvent.cs
  36. 4 4
      Unity/Assets/Scripts/Hotfix/Server/Demo/Session/NetServerComponentOnReadEvent.cs
  37. 1 1
      Unity/Assets/Scripts/Hotfix/Server/LockStep/Gate/C2G_MatchHandler.cs
  38. 1 1
      Unity/Assets/Scripts/Hotfix/Server/LockStep/Gate/Match2G_NotifyMatchSuccessHandler.cs
  39. 1 1
      Unity/Assets/Scripts/Hotfix/Server/LockStep/Map/Match2Map_GetRoomHandler.cs
  40. 2 2
      Unity/Assets/Scripts/Hotfix/Server/LockStep/Match/MatchComponentSystem.cs
  41. 4 4
      Unity/Assets/Scripts/Hotfix/Server/Module/Actor/ActorHandleHelper.cs
  42. 17 17
      Unity/Assets/Scripts/Hotfix/Server/Module/Actor/ActorMessageDispatcherComponentSystem.cs
  43. 3 3
      Unity/Assets/Scripts/Hotfix/Server/Module/Actor/ActorMessageHandler.cs
  44. 9 10
      Unity/Assets/Scripts/Hotfix/Server/Module/Actor/ActorMessageSenderComponentSystem.cs
  45. 7 7
      Unity/Assets/Scripts/Hotfix/Server/Module/ActorLocation/ActorLocationSenderComponentSystem.cs
  46. 2 2
      Unity/Assets/Scripts/Hotfix/Server/Module/ActorLocation/ActorLocationSenderSystem.cs
  47. 4 4
      Unity/Assets/Scripts/Hotfix/Server/Module/ActorLocation/ActorMessageLocationHandler.cs
  48. 18 18
      Unity/Assets/Scripts/Hotfix/Server/Module/ActorLocation/LocationOneTypeSystem.cs
  49. 14 14
      Unity/Assets/Scripts/Hotfix/Server/Module/ActorLocation/LocationProxyComponentSystem.cs
  50. 1 1
      Unity/Assets/Scripts/Hotfix/Server/Module/ActorLocation/ObjectAddRequestHandler.cs
  51. 1 2
      Unity/Assets/Scripts/Hotfix/Server/Module/ActorLocation/ObjectGetRequestHandler.cs
  52. 1 1
      Unity/Assets/Scripts/Hotfix/Server/Module/ActorLocation/ObjectLockRequestHandler.cs
  53. 1 1
      Unity/Assets/Scripts/Hotfix/Server/Module/ActorLocation/ObjectUnLockRequestHandler.cs
  54. 2 2
      Unity/Assets/Scripts/Hotfix/Server/Module/Message/NetInnerComponentSystem.cs
  55. 1 1
      Unity/Assets/Scripts/Hotfix/Server/Module/Message/NetServerComponentSystem.cs
  56. 1 1
      Unity/Assets/Scripts/Loader/MonoBehaviour/Init.cs
  57. 2 2
      Unity/Assets/Scripts/Model/Generate/Client/Message/LockStepOuter_C_11001.cs
  58. 3 4
      Unity/Assets/Scripts/Model/Generate/ClientServer/ConfigPartial/StartProcessConfig.cs
  59. 1 3
      Unity/Assets/Scripts/Model/Generate/ClientServer/ConfigPartial/StartSceneConfig.cs
  60. 6 6
      Unity/Assets/Scripts/Model/Generate/ClientServer/Message/InnerMessage_S_20001.cs
  61. 2 2
      Unity/Assets/Scripts/Model/Generate/ClientServer/Message/LockStepInner_S_21001.cs
  62. 2 2
      Unity/Assets/Scripts/Model/Generate/ClientServer/Message/LockStepOuter_C_11001.cs
  63. 1 1
      Unity/Assets/Scripts/Model/Generate/Server/ConfigPartial/StartProcessConfig.cs
  64. 1 3
      Unity/Assets/Scripts/Model/Generate/Server/ConfigPartial/StartSceneConfig.cs
  65. 6 6
      Unity/Assets/Scripts/Model/Generate/Server/Message/InnerMessage_S_20001.cs
  66. 2 2
      Unity/Assets/Scripts/Model/Generate/Server/Message/LockStepInner_S_21001.cs
  67. 2 2
      Unity/Assets/Scripts/Model/Generate/Server/Message/LockStepOuter_C_11001.cs
  68. 1 1
      Unity/Assets/Scripts/Model/Server/LockStep/Gate/PlayerRoomComponent.cs
  69. 2 2
      Unity/Assets/Scripts/Model/Server/Module/Actor/ActorMessageSender.cs
  70. 1 1
      Unity/Assets/Scripts/Model/Server/Module/Actor/IMActorHandler.cs
  71. 1 1
      Unity/Assets/Scripts/Model/Server/Module/ActorLocation/ActorLocationSender.cs
  72. 3 3
      Unity/Assets/Scripts/Model/Server/Module/ActorLocation/LocationComponent.cs
  73. 1 15
      Unity/Assets/Scripts/Model/Server/Module/Message/NetInnerComponent.cs
  74. 2 2
      Unity/Assets/Scripts/Model/Share/Module/Message/Session.cs
  75. 1 1
      Unity/ProjectSettings/ProjectSettings.asset

+ 1 - 0
DotNet/Loader/Init.cs

@@ -22,6 +22,7 @@ namespace ET
 						.WithParsed(World.Instance.AddSingleton);
 				World.Instance.AddSingleton<Logger>().ILog = new NLogger(Options.Instance.AppType.ToString(), Options.Instance.Process, "../Config/NLog/NLog.config");
 				ETTask.ExceptionHandler += Log.Error;
+				World.Instance.AddSingleton<IdValueGenerater>();
 				World.Instance.AddSingleton<ObjectPool>();
 				World.Instance.AddSingleton<WorldActor>();
 				World.Instance.AddSingleton<CodeLoader>();

+ 6 - 6
Unity/Assets/Config/Proto/InnerMessage_S_20001.proto

@@ -60,7 +60,7 @@ message ObjectAddRequest // IActorRequest
 	int32 RpcId = 1;
 	int32 Type = 2;
 	int64 Key = 3;
-	int64 InstanceId = 4;
+	ActorId ActorId = 4;
 }
 
 message ObjectAddResponse // IActorResponse
@@ -76,7 +76,7 @@ message ObjectLockRequest // IActorRequest
 	int32 RpcId = 1;
 	int32 Type = 2;
 	int64 Key = 3;
-	int64 InstanceId = 4;
+	ActorId ActorId = 4;
 	int32 Time = 5;
 }
 message ObjectLockResponse // IActorResponse
@@ -92,8 +92,8 @@ message ObjectUnLockRequest // IActorRequest
 	int32 RpcId = 1;
 	int32 Type = 2;
 	int64 Key = 3;
-	int64 OldInstanceId = 4;
-	int64 InstanceId = 5;
+	ActorId OldActorId = 4;
+	ActorId NewActorId = 5;
 }
 message ObjectUnLockResponse // IActorResponse
 {
@@ -129,7 +129,7 @@ message ObjectGetResponse // IActorResponse
 	int32 Error = 2;
 	string Message = 3;
 	int32 Type = 4;
-	int64 InstanceId = 5;
+	ActorId ActorId = 5;
 }
 
 //ResponseType G2R_GetLoginKey
@@ -165,7 +165,7 @@ message ObjectQueryResponse // IActorResponse
 message M2M_UnitTransferRequest // IActorRequest
 {
 	int32 RpcId = 1;
-	int64 OldInstanceId = 2;
+	ActorId OldActorId = 2;
 	bytes Unit = 3;
 	repeated bytes Entitys = 4;
 }

+ 2 - 2
Unity/Assets/Config/Proto/LockStepInner_S_21001.proto

@@ -30,8 +30,8 @@ message Map2Match_GetRoom // IActorResponse
 	int32 Error = 2;
 	string Message = 3;
 	
-	// 房间的instanceId
-	int64 InstanceId = 4;
+	// 房间的ActorId
+	ActorId ActorId = 4;
 }
 
 //ResponseType Room2G_Reconnect

+ 2 - 2
Unity/Assets/Config/Proto/LockStepOuter_C_11001.proto

@@ -18,8 +18,8 @@ message G2C_Match // IResponse
 message Match2G_NotifyMatchSuccess // IActorMessage
 {
 	int32 RpcId = 1;
-	// 房间的instanceId
-	int64 InstanceId = 2;
+	// 房间的ActorId
+	ActorId ActorId = 2;
 }
 
 // 客户端通知房间切换场景完成

+ 1 - 1
Unity/Assets/Config/Proto/OuterMessage_C_10001.proto

@@ -22,7 +22,7 @@ message C2M_TestRequest // IActorLocationRequest
 
 message M2C_TestResponse // IActorResponse
 {
-    int32 RpcId = 1;
+	int32 RpcId = 1;
 	int32 Error = 2;
 	string Message = 3;
 	string response = 4;

+ 7 - 0
Unity/Assets/Scripts/Core/Helper/ByteHelper.cs

@@ -67,6 +67,13 @@ namespace ET
 			bytes[offset + 3] = (byte)((num & 0xff000000) >> 24);
 		}
 		
+		public static void WriteTo(this byte[] bytes, int offset, ActorId num)
+		{
+			bytes.WriteTo(offset, num.Process);
+			bytes.WriteTo(offset + 4, num.VProcess);
+			bytes.WriteTo(offset + 8, num.InstanceId);
+		}
+		
 		public static void WriteTo(this byte[] bytes, int offset, int num)
 		{
 			bytes[offset] = (byte)(num & 0xff);

+ 5 - 0
Unity/Assets/Scripts/Core/VProcess/Module/Entity/Entity.cs

@@ -31,6 +31,11 @@ namespace ET
         [BsonIgnore]
         public long InstanceId { get; protected set; }
 
+        public ActorId GetActorId()
+        {
+            return new ActorId((short)Options.Instance.Process, this.VProcess().Id, this.InstanceId);
+        }
+
         protected Entity()
         {
         }

+ 52 - 182
Unity/Assets/Scripts/Core/VProcess/Module/IdGenerater/IdGenerater.cs

@@ -1,26 +1,28 @@
 using System;
 using System.Runtime.InteropServices;
-using MongoDB.Bson;
+using MemoryPack;
 
 namespace ET
 {
     [StructLayout(LayoutKind.Sequential, Pack = 1)]
     public struct IdStruct
     {
-        public int Process;  // 18bit
+        public short Process;  // 14bit
         public uint Time;    // 30bit
-        public ushort Value; // 16bit
+        public uint Value;   // 20bit
 
         public long ToLong()
         {
             ulong result = 0;
+            result |= (ushort) this.Process;
+            result <<= 14;
+            result |= this.Time;
+            result <<= 30;
             result |= this.Value;
-            result |= (ulong) this.Process << 16;
-            result |= (ulong) this.Time << 34;
             return (long) result;
         }
 
-        public IdStruct(uint time, int process, ushort value)
+        public IdStruct(uint time, short process, uint value)
         {
             this.Process = process;
             this.Time = time;
@@ -30,11 +32,11 @@ namespace ET
         public IdStruct(long id)
         {
             ulong result = (ulong) id; 
-            this.Value = (ushort) (result & ushort.MaxValue);
-            result >>= 16;
-            this.Process = (int) (result & IdGenerater.Mask18bit);
-            result >>= 18;
-            this.Time = (uint) result;
+            this.Value = (ushort) (result & IdGenerater.Mask20bit);
+            result >>= 20;
+            this.Time = (uint) result & IdGenerater.Mask30bit;
+            result >>= 30;
+            this.Process = (short) (result & IdGenerater.Mask14bit);
         }
 
         public override string ToString()
@@ -42,239 +44,107 @@ namespace ET
             return $"process: {this.Process}, time: {this.Time}, value: {this.Value}";
         }
     }
-
+    
     [StructLayout(LayoutKind.Sequential, Pack = 1)]
     public struct InstanceIdStruct
     {
-        public int Process; // 18bit
-        public uint Time;   // 当年开始的tick 28bit
-        public uint Value;  // 18bit
+        public uint Time;  // 32bit
+        public uint Value; // 32bit
 
         public long ToLong()
         {
             ulong result = 0;
+            result |= this.Time;
+            result <<= 32;
             result |= this.Value;
-            result |= (ulong)this.Process << 18;
-            result |= (ulong) this.Time << 36;
             return (long) result;
         }
 
-        public InstanceIdStruct(long id)
-        {
-            ulong result = (ulong) id;
-            this.Value = (uint)(result & IdGenerater.Mask18bit);
-            result >>= 18;
-            this.Process = (int)(result & IdGenerater.Mask18bit);
-            result >>= 18;
-            this.Time = (uint)result;
-        }
-
-        public InstanceIdStruct(uint time, int process, uint value)
-        {
-            this.Time = time;
-            this.Process = process;
-            this.Value = value;
-        }
-        
-        // 给SceneId使用
-        public InstanceIdStruct(int process, uint value)
+        public InstanceIdStruct(uint time, uint value)
         {
-            this.Time = 0;
-            this.Process = process;
+            this.Time = (uint)time;
             this.Value = value;
         }
 
-        public override string ToString()
-        {
-            return $"process: {this.Process}, value: {this.Value} time: {this.Time}";
-        }
-    }
-    
-    [StructLayout(LayoutKind.Sequential, Pack = 1)]
-    public struct UnitIdStruct
-    {
-        public uint Time;        // 30bit 34年
-        public ushort Zone;      // 10bit 1024个区
-        public byte ProcessMode; // 8bit  Process % 256  一个区最多256个进程
-        public ushort Value;     // 16bit 每秒每个进程最大16K个Unit
-
-        public long ToLong()
+        public InstanceIdStruct(long id)
         {
-            ulong result = 0;
-            result |= this.Value;
-            result |= (uint)this.ProcessMode << 16;
-            result |= (ulong) this.Zone << 24;
-            result |= (ulong) this.Time << 34;
-            return (long) result;
+            ulong result = (ulong) id; 
+            this.Value = (uint)(result & uint.MaxValue);
+            result >>= 32;
+            this.Time = (uint)(result & uint.MaxValue);
         }
 
-        public UnitIdStruct(int zone, int process, uint time, ushort value)
-        {
-            this.Time = time;
-            this.ProcessMode = (byte)(process % 256);
-            this.Value = value;
-            this.Zone = (ushort)zone;
-        }
-        
-        public UnitIdStruct(long id)
-        {
-            ulong result = (ulong) id;
-            this.Value = (ushort)(result & ushort.MaxValue);
-            result >>= 16;
-            this.ProcessMode = (byte)(result & byte.MaxValue);
-            result >>= 8;
-            this.Zone = (ushort)(result & 0x03ff);
-            result >>= 10;
-            this.Time = (uint)result;
-        }
-                        
         public override string ToString()
         {
-            return $"ProcessMode: {this.ProcessMode}, value: {this.Value} time: {this.Time}";
-        }
-        
-        public static int GetUnitZone(long unitId)
-        {
-            int v = (int) ((unitId >> 24) & 0x03ff); // 取出10bit
-            return v;
+            return $"time: {this.Time}, value: {this.Value}";
         }
     }
 
     public class IdGenerater: VProcessSingleton<IdGenerater>
     {
-        public const int Mask18bit = 0x03ffff;
-
         public const int MaxZone = 1024;
         
-        private long epoch2020;
-        private ushort value;
+        public const int Mask14bit = 0x3fff;
+        public const int Mask30bit = 0x3fffffff;
+        public const int Mask20bit = 0xfffff;
+        
+        private long epoch2022;
+        private uint value;
         private uint lastIdTime;
-
         
-        private long epochThisYear;
         private uint instanceIdValue;
-        private uint lastInstanceIdTime;
-        
         
-        private ushort unitIdValue;
-        private uint lastUnitIdTime;
-
         public IdGenerater()
         {
             long epoch1970tick = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).Ticks / 10000;
-            this.epoch2020 = new DateTime(2020, 1, 1, 0, 0, 0, DateTimeKind.Utc).Ticks / 10000 - epoch1970tick;
-            this.epochThisYear = new DateTime(DateTime.Now.Year, 1, 1, 0, 0, 0, DateTimeKind.Utc).Ticks / 10000 - epoch1970tick;
-            
-            this.lastInstanceIdTime = TimeSinceThisYear();
-            if (this.lastInstanceIdTime <= 0)
-            {
-                Log.Warning($"lastInstanceIdTime less than 0: {this.lastInstanceIdTime}");
-                this.lastInstanceIdTime = 1;
-            }
-            this.lastIdTime = TimeSince2020();
+            this.epoch2022 = new DateTime(2022, 1, 1, 0, 0, 0, DateTimeKind.Utc).Ticks / 10000 - epoch1970tick;
+            this.lastIdTime = TimeSince2022();
             if (this.lastIdTime <= 0)
             {
                 Log.Warning($"lastIdTime less than 0: {this.lastIdTime}");
                 this.lastIdTime = 1;
             }
-            this.lastUnitIdTime = TimeSince2020();
-            if (this.lastUnitIdTime <= 0)
-            {
-                Log.Warning($"lastUnitIdTime less than 0: {this.lastUnitIdTime}");
-                this.lastUnitIdTime = 1;
-            }
         }
 
-        private uint TimeSince2020()
+        private uint TimeSince2022()
         {
-            uint a = (uint)((TimeInfo.Instance.FrameTime - this.epoch2020) / 1000);
+            uint a = (uint)((TimeInfo.Instance.FrameTime - this.epoch2022) / 1000);
             return a;
         }
         
-        private uint TimeSinceThisYear()
-        {
-            uint a = (uint)((TimeInfo.Instance.FrameTime - this.epochThisYear) / 1000);
-            return a;
-        }
-        
-        public long GenerateInstanceId()
-        {
-            uint time = TimeSinceThisYear();
-
-            if (time > this.lastInstanceIdTime)
-            {
-                this.lastInstanceIdTime = time;
-                this.instanceIdValue = 0;
-            }
-            else
-            {
-                ++this.instanceIdValue;
-                
-                if (this.instanceIdValue > IdGenerater.Mask18bit - 1) // 18bit
-                {
-                    ++this.lastInstanceIdTime; // 借用下一秒
-                    this.instanceIdValue = 0;
-
-                    Log.Error($"instanceid count per sec overflow: {time} {this.lastInstanceIdTime}");
-                }
-            }
-
-            InstanceIdStruct instanceIdStruct = new InstanceIdStruct(this.lastInstanceIdTime, Options.Instance.Process, this.instanceIdValue);
-            return instanceIdStruct.ToLong();
-        }
-
         public long GenerateId()
         {
-            uint time = TimeSince2020();
+            uint time = TimeSince2022();
 
+            // 时间不会倒退
             if (time > this.lastIdTime)
             {
                 this.lastIdTime = time;
-                this.value = 0;
             }
-            else
-            {
-                ++this.value;
-                
-                if (value > ushort.MaxValue - 1)
-                {
-                    this.value = 0;
-                    ++this.lastIdTime; // 借用下一秒
-                    Log.Error($"id count per sec overflow: {time} {this.lastIdTime}");
-                }
-            }
-            
-            IdStruct idStruct = new IdStruct(this.lastIdTime, Options.Instance.Process, value);
+            this.value = IdValueGenerater.Instance.Value;
+
+            IdStruct idStruct = new(this.lastIdTime, (short)Options.Instance.Process, value);
             return idStruct.ToLong();
         }
         
-        public long GenerateUnitId(int zone)
+        public long GenerateInstanceId()
         {
-            if (zone > MaxZone)
-            {
-                throw new Exception($"zone > MaxZone: {zone}");
-            }
-            uint time = TimeSince2020();
+            uint time = this.TimeSince2022();
 
-            if (time > this.lastUnitIdTime)
+            // 时间不会倒退
+            if (time > this.lastIdTime)
             {
-                this.lastUnitIdTime = time;
-                this.unitIdValue = 0;
+                this.lastIdTime = time;
             }
-            else
-            {
-                ++this.unitIdValue;
+            ++this.instanceIdValue;
                 
-                if (this.unitIdValue > ushort.MaxValue - 1)
-                {
-                    this.unitIdValue = 0;
-                    ++this.lastUnitIdTime; // 借用下一秒
-                    Log.Error($"unitid count per sec overflow: {time} {this.lastUnitIdTime}");
-                }
+            if (this.instanceIdValue > Mask20bit - 1)
+            {
+                this.instanceIdValue = 0;
             }
 
-            UnitIdStruct unitIdStruct = new UnitIdStruct(zone, Options.Instance.Process, this.lastUnitIdTime, this.unitIdValue);
-            return unitIdStruct.ToLong();
+            InstanceIdStruct instanceIdStruct = new(this.lastIdTime, this.instanceIdValue);
+            return instanceIdStruct.ToLong();
         }
     }
 }

+ 1 - 1
Unity/Assets/Scripts/Core/VProcess/VProcess.cs

@@ -14,7 +14,7 @@ namespace ET
         public bool IsRuning;
 
         // 保存虚拟进程中的Instance,方便快速获取
-        private readonly Dictionary<Type, object> instances = new(); 
+        private readonly Dictionary<Type, object> instances = new();
 
         private readonly Stack<IVProcessSingleton> singletons = new();
 

+ 50 - 0
Unity/Assets/Scripts/Core/World/ActorId.cs

@@ -0,0 +1,50 @@
+using System;
+using System.Runtime.InteropServices;
+using MemoryPack;
+
+namespace ET
+{
+    [MemoryPackable]
+    [StructLayout(LayoutKind.Sequential, Pack = 1)]
+    public partial struct ActorId
+    {
+        public bool Equals(ActorId other)
+        {
+            return this.Process == other.Process && this.VProcess == other.VProcess && this.InstanceId == other.InstanceId;
+        }
+
+        public override bool Equals(object obj)
+        {
+            return obj is ActorId other && Equals(other);
+        }
+
+        public override int GetHashCode()
+        {
+            return HashCode.Combine(this.Process, this.VProcess, this.InstanceId);
+        }
+
+        [MemoryPackOrder(0)]
+        public short Process;
+        [MemoryPackOrder(1)]
+        public int VProcess;
+        [MemoryPackOrder(2)]
+        public long InstanceId;
+        
+        public ActorId(short process, int vProcess, long instanceId)
+        {
+            this.Process = process;
+            this.VProcess = vProcess;
+            this.InstanceId = instanceId;
+        }
+
+        public static bool operator ==(ActorId left, ActorId right)
+        {
+            return left.InstanceId == right.InstanceId && left.Process == right.Process && left.VProcess == right.VProcess;
+        }
+
+        public static bool operator !=(ActorId left, ActorId right)
+        {
+            return !(left == right);
+        }
+    }
+}

+ 3 - 0
Unity/Assets/Scripts/Core/World/ActorId.cs.meta

@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 9e8f0bd4aa4045ddb59117f81ff62be5
+timeCreated: 1687104833

+ 3 - 0
Unity/Assets/Scripts/Core/World/Module/IdGenerater.meta

@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 7e3e2aed9e0845edb35993d7496f871f
+timeCreated: 1687098052

+ 22 - 0
Unity/Assets/Scripts/Core/World/Module/IdGenerater/IdValueGenerater.cs

@@ -0,0 +1,22 @@
+namespace ET
+{
+    public class IdValueGenerater: Singleton<IdValueGenerater>
+    {
+        private uint value;
+
+        public uint Value
+        {
+            get
+            {
+                lock (this)
+                {
+                    if (++this.value > IdGenerater.Mask20bit - 1)
+                    {
+                        this.value = 0;
+                    }
+                    return this.value;
+                }
+            }
+        }
+    }
+}

+ 3 - 0
Unity/Assets/Scripts/Core/World/Module/IdGenerater/IdValueGenerater.cs.meta

@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: d4510ce4f5e843f9a9efc99d1714845a
+timeCreated: 1687098066

+ 1 - 1
Unity/Assets/Scripts/Core/World/Module/Network/AChannel.cs

@@ -17,7 +17,7 @@ namespace ET
 		public const int KcpOpcodeIndex = 0;
 		public const int OpcodeLength = 2;
 		public const int ActorIdIndex = 0;
-		public const int ActorIdLength = 8;
+		public const int ActorIdLength = 14;
 		public const int MessageIndex = 10;
 
 		public ushort Opcode;

+ 1 - 1
Unity/Assets/Scripts/Core/World/Module/Network/AService.cs

@@ -44,7 +44,7 @@ namespace ET
 
         public abstract void Create(long id, IPEndPoint address);
 
-        public abstract void Send(long channelId, long actorId, MessageObject message);
+        public abstract void Send(long channelId, ActorId actorId, MessageObject message);
 
         public virtual (uint, uint) GetChannelConn(long channelId)
         {

+ 8 - 5
Unity/Assets/Scripts/Core/World/Module/Network/KChannel.cs

@@ -11,7 +11,7 @@ namespace ET
 	
 	public struct KcpWaitSendMessage
 	{
-		public long ActorId;
+		public ActorId ActorId;
 		public MessageObject Message;
 	}
 	
@@ -400,7 +400,7 @@ namespace ET
 			}
 		}
 
-        private void KcpSend(long actorId, MemoryBuffer memoryStream)
+        private void KcpSend(ActorId actorId, MemoryBuffer memoryStream)
 		{
 			if (this.IsDisposed)
 			{
@@ -452,7 +452,7 @@ namespace ET
 			this.Service.AddToUpdate(0, this.Id);
 		}
 		
-		public void Send(long actorId, MessageObject message)
+		public void Send(ActorId actorId, MessageObject message)
 		{
 			if (!this.IsConnected)
 			{
@@ -499,7 +499,7 @@ namespace ET
 			{
 				long channelId = this.Id;
 				object message = null;
-				long actorId = 0;
+				ActorId actorId = default;
 				switch (this.Service.ServiceType)
 				{
 					case ServiceType.Outer:
@@ -511,7 +511,10 @@ namespace ET
 					}
 					case ServiceType.Inner:
 					{
-						actorId = BitConverter.ToInt64(memoryStream.GetBuffer(), Packet.ActorIdIndex);
+						byte[] buffer = memoryStream.GetBuffer();
+						actorId.Process = BitConverter.ToInt16(buffer, Packet.ActorIdIndex);
+						actorId.VProcess = BitConverter.ToInt32(buffer, Packet.ActorIdIndex + 2);
+						actorId.InstanceId = BitConverter.ToInt64(buffer, Packet.ActorIdIndex + 6);
 						ushort opcode = BitConverter.ToUInt16(memoryStream.GetBuffer(), Packet.OpcodeIndex);
 						Type type = NetServices.Instance.GetType(opcode);
 						message = MessageSerializeHelper.Deserialize(type, memoryStream);

+ 1 - 1
Unity/Assets/Scripts/Core/World/Module/Network/KService.cs

@@ -517,7 +517,7 @@ namespace ET
             Log.Info($"channel send fin: {localConn} {remoteConn} {address} {error}");
         }
         
-        public override void Send(long channelId, long actorId, MessageObject message)
+        public override void Send(long channelId, ActorId actorId, MessageObject message)
         {
             KChannel channel = this.Get(channelId);
             if (channel == null)

+ 15 - 15
Unity/Assets/Scripts/Core/World/Module/Network/NetServices.cs

@@ -37,7 +37,7 @@ namespace ET
         public NetOp Op; // 操作码
         public int ServiceId;
         public long ChannelId;
-        public long ActorId;
+        public ActorId ActorId;
         public object Object; // 参数
     }
 
@@ -124,7 +124,7 @@ namespace ET
         #region 主线程
 
         private readonly Dictionary<int, Action<long, IPEndPoint>> acceptCallback = new();
-        private readonly Dictionary<int, Action<long, long, object>> readCallback = new();
+        private readonly Dictionary<int, Action<long, ActorId, object>> readCallback = new();
         private readonly Dictionary<int, Action<long, int>> errorCallback = new();
 
         private int serviceIdGenerator;
@@ -162,7 +162,7 @@ namespace ET
             ToNetThread(ref netOperator);
         }
 
-        public void SendMessage(int serviceId, long channelId, long actorId, MessageObject message)
+        public void SendMessage(int serviceId, long channelId, ActorId actorId, MessageObject message)
         {
             NetOperator netOperator = new NetOperator()
             {
@@ -178,26 +178,26 @@ namespace ET
         public int AddService(AService aService)
         {
             aService.Id = ++this.serviceIdGenerator;
-            NetOperator netOperator = new NetOperator() { Op = NetOp.AddService, ServiceId = aService.Id, ChannelId = 0, Object = aService };
+            NetOperator netOperator = new() { Op = NetOp.AddService, ServiceId = aService.Id, ChannelId = 0, Object = aService };
             ToNetThread(ref netOperator);
             return aService.Id;
         }
 
         public void RemoveService(int serviceId)
         {
-            NetOperator netOperator = new NetOperator() { Op = NetOp.RemoveService, ServiceId = serviceId };
+            NetOperator netOperator = new() { Op = NetOp.RemoveService, ServiceId = serviceId };
             ToNetThread(ref netOperator);
         }
 
         public void RemoveChannel(int serviceId, long channelId, int error)
         {
-            NetOperator netOperator = new NetOperator() { Op = NetOp.RemoveChannel, ServiceId = serviceId, ChannelId = channelId, ActorId = error };
+            NetOperator netOperator = new() { Op = NetOp.RemoveChannel, ServiceId = serviceId, ChannelId = channelId, ActorId = new ActorId(0, error, 0) };
             ToNetThread(ref netOperator);
         }
 
         public void CreateChannel(int serviceId, long channelId, IPEndPoint address)
         {
-            NetOperator netOperator = new NetOperator() { Op = NetOp.CreateChannel, ServiceId = serviceId, ChannelId = channelId, Object = address };
+            NetOperator netOperator = new() { Op = NetOp.CreateChannel, ServiceId = serviceId, ChannelId = channelId, Object = address };
             ToNetThread(ref netOperator);
         }
 
@@ -206,7 +206,7 @@ namespace ET
             this.acceptCallback.Add(serviceId, action);
         }
 
-        public void RegisterReadCallback(int serviceId, Action<long, long, object> action)
+        public void RegisterReadCallback(int serviceId, Action<long, ActorId, object> action)
         {
             this.readCallback.Add(serviceId, action);
         }
@@ -244,12 +244,12 @@ namespace ET
                     }
                     case NetOp.OnError:
                     {
-                        if (!this.errorCallback.TryGetValue(op.ServiceId, out var action))
+                        if (!this.errorCallback.TryGetValue(op.ServiceId, out Action<long, int> action))
                         {
                             return;
                         }
 
-                        action.Invoke(op.ChannelId, (int) op.ActorId);
+                        action.Invoke(op.ChannelId, op.ActorId.VProcess);
                         break;
                     }
                     default:
@@ -394,7 +394,7 @@ namespace ET
                         AService service = this.Get(op.ServiceId);
                         if (service != null)
                         {
-                            service.Remove(op.ChannelId, (int) op.ActorId);
+                            service.Remove(op.ChannelId, op.ActorId.Process);
                         }
 
                         break;
@@ -485,13 +485,13 @@ namespace ET
 
         public void OnAccept(int serviceId, long channelId, IPEndPoint ipEndPoint)
         {
-            NetOperator netOperator = new NetOperator() { Op = NetOp.OnAccept, ServiceId = serviceId, ChannelId = channelId, Object = ipEndPoint };
+            NetOperator netOperator = new() { Op = NetOp.OnAccept, ServiceId = serviceId, ChannelId = channelId, Object = ipEndPoint };
             ToMainThread(ref netOperator);
         }
 
-        public void OnRead(int serviceId, long channelId, long actorId, object message)
+        public void OnRead(int serviceId, long channelId, ActorId actorId, object message)
         {
-            NetOperator netOperator = new NetOperator()
+            NetOperator netOperator = new()
             {
                 Op = NetOp.OnRead,
                 ServiceId = serviceId,
@@ -504,7 +504,7 @@ namespace ET
 
         public void OnError(int serviceId, long channelId, int error)
         {
-            NetOperator netOperator = new NetOperator() { Op = NetOp.OnError, ServiceId = serviceId, ChannelId = channelId, ActorId = error };
+            NetOperator netOperator = new() { Op = NetOp.OnError, ServiceId = serviceId, ChannelId = channelId, ActorId = new ActorId(0, error, 0) };
             ToMainThread(ref netOperator);
         }
 

+ 7 - 4
Unity/Assets/Scripts/Core/World/Module/Network/TChannel.cs

@@ -92,7 +92,7 @@ namespace ET
 			this.socket = null;
 		}
 
-		public void Send(long actorId, MessageObject message)
+		public void Send(ActorId actorId, MessageObject message)
 		{
 			if (this.IsDisposed)
 			{
@@ -362,7 +362,7 @@ namespace ET
 			{
 				long channelId = this.Id;
 				object message = null;
-				long actorId = 0;
+				ActorId actorId = default;
 				switch (this.Service.ServiceType)
 				{
 					case ServiceType.Outer:
@@ -374,8 +374,11 @@ namespace ET
 					}
 					case ServiceType.Inner:
 					{
-						actorId = BitConverter.ToInt64(memoryStream.GetBuffer(), Packet.ActorIdIndex);
-						ushort opcode = BitConverter.ToUInt16(memoryStream.GetBuffer(), Packet.OpcodeIndex);
+						byte[] buffer = memoryStream.GetBuffer();
+						actorId.Process = BitConverter.ToInt16(buffer, Packet.ActorIdIndex);
+						actorId.VProcess = BitConverter.ToInt32(buffer, Packet.ActorIdIndex + 2);
+						actorId.InstanceId = BitConverter.ToInt64(buffer, Packet.ActorIdIndex + 6);
+						ushort opcode = BitConverter.ToUInt16(buffer, Packet.OpcodeIndex);
 						Type type = NetServices.Instance.GetType(opcode);
 						message = MessageSerializeHelper.Deserialize(type, memoryStream);
 						break;

+ 1 - 1
Unity/Assets/Scripts/Core/World/Module/Network/TService.cs

@@ -161,7 +161,7 @@ namespace ET
 			this.idChannels.Remove(id);
 		}
 
-		public override void Send(long channelId, long actorId, MessageObject message)
+		public override void Send(long channelId, ActorId actorId, MessageObject message)
 		{
 			try
 			{

+ 1 - 10
Unity/Assets/Scripts/Core/World/Module/Network/WChannel.cs

@@ -220,7 +220,6 @@ namespace ET
             {
                 long channelId = this.Id;
                 object message = null;
-                long actorId = 0;
                 switch (this.Service.ServiceType)
                 {
                     case ServiceType.Outer:
@@ -230,16 +229,8 @@ namespace ET
                         message = MessageSerializeHelper.Deserialize(type, memoryStream);
                         break;
                     }
-                    case ServiceType.Inner:
-                    {
-                        actorId = BitConverter.ToInt64(memoryStream.GetBuffer(), Packet.ActorIdIndex);
-                        ushort opcode = BitConverter.ToUInt16(memoryStream.GetBuffer(), Packet.OpcodeIndex);
-                        Type type = NetServices.Instance.GetType(opcode);
-                        message = MessageSerializeHelper.Deserialize(type, memoryStream);
-                        break;
-                    }
                 }
-                NetServices.Instance.OnRead(this.Service.Id, channelId, actorId, message);
+                NetServices.Instance.OnRead(this.Service.Id, channelId, new ActorId(), message);
             }
             catch (Exception e)
             {

+ 1 - 1
Unity/Assets/Scripts/Core/World/Module/Network/WService.cs

@@ -133,7 +133,7 @@ namespace ET
             throw new NotImplementedException();
         }
 
-        public override void Send(long channelId, long actorId, MessageObject message)
+        public override void Send(long channelId, ActorId actorId, MessageObject message)
         {
             this.channels.TryGetValue(channelId, out WChannel channel);
             if (channel == null)

+ 4 - 5
Unity/Assets/Scripts/Core/World/World.cs

@@ -25,7 +25,7 @@ namespace ET
             }
 
             singletons[singleton.GetType()] = singleton;
-
+            singleton.Register();
             return (T)singleton;
         }
         
@@ -39,7 +39,7 @@ namespace ET
             }
 
             singletons[singleton.GetType()] = singleton;
-
+            singleton.Register();
             return (T)singleton;
         }
         
@@ -53,7 +53,7 @@ namespace ET
             }
 
             singletons[singleton.GetType()] = singleton;
-
+            singleton.Register();
             return (T)singleton;
         }
         
@@ -67,7 +67,7 @@ namespace ET
             }
 
             singletons[singleton.GetType()] = singleton;
-
+            singleton.Register();
             return (T)singleton;
         }
 
@@ -79,7 +79,6 @@ namespace ET
             }
             
             singletons[singleton.GetType()] = singleton;
-
             singleton.Register();
         }
 

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Client/LockStep/G2C_ChangeSceneHandler.cs

@@ -5,7 +5,7 @@ namespace ET.Client
     {
         protected override async ETTask Run(Session session, Match2G_NotifyMatchSuccess message)
         {
-            await LSSceneChangeHelper.SceneChangeTo(session.Scene(), "Map1", message.InstanceId);
+            await LSSceneChangeHelper.SceneChangeTo(session.Scene(), "Map1", message.ActorId.InstanceId);
         }
     }
 }

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Client/Module/Message/NetClientComponentSystem.cs

@@ -20,7 +20,7 @@ namespace ET.Client
             NetServices.Instance.RemoveService(self.ServiceId);
         }
 
-        private static void OnRead(this NetClientComponent self, long channelId, long actorId, object message)
+        private static void OnRead(this NetClientComponent self, long channelId, ActorId actorId, object message)
         {
             Session session = self.GetChild<Session>(channelId);
             if (session == null)

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Server/Demo/EntryEvent2_InitServer.cs

@@ -29,7 +29,7 @@ namespace ET.Server
                     var processScenes = StartSceneConfigCategory.Instance.GetByProcess(Options.Instance.Process);
                     foreach (StartSceneConfig startConfig in processScenes)
                     {
-                        await SceneFactory.CreateServerScene(ServerSceneManagerComponent.Instance, startConfig.Id, startConfig.InstanceId, startConfig.Zone, startConfig.Name,
+                        await SceneFactory.CreateServerScene(ServerSceneManagerComponent.Instance, startConfig.Id, startConfig.ActorId.InstanceId, startConfig.Zone, startConfig.Name,
                             startConfig.Type, startConfig);
                     }
 

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Server/Demo/Helper/MessageHelper.cs

@@ -48,7 +48,7 @@ namespace ET.Server
         /// </summary>
         /// <param name="actorId">注册Actor的InstanceId</param>
         /// <param name="message"></param>
-        public static void SendActor(long actorId, IActorMessage message)
+        public static void SendActor(ActorId actorId, IActorMessage message)
         {
             ActorMessageSenderComponent.Instance.Send(actorId, message);
         }

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Server/Demo/Scenes/Gate/C2G_EnterMapHandler.cs

@@ -20,7 +20,7 @@
 			response.MyId = player.Id;
 
 			// 等到一帧的最后面再传送,先让G2C_EnterMap返回,否则传送消息可能比G2C_EnterMap还早
-			TransferHelper.TransferAtFrameFinish(unit, startSceneConfig.InstanceId, startSceneConfig.Name).Coroutine();
+			TransferHelper.TransferAtFrameFinish(unit, startSceneConfig.ActorId, startSceneConfig.Name).Coroutine();
 		}
 	}
 }

+ 2 - 2
Unity/Assets/Scripts/Hotfix/Server/Demo/Scenes/Gate/C2G_LoginGateHandler.cs

@@ -39,7 +39,7 @@ namespace ET.Server
             {
                 // 判断是否在战斗
                 PlayerRoomComponent playerRoomComponent = player.GetComponent<PlayerRoomComponent>();
-                if (playerRoomComponent.RoomInstanceId != 0)
+                if (playerRoomComponent.RoomActorId != default)
                 {
                     CheckRoom(player, session).Coroutine();
                 }
@@ -59,7 +59,7 @@ namespace ET.Server
             await player.VProcess().WaitFrameFinish();
             
             Room2G_Reconnect room2GateReconnect = await ActorMessageSenderComponent.Instance.Call(
-                player.GetComponent<PlayerRoomComponent>().RoomInstanceId,
+                player.GetComponent<PlayerRoomComponent>().RoomActorId,
                 new G2Room_Reconnect() { PlayerId = player.Id }) as Room2G_Reconnect;
             session.Send(new G2C_Reconnect() { StartTime = room2GateReconnect.StartTime, UnitInfos = room2GateReconnect.UnitInfos, Frame = room2GateReconnect.Frame});
             session.AddComponent<SessionPlayerComponent>().Player = player;

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Server/Demo/Scenes/Map/Transfer/C2M_TransferMapHandler.cs

@@ -22,7 +22,7 @@ namespace ET.Server
 
 			StartSceneConfig startSceneConfig = StartSceneConfigCategory.Instance.GetBySceneName(unit.Scene().Zone, toMap);
 			
-			TransferHelper.TransferAtFrameFinish(unit, startSceneConfig.InstanceId, toMap).Coroutine();
+			TransferHelper.TransferAtFrameFinish(unit, startSceneConfig.ActorId, toMap).Coroutine();
 		}
 	}
 }

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Server/Demo/Scenes/Map/Transfer/M2M_UnitTransferRequestHandler.cs

@@ -39,7 +39,7 @@ namespace ET.Server
             unit.AddComponent<AOIEntity, int, float3>(9 * 1000, unit.Position);
 
             // 解锁location,可以接收发给Unit的消息
-            await LocationProxyComponent.Instance.UnLock(LocationType.Unit, unit.Id, request.OldInstanceId, unit.InstanceId);
+            await LocationProxyComponent.Instance.UnLock(LocationType.Unit, unit.Id, request.OldActorId, unit.GetActorId());
         }
     }
 }

+ 5 - 6
Unity/Assets/Scripts/Hotfix/Server/Demo/Scenes/Map/Transfer/TransferHelper.cs

@@ -5,7 +5,7 @@ namespace ET.Server
 {
     public static partial class TransferHelper
     {
-        public static async ETTask TransferAtFrameFinish(Unit unit, long sceneInstanceId, string sceneName)
+        public static async ETTask TransferAtFrameFinish(Unit unit, ActorId sceneInstanceId, string sceneName)
         {
             await unit.VProcess().WaitFrameFinish();
 
@@ -13,14 +13,13 @@ namespace ET.Server
         }
         
 
-        public static async ETTask Transfer(Unit unit, long sceneInstanceId, string sceneName)
+        public static async ETTask Transfer(Unit unit, ActorId sceneInstanceId, string sceneName)
         {
             // location加锁
             long unitId = unit.Id;
-            long unitInstanceId = unit.InstanceId;
             
-            M2M_UnitTransferRequest request = new M2M_UnitTransferRequest() {Entitys = new List<byte[]>()};
-            request.OldInstanceId = unitInstanceId;
+            M2M_UnitTransferRequest request = new() {Entitys = new List<byte[]>()};
+            request.OldActorId = unit.GetActorId();
             request.Unit = unit.ToBson();
             foreach (Entity entity in unit.Components.Values)
             {
@@ -31,7 +30,7 @@ namespace ET.Server
             }
             unit.Dispose();
             
-            await LocationProxyComponent.Instance.Lock(LocationType.Unit, unitId, unitInstanceId);
+            await LocationProxyComponent.Instance.Lock(LocationType.Unit, unitId, request.OldActorId);
             await ActorMessageSenderComponent.Instance.Call(sceneInstanceId, request);
         }
     }

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Server/Demo/Scenes/Realm/C2R_LoginHandler.cs

@@ -15,7 +15,7 @@ namespace ET.Server
 			
 			// 向gate请求一个key,客户端可以拿着这个key连接gate
 			G2R_GetLoginKey g2RGetLoginKey = (G2R_GetLoginKey) await ActorMessageSenderComponent.Instance.Call(
-				config.InstanceId, new R2G_GetLoginKey() {Account = request.Account});
+				config.ActorId, new R2G_GetLoginKey() {Account = request.Account});
 
 			response.Address = config.InnerIPOutPort.ToString();
 			response.Key = g2RGetLoginKey.Key;

+ 3 - 7
Unity/Assets/Scripts/Hotfix/Server/Demo/Session/NetInnerComponentOnReadEvent.cs

@@ -9,7 +9,7 @@ namespace ET.Server
         {
             try
             {
-                long actorId = args.ActorId;
+                ActorId actorId = args.ActorId;
                 object message = args.Message;
                 
                 if (message is IActorResponse iActorResponse)
@@ -18,22 +18,18 @@ namespace ET.Server
                     return;
                 }
                 
-                InstanceIdStruct instanceIdStruct = new(actorId);
-                int fromProcess = instanceIdStruct.Process;
-                instanceIdStruct.Process = Options.Instance.Process;
-                long realActorId = instanceIdStruct.ToLong();
                 
                 // 收到actor消息,放入actor队列
                 switch (message)
                 {
                     case IActorRequest iActorRequest:
                     {
-                        await ActorMessageDispatcherComponent.Instance.HandleIActorRequest(fromProcess, realActorId, iActorRequest);
+                        await ActorMessageDispatcherComponent.Instance.HandleIActorRequest(actorId, iActorRequest);
                         break;
                     }
                     case IActorMessage iActorMessage:
                     {
-                        await ActorMessageDispatcherComponent.Instance.HandleIActorMessage(fromProcess, realActorId, iActorMessage);
+                        await ActorMessageDispatcherComponent.Instance.HandleIActorMessage(actorId, iActorMessage);
                         break;
                     }
                 }

+ 4 - 4
Unity/Assets/Scripts/Hotfix/Server/Demo/Session/NetServerComponentOnReadEvent.cs

@@ -20,17 +20,17 @@
                 case FrameMessage frameMessage:
                 {
                     Player player = session.GetComponent<SessionPlayerComponent>().Player;
-                    long roomInstanceId = player.GetComponent<PlayerRoomComponent>().RoomInstanceId;
+                    ActorId roomActorId = player.GetComponent<PlayerRoomComponent>().RoomActorId;
                     frameMessage.PlayerId = player.Id;
-                    ActorMessageSenderComponent.Instance.Send(roomInstanceId, frameMessage);
+                    ActorMessageSenderComponent.Instance.Send(roomActorId, frameMessage);
                     break;
                 }
                 case IActorRoom actorRoom:
                 {
                     Player player = session.GetComponent<SessionPlayerComponent>().Player;
-                    long roomInstanceId = player.GetComponent<PlayerRoomComponent>().RoomInstanceId;
+                    ActorId roomActorId = player.GetComponent<PlayerRoomComponent>().RoomActorId;
                     actorRoom.PlayerId = player.Id;
-                    ActorMessageSenderComponent.Instance.Send(roomInstanceId, actorRoom);
+                    ActorMessageSenderComponent.Instance.Send(roomActorId, actorRoom);
                     break;
                 }
                 case IActorLocationMessage actorLocationMessage:

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Server/LockStep/Gate/C2G_MatchHandler.cs

@@ -9,7 +9,7 @@
 
 			StartSceneConfig startSceneConfig = StartSceneConfigCategory.Instance.Match;
 
-			await ActorMessageSenderComponent.Instance.Call(startSceneConfig.InstanceId,
+			await ActorMessageSenderComponent.Instance.Call(startSceneConfig.ActorId,
 				new G2Match_Match() { Id = player.Id });
 		}
 	}

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Server/LockStep/Gate/Match2G_NotifyMatchSuccessHandler.cs

@@ -8,7 +8,7 @@ namespace ET.Server
 	{
 		protected override async ETTask Run(Player player, Match2G_NotifyMatchSuccess message)
 		{
-			player.AddComponent<PlayerRoomComponent>().RoomInstanceId = message.InstanceId;
+			player.AddComponent<PlayerRoomComponent>().RoomActorId = message.ActorId;
 			
 			player.GetComponent<PlayerSessionComponent>().Session.Send(message);
 			await ETTask.CompletedTask;

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Server/LockStep/Map/Match2Map_GetRoomHandler.cs

@@ -10,7 +10,7 @@ namespace ET.Server
 		{
 			RoomManagerComponent roomManagerComponent = scene.GetComponent<RoomManagerComponent>();
 			Room room = await roomManagerComponent.CreateServerRoom(request);
-			response.InstanceId = room.InstanceId;
+			response.ActorId = room.GetActorId();
 			await ETTask.CompletedTask;
 		}
 	}

+ 2 - 2
Unity/Assets/Scripts/Hotfix/Server/LockStep/Match/MatchComponentSystem.cs

@@ -31,9 +31,9 @@ namespace ET.Server
             self.waitMatchPlayers.Clear();
             
             Map2Match_GetRoom map2MatchGetRoom = await ActorMessageSenderComponent.Instance.Call(
-                startSceneConfig.InstanceId, match2MapGetRoom) as Map2Match_GetRoom;
+                startSceneConfig.ActorId, match2MapGetRoom) as Map2Match_GetRoom;
 
-            Match2G_NotifyMatchSuccess match2GNotifyMatchSuccess = new() { InstanceId = map2MatchGetRoom.InstanceId };
+            Match2G_NotifyMatchSuccess match2GNotifyMatchSuccess = new() { ActorId = map2MatchGetRoom.ActorId };
             foreach (long id in match2MapGetRoom.PlayerIds) // 这里发送消息线程不会修改PlayerInfo,所以可以直接使用
             {
                 ActorLocationSenderComponent.Instance.Get(LocationType.Player).Send(id, match2GNotifyMatchSuccess);

+ 4 - 4
Unity/Assets/Scripts/Hotfix/Server/Module/Actor/ActorHandleHelper.cs

@@ -4,20 +4,20 @@ namespace ET.Server
 {
     public static partial class ActorHandleHelper
     {
-        public static void Reply(int fromProcess, IActorResponse response)
+        public static void Reply(ActorId actorId, IActorResponse response)
         {
-            if (fromProcess == Options.Instance.Process) // 返回消息是同一个进程
+            if (actorId.Process == Options.Instance.Process) // 返回消息是同一个进程
             {
                 async ETTask HandleMessageInNextFrame()
                 {
                     await TimerComponent.Instance.WaitFrameAsync();
-                    NetInnerComponent.Instance.HandleMessage(0, response);
+                    NetInnerComponent.Instance.HandleMessage(actorId, response);
                 }
                 HandleMessageInNextFrame().Coroutine();
                 return;
             }
 
-            Session replySession = NetInnerComponent.Instance.Get(fromProcess);
+            Session replySession = NetInnerComponent.Instance.Get(actorId.Process);
             replySession.Send(response);
         }
     }

+ 17 - 17
Unity/Assets/Scripts/Hotfix/Server/Module/Actor/ActorMessageDispatcherComponentSystem.cs

@@ -88,7 +88,7 @@ namespace ET.Server
             self.ActorMessageHandlers[type].Add(handler);
         }
 
-        private static async ETTask Handle(this ActorMessageDispatcherComponent self, Entity entity, int fromProcess, object message)
+        private static async ETTask Handle(this ActorMessageDispatcherComponent self, Entity entity, ActorId actorId, object message)
         {
             List<ActorMessageDispatcherInfo> list;
             if (!self.ActorMessageHandlers.TryGetValue(message.GetType(), out list))
@@ -103,7 +103,7 @@ namespace ET.Server
                 {
                     continue;
                 }
-                await actorMessageDispatcherInfo.IMActorHandler.Handle(entity, fromProcess, message);   
+                await actorMessageDispatcherInfo.IMActorHandler.Handle(entity, actorId, message);   
             }
         }
 
@@ -112,13 +112,13 @@ namespace ET.Server
         /// 分发actor消息
         /// </summary>
         [EnableAccessEntiyChild]
-        public static async ETTask HandleIActorRequest(this ActorMessageDispatcherComponent self, int fromProcess, long actorId, IActorRequest iActorRequest)
+        public static async ETTask HandleIActorRequest(this ActorMessageDispatcherComponent self, ActorId actorId, IActorRequest iActorRequest)
         {
-            Entity entity = self.Get(actorId);
+            Entity entity = self.Get(actorId.InstanceId);
             if (entity == null)
             {
                 IActorResponse response = ActorHelper.CreateResponse(iActorRequest, ErrorCore.ERR_NotFoundActor);
-                ActorHandleHelper.Reply(fromProcess, response);
+                ActorHandleHelper.Reply(actorId, response);
                 return;
             }
             
@@ -129,7 +129,7 @@ namespace ET.Server
             {
                 Log.Warning($"actor not found mailbox: {entity.GetType().FullName} {actorId} {iActorRequest}");
                 IActorResponse response = ActorHelper.CreateResponse(iActorRequest, ErrorCore.ERR_NotFoundActor);
-                ActorHandleHelper.Reply(fromProcess, response);
+                ActorHandleHelper.Reply(actorId, response);
                 return;
             }
             
@@ -137,21 +137,21 @@ namespace ET.Server
             {
                 case MailboxType.OrderedMessage:
                 {
-                    using (await CoroutineLockComponent.Instance.Wait(CoroutineLockType.Mailbox, actorId))
+                    using (await CoroutineLockComponent.Instance.Wait(CoroutineLockType.Mailbox, actorId.InstanceId))
                     {
-                        if (entity.InstanceId != actorId)
+                        if (entity.InstanceId != actorId.InstanceId)
                         {
                             IActorResponse response = ActorHelper.CreateResponse(iActorRequest, ErrorCore.ERR_NotFoundActor);
-                            ActorHandleHelper.Reply(fromProcess, response);
+                            ActorHandleHelper.Reply(actorId, response);
                             break;
                         }
-                        await self.Handle(entity, fromProcess, iActorRequest);
+                        await self.Handle(entity, actorId, iActorRequest);
                     }
                     break;
                 }
                 case MailboxType.UnOrderMessageDispatcher:
                 {
-                    await self.Handle(entity, fromProcess, iActorRequest);
+                    await self.Handle(entity, actorId, iActorRequest);
                     break;
                 }
                 default:
@@ -163,9 +163,9 @@ namespace ET.Server
         /// 分发actor消息
         /// </summary>
         [EnableAccessEntiyChild]
-        public static async ETTask HandleIActorMessage(this ActorMessageDispatcherComponent self, int fromProcess, long actorId, IActorMessage iActorMessage)
+        public static async ETTask HandleIActorMessage(this ActorMessageDispatcherComponent self, ActorId actorId, IActorMessage iActorMessage)
         {
-            Entity entity = self.Get(actorId);
+            Entity entity = self.Get(actorId.InstanceId);
             if (entity == null)
             {
                 Log.Error($"not found actor: {actorId} {iActorMessage}");
@@ -183,19 +183,19 @@ namespace ET.Server
             {
                 case MailboxType.OrderedMessage:
                 {
-                    using (await CoroutineLockComponent.Instance.Wait(CoroutineLockType.Mailbox, actorId))
+                    using (await CoroutineLockComponent.Instance.Wait(CoroutineLockType.Mailbox, actorId.InstanceId))
                     {
-                        if (entity.InstanceId != actorId)
+                        if (entity.InstanceId != actorId.InstanceId)
                         {
                             break;
                         }
-                        await self.Handle(entity, fromProcess, iActorMessage);
+                        await self.Handle(entity, actorId, iActorMessage);
                     }
                     break;
                 }
                 case MailboxType.UnOrderMessageDispatcher:
                 {
-                    await self.Handle(entity, fromProcess, iActorMessage);
+                    await self.Handle(entity, actorId, iActorMessage);
                     break;
                 }
                 case MailboxType.GateSession:

+ 3 - 3
Unity/Assets/Scripts/Hotfix/Server/Module/Actor/ActorMessageHandler.cs

@@ -7,7 +7,7 @@ namespace ET.Server
     {
         protected abstract ETTask Run(E entity, Message message);
 
-        public async ETTask Handle(Entity entity, int fromProcess, object actorMessage)
+        public async ETTask Handle(Entity entity, ActorId actorId, object actorMessage)
         {
             if (actorMessage is not Message msg)
             {
@@ -47,7 +47,7 @@ namespace ET.Server
     {
         protected abstract ETTask Run(E unit, Request request, Response response);
 
-        public async ETTask Handle(Entity entity, int fromProcess, object actorMessage)
+        public async ETTask Handle(Entity entity, ActorId actorId, object actorMessage)
         {
             try
             {
@@ -78,7 +78,7 @@ namespace ET.Server
                 }
                 
                 response.RpcId = rpcId;
-                ActorHandleHelper.Reply(fromProcess, response);
+                ActorHandleHelper.Reply(actorId, response);
             }
             catch (Exception e)
             {

+ 9 - 10
Unity/Assets/Scripts/Hotfix/Server/Module/Actor/ActorMessageSenderComponentSystem.cs

@@ -88,17 +88,16 @@ namespace ET.Server
             self.TimeoutActorMessageSenders.Clear();
         }
 
-        public static void Send(this ActorMessageSenderComponent self, long actorId, IMessage message)
+        public static void Send(this ActorMessageSenderComponent self, ActorId actorId, IMessage message)
         {
-            if (actorId == 0)
+            if (actorId == default)
             {
                 throw new Exception($"actor id is 0: {message}");
             }
             
-            ProcessActorId processActorId = new(actorId);
             
             // 这里做了优化,如果发向同一个进程,则等一帧直接处理,不需要通过网络层
-            if (processActorId.Process == Options.Instance.Process)
+            if (actorId.Process == Options.Instance.Process)
             {
                 async ETTask HandleMessageInNextFrame()
                 {
@@ -109,8 +108,8 @@ namespace ET.Server
                 return;
             }
             
-            Session session = NetInnerComponent.Instance.Get(processActorId.Process);
-            session.Send(processActorId.ActorId, message);
+            Session session = NetInnerComponent.Instance.Get(actorId.Process);
+            session.Send(actorId, message);
         }
 
 
@@ -122,14 +121,14 @@ namespace ET.Server
 
         public static async ETTask<IActorResponse> Call(
                 this ActorMessageSenderComponent self,
-                long actorId,
+                ActorId actorId,
                 IActorRequest request,
                 bool needException = true
         )
         {
             request.RpcId = self.GetRpcId();
             
-            if (actorId == 0)
+            if (actorId == default)
             {
                 throw new Exception($"actor id is 0: {request}");
             }
@@ -139,13 +138,13 @@ namespace ET.Server
         
         public static async ETTask<IActorResponse> Call(
                 this ActorMessageSenderComponent self,
-                long actorId,
+                ActorId actorId,
                 int rpcId,
                 IActorRequest iActorRequest,
                 bool needException = true
         )
         {
-            if (actorId == 0)
+            if (actorId == default)
             {
                 throw new Exception($"actor id is 0: {iActorRequest}");
             }

+ 7 - 7
Unity/Assets/Scripts/Hotfix/Server/Module/ActorLocation/ActorLocationSenderComponentSystem.cs

@@ -98,7 +98,7 @@ namespace ET.Server
         {
             ActorLocationSender actorLocationSender = self.GetOrCreate(entityId);
 
-            if (actorLocationSender.ActorId != 0)
+            if (actorLocationSender.ActorId != default)
             {
                 actorLocationSender.LastSendOrRecvTime = TimeHelper.ServerNow();
                 ActorMessageSenderComponent.Instance.Send(actorLocationSender.ActorId, message);
@@ -115,7 +115,7 @@ namespace ET.Server
                     throw new RpcException(ErrorCore.ERR_ActorTimeout, $"{message}");
                 }
                 
-                if (actorLocationSender.ActorId == 0)
+                if (actorLocationSender.ActorId == default)
                 {
                     actorLocationSender.ActorId = await LocationProxyComponent.Instance.Get(self.LocationType, actorLocationSender.Id);
                     if (actorLocationSender.InstanceId != instanceId)
@@ -135,7 +135,7 @@ namespace ET.Server
         {
             ActorLocationSender actorLocationSender = self.GetOrCreate(entityId);
 
-            if (actorLocationSender.ActorId != 0)
+            if (actorLocationSender.ActorId != default)
             {
                 actorLocationSender.LastSendOrRecvTime = TimeHelper.ServerNow();
                 return await ActorMessageSenderComponent.Instance.Call(actorLocationSender.ActorId, request);
@@ -151,7 +151,7 @@ namespace ET.Server
                     throw new RpcException(ErrorCore.ERR_ActorTimeout, $"{request}");
                 }
 
-                if (actorLocationSender.ActorId == 0)
+                if (actorLocationSender.ActorId == default)
                 {
                     actorLocationSender.ActorId = await LocationProxyComponent.Instance.Get(self.LocationType, actorLocationSender.Id);
                     if (actorLocationSender.InstanceId != instanceId)
@@ -218,7 +218,7 @@ namespace ET.Server
             
             while (true)
             {
-                if (actorLocationSender.ActorId == 0)
+                if (actorLocationSender.ActorId == default)
                 {
                     actorLocationSender.ActorId = await LocationProxyComponent.Instance.Get(self.LocationType, actorLocationSender.Id);
                     if (actorLocationSender.InstanceId != instanceId)
@@ -227,7 +227,7 @@ namespace ET.Server
                     }
                 }
 
-                if (actorLocationSender.ActorId == 0)
+                if (actorLocationSender.ActorId == default)
                 {
                     actorLocationSender.Error = ErrorCore.ERR_NotFoundActor;
                     return ActorHelper.CreateResponse(iActorRequest, ErrorCore.ERR_NotFoundActor);
@@ -259,7 +259,7 @@ namespace ET.Server
                             throw new RpcException(ErrorCore.ERR_ActorLocationSenderTimeout4, $"{iActorRequest}");
                         }
 
-                        actorLocationSender.ActorId = 0;
+                        actorLocationSender.ActorId = default;
                         continue;
                     }
                     case ErrorCore.ERR_ActorTimeout:

+ 2 - 2
Unity/Assets/Scripts/Hotfix/Server/Module/ActorLocation/ActorLocationSenderSystem.cs

@@ -9,7 +9,7 @@ namespace ET.Server
         private static void Awake(this ActorLocationSender self)
         {
             self.LastSendOrRecvTime = TimeHelper.ServerNow();
-            self.ActorId = 0;
+            self.ActorId = default;
             self.Error = 0;
         }
         
@@ -18,7 +18,7 @@ namespace ET.Server
         {
             Log.Debug($"actor location remove: {self.Id}");
             self.LastSendOrRecvTime = 0;
-            self.ActorId = 0;
+            self.ActorId = default;
             self.Error = 0;
         }
     }

+ 4 - 4
Unity/Assets/Scripts/Hotfix/Server/Module/ActorLocation/ActorMessageLocationHandler.cs

@@ -7,7 +7,7 @@ namespace ET.Server
     {
         protected abstract ETTask Run(E entity, Message message);
 
-        public async ETTask Handle(Entity entity, int fromProcess, object actorMessage)
+        public async ETTask Handle(Entity entity, ActorId actorId, object actorMessage)
         {
             if (actorMessage is not Message message)
             {
@@ -22,7 +22,7 @@ namespace ET.Server
             }
             
             ActorResponse response = new() {RpcId = message.RpcId};
-            ActorHandleHelper.Reply(fromProcess, response);
+            ActorHandleHelper.Reply(actorId, response);
 
             await this.Run(e, message);
         }
@@ -45,7 +45,7 @@ namespace ET.Server
     {
         protected abstract ETTask Run(E unit, Request request, Response response);
 
-        public async ETTask Handle(Entity entity, int fromProcess, object actorMessage)
+        public async ETTask Handle(Entity entity, ActorId actorId, object actorMessage)
         {
             try
             {
@@ -75,7 +75,7 @@ namespace ET.Server
                     response.Message = exception.ToString();
                 }
                 response.RpcId = rpcId;
-                ActorHandleHelper.Reply(fromProcess, response);
+                ActorHandleHelper.Reply(actorId, response);
             }
             catch (Exception e)
             {

+ 18 - 18
Unity/Assets/Scripts/Hotfix/Server/Module/ActorLocation/LocationOneTypeSystem.cs

@@ -6,17 +6,17 @@ namespace ET.Server
     public static partial class LockInfoSystem
     {
         [EntitySystem]
-        private static void Awake(this LockInfo self, long lockInstanceId, CoroutineLock coroutineLock)
+        private static void Awake(this LockInfo self, ActorId lockActorId, CoroutineLock coroutineLock)
         {
             self.CoroutineLock = coroutineLock;
-            self.LockInstanceId = lockInstanceId;
+            self.LockActorId = lockActorId;
         }
         
         [EntitySystem]
         private static void Destroy(this LockInfo self)
         {
             self.CoroutineLock.Dispose();
-            self.LockInstanceId = 0;
+            self.LockActorId = default;
         }
     }
     
@@ -32,7 +32,7 @@ namespace ET.Server
             self.LocationType = locationType;
         }
         
-        public static async ETTask Add(this LocationOneType self, long key, long instanceId)
+        public static async ETTask Add(this LocationOneType self, long key, ActorId instanceId)
         {
             int coroutineLockType = (self.LocationType << 16) | CoroutineLockType.Location;
             using (await CoroutineLockComponent.Instance.Wait(coroutineLockType, key))
@@ -52,15 +52,15 @@ namespace ET.Server
             }
         }
 
-        public static async ETTask Lock(this LocationOneType self, long key, long instanceId, int time = 0)
+        public static async ETTask Lock(this LocationOneType self, long key, ActorId actorId, int time = 0)
         {
             int coroutineLockType = (self.LocationType << 16) | CoroutineLockType.Location;
             CoroutineLock coroutineLock = await CoroutineLockComponent.Instance.Wait(coroutineLockType, key);
 
-            LockInfo lockInfo = self.AddChild<LockInfo, long, CoroutineLock>(instanceId, coroutineLock);
+            LockInfo lockInfo = self.AddChild<LockInfo, ActorId, CoroutineLock>(actorId, coroutineLock);
             self.lockInfos.Add(key, lockInfo);
 
-            Log.Info($"location lock key: {key} instanceId: {instanceId}");
+            Log.Info($"location lock key: {key} instanceId: {actorId}");
 
             if (time > 0)
             {
@@ -72,28 +72,28 @@ namespace ET.Server
                     {
                         return;
                     }
-                    Log.Info($"location timeout unlock key: {key} instanceId: {instanceId} newInstanceId: {instanceId}");
-                    self.UnLock(key, instanceId, instanceId);
+                    Log.Info($"location timeout unlock key: {key} instanceId: {actorId} newInstanceId: {actorId}");
+                    self.UnLock(key, actorId, actorId);
                 }
                 TimeWaitAsync().Coroutine();
             }
         }
 
-        public static void UnLock(this LocationOneType self, long key, long oldInstanceId, long newInstanceId)
+        public static void UnLock(this LocationOneType self, long key, ActorId oldActorId, ActorId newInstanceId)
         {
             if (!self.lockInfos.TryGetValue(key, out LockInfo lockInfo))
             {
-                Log.Error($"location unlock not found key: {key} {oldInstanceId}");
+                Log.Error($"location unlock not found key: {key} {oldActorId}");
                 return;
             }
 
-            if (oldInstanceId != lockInfo.LockInstanceId)
+            if (oldActorId != lockInfo.LockActorId)
             {
-                Log.Error($"location unlock oldInstanceId is different: {key} {oldInstanceId}");
+                Log.Error($"location unlock oldInstanceId is different: {key} {oldActorId}");
                 return;
             }
 
-            Log.Info($"location unlock key: {key} instanceId: {oldInstanceId} newInstanceId: {newInstanceId}");
+            Log.Info($"location unlock key: {key} instanceId: {oldActorId} newInstanceId: {newInstanceId}");
 
             self.locations[key] = newInstanceId;
 
@@ -103,14 +103,14 @@ namespace ET.Server
             lockInfo.Dispose();
         }
 
-        public static async ETTask<long> Get(this LocationOneType self, long key)
+        public static async ETTask<ActorId> Get(this LocationOneType self, long key)
         {
             int coroutineLockType = (self.LocationType << 16) | CoroutineLockType.Location;
             using (await CoroutineLockComponent.Instance.Wait(coroutineLockType, key))
             {
-                self.locations.TryGetValue(key, out long instanceId);
-                Log.Info($"location get key: {key} instanceId: {instanceId}");
-                return instanceId;
+                self.locations.TryGetValue(key, out ActorId actorId);
+                Log.Info($"location get key: {key} actorId: {actorId}");
+                return actorId;
             }
         }
     }

+ 14 - 14
Unity/Assets/Scripts/Hotfix/Server/Module/ActorLocation/LocationProxyComponentSystem.cs

@@ -16,30 +16,30 @@ namespace ET.Server
             LocationProxyComponent.Instance = null;
         }
         
-        private static long GetLocationSceneId(long key)
+        private static ActorId GetLocationSceneId(long key)
         {
-            return StartSceneConfigCategory.Instance.LocationConfig.InstanceId;
+            return StartSceneConfigCategory.Instance.LocationConfig.ActorId;
         }
 
-        public static async ETTask Add(this LocationProxyComponent self, int type, long key, long instanceId)
+        public static async ETTask Add(this LocationProxyComponent self, int type, long key, ActorId actorId)
         {
-            Log.Info($"location proxy add {key}, {instanceId} {TimeHelper.ServerNow()}");
+            Log.Info($"location proxy add {key}, {actorId} {TimeHelper.ServerNow()}");
             await ActorMessageSenderComponent.Instance.Call(GetLocationSceneId(key),
-                new ObjectAddRequest() { Type = type, Key = key, InstanceId = instanceId });
+                new ObjectAddRequest() { Type = type, Key = key, ActorId = actorId });
         }
 
-        public static async ETTask Lock(this LocationProxyComponent self, int type, long key, long instanceId, int time = 60000)
+        public static async ETTask Lock(this LocationProxyComponent self, int type, long key, ActorId actorId, int time = 60000)
         {
-            Log.Info($"location proxy lock {key}, {instanceId} {TimeHelper.ServerNow()}");
+            Log.Info($"location proxy lock {key}, {actorId} {TimeHelper.ServerNow()}");
             await ActorMessageSenderComponent.Instance.Call(GetLocationSceneId(key),
-                new ObjectLockRequest() { Type = type, Key = key, InstanceId = instanceId, Time = time });
+                new ObjectLockRequest() { Type = type, Key = key, ActorId = actorId, Time = time });
         }
 
-        public static async ETTask UnLock(this LocationProxyComponent self, int type, long key, long oldInstanceId, long instanceId)
+        public static async ETTask UnLock(this LocationProxyComponent self, int type, long key, ActorId oldActorId, ActorId newActorId)
         {
-            Log.Info($"location proxy unlock {key}, {instanceId} {TimeHelper.ServerNow()}");
+            Log.Info($"location proxy unlock {key}, {newActorId} {TimeHelper.ServerNow()}");
             await ActorMessageSenderComponent.Instance.Call(GetLocationSceneId(key),
-                new ObjectUnLockRequest() { Type = type, Key = key, OldInstanceId = oldInstanceId, InstanceId = instanceId });
+                new ObjectUnLockRequest() { Type = type, Key = key, OldActorId = oldActorId, NewActorId = newActorId });
         }
 
         public static async ETTask Remove(this LocationProxyComponent self, int type, long key)
@@ -49,7 +49,7 @@ namespace ET.Server
                 new ObjectRemoveRequest() { Type = type, Key = key });
         }
 
-        public static async ETTask<long> Get(this LocationProxyComponent self, int type, long key)
+        public static async ETTask<ActorId> Get(this LocationProxyComponent self, int type, long key)
         {
             if (key == 0)
             {
@@ -60,12 +60,12 @@ namespace ET.Server
             ObjectGetResponse response =
                     (ObjectGetResponse) await ActorMessageSenderComponent.Instance.Call(GetLocationSceneId(key),
                         new ObjectGetRequest() { Type = type, Key = key });
-            return response.InstanceId;
+            return response.ActorId;
         }
 
         public static async ETTask AddLocation(this Entity self, int type)
         {
-            await LocationProxyComponent.Instance.Add(type, self.Id, self.InstanceId);
+            await LocationProxyComponent.Instance.Add(type, self.Id, self.GetActorId());
         }
 
         public static async ETTask RemoveLocation(this Entity self, int type)

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Server/Module/ActorLocation/ObjectAddRequestHandler.cs

@@ -7,7 +7,7 @@ namespace ET.Server
     {
         protected override async ETTask Run(Scene scene, ObjectAddRequest request, ObjectAddResponse response)
         {
-            await scene.GetComponent<LocationManagerComoponent>().Get(request.Type).Add(request.Key, request.InstanceId);
+            await scene.GetComponent<LocationManagerComoponent>().Get(request.Type).Add(request.Key, request.ActorId);
         }
     }
 }

+ 1 - 2
Unity/Assets/Scripts/Hotfix/Server/Module/ActorLocation/ObjectGetRequestHandler.cs

@@ -7,8 +7,7 @@ namespace ET.Server
     {
         protected override async ETTask Run(Scene scene, ObjectGetRequest request, ObjectGetResponse response)
         {
-            long instanceId = await scene.GetComponent<LocationManagerComoponent>().Get(request.Type).Get(request.Key);
-            response.InstanceId = instanceId;
+            response.ActorId = await scene.GetComponent<LocationManagerComoponent>().Get(request.Type).Get(request.Key);
         }
     }
 }

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Server/Module/ActorLocation/ObjectLockRequestHandler.cs

@@ -7,7 +7,7 @@ namespace ET.Server
     {
         protected override async ETTask Run(Scene scene, ObjectLockRequest request, ObjectLockResponse response)
         {
-            await scene.GetComponent<LocationManagerComoponent>().Get(request.Type).Lock(request.Key, request.InstanceId, request.Time);
+            await scene.GetComponent<LocationManagerComoponent>().Get(request.Type).Lock(request.Key, request.ActorId, request.Time);
         }
     }
 }

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Server/Module/ActorLocation/ObjectUnLockRequestHandler.cs

@@ -7,7 +7,7 @@ namespace ET.Server
     {
         protected override async ETTask Run(Scene scene, ObjectUnLockRequest request, ObjectUnLockResponse response)
         {
-            scene.GetComponent<LocationManagerComoponent>().Get(request.Type).UnLock(request.Key, request.OldInstanceId, request.InstanceId);
+            scene.GetComponent<LocationManagerComoponent>().Get(request.Type).UnLock(request.Key, request.OldActorId, request.NewActorId);
 
             await ETTask.CompletedTask;
         }

+ 2 - 2
Unity/Assets/Scripts/Hotfix/Server/Module/Message/NetInnerComponentSystem.cs

@@ -59,7 +59,7 @@ namespace ET.Server
             NetServices.Instance.RemoveService(self.ServiceId);
         }
 
-        private static void OnRead(this NetInnerComponent self, long channelId, long actorId, object message)
+        private static void OnRead(this NetInnerComponent self, long channelId, ActorId actorId, object message)
         {
             Session session = self.GetChild<Session>(channelId);
             if (session == null)
@@ -72,7 +72,7 @@ namespace ET.Server
             self.HandleMessage(actorId, message);
         }
 
-        public static void HandleMessage(this NetInnerComponent self, long actorId, object message)
+        public static void HandleMessage(this NetInnerComponent self, ActorId actorId, object message)
         {
             EventSystem.Instance.Publish(self.Root(), new NetInnerComponentOnRead() { ActorId = actorId, Message = message });
         }

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Server/Module/Message/NetServerComponentSystem.cs

@@ -47,7 +47,7 @@ namespace ET.Server
             }
         }
         
-        private static void OnRead(this NetServerComponent self, long channelId, long actorId, object message)
+        private static void OnRead(this NetServerComponent self, long channelId, ActorId actorId, object message)
         {
             Session session = self.GetChild<Session>(channelId);
             if (session == null)

+ 1 - 1
Unity/Assets/Scripts/Loader/MonoBehaviour/Init.cs

@@ -24,7 +24,7 @@ namespace ET
 			
 			World.Instance.AddSingleton<Logger>().ILog = new UnityLogger();
 			ETTask.ExceptionHandler += Log.Error;
-			
+			World.Instance.AddSingleton<IdValueGenerater>();
 			World.Instance.AddSingleton<ObjectPool>();
 			World.Instance.AddSingleton<WorldActor>();
 			World.Instance.AddSingleton<CodeLoader>();

+ 2 - 2
Unity/Assets/Scripts/Model/Generate/Client/Message/LockStepOuter_C_11001.cs

@@ -48,9 +48,9 @@ namespace ET
 		[MemoryPackOrder(0)]
 		public int RpcId { get; set; }
 
-// 房间的instanceId
+// 房间的ActorId
 		[MemoryPackOrder(1)]
-		public long InstanceId { get; set; }
+		public ActorId ActorId { get; set; }
 
 	}
 

+ 3 - 4
Unity/Assets/Scripts/Model/Generate/ClientServer/ConfigPartial/StartProcessConfig.cs

@@ -6,7 +6,7 @@ namespace ET
     {
         private IPEndPoint innerIPPort;
 
-        public long SceneId;
+        public ActorId ActorId;
 
         public IPEndPoint InnerIPPort
         {
@@ -29,9 +29,8 @@ namespace ET
 
         public override void EndInit()
         {
-            InstanceIdStruct instanceIdStruct = new InstanceIdStruct((int)this.Id, 0);
-            this.SceneId = instanceIdStruct.ToLong();
-            Log.Info($"StartProcess info: {this.MachineId} {this.Id} {this.SceneId}");
+            this.ActorId = new ActorId((short)this.Id, 0, 0);
+            Log.Info($"StartProcess info: {this.MachineId} {this.Id} {this.ActorId}");
         }
     }
 }

+ 1 - 3
Unity/Assets/Scripts/Model/Generate/ClientServer/ConfigPartial/StartSceneConfig.cs

@@ -81,7 +81,7 @@ namespace ET
     
     public partial class StartSceneConfig: ISupportInitialize
     {
-        public long InstanceId;
+        public ActorId ActorId;
         
         public SceneType Type;
 
@@ -136,8 +136,6 @@ namespace ET
         public override void EndInit()
         {
             this.Type = EnumHelper.FromString<SceneType>(this.SceneType);
-            InstanceIdStruct instanceIdStruct = new InstanceIdStruct(this.Process, (uint) this.Id);
-            this.InstanceId = instanceIdStruct.ToLong();
         }
     }
 }

+ 6 - 6
Unity/Assets/Scripts/Model/Generate/ClientServer/Message/InnerMessage_S_20001.cs

@@ -154,7 +154,7 @@ namespace ET
 		public long Key { get; set; }
 
 		[MemoryPackOrder(3)]
-		public long InstanceId { get; set; }
+		public ActorId ActorId { get; set; }
 
 	}
 
@@ -196,7 +196,7 @@ namespace ET
 		public long Key { get; set; }
 
 		[MemoryPackOrder(3)]
-		public long InstanceId { get; set; }
+		public ActorId ActorId { get; set; }
 
 		[MemoryPackOrder(4)]
 		public int Time { get; set; }
@@ -241,10 +241,10 @@ namespace ET
 		public long Key { get; set; }
 
 		[MemoryPackOrder(3)]
-		public long OldInstanceId { get; set; }
+		public ActorId OldActorId { get; set; }
 
 		[MemoryPackOrder(4)]
-		public long InstanceId { get; set; }
+		public ActorId NewActorId { get; set; }
 
 	}
 
@@ -347,7 +347,7 @@ namespace ET
 		public int Type { get; set; }
 
 		[MemoryPackOrder(4)]
-		public long InstanceId { get; set; }
+		public ActorId ActorId { get; set; }
 
 	}
 
@@ -441,7 +441,7 @@ namespace ET
 		public int RpcId { get; set; }
 
 		[MemoryPackOrder(1)]
-		public long OldInstanceId { get; set; }
+		public ActorId OldActorId { get; set; }
 
 		[MemoryPackOrder(2)]
 		public byte[] Unit { get; set; }

+ 2 - 2
Unity/Assets/Scripts/Model/Generate/ClientServer/Message/LockStepInner_S_21001.cs

@@ -74,9 +74,9 @@ namespace ET
 		[MemoryPackOrder(2)]
 		public string Message { get; set; }
 
-// 房间的instanceId
+// 房间的ActorId
 		[MemoryPackOrder(3)]
-		public long InstanceId { get; set; }
+		public ActorId ActorId { get; set; }
 
 	}
 

+ 2 - 2
Unity/Assets/Scripts/Model/Generate/ClientServer/Message/LockStepOuter_C_11001.cs

@@ -48,9 +48,9 @@ namespace ET
 		[MemoryPackOrder(0)]
 		public int RpcId { get; set; }
 
-// 房间的instanceId
+// 房间的ActorId
 		[MemoryPackOrder(1)]
-		public long InstanceId { get; set; }
+		public ActorId ActorId { get; set; }
 
 	}
 

+ 1 - 1
Unity/Assets/Scripts/Model/Generate/Server/ConfigPartial/StartProcessConfig.cs

@@ -29,7 +29,7 @@ namespace ET
 
         public override void EndInit()
         {
-            InstanceIdStruct instanceIdStruct = new InstanceIdStruct((int)this.Id, 0);
+            InstanceIdStruct instanceIdStruct = new InstanceIdStruct(0, (uint)this.Id);
             this.SceneId = instanceIdStruct.ToLong();
             Log.Info($"StartProcess info: {this.MachineId} {this.Id} {this.SceneId}");
         }

+ 1 - 3
Unity/Assets/Scripts/Model/Generate/Server/ConfigPartial/StartSceneConfig.cs

@@ -81,7 +81,7 @@ namespace ET
     
     public partial class StartSceneConfig: ISupportInitialize
     {
-        public long InstanceId;
+        public ActorId ActorId;
         
         public SceneType Type;
 
@@ -136,8 +136,6 @@ namespace ET
         public override void EndInit()
         {
             this.Type = EnumHelper.FromString<SceneType>(this.SceneType);
-            InstanceIdStruct instanceIdStruct = new InstanceIdStruct(this.Process, (uint) this.Id);
-            this.InstanceId = instanceIdStruct.ToLong();
         }
     }
 }

+ 6 - 6
Unity/Assets/Scripts/Model/Generate/Server/Message/InnerMessage_S_20001.cs

@@ -154,7 +154,7 @@ namespace ET
 		public long Key { get; set; }
 
 		[MemoryPackOrder(3)]
-		public long InstanceId { get; set; }
+		public ActorId ActorId { get; set; }
 
 	}
 
@@ -196,7 +196,7 @@ namespace ET
 		public long Key { get; set; }
 
 		[MemoryPackOrder(3)]
-		public long InstanceId { get; set; }
+		public ActorId ActorId { get; set; }
 
 		[MemoryPackOrder(4)]
 		public int Time { get; set; }
@@ -241,10 +241,10 @@ namespace ET
 		public long Key { get; set; }
 
 		[MemoryPackOrder(3)]
-		public long OldInstanceId { get; set; }
+		public ActorId OldActorId { get; set; }
 
 		[MemoryPackOrder(4)]
-		public long InstanceId { get; set; }
+		public ActorId NewActorId { get; set; }
 
 	}
 
@@ -347,7 +347,7 @@ namespace ET
 		public int Type { get; set; }
 
 		[MemoryPackOrder(4)]
-		public long InstanceId { get; set; }
+		public ActorId ActorId { get; set; }
 
 	}
 
@@ -441,7 +441,7 @@ namespace ET
 		public int RpcId { get; set; }
 
 		[MemoryPackOrder(1)]
-		public long OldInstanceId { get; set; }
+		public ActorId OldActorId { get; set; }
 
 		[MemoryPackOrder(2)]
 		public byte[] Unit { get; set; }

+ 2 - 2
Unity/Assets/Scripts/Model/Generate/Server/Message/LockStepInner_S_21001.cs

@@ -74,9 +74,9 @@ namespace ET
 		[MemoryPackOrder(2)]
 		public string Message { get; set; }
 
-// 房间的instanceId
+// 房间的ActorId
 		[MemoryPackOrder(3)]
-		public long InstanceId { get; set; }
+		public ActorId ActorId { get; set; }
 
 	}
 

+ 2 - 2
Unity/Assets/Scripts/Model/Generate/Server/Message/LockStepOuter_C_11001.cs

@@ -48,9 +48,9 @@ namespace ET
 		[MemoryPackOrder(0)]
 		public int RpcId { get; set; }
 
-// 房间的instanceId
+// 房间的ActorId
 		[MemoryPackOrder(1)]
-		public long InstanceId { get; set; }
+		public ActorId ActorId { get; set; }
 
 	}
 

+ 1 - 1
Unity/Assets/Scripts/Model/Server/LockStep/Gate/PlayerRoomComponent.cs

@@ -4,6 +4,6 @@ namespace ET.Server
     [ComponentOf(typeof (Player))]
     public class PlayerRoomComponent: Entity, IAwake
     {
-        public long RoomInstanceId { get; set; }
+        public ActorId RoomActorId { get; set; }
     }
 }

+ 2 - 2
Unity/Assets/Scripts/Model/Server/Module/Actor/ActorMessageSender.cs

@@ -5,7 +5,7 @@ namespace ET.Server
     // 知道对方的instanceId,使用这个类发actor消息
     public readonly struct ActorMessageSender
     {
-        public long ActorId { get; }
+        public ActorId ActorId { get; }
 
         // 最近接收或者发送消息的时间
         public long CreateTime { get; }
@@ -16,7 +16,7 @@ namespace ET.Server
 
         public ETTask<IActorResponse> Tcs { get; }
 
-        public ActorMessageSender(long actorId, IActorRequest iActorRequest, ETTask<IActorResponse> tcs, bool needException)
+        public ActorMessageSender(ActorId actorId, IActorRequest iActorRequest, ETTask<IActorResponse> tcs, bool needException)
         {
             this.ActorId = actorId;
             this.Request = iActorRequest;

+ 1 - 1
Unity/Assets/Scripts/Model/Server/Module/Actor/IMActorHandler.cs

@@ -4,7 +4,7 @@ namespace ET.Server
 {
     public interface IMActorHandler
     {
-        ETTask Handle(Entity entity, int fromProcess, object actorMessage);
+        ETTask Handle(Entity entity, ActorId actorId, object actorMessage);
         Type GetRequestType();
         Type GetResponseType();
     }

+ 1 - 1
Unity/Assets/Scripts/Model/Server/Module/ActorLocation/ActorLocationSender.cs

@@ -6,7 +6,7 @@ namespace ET.Server
     [ChildOf(typeof(ActorLocationSenderOneType))]
     public class ActorLocationSender: Entity, IAwake, IDestroy
     {
-        public long ActorId;
+        public ActorId ActorId;
 
         // 最近接收或者发送消息的时间
         public long LastSendOrRecvTime;

+ 3 - 3
Unity/Assets/Scripts/Model/Server/Module/ActorLocation/LocationComponent.cs

@@ -14,9 +14,9 @@ namespace ET.Server
     }
     
     [ChildOf(typeof(LocationOneType))]
-    public class LockInfo: Entity, IAwake<long, CoroutineLock>, IDestroy
+    public class LockInfo: Entity, IAwake<ActorId, CoroutineLock>, IDestroy
     {
-        public long LockInstanceId;
+        public ActorId LockActorId;
 
         public CoroutineLock CoroutineLock;
     }
@@ -26,7 +26,7 @@ namespace ET.Server
     {
         public int LocationType;
         
-        public readonly Dictionary<long, long> locations = new Dictionary<long, long>();
+        public readonly Dictionary<long, ActorId> locations = new Dictionary<long, ActorId>();
 
         public readonly Dictionary<long, LockInfo> lockInfos = new Dictionary<long, LockInfo>();
     }

+ 1 - 15
Unity/Assets/Scripts/Model/Server/Module/Message/NetInnerComponent.cs

@@ -3,23 +3,9 @@ using System.Net;
 
 namespace ET.Server
 {
-    public struct ProcessActorId
-    {
-        public int Process;
-        public long ActorId;
-
-        public ProcessActorId(long actorId)
-        {
-            InstanceIdStruct instanceIdStruct = new InstanceIdStruct(actorId);
-            this.Process = instanceIdStruct.Process;
-            instanceIdStruct.Process = Options.Instance.Process;
-            this.ActorId = instanceIdStruct.ToLong();
-        }
-    }
-    
     public struct NetInnerComponentOnRead
     {
-        public long ActorId;
+        public ActorId ActorId;
         public object Message;
     }
     

+ 2 - 2
Unity/Assets/Scripts/Model/Share/Module/Message/Session.cs

@@ -113,10 +113,10 @@ namespace ET
 
         public static void Send(this Session self, IMessage message)
         {
-            self.Send(0, message);
+            self.Send(default, message);
         }
         
-        public static void Send(this Session self, long actorId, IMessage message)
+        public static void Send(this Session self, ActorId actorId, IMessage message)
         {
             self.LastSendTime = TimeHelper.ClientNow();
             self.LogMsg(message);

+ 1 - 1
Unity/ProjectSettings/ProjectSettings.asset

@@ -842,7 +842,7 @@ PlayerSettings:
     Android: UNITY;SINGLE_THREAD
     Server: UNITY
     Standalone: UNITY;SINGLE_THREAD;ENABLE_VIEW;ENABLE_CODES
-    WebGL: UNITY;ENABLE_CODES;ENABLE_DLL
+    WebGL: UNITY;ENABLE_CODES
     iPhone: UNITY;SINGLE_THREAD;ENABLE_CODES
   additionalCompilerArguments: {}
   platformArchitecture: