Josh Engebretson 10 жил өмнө
parent
commit
23fc5d79ae

+ 13 - 3
Build/AtomicSharp/AtomicEngine.cs

@@ -67,10 +67,21 @@ namespace AtomicEngine
 		{
 			ContainerModule.Initialize ();
 			CoreModule.Initialize ();
+			MathModule.Initialize ();
+			EngineModule.Initialize ();
+			InputModule.Initialize ();
 			IOModule.Initialize ();
 			ResourceModule.Initialize ();
+			AudioModule.Initialize ();
 			GraphicsModule.Initialize ();
-			SceneModule.Initialize ();		
+			SceneModule.Initialize ();	
+			Atomic2DModule.Initialize ();
+			Atomic3DModule.Initialize ();
+			NavigationModule.Initialize ();
+			NetworkModule.Initialize ();
+			PhysicsModule.Initialize ();
+			EnvironmentModule.Initialize ();
+			UIModule.Initialize ();
 
 			AtomicPlayer.PlayerModule.Initialize ();
 
@@ -98,6 +109,7 @@ namespace AtomicEngine
 			registerSubsystem (NativeCore.WrapNative<Player> (csb_AtomicEngine_GetSubsystem("Player")));	
 			registerSubsystem (NativeCore.WrapNative<Graphics> (csb_AtomicEngine_GetSubsystem("Graphics")));	
 			registerSubsystem (NativeCore.WrapNative<Renderer> (csb_AtomicEngine_GetSubsystem("Renderer")));	
+			registerSubsystem (NativeCore.WrapNative<ResourceCache> (csb_AtomicEngine_GetSubsystem("ResourceCache")));	
 		}
 
 	}
@@ -105,8 +117,6 @@ namespace AtomicEngine
 	public static partial class Constants
 	{
 		public const string LIBNAME = "/Users/josh/Dev/atomic/AtomicGameEngineSharp-build/Source/AtomicSharp/AtomicSharp";
-
-		public const uint M_MAX_UNSIGNED = 0xffffffff;
 	}
 		
 	public partial class RefCounted

+ 27 - 0
Build/AtomicSharp/AtomicSharp.csproj

@@ -68,6 +68,33 @@
     <Compile Include="..\Source\Generated\MACOSX\CSharp\Packages\Atomic\Managed\CSModuleAtomic2D.cs">
       <Link>CSModuleAtomic2D.cs</Link>
     </Compile>
+    <Compile Include="..\Source\Generated\MACOSX\CSharp\Packages\Atomic\Managed\CSModuleAtomic3D.cs">
+      <Link>CSModuleAtomic3D.cs</Link>
+    </Compile>
+    <Compile Include="..\Source\Generated\MACOSX\CSharp\Packages\Atomic\Managed\CSModuleAudio.cs">
+      <Link>CSModuleAudio.cs</Link>
+    </Compile>
+    <Compile Include="..\Source\Generated\MACOSX\CSharp\Packages\Atomic\Managed\CSModuleEngine.cs">
+      <Link>CSModuleEngine.cs</Link>
+    </Compile>
+    <Compile Include="..\Source\Generated\MACOSX\CSharp\Packages\Atomic\Managed\CSModuleEnvironment.cs">
+      <Link>CSModuleEnvironment.cs</Link>
+    </Compile>
+    <Compile Include="..\Source\Generated\MACOSX\CSharp\Packages\Atomic\Managed\CSModuleMath.cs">
+      <Link>CSModuleMath.cs</Link>
+    </Compile>
+    <Compile Include="..\Source\Generated\MACOSX\CSharp\Packages\Atomic\Managed\CSModuleNavigation.cs">
+      <Link>CSModuleNavigation.cs</Link>
+    </Compile>
+    <Compile Include="..\Source\Generated\MACOSX\CSharp\Packages\Atomic\Managed\CSModuleNetwork.cs">
+      <Link>CSModuleNetwork.cs</Link>
+    </Compile>
+    <Compile Include="..\Source\Generated\MACOSX\CSharp\Packages\Atomic\Managed\CSModulePhysics.cs">
+      <Link>CSModulePhysics.cs</Link>
+    </Compile>
+    <Compile Include="..\Source\Generated\MACOSX\CSharp\Packages\Atomic\Managed\CSModuleUI.cs">
+      <Link>CSModuleUI.cs</Link>
+    </Compile>
   </ItemGroup>
   <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
 </Project>

+ 168 - 23
Build/AtomicSharp/AtomicSharpTest/Program.cs

@@ -1,13 +1,177 @@
 
 using System;
+using System.Collections.Generic;
 using AtomicEngine;
 using AtomicPlayer;
 
-class MyObject : ScriptObject
+class BunnyMark : ScriptObject
 {
-	
+	class Bunny
+	{
+		public Node node;
+		public Vector2 position = new Vector2 ();
+		public Vector2 speed = new Vector2 ();
+	}
+
+	public BunnyMark ()
+	{
+		var player = Atomic.GetSubsystem<Player> ();
+
+		player.LoadScene ("Scenes/Scene.scene");	
+		scene = player.CurrentScene;
+
+		SubscribeToEvent ("Update", handleUpdate);
+		SubscribeToEvent ("MouseButtonDown", handleMouseButtonDown);
+		SubscribeToEvent ("MouseButtonUp", handleMouseButtonUp);
+
+		var graphics = Atomic.GetSubsystem<Graphics> ();
+		var cache = Atomic.GetSubsystem<ResourceCache> ();
+
+		halfWidth = graphics.Width * pixelSize * 0.5f;
+		halfHeight = graphics.Height * pixelSize * 0.5f;
+
+		maxX = halfWidth;
+		minX = -halfWidth;
+		maxY = halfHeight;
+		minY = -halfHeight;
+
+		// TODO: generic version of this
+		var sheet = (SpriteSheet2D)cache.GetResource ("SpriteSheet2D", "Sprites/bunnys_sheet.xml");
+
+		var bunny1 = sheet.GetSprite ("bunny1");
+		var bunny2 = sheet.GetSprite ("bunny2");
+		var bunny3 = sheet.GetSprite ("bunny3");
+		var bunny4 = sheet.GetSprite ("bunny4");
+		var bunny5 = sheet.GetSprite ("bunny5");
+
+		bunnyTextures = new Sprite2D[] { bunny1, bunny2, bunny3, bunny4, bunny5 };
+		bunnyType = 2;
+		currentTexture = bunnyTextures [bunnyType];
+
+	}
+
+	void handleMouseButtonDown (VariantMap eventData)
+	{
+		isAdding = true;
+	}
+
+	void handleMouseButtonUp (VariantMap eventData)
+	{
+		isAdding = false;
+		bunnyType++;
+		bunnyType %= 5;
+		currentTexture = bunnyTextures [bunnyType];
+
+	}
+
+	void handleUpdate (VariantMap eventData)
+	{
+
+		if (isAdding) {
+
+			var scale = new Vector2 ();
+			var initPos = new Vector2 (minX, maxY);
+
+
+			for (var i = 0; i < amount; i++) {
+
+				var bunny = new Bunny ();
+				bunnies.Add (bunny);
+
+				var node = scene.CreateChild ();
+				bunny.node = node;
+
+				var sprite = (StaticSprite2D)node.CreateComponent ("StaticSprite2D");
+				sprite.BlendMode = BlendMode.BLEND_ALPHA;
+				sprite.Sprite = currentTexture;
+
+				node.Position2D = bunny.position = initPos;
+				bunny.speed.x = (float)(random.NextDouble () * 10);
+				bunny.speed.y = (float)(random.NextDouble () * 10) - 5;
+
+
+				scale.x = scale.y = (0.5f + ((float)random.NextDouble ()) * 0.5f);
+				node.Scale2D = scale;
+
+				node.Rotation2D = (((float)random.NextDouble ()) - 0.5f);
+			}
+		}
+
+		foreach (var bunny in bunnies) {
+
+			var px = bunny.position.x;
+			var py = bunny.position.y;
+
+			var speedX = bunny.speed.x;
+			var speedY = bunny.speed.y;
+
+			px += speedX * .002f;
+			py += speedY * .002f;
+
+			if (px > maxX) {
+				speedX *= -1;
+				px = maxX;
+			} else if (px < minX) {
+				speedX *= -1;
+				px = minX;
+			}
+
+			if (py > maxY) {
+				speedY = 0;
+				py = maxY;
+
+			} else if (py < minY) {
+
+				speedY *= -0.95f;
+
+				if (((float)random.NextDouble ()) > 0.5f) {
+					speedY -= ((float)random.NextDouble ()) * 6f;
+				}
+
+				py = minY;
+			}
+
+			bunny.speed.x = speedX;
+			bunny.speed.y = speedY + gravity;
+
+			bunny.position.x = px;
+			bunny.position.y = py;
+			bunny.node.Position2D = bunny.position;
+			;
+
+		}
+				
+	}
+
+	Random random = new Random ();
+
+	List<Bunny> bunnies = new List<Bunny> ();
+
+	int amount = 3;
+	float gravity = -0.5f;
+	Scene scene;
+
+	Sprite2D[] bunnyTextures;
+
+	bool isAdding = false;
+
+	int bunnyType = 2;
+	Sprite2D currentTexture;
+
+
+	float pixelSize = 0.01f;
+
+	float halfWidth;
+	float halfHeight;
+
+	float maxX;
+	float minX;
+	float maxY;
+	float minY;
+
 }
 
+/*
 class Spinner : CSComponent
 {
 	public float Speed = 1.0f;
@@ -55,6 +219,7 @@ class Spinner : CSComponent
 	MyObject myObject;
 
 }
+*/
 	
 class MyGame
 {
@@ -63,27 +228,7 @@ class MyGame
 
 		Atomic.RegisterAssemblyComponents (typeof(MyGame).Assembly);
 
-		var player = Atomic.GetSubsystem<Player> ();
-		var graphics = Atomic.GetSubsystem<Graphics> ();
-
-		Console.WriteLine ("{0}, {1}", graphics.Width, graphics.Height);
-
-		player.LoadScene ("Scenes/Scene.scene", null);		
-
-		var scene = player.CurrentScene;
-
-		var zone = scene.GetComponent <Zone> (true);
-
-		var name = zone.Node.Name;
-
-		/*
-		var chestNode = scene.GetChild ("Chest", true);
-		var c = chestNode.AddComponent <Spinner> ();
-		c.Speed = 10.0f;
-		c.Destroy ();
-		*/
-
-		zone.SetAmbientColor( new Color(1, 0, 0) );
+		var bunnyMark = new BunnyMark ();
 
 		Atomic.Run ();
 

+ 29 - 0
Build/AtomicSharp/Math.cs

@@ -50,11 +50,40 @@ namespace AtomicEngine
 	[StructLayout (LayoutKind.Sequential, CharSet = CharSet.Ansi)]
 	public struct Vector2
 	{
+		public Vector2 (float x, float y)
+		{
+			this.x = x;
+			this.y = y;
+		}
+			
+		public float x;
+		public float y;
+
 	}
 
 	[StructLayout (LayoutKind.Sequential, CharSet = CharSet.Ansi)]
 	public struct Quaternion
 	{
+		public Quaternion (float w = 1.0f, float x = 0.0f, float y = 0.0f, float z = 0.0f)
+		{
+			this.w = w;
+			this.x = x;
+			this.y = y;
+			this.z = z;
+		}
+
+		public override string ToString()
+		{
+			return x + ", " + y + ", " + z;
+		}
+
+		public float w;
+		public float x;
+		public float y;
+		public float z;
+			
+		static public readonly Quaternion Identity = new Quaternion();
+
 	}
 
 	[StructLayout (LayoutKind.Sequential, CharSet = CharSet.Ansi)]

+ 1 - 1
Source/AtomicSharp/AtomicSharpApp.cpp

@@ -88,7 +88,7 @@ namespace AtomicPlayer
         engineParameters_["FullScreen"] = false;
         engineParameters_["WindowWidth"] = 1280 * .55f;
         engineParameters_["WindowHeight"] = 720 * .55f;
-        engineParameters_["ResourcePaths"] = "/Users/josh/Dev/atomic/AtomicGameEngineSharp/Resources/CoreData;/Users/josh/Dev/atomic/AtomicGameEngineSharp/Resources/PlayerData;/Users/josh/Dev/atomic/AtomicExamples/Basic3D/Resources;/Users/josh/Dev/atomic/AtomicExamples/Basic3D/";
+        engineParameters_["ResourcePaths"] = "/Users/josh/Dev/atomic/AtomicGameEngineSharp/Resources/CoreData;/Users/josh/Dev/atomic/AtomicGameEngineSharp/Resources/PlayerData;/Users/josh/Dev/atomic/AtomicExamples/BunnyMark/Resources;/Users/josh/Dev/atomic/AtomicExamples/BunnyMark/";
 #endif
 
 #if ATOMIC_PLATFORM_WINDOWS

+ 14 - 2
Source/ToolCore/JSBind/CSharp/CSFunctionWriter.cpp

@@ -390,6 +390,10 @@ void CSFunctionWriter::WriteManagedPInvokeFunctionSignature(String& source)
 
             if (name == "object")
                 name = "_object";
+            else if (name == "readonly")
+                name = "readOnly";
+            else if (name == "params")
+                name = "parameters";
 
             // ignore "Context" parameters
             if (ptype->type_->asClassType())
@@ -566,6 +570,10 @@ void CSFunctionWriter::GenPInvokeCallParameters(String& sig)
 
             if (name == "object")
                 name = "_object";
+            else if (name == "readonly")
+                name = "readOnly";
+            else if (name == "params")
+                name = "parameters";
 
             if (ptype->type_->asClassType())
             {
@@ -838,9 +846,13 @@ String CSFunctionWriter::MapDefaultParameter(JSBFunctionType* parameter)
         return "default(IntVector2)";
     }
 
-
     if (init == "Quaternion::IDENTITY")
-        return "Quaternion.Identity";
+    {
+        dparm.type = "Quaternion";
+        dparm.assignment = "Quaternion.Identity";
+        defaultStructParameters_.Push(dparm);
+        return "default(Quaternion)";
+    }
 
 
     LOGINFOF("HEY! %s", init.CString());

+ 8 - 0
Source/ToolCore/JSBind/CSharp/CSTypeHelper.cpp

@@ -73,6 +73,14 @@ String CSTypeHelper::GetManagedTypeString(JSBFunctionType* ftype, bool addName)
             {
                 parameter += " _object";
             }
+            else if (ftype->name_ == "readonly")
+            {
+                parameter += " readOnly";
+            }
+            else if (ftype->name_ == "params")
+            {
+                parameter += " parameters";
+            }
             else
             {
                 parameter += " " + ftype->name_;