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

修复ReloadDll的问题,成功Reload

tanghai пре 2 година
родитељ
комит
314a7ce4aa

+ 1 - 1
DotNet/Loader/Init.cs

@@ -18,7 +18,7 @@ namespace ET
 				// 命令行参数
 				Parser.Default.ParseArguments<Options>(System.Environment.GetCommandLineArgs())
 						.WithNotParsed(error => throw new Exception($"命令行格式错误! {error}"))
-						.WithParsed(World.Instance.AddSingleton);
+						.WithParsed((o)=>World.Instance.AddSingleton(o));
 				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<CodeLoader>();

+ 1 - 1
Share/Tool/Init.cs

@@ -19,7 +19,7 @@ namespace ET.Server
                 // 命令行参数
                 Parser.Default.ParseArguments<Options>(args)
                     .WithNotParsed(error => throw new Exception($"命令行格式错误! {error}"))
-                    .WithParsed(World.Instance.AddSingleton);
+                    .WithParsed((o)=>World.Instance.AddSingleton(o));
                 World.Instance.AddSingleton<Logger>().ILog = new NLogger(Options.Instance.AppType.ToString(), Options.Instance.Process, "../Config/NLog/NLog.config");
                 
                 //Process process = Game.Instance.Create();

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

@@ -28,6 +28,11 @@ namespace ET
             }
         }
         
+        public override void Load()
+        {
+            World.Instance.AddSingleton<EntitySystemSingleton>(true);
+        }
+        
         public void Serialize(Entity component)
         {
             if (component is not ISerialize)

+ 21 - 13
Unity/Assets/Scripts/Core/Fiber/EntitySystem.cs

@@ -101,25 +101,33 @@ namespace ET
                     continue;
                 }
 
-                List<object> iUpdateSystems = EntitySystemSingleton.Instance.TypeSystems.GetSystems(component.GetType(), typeof (IUpdateSystem));
-                if (iUpdateSystems == null)
+                try
                 {
-                    continue;
-                }
-
-                queue.Enqueue(component);
-
-                foreach (IUpdateSystem iUpdateSystem in iUpdateSystems)
-                {
-                    try
+                    List<object> iUpdateSystems = EntitySystemSingleton.Instance.TypeSystems.GetSystems(component.GetType(), typeof (IUpdateSystem));
+                    if (iUpdateSystems == null)
                     {
-                        iUpdateSystem.Run(component);
+                        continue;
                     }
-                    catch (Exception e)
+
+                    queue.Enqueue(component);
+
+                    foreach (IUpdateSystem iUpdateSystem in iUpdateSystems)
                     {
-                        Log.Error(e);
+                        try
+                        {
+                            iUpdateSystem.Run(component);
+                        }
+                        catch (Exception e)
+                        {
+                            Log.Error(e);
+                        }
                     }
                 }
+                catch (Exception e)
+                {
+                    throw new Exception($"entity system update fail: {component.GetType().FullName}", e);
+                }
+
             }
         }
 

+ 5 - 0
Unity/Assets/Scripts/Core/Network/OpcodeType.cs

@@ -57,6 +57,11 @@ namespace ET
             }
         }
         
+        public override void Load()
+        {
+            World.Instance.AddSingleton<OpcodeType>(true);
+        }
+        
         public ushort GetOpcode(Type type)
         {
             return this.typeOpcode.GetValueByKey(type);

+ 1 - 1
Unity/Assets/Scripts/Core/World/ISingletonLoad.cs

@@ -2,6 +2,6 @@
 {
     public interface ISingletonLoad
     {
-        ISingleton Load();
+        void Load();
     }
 }

+ 5 - 0
Unity/Assets/Scripts/Core/World/Module/Actor/ActorMessageDispatcherComponent.cs

@@ -40,6 +40,11 @@ namespace ET
             }
         }
         
+        public override void Load()
+        {
+            World.Instance.AddSingleton<ActorMessageDispatcherComponent>(true);
+        }
+        
         private void Register(Type type)
         {
             object obj = Activator.CreateInstance(type);

+ 1 - 4
Unity/Assets/Scripts/Core/World/Singleton.cs

@@ -113,9 +113,6 @@ namespace ET
             this.Destroy();
         }
 
-        public virtual ISingleton Load()
-        {
-            return new T();
-        }
+        public abstract void Load();
     }
 }

+ 15 - 14
Unity/Assets/Scripts/Core/World/World.cs

@@ -37,49 +37,52 @@ namespace ET
             }
         }
 
-        public T AddSingleton<T>() where T : class, ISingleton, ISingletonAwake, new()
+        public T AddSingleton<T>(bool replace = false) where T : class, ISingleton, ISingletonAwake, new()
         {
             T singleton = new();
             singleton.Awake();
 
-            AddSingleton(singleton);
+            AddSingleton(singleton, replace);
             return singleton;
         }
         
