ソースを参照

之前以为mongo驱动反序列化会在另外的线程,测试发现还是会在主线程,所以InstanceId可以在Component构造函数中设置

tanghai 7 年 前
コミット
278f2769a6

+ 1 - 1
Config/StartConfig/LocalAllServer.txt

@@ -1 +1 @@
-{ "_t" : "StartConfig", "_id" : NumberLong("98547768819754"), "C" : [{ "_t" : "OuterConfig", "Address" : "127.0.0.1:10002", "Address2" : "127.0.0.1:10002" }, { "_t" : "InnerConfig", "Address" : "127.0.0.1:20000" }, { "_t" : "HttpConfig", "Url" : "http://*:8080/", "AppId" : 0, "AppKey" : "", "ManagerSystemUrl" : "" }, { "_t" : "DBConfig", "ConnectionString" : null, "DBName" : null }], "AppId" : 1, "AppType" : "AllServer", "ServerIP" : "*" }
+{ "_t" : "StartConfig", "_id" : NumberLong("98547768819754"), "C" : [{ "_t" : "OuterConfig", "Address" : "127.0.0.1:10002", "Address2" : "127.0.0.1:10002" }, { "_t" : "InnerConfig", "Address" : "127.0.0.1:20000" }, { "_t" : "HttpConfig", "Url" : "http://*:8080/", "AppId" : 0, "AppKey" : "", "ManagerSystemUrl" : "" }, { "_t" : "DBConfig", "ConnectionString" : "mongodb://172.16.100.40:27017/", "DBName" : "ET" }], "AppId" : 1, "AppType" : "AllServer", "ServerIP" : "*" }

+ 3 - 3
Server/App/Program.cs

@@ -85,9 +85,9 @@ namespace App
 						Game.Scene.AddComponent<ActorLocationSenderComponent>();
 						Game.Scene.AddComponent<PlayerComponent>();
 						Game.Scene.AddComponent<UnitComponent>();
-						Game.Scene.AddComponent<DBComponent>();
-						Game.Scene.AddComponent<DBProxyComponent>();
-						Game.Scene.AddComponent<DBCacheComponent>();
+						//Game.Scene.AddComponent<DBComponent>();
+						//Game.Scene.AddComponent<DBProxyComponent>();
+						//Game.Scene.AddComponent<DBCacheComponent>();
 						Game.Scene.AddComponent<LocationComponent>();
 						Game.Scene.AddComponent<ActorMessageDispatherComponent>();
 						Game.Scene.AddComponent<NetInnerComponent, string>(innerConfig.Address);

+ 0 - 2
Server/Model/Entity/Scene.cs

@@ -6,12 +6,10 @@
 
 		public Scene()
 		{
-			this.InstanceId = IdGenerater.GenerateId();
 		}
 
 		public Scene(long id): base(id)
 		{
-			this.InstanceId = IdGenerater.GenerateId();
 		}
 
 		public override void Dispose()

+ 4 - 4
Server/Model/Module/DB/DBComponent.cs

@@ -21,10 +21,10 @@ namespace ETModel
 
 		public void Awake()
 		{
-			//DBConfig config = Game.Scene.GetComponent<StartConfigComponent>().StartConfig.GetComponent<DBConfig>();
-			//string connectionString = config.ConnectionString;
-			//mongoClient = new MongoClient(connectionString);
-			//this.database = this.mongoClient.GetDatabase(config.DBName);
+			DBConfig config = Game.Scene.GetComponent<StartConfigComponent>().StartConfig.GetComponent<DBConfig>();
+			string connectionString = config.ConnectionString;
+			mongoClient = new MongoClient(connectionString);
+			this.database = this.mongoClient.GetDatabase(config.DBName);
 		}
 
 		public IMongoCollection<ComponentWithId> GetCollection(string name)

+ 5 - 0
Server/Model/Entity/Unit.cs → Server/Model/Module/Demo/Unit.cs

@@ -30,6 +30,11 @@ namespace ETModel
 			this.UnitType = unitType;
 		}
 
