Browse Source

Atomic C# work

Josh Engebretson 10 years ago
parent
commit
4656905e7d

+ 27 - 3
Build/AtomicSharp/MyClass.cs → Build/AtomicSharp/AtomicEngine.cs

@@ -2,10 +2,12 @@
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.Runtime.InteropServices;
 using System.Runtime.InteropServices;
 
 
-namespace Atomic
+using AtomicPlayer;
+
+namespace AtomicEngine
 {
 {
 
 
-	public static class AtomicSharp
+	public static class Atomic
 	{
 	{
 		[DllImport (Constants.LIBNAME, CallingConvention = CallingConvention.Cdecl)]
 		[DllImport (Constants.LIBNAME, CallingConvention = CallingConvention.Cdecl)]
 		private static extern int atomicsharp_initialize ();
 		private static extern int atomicsharp_initialize ();
@@ -13,7 +15,9 @@ namespace Atomic
 		[DllImport (Constants.LIBNAME, CallingConvention = CallingConvention.Cdecl)]
 		[DllImport (Constants.LIBNAME, CallingConvention = CallingConvention.Cdecl)]
 		private static extern bool atomicsharp_runframe ();
 		private static extern bool atomicsharp_runframe ();
 
 
-
+		[DllImport (Constants.LIBNAME, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+		private static extern IntPtr csb_AtomicEngine_GetSubsystem(string name);
+					
 		public static bool RunFrame()
 		public static bool RunFrame()
 		{
 		{
 			GC.Collect();
 			GC.Collect();
@@ -36,7 +40,27 @@ namespace Atomic
 			AtomicPlayer.PlayerModule.Initialize ();
 			AtomicPlayer.PlayerModule.Initialize ();
 
 
 			atomicsharp_initialize ();
 			atomicsharp_initialize ();
+
+			initSubsystems ();
+		}
+
+		static Dictionary<Type, RefCounted> subSystems = new Dictionary<Type, RefCounted>();
+
+		static private void registerSubsystem (RefCounted subsystem)
+		{
+			subSystems[subsystem.GetType()] = subsystem;
+		}
+
+		static public T GetSubsystem<T>() where T : RefCounted
+		{
+			return (T) subSystems [typeof(T)];
 		}
 		}
+
+		static private void initSubsystems()
+		{
+			registerSubsystem (NativeCore.WrapNative<Player> (csb_AtomicEngine_GetSubsystem("Player")));	
+		}
+
 	}
 	}
 
 
 	public static partial class Constants
 	public static partial class Constants

+ 1 - 1
Build/AtomicSharp/AtomicSharp.csproj

@@ -31,7 +31,6 @@
     <Reference Include="System" />
     <Reference Include="System" />
   </ItemGroup>
   </ItemGroup>
   <ItemGroup>
   <ItemGroup>
-    <Compile Include="MyClass.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
     <Compile Include="..\Source\Generated\MACOSX\CSharp\Packages\Atomic\Managed\CSModuleContainer.cs">
     <Compile Include="..\Source\Generated\MACOSX\CSharp\Packages\Atomic\Managed\CSModuleContainer.cs">
       <Link>CSModuleContainer.cs</Link>
       <Link>CSModuleContainer.cs</Link>
@@ -54,6 +53,7 @@
     <Compile Include="..\Source\Generated\MACOSX\CSharp\Packages\AtomicPlayer\Managed\CSModulePlayer.cs">
     <Compile Include="..\Source\Generated\MACOSX\CSharp\Packages\AtomicPlayer\Managed\CSModulePlayer.cs">
       <Link>CSModulePlayer.cs</Link>
       <Link>CSModulePlayer.cs</Link>
     </Compile>
     </Compile>
+    <Compile Include="AtomicEngine.cs" />
   </ItemGroup>
   </ItemGroup>
   <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
   <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
 </Project>
 </Project>

+ 7 - 15
Build/AtomicSharp/AtomicSharpTest/Program.cs

@@ -1,28 +1,20 @@
 using System;
 using System;
-
-using Atomic;
+using AtomicEngine;
 using AtomicPlayer;
 using AtomicPlayer;
 
 
 namespace AtomicSharpTest
 namespace AtomicSharpTest
 {
 {
 	class MainClass
 	class MainClass
-	{
-		static Scene CreateScene() {
-
-			var node = new Node ();
-			var player = (Player)node.GetSubsystem ("Player");
-			player.LoadScene ("Scenes/Scene.scene", null);		
-			return player.CurrentScene;
-
-		}
-				
+	{				
 		public static void Main (string[] args)
 		public static void Main (string[] args)
 		{
 		{
-			Atomic.AtomicSharp.Initialize ();
+			Atomic.Initialize ();
 
 
-			CreateScene ();
+			var player = Atomic.GetSubsystem<Player> ();
+
+			player.LoadScene ("Scenes/Scene.scene", null);		
 
 
-			while (Atomic.AtomicSharp.RunFrame ()) {
+			while (Atomic.RunFrame ()) {
 						
 						
 				
 				
 			}
 			}

+ 6 - 0
Source/AtomicSharp/AtomicSharpAPI.cpp

@@ -26,4 +26,10 @@ ClassID csb_RefCounted_GetClassID(RefCounted* refCounted)
     return refCounted->GetClassID();
     return refCounted->GetClassID();
 }
 }
 
 
+RefCounted* csb_AtomicEngine_GetSubsystem(const char* name)
+{
+    return AtomicSharp::GetContext()->GetSubsystem(name);
+}
+
+
 }
 }

+ 5 - 2
Source/ToolCore/JSBind/CSharp/CSModuleWriter.cpp

@@ -347,9 +347,12 @@ void CSModuleWriter::GenerateManagedSource()
 
 
     source += "\nusing System;\nusing System.Collections.Generic;\nusing System.Runtime.InteropServices;\n";
     source += "\nusing System;\nusing System.Collections.Generic;\nusing System.Runtime.InteropServices;\n";
 
 
-    if (moduleName != "Atomic")
+    if (moduleName == "Atomic")
+        moduleName = "AtomicEngine";
+
+    if (moduleName != "AtomicEngine")
     {
     {
-        source += "using Atomic;\n";
+        source += "using AtomicEngine;\n";
     }
     }
 
 
     source += "\n\n";
     source += "\n\n";