-        public T AddSingleton<T, A>(A a) where T : class, ISingleton, ISingletonAwake<A>, new()
+        public T AddSingleton<T, A>(A a, bool replace = false) where T : class, ISingleton, ISingletonAwake<A>, new()
         {
             T singleton = new();
             singleton.Awake(a);
 
-            AddSingleton(singleton);
+            AddSingleton(singleton, replace);
             return singleton;
         }
         
-        public T AddSingleton<T, A, B>(A a, B b) where T : class, ISingleton, ISingletonAwake<A, B>, new()
+        public T AddSingleton<T, A, B>(A a, B b, bool replace = false) where T : class, ISingleton, ISingletonAwake<A, B>, new()
         {
             T singleton = new();
             singleton.Awake(a, b);
 
-            AddSingleton(singleton);
+            AddSingleton(singleton, replace);
             return singleton;
         }
         
-        public T AddSingleton<T, A, B, C>(A a, B b, C c) where T : class, ISingleton, ISingletonAwake<A, B, C>, new()
+        public T AddSingleton<T, A, B, C>(A a, B b, C c, bool replace = false) where T : class, ISingleton, ISingletonAwake<A, B, C>, new()
         {
             T singleton = new();
             singleton.Awake(a, b, c);
 
-            AddSingleton(singleton);
+            AddSingleton(singleton, replace);
             return singleton;
         }
 
-        public void AddSingleton(ISingleton singleton)
+        public void AddSingleton(ISingleton singleton, bool replace = false)
         {
             lock (this)
             {
                 Type type = singleton.GetType();
-                this.stack.Push(type);
-                singletons.Add(type, singleton);
+                if (!replace)
+                {
+                    this.stack.Push(type);    
+                }
+                singletons[type] = singleton;
             }
 
             singleton.Register();
@@ -98,9 +101,7 @@ namespace ET
                         continue;
                     }
                     
-                    singleton = iSingletonLoad.Load();
-                    this.singletons[type] = singleton;
-                    singleton.Register();
+                    iSingletonLoad.Load();
                 }
             }
         }

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

@@ -20,7 +20,7 @@ namespace ET
 			string[] args = "".Split(" ");
 			Parser.Default.ParseArguments<Options>(args)
 				.WithNotParsed(error => throw new Exception($"命令行格式错误! {error}"))
-				.WithParsed(World.Instance.AddSingleton);
+				.WithParsed((o)=>World.Instance.AddSingleton(o));
 			Options.Instance.StartConfig = $"StartConfig/Localhost";
 			
 			World.Instance.AddSingleton<Logger>().ILog = new UnityLogger();

+ 5 - 0
Unity/Assets/Scripts/Model/Share/LockStep/LSEntitySystemSingleton.cs

@@ -37,6 +37,11 @@ namespace ET
             }
         }
         
+        public override void Load()
+        {
+            World.Instance.AddSingleton<LSEntitySystemSingleton>(true);
+        }
+        
         public TypeSystems.OneTypeSystems GetOneTypeSystems(Type type)
         {
             return this.TypeSystems.GetOneTypeSystems(type);

+ 5 - 0
Unity/Assets/Scripts/Model/Share/Module/AI/AIDispatcherComponent.cs

@@ -27,5 +27,10 @@ namespace ET
             this.aiHandlers.TryGetValue(key, out var aaiHandler);
             return aaiHandler;
         }
+
+        public override void Load()
+        {
+            World.Instance.AddSingleton<AIDispatcherComponent>(true);
+        }
     }
 }

+ 5 - 0
Unity/Assets/Scripts/Model/Share/Module/Message/MessageDispatcherComponent.cs

@@ -53,6 +53,11 @@ namespace ET
             }
         }
         
+        public override void Load()
+        {
+            World.Instance.AddSingleton<MessageDispatcherComponent>(true);
+        }
+        
         private void RegisterHandler(ushort opcode, MessageDispatcherInfo handler)
         {
             if (!this.handlers.ContainsKey(opcode))

+ 5 - 0
Unity/Assets/Scripts/Model/Share/Module/Numeric/NumericWatcherComponent.cs

@@ -43,6 +43,11 @@ namespace ET
             }
         }
         
+        public override void Load()
+        {
+            World.Instance.AddSingleton<NumericWatcherComponent>(true);
+        }
+        
         public void Run(Unit unit, EventType.NumbericChange args)
         {
             List<NumericWatcherInfo> list;

+ 5 - 0
Unity/Assets/Scripts/ModelView/Client/Module/UI/UIEventComponent.cs

@@ -27,5 +27,10 @@ namespace ET.Client
                 this.UIEvents.Add(uiEventAttribute.UIType, aUIEvent);
             }
         }
+        
+        public override void Load()
+        {
+	        World.Instance.AddSingleton<UIEventComponent>(true);
+        }
 	}
 }