Browse Source

Working on C#

Josh Engebretson 10 years ago
parent
commit
42f6ea5102

+ 54 - 13
Build/AtomicSharp/AtomicEngine.cs

@@ -7,7 +7,6 @@ using AtomicPlayer;
 
 namespace AtomicEngine
 {
-
 	public static class Atomic
 	{
 		[DllImport (Constants.LIBNAME, CallingConvention = CallingConvention.Cdecl)]
@@ -18,7 +17,14 @@ namespace AtomicEngine
 
 		[DllImport (Constants.LIBNAME, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
 		private static extern IntPtr csb_AtomicEngine_GetSubsystem(string name);
-			
+
+		[DllImport (Constants.LIBNAME, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+		private static extern uint csb_Atomic_StringToStringHash(string name);
+					
+		public static uint StringToStringHash(string value)
+		{
+			return csb_Atomic_StringToStringHash (value);
+		}
 
 		static Atomic()
 		{
@@ -90,6 +96,8 @@ namespace AtomicEngine
 		static private void initSubsystems()
 		{
 			registerSubsystem (NativeCore.WrapNative<Player> (csb_AtomicEngine_GetSubsystem("Player")));	
+			registerSubsystem (NativeCore.WrapNative<Graphics> (csb_AtomicEngine_GetSubsystem("Graphics")));	
+			registerSubsystem (NativeCore.WrapNative<Renderer> (csb_AtomicEngine_GetSubsystem("Renderer")));	
 		}
 
 	}
@@ -102,15 +110,31 @@ namespace AtomicEngine
 	public partial class RefCounted
 	{		
 		public RefCounted()
+		{
+
+		}
+
+		public void AllocGCHandle()
 		{
 			// if we're not a native type, we need to not be kept alive
 			// as we need to save managed state, native types don't 
-			// save local state
-			if (!NativeCore.GetNativeType (this.GetType ())) {
+			// save managed state and can be trivially regenerated
+			// by creating a GCHandle this managed instance will
+			// be used whenever we get a native ptr back from engine
 
+			if (!handle.IsAllocated)
+			{
 				handle = GCHandle.Alloc (this);
 			}
-		
+		}
+
+
+		public void FreeGCHandle()
+		{
+			if (handle.IsAllocated)
+			{
+				handle.Free();
+			}
 		}
 
 		protected RefCounted (IntPtr native)
@@ -120,27 +144,44 @@ namespace AtomicEngine
 			
 		public IntPtr nativeInstance;
 
-		static public void _AddRef(IntPtr native)
+
+		public static void SafeAddRef(uint id)
 		{
-			csb_Atomic_RefCounted_AddRef(native);
+			csb_Atomic_RefCounted_SafeAddRef (id);
 		}
-			
-		static public void _ReleaseRef(IntPtr native)
+
+		public static void SafeReleaseRef(uint id)
 		{
-			csb_Atomic_RefCounted_ReleaseRef(native);
+			csb_Atomic_RefCounted_SafeReleaseRef (id);
 		}
 
 		[DllImport (Constants.LIBNAME, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
-		public static extern IntPtr csb_RefCounted_GetClassID (IntPtr self);
+		public static extern void csb_Atomic_RefCounted_SafeAddRef (uint id);
+
+		[DllImport (Constants.LIBNAME, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+		public static extern void csb_Atomic_RefCounted_SafeReleaseRef (uint id);
+
+		[DllImport (Constants.LIBNAME, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+		public static extern IntPtr csb_Atomic_RefCounted_GetClassID (IntPtr self);
 
 		GCHandle handle;
 
 	}
 
-	public partial class AObject
+
+	public partial class Component : Animatable
 	{
+		public void Destroy()
+		{
+			if (Node != null)
+				Node.RemoveComponent (this);
+
+			// if we're a CSComponent notify ComponentCore
+			ComponentCore.DestroyComponent (this);
+
+		}
 	}
-		
+
 	public partial class Node : Animatable
 	{
 		public T GetComponent<T> (bool recursive  = false) where T:Component

+ 14 - 0
Build/AtomicSharp/AtomicInterop.cs

@@ -30,10 +30,24 @@ namespace AtomicEngine
 			ComponentCore.CallComponentMethod (componentID, method, value);
 		}
 
+		// Events
+
+		[UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+		delegate void CSBeginSendEventDelegate (uint senderRefId, uint eventType, IntPtr eventData);
+
+		[DllImport (Constants.LIBNAME, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+		private static extern void csb_AtomicEngine_AtomicInterop_Set_CSBeginSendEvent(CSBeginSendEventDelegate method);	
+
+		static void CSBeginSendEvent(uint senderRefId, uint eventType, IntPtr eventData)
+		{
+			EventCore.BeginSendEvent (senderRefId, eventType, eventData);
+		}
+
 		public static void Initialize()
 		{
 			csb_AtomicEngine_AtomicInterop_Set_CSComponentCreate (CSComponentCreate);	
 			csb_AtomicEngine_AtomicInterop_Set_CSComponentCallMethod (CSComponentCallMethod);
+			csb_AtomicEngine_AtomicInterop_Set_CSBeginSendEvent (CSBeginSendEvent);
 		}
 
 	}

+ 1 - 0
Build/AtomicSharp/AtomicSharp.csproj

@@ -59,6 +59,7 @@
     <Compile Include="CSComponent.cs" />
     <Compile Include="AtomicInterop.cs" />
     <Compile Include="NativeCore.cs" />
+    <Compile Include="EventCore.cs" />
   </ItemGroup>
   <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
 </Project>

+ 18 - 1
Build/AtomicSharp/AtomicSharpTest/Program.cs

@@ -9,7 +9,17 @@ class Spinner : CSComponent
 
 	override public void Start()
 	{
-		
+		//var renderer = Atomic.GetSubsystem<Renderer> ();
+		//SubscribeToEvent (renderer, "BeginViewUpdate", handleEvent);
+
+		SubscribeToEvent ("BeginViewUpdate", handleEvent);
+	}
+
+	void handleEvent(VariantMap eventData)
+	{
+		View view = eventData.Get<View> ("view");
+		view.Camera.Zoom = zoom;
+		zoom += .01f;
 	}
 
 	override public void Update(float timeStep)
@@ -17,6 +27,8 @@ class Spinner : CSComponent
 		Node.Yaw (timeStep * 75 * Speed, TransformSpace.TS_LOCAL);
 	}
 
+	float zoom = 1.0f;
+
 }
 	
 class MyGame
@@ -27,6 +39,9 @@ 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);		
 
@@ -40,6 +55,8 @@ class MyGame
 		var c = chestNode.AddComponent <Spinner> ();
 		c.Speed = 10.0f;
 
+		c.Destroy ();
+
 		zone.SetAmbientColor( new Color(1, 0, 0) );
 
 		Atomic.Run ();

+ 6 - 12
Build/AtomicSharp/CSComponent.cs

@@ -4,6 +4,8 @@ using System.Runtime.InteropServices;
 
 namespace AtomicEngine
 {
+	public delegate void AtomicEventDelegate (VariantMap eventData);
+	
 	public class CSComponent : Component
 	{
 		public uint ManagedID;
@@ -29,18 +31,14 @@ namespace AtomicEngine
 
 		}
 
-		// function would be a C# method, and all classes other than component and uiwidget are sealed
-		// so basically, not having inheritance means no local state for native classes
-		// allowing inheritance, neans need to GCHandle the object as can have local state
-		// and can't regenerate it, comes down to components and UI?
-		public void SubscribeToEvent(AObject sender, string eventType, object function)
+		public void SubscribeToEvent(AObject sender, string eventType, AtomicEventDelegate function)
 		{
-
+			EventCore.SubscribeToEvent (this, sender, eventType, function);
 		}
 
-		public void SubscribeToEvent(string eventType, object function)
+		public void SubscribeToEvent(string eventType, AtomicEventDelegate function)
 		{
-
+			EventCore.SubscribeToEvent (this, null, eventType, function);
 		}
 
 		void handleEvent(string eventType, Dictionary<uint, object> eventData)
@@ -51,10 +49,6 @@ namespace AtomicEngine
 		[DllImport (Constants.LIBNAME, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
 		private static extern IntPtr csb_Atomic_CSComponent_Constructor();
 
-		[DllImport (Constants.LIBNAME, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
-		private static extern void csb_Atomic_CSComponent_SetManagedID(IntPtr self, uint managedID);
-
-
 	}
 }
 

+ 12 - 2
Build/AtomicSharp/ComponentCore.cs

@@ -19,6 +19,7 @@ namespace AtomicEngine
 	{
 		static Dictionary<String, Type> componentTypes = new Dictionary<String, Type>();
 
+		// holds a reference
 		static Dictionary<uint, CSComponent> liveComponents = new Dictionary<uint, CSComponent>();
 
 		public static IntPtr CurrentCSComponentNativeInstance = default(IntPtr);
@@ -46,10 +47,20 @@ namespace AtomicEngine
 
 		public static void RegisterCSComponent(CSComponent component)
 		{
-			// register
+			// register (holds a reference)
 			liveComponents [component.RefID] = component;
 		}
 
+		public static void DestroyComponent(Component component)
+		{
+			var c = component as CSComponent;
+
+			if (c != null) {
+
+				liveComponents.Remove (c.RefID);
+			}
+		}
+			
 		// native create CSComponent
 		public static IntPtr CreateCSComponent(string name) 
 		{
@@ -59,7 +70,6 @@ namespace AtomicEngine
 
 				// create an instance of the component type
 				var component = (CSComponent) Activator.CreateInstance(type);
-				RegisterCSComponent (component);
 
 				return component.nativeInstance;
 

+ 151 - 0
Build/AtomicSharp/EventCore.cs

@@ -0,0 +1,151 @@
+using System;
+using System.Collections.Generic;
+using System.Runtime.InteropServices;
+
+namespace AtomicEngine
+{
+
+	public class VariantMap
+	{		
+		public VariantMap(IntPtr native)
+		{
+			this.native = native;
+		}
+
+		public void Invalidate()
+		{
+			native = IntPtr.Zero;
+		}
+
+		void checkValid()
+		{
+			if (native == IntPtr.Zero)
+				throw new System.AccessViolationException("Event data only valid during event");
+
+		}
+
+		public T Get<T>(string key) where T:RefCounted
+		{
+			checkValid ();
+
+			// TODO: safe case
+
+			IntPtr r = csb_Atomic_VariantMap_GetInstance (native, key);
+							
+			return r == IntPtr.Zero ? null :  NativeCore.WrapNative<T> (r);
+		}
+
+		public int GetInt(string key)
+		{
+			checkValid ();
+
+			return 0;
+		}
+
+		~VariantMap()
+		{
+
+		}
+
+		IntPtr native = default(IntPtr);
+
+		[DllImport (Constants.LIBNAME, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+		private static extern IntPtr csb_Atomic_VariantMap_GetInstance(IntPtr native, string key);
+
+
+	}
+
+	public static class EventCore
+	{
+		class Subscription
+		{
+			public uint SenderRefID;
+			public AtomicEventDelegate Handler;			
+		}
+
+		// event type -> subscribers
+		static Dictionary<uint, List<uint> > eventSubscribers = new Dictionary<uint, List<uint>>();
+
+		static Dictionary<uint, Dictionary<uint, Subscription> > subscriptions = new Dictionary<uint, Dictionary<uint, Subscription> >();
+		
+		public static void SubscribeToEvent(AObject subscriber, AObject sender, string eventType, AtomicEventDelegate function)
+		{
+			var eventTypeID = Atomic.StringToStringHash (eventType);			
+
+			Dictionary<uint, Subscription> subs;
+
+			if (!subscriptions.TryGetValue (subscriber.RefID, out subs)) {
+
+				subs = new Dictionary<uint, Subscription> ();
+				subscriptions [subscriber.RefID] = subs;
+
+			}
+
+			Subscription sub;
+
+			if (!subs.TryGetValue (eventTypeID, out sub)) {
+
+				sub = new Subscription ();
+				subs [eventTypeID] = sub;				
+			}
+
+			sub.SenderRefID = sender == null ? 0 : sender.RefID;
+			sub.Handler = function;
+
+			List<uint> subscribers;
+
+			if (!eventSubscribers.TryGetValue (eventTypeID, out subscribers)) {
+
+				subscribers = new List<uint> ();
+				eventSubscribers [eventTypeID] = subscribers;
+			}
+
+			if (!subscribers.Contains (subscriber.RefID)) {
+
+				subscribers.Add (subscriber.RefID);
+			}
+									
+		}
+
+		public static void BeginSendEvent(uint senderRefId, uint eventType, IntPtr eventData)
+		{
+			List<uint> subscribers;
+
+			if (!eventSubscribers.TryGetValue (eventType, out subscribers)) {				
+				return;			
+			}
+
+			if (subscribers.Count == 0) {
+				return;
+			}
+
+			VariantMap vmap = new VariantMap (eventData);
+
+			foreach (var id in subscribers) {
+
+				Dictionary<uint, Subscription> subs;
+
+				if (subscriptions.TryGetValue (id, out subs)) {
+
+					Subscription sub;
+
+					if (subs.TryGetValue (eventType, out sub)) {
+
+						if (sub.SenderRefID == 0 || sub.SenderRefID == senderRefId) {
+
+							sub.Handler (vmap);
+							
+						}
+
+					}
+
+				}
+
+			}
+
+			vmap.Invalidate ();
+
+		}
+	}
+}
+

+ 37 - 17
Build/AtomicSharp/NativeCore.cs

@@ -1,4 +1,5 @@
 using System;
+using System.Runtime.InteropServices;
 using System.Collections.Generic;
 
 namespace AtomicEngine
@@ -12,15 +13,20 @@ namespace AtomicEngine
 
 	// can we detect a native class?  
 
+	// we shouldn't go off IntPtr here, as a pointer could be reused native before recycles
+
 	static class NativeCore
 	{
 		// given an existing instance classID, construct the managed instance, with downcast support (ask for Component, get StaticModel for example)
 		public static Dictionary<IntPtr, Func<IntPtr, RefCounted>> nativeClassIDToManagedConstructor = new Dictionary<IntPtr, Func<IntPtr, RefCounted>>();
 
-		public static Dictionary<IntPtr, WeakReference> nativeLookup = new Dictionary<IntPtr, WeakReference> ();
-
+		// native engine types, instances of these types can be trivially recreated managed side
 		private static Dictionary<Type, Type> nativeTypes = new Dictionary<Type, Type> ();
 
+		// RefID -> WeakReference of managed instance
+		public static Dictionary<uint, WeakReference> nativeLookup = new Dictionary<uint, WeakReference> ();
+
+
 		public static bool GetNativeType (Type type)
 		{
 			return nativeTypes.ContainsKey (type);
@@ -33,17 +39,20 @@ namespace AtomicEngine
 
 		public static IntPtr RegisterNative (IntPtr native, RefCounted r)
 		{
+			r.nativeInstance = native;
+
 			var w = new WeakReference (r);
-			NativeCore.nativeLookup [native] = w;
-			RefCounted._AddRef (native);
+			NativeCore.nativeLookup [r.RefID] = w;
+			r.AddRef();
+
 			return native;
 		}
 
 		public static void ReleaseExpiredNativeReferences()
 		{
-			List<IntPtr> released = new List<IntPtr> ();
+			List<uint> released = new List<uint> ();
 
-			foreach(KeyValuePair<IntPtr, WeakReference> entry in nativeLookup)
+			foreach(KeyValuePair<uint, WeakReference> entry in nativeLookup)
 			{
 
 				if (entry.Value.Target == null || !entry.Value.IsAlive) {										
@@ -55,9 +64,11 @@ namespace AtomicEngine
 
 			}
 
-			foreach (IntPtr native in released) {
-				RefCounted._ReleaseRef(native);
-				nativeLookup.Remove (native);
+			foreach (uint id in released) {
+
+				// use safe release
+				RefCounted.SafeReleaseRef (id);
+				nativeLookup.Remove (id);
 			}
 
 		}
@@ -68,10 +79,13 @@ namespace AtomicEngine
 			if (native == IntPtr.Zero)
 				return null;
 
+			// instance id
+			uint id = csb_Atomic_RefCounted_GetRefID (native);
+
 			WeakReference w;
 
 			// first see if we're already available
-			if (nativeLookup.TryGetValue (native, out w)) {
+			if (nativeLookup.TryGetValue (id, out w)) {
 
 				if (w.IsAlive) {
 
@@ -81,23 +95,29 @@ namespace AtomicEngine
 				} else {
 
 					// we were seen before, but have since been GC'd, remove!
-					nativeLookup.Remove (native);
+					nativeLookup.Remove (id);
 				}
 			}
 
-			IntPtr classID = RefCounted.csb_RefCounted_GetClassID (native);
+			IntPtr classID = RefCounted.csb_Atomic_RefCounted_GetClassID (native);
 
 			// and store, with downcast support for instance Component -> StaticModel
-			// we never want to hit this path for scripted natives
-			w = new WeakReference (nativeClassIDToManagedConstructor[classID](native));
-			NativeCore.nativeLookup [native] = w;
+			// we never want to hit this path for script inherited natives
+
+			RefCounted r = nativeClassIDToManagedConstructor[classID](native);
+			w = new WeakReference (r);
+			NativeCore.nativeLookup [id] = w;
 
 			// store a ref, so native side will not be released while we still have a reference in managed code
-			RefCounted._AddRef (native);
+			r.AddRef();
 
-			return (T) w.Target;
+			return (T) r;
 
 		}
+
+		[DllImport (Constants.LIBNAME, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+		private static extern uint csb_Atomic_RefCounted_GetRefID(IntPtr self);
+
 	}
 
 }

+ 3 - 2
Script/Packages/Atomic/Scene.json

@@ -18,7 +18,8 @@
 			"GetChild" : ["String", "bool"],
 			"SetScale" : ["Vector3"],
 			"SetPosition2D" : ["Vector2"],
-			"SetScale2D" : ["Vector2"]
+			"SetScale2D" : ["Vector2"],
+			"RemoveComponent" : ["Component"]
 		},
 		"ValueAnimationInfo" : {
 			"ValueAnimationInfo" : ["ValueAnimation", "WrapMode", "float"]
@@ -49,7 +50,7 @@
 		]
 	},
 	"haxe_decl" : {
-		
+
 		"Node" : [
 			"function saveXML(file:File):Bool;",
 			"function getChildrenWithName(name:String, ?recursive:Bool):Array<Node>;",

+ 1 - 0
Source/Atomic/Container/RefCounted.cpp

@@ -31,6 +31,7 @@ namespace Atomic
 
 // ATOMIC BEGIN
 unsigned RefCounted::refIDCounter_ = 1;
+HashMap<unsigned, RefCounted*> RefCounted::refLookup_;
 // ATOMIC END
 
 RefCounted::RefCounted() :

+ 2 - 1
Source/Atomic/Container/RefCounted.h

@@ -91,6 +91,7 @@ public:
     static ClassID GetClassIDStatic() { static const int typeID = 0; return (ClassID) &typeID; }
 
     inline unsigned GetRefID() const { return refID_; }
+    inline static RefCounted* GetByID(unsigned id) { if (!refLookup_.Contains(id)) return 0; return refLookup_[id]; }
 
     /// JavaScript VM, heap object which can be pushed directly on stack without any lookups
     inline void* JSGetHeapPtr() const { return jsHeapPtr_; }
@@ -109,9 +110,9 @@ private:
 
     // ATOMIC BEGIN
 
-    HashMap<unsigned, RefCounted*> refLookup_;
     unsigned refID_;
     static unsigned refIDCounter_;
+    static HashMap<unsigned, RefCounted*> refLookup_;
 
     void* jsHeapPtr_;
 

+ 9 - 0
Source/AtomicSharp/AtomicSharp.cpp

@@ -1,4 +1,5 @@
 
+#include "CSEventHelper.h"
 #include "CSComponent.h"
 #include "AtomicSharp.h"
 
@@ -20,10 +21,18 @@ AtomicSharp::AtomicSharp(Context* context) :
     assert(!instance_);
     instance_ = this;
     csContext_ = context;
+
+    SharedPtr<CSEventDispatcher> dispatcher(new CSEventDispatcher(context_));
+    context_->RegisterSubsystem(dispatcher);
+    context_->AddGlobalEventListener(dispatcher);
+
 }
 
 AtomicSharp::~AtomicSharp()
 {
+    context_->RemoveGlobalEventListener(context_->GetSubsystem<CSEventDispatcher>());
+    context_->RemoveSubsystem(CSEventDispatcher::GetTypeStatic());
+
     instance_ = NULL;
 }
 

+ 45 - 1
Source/AtomicSharp/AtomicSharpAPI.cpp

@@ -53,6 +53,21 @@ void CSComponentCallMethod(unsigned id, CSComponentMethod methodID, float value)
     _CSComponentCallMethod(id, methodID, value);
 }
 
+// Event Handling
+
+typedef void (*CSBeginSendEventPtr)(unsigned senderRefID, unsigned eventType, VariantMap* eventData);
+CSBeginSendEventPtr _CSBeginSendEvent = 0;
+ATOMIC_EXPORT_API void csb_AtomicEngine_AtomicInterop_Set_CSBeginSendEvent(CSBeginSendEventPtr method)
+{
+    _CSBeginSendEvent = method;
+}
+
+void CSBeginSendEvent(unsigned senderRefID, unsigned eventType, VariantMap* eventData)
+{
+    assert(_CSBeginSendEvent);
+    _CSBeginSendEvent(senderRefID, eventType, eventData);
+}
+
 // Instance methods
 
 ATOMIC_EXPORT_API RefCounted* csb_Atomic_CSComponent_Constructor()
@@ -60,7 +75,7 @@ ATOMIC_EXPORT_API RefCounted* csb_Atomic_CSComponent_Constructor()
    return new CSComponent(AtomicSharp::GetContext());
 }
 
-ATOMIC_EXPORT_API ClassID csb_RefCounted_GetClassID(RefCounted* refCounted)
+ATOMIC_EXPORT_API ClassID csb_Atomic_RefCounted_GetClassID(RefCounted* refCounted)
 {
     if (!refCounted)
         return 0;
@@ -73,5 +88,34 @@ ATOMIC_EXPORT_API RefCounted* csb_AtomicEngine_GetSubsystem(const char* name)
     return AtomicSharp::GetContext()->GetSubsystem(name);
 }
 
+ATOMIC_EXPORT_API void csb_Atomic_RefCounted_SafeAddRef(unsigned id)
+{
+    RefCounted* ref = RefCounted::GetByID(id);
+    if (ref)
+        ref->AddRef();
+
+}
+
+ATOMIC_EXPORT_API void csb_Atomic_RefCounted_SafeReleaseRef(unsigned id)
+{
+    RefCounted* ref = RefCounted::GetByID(id);
+    if (ref)
+        ref->ReleaseRef();
+
+}
+
+ATOMIC_EXPORT_API unsigned csb_Atomic_StringToStringHash(const char* stringValue)
+{
+    StringHash hash = stringValue;
+    return hash.Value();
+}
+
+// Variant Map
+
+ATOMIC_EXPORT_API RefCounted* csb_Atomic_VariantMap_GetInstance(VariantMap& vmap, const char* key)
+{
+    return vmap[key].GetPtr();
+}
+
 
 }

+ 4 - 0
Source/AtomicSharp/AtomicSharpAPI.h

@@ -25,6 +25,10 @@ CSComponent* CSComponentCreate(String name);
 
 void CSComponentCallMethod(unsigned id, CSComponentMethod methodID, float value = 0.0f);
 
+void CSBeginSendEvent(unsigned senderRefID, unsigned eventType, VariantMap* eventData);
+
+void CSEndSendEvent(unsigned senderRefID, unsigned eventType, VariantMap* eventData);
+
 }
 
 }

+ 2 - 1
Source/AtomicSharp/AtomicSharpApp.cpp

@@ -164,8 +164,9 @@ namespace AtomicPlayer
         // as if not, will hold on engine subsystems, which is bad
         assert(!JSVM::GetJSVM(0));
 
-        Application::Stop();
+        context_->RemoveSubsystem<AtomicSharp>();
 
+        Application::Stop();
 
     }
 

+ 6 - 3
Source/AtomicSharp/CSEventHelper.cpp

@@ -20,7 +20,10 @@
 // THE SOFTWARE.
 //
 
+#include <Atomic/IO/Log.h>
 #include <Atomic/UI/UIEvents.h>
+
+#include "AtomicSharpAPI.h"
 #include "CSEventHelper.h"
 
 namespace Atomic
@@ -39,19 +42,18 @@ CSEventDispatcher::~CSEventDispatcher()
 
 void CSEventDispatcher::BeginSendEvent(Context* context, Object* sender, StringHash eventType, VariantMap& eventData)
 {
+    CSBeginSendEvent(sender->GetRefID(), eventType.ToHash(), &eventData);
 }
 
 void CSEventDispatcher::EndSendEvent(Context* context, Object* sender, StringHash eventType, VariantMap& eventData)
 {
-    if (!csEvents_.Contains(eventType))
-        return;
 
 }
 
+/*
 CSEventHelper::CSEventHelper(Context* context, Object* object) :
     Object(context),
     object_(object)
-
 {
 
 }
@@ -82,6 +84,7 @@ void CSEventHelper::HandleEvent(StringHash eventType, VariantMap& eventData)
     if (object_.Null())
         return;
 }
+*/
 
 
 }

+ 2 - 4
Source/AtomicSharp/CSEventHelper.h

@@ -38,17 +38,14 @@ public:
     /// Destruct.
     virtual ~CSEventDispatcher();
 
-    void RegisterCSEvent(StringHash hash) { csEvents_[hash] = true; }
-
 private:
 
     void BeginSendEvent(Context* context, Object* sender, StringHash eventType, VariantMap& eventData);
     void EndSendEvent(Context* context, Object* sender, StringHash eventType, VariantMap& eventData);
 
-    HashMap<StringHash, bool> csEvents_;
-
 };
 
+/*
 class ATOMIC_API CSEventHelper : public Object
 {
     OBJECT(CSEventHelper);
@@ -69,6 +66,7 @@ private:
     WeakPtr<Object> object_;
 
 };
+*/
 
 
 }