AtomicNET.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Runtime.InteropServices;
  4. using AtomicPlayer;
  5. namespace AtomicEngine
  6. {
  7. public static class AtomicNET
  8. {
  9. public static Context Context => context;
  10. public static ResourceCache Cache;
  11. public static T GetSubsystem<T>() where T : AObject
  12. {
  13. AObject subSystem = null;
  14. subSystems.TryGetValue(typeof(T), out subSystem);
  15. return (T)subSystem;
  16. }
  17. public static void RegisterSubsystem(String name, AObject instance = null)
  18. {
  19. if (instance != null)
  20. {
  21. subSystems[instance.GetType()] = instance;
  22. return;
  23. }
  24. var subsystem = AtomicNET.Context.GetSubsystem(name);
  25. if (subsystem == null)
  26. {
  27. throw new System.InvalidOperationException("AtomicNET.RegisterSubsystem - Attempting to register null subsystem");
  28. }
  29. subSystems[subsystem.GetType()] = subsystem;
  30. }
  31. public static uint StringToStringHash(string value)
  32. {
  33. return csi_Atomic_AtomicNET_StringToStringHash(value);
  34. }
  35. [DllImport(Constants.LIBNAME, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
  36. private static extern uint csi_Atomic_AtomicNET_StringToStringHash(string name);
  37. public static void Initialize()
  38. {
  39. // Atomic Modules
  40. CoreModule.Initialize();
  41. MathModule.Initialize();
  42. EngineModule.Initialize();
  43. InputModule.Initialize();
  44. IOModule.Initialize();
  45. ResourceModule.Initialize();
  46. AudioModule.Initialize();
  47. GraphicsModule.Initialize();
  48. SceneModule.Initialize();
  49. Atomic2DModule.Initialize();
  50. NavigationModule.Initialize();
  51. NetworkModule.Initialize();
  52. PhysicsModule.Initialize();
  53. EnvironmentModule.Initialize();
  54. UIModule.Initialize();
  55. #if ATOMIC_DESKTOP
  56. IPCModule.Initialize();
  57. #endif
  58. AtomicAppModule.Initialize();
  59. ScriptModule.Initialize();
  60. AtomicNETScriptModule.Initialize();
  61. AtomicNETNativeModule.Initialize();
  62. PlayerModule.Initialize();
  63. coreDelegates = new CoreDelegates();
  64. coreDelegates.eventDispatch = NativeCore.EventDispatch;
  65. coreDelegates.updateDispatch = NativeCore.UpdateDispatch;
  66. IntPtr coreptr = csi_Atomic_NETCore_Initialize(ref coreDelegates);
  67. NETCore core = (coreptr == IntPtr.Zero ? null : NativeCore.WrapNative<NETCore>(coreptr));
  68. if (core != null)
  69. AtomicNET.RegisterSubsystem("NETCore", core);
  70. context = core.Context;
  71. NativeCore.Initialize();
  72. CSComponentCore.Initialize();
  73. #if ATOMIC_DESKTOP
  74. string[] arguments = Environment.GetCommandLineArgs();
  75. foreach (string arg in arguments)
  76. AppBase.AddArgument(arg);
  77. #endif
  78. }
  79. [DllImport(Constants.LIBNAME, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
  80. private static extern IntPtr csi_Atomic_NETCore_Initialize(ref CoreDelegates delegates);
  81. private static Context context;
  82. private static CoreDelegates coreDelegates;
  83. private static Dictionary<Type, AObject> subSystems = new Dictionary<Type, AObject>();
  84. }
  85. }