+		public override void EndDeSerialize()
+		{
+			Game.EventSystem.Add(this);
+		}
+
 		public override void Dispose()
 		{
 			if (this.IsDisposed)

+ 1 - 1
Unity/Assets/Hotfix/Base/Object/Component.cs

@@ -6,7 +6,6 @@ namespace ETHotfix
 	[BsonIgnoreExtraElements]
 	public abstract class Component : Object, IDisposable, IComponentSerialize
 	{
-		// 只有Game.EventSystem.Add方法中会设置该值,如果new出来的对象不想加入Game.EventSystem中,则需要自己在构造函数中设置
 		[BsonIgnore]
 		public long InstanceId { get; protected set; }
 
@@ -62,6 +61,7 @@ namespace ETHotfix
 
 		protected Component()
 		{
+			this.InstanceId = IdGenerater.GenerateId();
 		}
 		
 		public virtual void Dispose()

+ 2 - 2
Unity/Assets/Model/Base/Object/Component.cs

@@ -6,9 +6,8 @@ namespace ETModel
 	[BsonIgnoreExtraElements]
 	public abstract class Component : Object, IDisposable, IComponentSerialize
 	{
-		// 只有Game.EventSystem.Add方法中会设置该值,如果new出来的对象不想加入Game.EventSystem中,则需要自己在构造函数中设置
 		[BsonIgnore]
-		public long InstanceId { get; protected set; }
+		public long InstanceId { get; private set; }
 
 		[BsonIgnore]
 		private bool isFromPool;
@@ -62,6 +61,7 @@ namespace ETModel
 		
 		protected Component()
 		{
+			this.InstanceId = IdGenerater.GenerateId();
 		}
 
 		public virtual void Dispose()

+ 0 - 2
Unity/Assets/Model/Entity/Scene.cs

@@ -19,12 +19,10 @@
 
 		public Scene()
 		{
-			this.InstanceId = IdGenerater.GenerateId();
 		}
 
 		public Scene(long id): base(id)
 		{
-			this.InstanceId = IdGenerater.GenerateId();
 		}
 
 		public override void Dispose()

+ 0 - 2
Unity/Assets/Model/Module/AssetsBundle/ResourcesComponent.cs

@@ -33,8 +33,6 @@ namespace ETModel
 
 		public ABInfo(string name, AssetBundle ab)
 		{
-			this.InstanceId = IdGenerater.GenerateId();
-			
 			this.Name = name;
 			this.AssetBundle = ab;
 			this.RefCount = 1;

+ 0 - 2
Unity/Assets/Model/Module/Message/Network/KCP/KChannel.cs

@@ -42,7 +42,6 @@ namespace ETModel
 		// accept
 		public KChannel(uint localConn, uint remoteConn, Socket socket, IPEndPoint remoteEndPoint, KService kService) : base(kService, ChannelType.Accept)
 		{
-			this.InstanceId = IdGenerater.GenerateId();
 			this.memoryStream = this.GetService().MemoryStreamManager.GetStream("message", ushort.MaxValue);
 
 			this.LocalConn = localConn;
@@ -69,7 +68,6 @@ namespace ETModel
 		// connect
 		public KChannel(uint localConn, Socket socket, IPEndPoint remoteEndPoint, KService kService) : base(kService, ChannelType.Connect)
 		{
-			this.InstanceId = IdGenerater.GenerateId();
 			this.memoryStream = this.GetService().MemoryStreamManager.GetStream("message", ushort.MaxValue);
 
 			this.LocalConn = localConn;

+ 0 - 4
Unity/Assets/Model/Module/Message/Network/KCP/KService.cs

@@ -59,8 +59,6 @@ namespace ETModel
 
 		public KService(IPEndPoint ipEndPoint, Action<AChannel> acceptCallback)
 		{
-			this.InstanceId = ETModel.IdGenerater.GenerateId();
-			
 			this.AcceptCallback += acceptCallback;
 			
 			this.StartTime = TimeHelper.ClientNow();
@@ -82,8 +80,6 @@ namespace ETModel
 
 		public KService()
 		{
-			this.InstanceId = ETModel.IdGenerater.GenerateId();
-			
 			this.StartTime = TimeHelper.ClientNow();
 			this.TimeNow = (uint)(TimeHelper.ClientNow() - this.StartTime);
 			this.socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);

+ 0 - 2
Unity/Assets/Model/Module/Message/Network/TCP/TChannel.cs

@@ -34,7 +34,6 @@ namespace ETModel
 		
 		public TChannel(IPEndPoint ipEndPoint, TService service): base(service, ChannelType.Connect)
 		{
-			this.InstanceId = IdGenerater.GenerateId();
 			this.memoryStream = this.GetService().MemoryStreamManager.GetStream("message", ushort.MaxValue);
 			
 			this.socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
@@ -51,7 +50,6 @@ namespace ETModel
 		
 		public TChannel(Socket socket, TService service): base(service, ChannelType.Accept)
 		{
-			this.InstanceId = IdGenerater.GenerateId();
 			this.memoryStream = this.GetService().MemoryStreamManager.GetStream("message", ushort.MaxValue);
 			
 			this.socket = socket;

+ 0 - 2
Unity/Assets/Model/Module/Message/Network/TCP/TService.cs

@@ -24,7 +24,6 @@ namespace ETModel
 		/// </summary>
 		public TService(IPEndPoint ipEndPoint, Action<AChannel> acceptCallback)
 		{
-			this.InstanceId = IdGenerater.GenerateId();
 			this.AcceptCallback += acceptCallback;
 			
 			this.acceptor = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
@@ -39,7 +38,6 @@ namespace ETModel
 
 		public TService()
 		{
-			this.InstanceId = IdGenerater.GenerateId();
 		}
 		
 		public override void Dispose()

+ 0 - 4
Unity/Assets/Model/Module/Message/Network/WebSocket/WChannel.cs

@@ -26,8 +26,6 @@ namespace ETModel
         
         public WChannel(HttpListenerWebSocketContext webSocketContext, AService service): base(service, ChannelType.Accept)
         {
-            this.InstanceId = IdGenerater.GenerateId();
-            
             this.WebSocketContext = webSocketContext;
 
             this.webSocket = webSocketContext.WebSocket;
@@ -40,8 +38,6 @@ namespace ETModel
         
         public WChannel(WebSocket webSocket, AService service): base(service, ChannelType.Connect)
         {
-            this.InstanceId = IdGenerater.GenerateId();
-
             this.webSocket = webSocket;
             
             this.memoryStream = this.GetService().MemoryStreamManager.GetStream("message", ushort.MaxValue);

+ 0 - 3
Unity/Assets/Model/Module/Message/Network/WebSocket/WService.cs

@@ -16,8 +16,6 @@ namespace ETModel
 
         public WService(IEnumerable<string> prefixs, Action<AChannel> acceptCallback)
         {
-            this.InstanceId = IdGenerater.GenerateId();
-
             this.AcceptCallback += acceptCallback;
             
             this.httpListener = new HttpListener();
@@ -27,7 +25,6 @@ namespace ETModel
         
         public WService()
         {
-            this.InstanceId = IdGenerater.GenerateId();
         }
         
         public override AChannel GetChannel(long id)

+ 6 - 6
Unity/Unity.sln

@@ -4,10 +4,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Unity.Model", "Unity.Model.
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Unity.ThirdParty", "Unity.ThirdParty.csproj", "{E15BADD2-3A26-309A-AB0F-DC5B08044350}"
 EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Unity.Hotfix", "Unity.Hotfix.csproj", "{1066F652-6A89-D1C4-9881-1A19DF7AB80E}"
-EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Unity.Editor", "Unity.Editor.csproj", "{CD311104-1830-B119-81B6-5DBEE2467FFB}"
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Unity.Hotfix", "Unity.Hotfix.csproj", "{1066F652-6A89-D1C4-9881-1A19DF7AB80E}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
@@ -22,14 +22,14 @@ Global
 		{E15BADD2-3A26-309A-AB0F-DC5B08044350}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{E15BADD2-3A26-309A-AB0F-DC5B08044350}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{E15BADD2-3A26-309A-AB0F-DC5B08044350}.Release|Any CPU.Build.0 = Release|Any CPU
-		{1066F652-6A89-D1C4-9881-1A19DF7AB80E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
-		{1066F652-6A89-D1C4-9881-1A19DF7AB80E}.Debug|Any CPU.Build.0 = Debug|Any CPU
-		{1066F652-6A89-D1C4-9881-1A19DF7AB80E}.Release|Any CPU.ActiveCfg = Release|Any CPU
-		{1066F652-6A89-D1C4-9881-1A19DF7AB80E}.Release|Any CPU.Build.0 = Release|Any CPU
 		{CD311104-1830-B119-81B6-5DBEE2467FFB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
 		{CD311104-1830-B119-81B6-5DBEE2467FFB}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{CD311104-1830-B119-81B6-5DBEE2467FFB}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{CD311104-1830-B119-81B6-5DBEE2467FFB}.Release|Any CPU.Build.0 = Release|Any CPU
+		{1066F652-6A89-D1C4-9881-1A19DF7AB80E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{1066F652-6A89-D1C4-9881-1A19DF7AB80E}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{1066F652-6A89-D1C4-9881-1A19DF7AB80E}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{1066F652-6A89-D1C4-9881-1A19DF7AB80E}.Release|Any CPU.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE