Browse Source

Merge pull request #1124 from AtomicGameEngine/JME-ATOMIC-1122

AtomicNET Subsystem cleanups
JoshEngebretson 9 years ago
parent
commit
a0505c2173

+ 0 - 2
Script/AtomicNET/AtomicNET/Application/NETAtomicPlayer.cs

@@ -17,8 +17,6 @@ namespace AtomicEngine
 
 
             app.Initialize();
             app.Initialize();
 
 
-            RegisterSubsystems();
-
             return app;
             return app;
         }
         }
 
 

+ 0 - 2
Script/AtomicNET/AtomicNET/Application/NETIPCPlayerApp.cs

@@ -22,8 +22,6 @@ namespace AtomicEngine
 
 
             app.Initialize();
             app.Initialize();
 
 
-            RegisterSubsystems();
-
             return app;
             return app;
         }
         }
 
 

+ 0 - 2
Script/AtomicNET/AtomicNET/Application/NETServiceApplication.cs

@@ -20,8 +20,6 @@ namespace AtomicEngine
 
 
             app.Initialize();
             app.Initialize();
 
 
-            AtomicNET.RegisterSubsystem("IPC");
-
             return app;
             return app;
         }
         }
 
 

+ 0 - 21
Script/AtomicNET/AtomicNET/Application/PlayerApp.cs

@@ -9,27 +9,6 @@ namespace AtomicEngine
     public partial class PlayerApp : AppBase
     public partial class PlayerApp : AppBase
     {
     {
 
 
-        static protected void RegisterSubsystems()
-        {
-            // TODO: Refactor these registrations
-
-            AtomicNET.RegisterSubsystem("Engine");
-
-            AtomicNET.RegisterSubsystem("FileSystem");
-
-            AtomicNET.RegisterSubsystem("Graphics");
-            AtomicNET.RegisterSubsystem("Player");
-
-            AtomicNET.RegisterSubsystem("Audio");
-            AtomicNET.RegisterSubsystem("Input");
-            AtomicNET.RegisterSubsystem("Renderer");
-            AtomicNET.RegisterSubsystem("UI");
-
-            AtomicNET.RegisterSubsystem("ResourceCache");
-            AtomicNET.Cache = AtomicNET.GetSubsystem<ResourceCache>();
-
-        }
-
     }
     }
 
 
 
 

+ 33 - 17
Script/AtomicNET/AtomicNET/Core/AtomicNET.cs

@@ -9,33 +9,49 @@ namespace AtomicEngine
 
 
     public static class AtomicNET
     public static class AtomicNET
     {
     {
-
-        public static Context Context => context;
-        public static ResourceCache Cache;
+        public static Context Context => context;        
 
 
         public static T GetSubsystem<T>() where T : AObject
         public static T GetSubsystem<T>() where T : AObject
         {
         {
-            AObject subSystem = null;
-            subSystems.TryGetValue(typeof(T), out subSystem);
-            return (T)subSystem;
-        }
+            AObject subsystem = null;
+            var type = typeof(T);
 
 
-        public static void RegisterSubsystem(String name, AObject instance = null)
-        {
-            if (instance != null)
+            // See if already registered (or a managed subsystem which will only be in the dictionary)
+            if (subSystems.TryGetValue(type, out subsystem))
             {
             {
-                subSystems[instance.GetType()] = instance;
-                return;
+                return (T) subsystem;
+            }
+
+            // If we're a managed type, throw error
+            if (!NativeCore.IsNativeType(type))
+            {
+                throw new System.InvalidOperationException($"AtomicNET.GetSubsystem<T> - Attempting to get null subsystem: {type.Name}");
             }
             }
 
 
-            var subsystem = AtomicNET.Context.GetSubsystem(name);
+            // Look up possible native subsystem 
+            subsystem = AtomicNET.Context.GetSubsystem(type.Name);
 
 
+            // If we didn't find one, this is an error
             if (subsystem == null)
             if (subsystem == null)
             {
             {
-                throw new System.InvalidOperationException("AtomicNET.RegisterSubsystem - Attempting to register null subsystem");
+                throw new System.InvalidOperationException($"AtomicNET.GetSubsystem<T> - Attempting to get null subsystem: {type.Name}");
             }
             }
 
 
-            subSystems[subsystem.GetType()] = subsystem;
+            // register the subsystem
+            RegisterSubsystem(subsystem);
+
+            return (T)subsystem;
+        }
+
+        public static void RegisterSubsystem(AObject instance)
+        {
+            var type = instance.GetType();
+            if (subSystems.ContainsKey(type))
+            {
+                Log.Error($"AtomicNET.RegisterSubsystem - Attempting to reregister subsystem: {type.Name}");
+                return;
+            }
+            subSystems[instance.GetType()] = instance;
         }
         }
 
 
         public static uint StringToStringHash(string value)
         public static uint StringToStringHash(string value)
@@ -87,9 +103,9 @@ namespace AtomicEngine
             NETCore core = (coreptr == IntPtr.Zero ? null : NativeCore.WrapNative<NETCore>(coreptr));
             NETCore core = (coreptr == IntPtr.Zero ? null : NativeCore.WrapNative<NETCore>(coreptr));
 
 
             if (core != null)
             if (core != null)
-                AtomicNET.RegisterSubsystem("NETCore", core);
+                AtomicNET.RegisterSubsystem(core);
 
 
-            context = core.Context;
+            context = core.Context;            
 
 
             NativeCore.Initialize();
             NativeCore.Initialize();
             CSComponentCore.Initialize();
             CSComponentCore.Initialize();