فهرست منبع

增加一个OptionsComponent 用来保存命令行参数

tanghai 9 سال پیش
والد
کامیت
40571bd76a

+ 12 - 5
Server/App/Program.cs

@@ -13,10 +13,11 @@ namespace App
 			{
 				Game.DisposerEventManager.Register("Model", typeof(Game).Assembly);
 				Game.DisposerEventManager.Register("Controller", DllHelper.GetController());
-				
-				StartConfig startConfig = Game.Scene.AddComponent<StartConfigComponent, string[]>(args).MyConfig;
 
-				IdGenerater.AppId = startConfig.AppId;
+				Options options = Game.Scene.AddComponent<OptionComponent>().Options;
+				StartConfig startConfig = Game.Scene.AddComponent<StartConfigComponent, string, int>(options.Config, options.AppId).StartConfig;
+
+				IdGenerater.AppId = options.AppId;
 
 				LogManager.Configuration.Variables["appType"] = startConfig.AppType.ToString();
 				LogManager.Configuration.Variables["appId"] = startConfig.AppId.ToString();
@@ -25,7 +26,6 @@ namespace App
 				
 				Game.Scene.AddComponent<EventComponent>();
 				Game.Scene.AddComponent<TimerComponent>();
-				
 				Game.Scene.AddComponent<MessageDispatherComponent, AppType>(startConfig.AppType);
 
 				// 根据不同的AppType添加不同的组件
@@ -66,7 +66,14 @@ namespace App
 
 				while (true)
 				{
-					Game.Update();
+					try
+					{
+						Game.DisposerEventManager.Update();
+					}
+					catch (Exception e)
+					{
+						Log.Error(e.ToString());
+					}
 				}
 			}
 			catch (Exception e)

+ 1 - 1
Server/Controller/Message/M2A_ReloadHandler.cs

@@ -17,7 +17,7 @@ namespace Controller
 			catch (Exception e)
 			{
 				a2MReload.Error = ErrorCode.ERR_ReloadFail;
-				StartConfig myStartConfig = Game.Scene.GetComponent<StartConfigComponent>().MyConfig;
+				StartConfig myStartConfig = Game.Scene.GetComponent<StartConfigComponent>().StartConfig;
 				InnerConfig innerConfig = myStartConfig.GetComponent<InnerConfig>();
 				a2MReload.Message = $"{innerConfig.Address} reload fail, {e}";
 			}

+ 2 - 1
Server/Model/Component/AppManagerComponent.cs

@@ -36,8 +36,9 @@ namespace Model
 
 		private void StartProcess(int appId)
 		{
+			OptionComponent optionComponent = Game.Scene.GetComponent<OptionComponent>();
 			StartConfigComponent startConfigComponent = Game.Scene.GetComponent<StartConfigComponent>();
-			string configFile = startConfigComponent.Options.Config;
+			string configFile = optionComponent.Options.Config;
 			StartConfig startConfig = startConfigComponent.Get(appId);
 #if __MonoCS__
 			const string exe = @"mono";

+ 19 - 0
Server/Model/Component/OptionComponent.cs

@@ -0,0 +1,19 @@
+using System;
+using CommandLine;
+
+namespace Model
+{
+	[DisposerEvent(typeof(OptionComponent))]
+	public class OptionComponent : Component
+	{
+		public Options Options { get; } = new Options();
+
+		private void Awake(string[] args)
+		{
+			if (!Parser.Default.ParseArguments(args, this.Options))
+			{
+				throw new Exception($"命令行格式错误!");
+			}
+		}
+	}
+}

+ 5 - 13
Server/Model/Component/StartConfigComponent.cs

@@ -2,7 +2,6 @@
 using System.Collections.Generic;
 using System.IO;
 using Base;
-using CommandLine;
 
 namespace Model
 {
@@ -12,19 +11,12 @@ namespace Model
 		private readonly List<StartConfig> allConfigs = new List<StartConfig>();
 
 		private readonly Dictionary<int, StartConfig> configDict = new Dictionary<int, StartConfig>();
+		
+		public StartConfig StartConfig { get; private set; }
 
-		public Options Options = new Options();
-
-		public StartConfig MyConfig { get; private set; }
-
-		private void Awake(string[] args)
+		private void Awake(string path, int appId)
 		{
-			if (!Parser.Default.ParseArguments(args, this.Options))
-			{
-				throw new Exception($"命令行格式错误!");
-			}
-			
-			string[] ss = File.ReadAllText(this.Options.Config).Split('\n');
+			string[] ss = File.ReadAllText(path).Split('\n');
 			foreach (string s in ss)
 			{
 				string s2 = s.Trim();
@@ -44,7 +36,7 @@ namespace Model
 				}
 			}
 
-			this.MyConfig = this.Get(this.Options.AppId);
+			this.StartConfig = this.Get(appId);
 		}
 
 		public StartConfig Get(int id)

+ 1 - 0
Server/Model/Server.Model.csproj

@@ -200,6 +200,7 @@
     <Compile Include="Component\AppManagerComponent.cs" />
     <Compile Include="Component\GateSessionKeyComponent.cs" />
     <Compile Include="Component\RealmGateAddressComponent.cs" />
+    <Compile Include="Component\OptionComponent.cs" />
     <Compile Include="Component\StartConfigComponent.cs" />
     <Compile Include="Config\ConfigHelper.cs" />
     <Compile Include="Helper\DllHelper.cs" />

+ 1 - 1
Unity/Assets/Editor/EditorInit.cs

@@ -23,7 +23,7 @@ namespace MyEditor
 
 			try
 			{
-				Game.Update();
+				Game.DisposerEventManager.Update();
 			}
 			catch (Exception e)
 			{

+ 0 - 17
Unity/Assets/Scripts/Entity/Game.cs

@@ -44,23 +44,6 @@ namespace Base
 			}
 		}
 
-		public static void Add(Disposer disposer)
-		{
-			disposers.Add(disposer);
-			disposerEventManager.Add(disposer);
-		}
-
-		public static void Remove(Disposer disposer)
-		{
-			disposers.Remove(disposer);
-			disposerEventManager.Remove(disposer);
-		}
-
-		public static void Update()
-		{
-			disposerEventManager.Update();
-		}
-
 		public static string DisposerInfo()
 		{
 			var info = new Dictionary<string, int>();

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

@@ -18,7 +18,7 @@ namespace Model
 		{
 			try
 			{
-				Game.Update();
+				Game.DisposerEventManager.Update();
 			}
 			catch (Exception e)
 			{

+ 4 - 4
Unity/Assets/Scripts/Object/Disposer.cs

@@ -7,17 +7,17 @@ namespace Model
 	{
 		protected Disposer(): base(IdGenerater.GenerateId())
 		{
-			Game.Add(this);
+			Game.DisposerEventManager.Add(this);
 		}
 
 		protected Disposer(long id): base(id)
 		{
-			Game.Add(this);
+			Game.DisposerEventManager.Add(this);
 		}
 
 		public virtual void Dispose()
 		{
-			Game.Remove(this);
+			Game.DisposerEventManager.Remove(this);
 			this.Id = 0;
 		}
 
@@ -27,7 +27,7 @@ namespace Model
 
 		public override void EndInit()
 		{
-			Game.Add(this);
+			Game.DisposerEventManager.Add(this);
 		}
 	}
 }