Browse Source

ATOMIC-124: Add efficient RTTI to RefCounted, support pushing RefCounted from Variants

Josh Engebretson 10 years ago
parent
commit
1f87503a00

+ 2 - 0
Source/Atomic/Atomic2D/Animation2D.h

@@ -101,6 +101,8 @@ struct AnimationTrack2D
 /// 2D Animation.
 /// 2D Animation.
 class ATOMIC_API Animation2D : public RefCounted
 class ATOMIC_API Animation2D : public RefCounted
 {
 {
+    REFCOUNTED(Animation2D)
+
 public:
 public:
     /// Construct.
     /// Construct.
     Animation2D(AnimationSet2D* animationSet);
     Animation2D(AnimationSet2D* animationSet);

+ 7 - 0
Source/Atomic/Atomic2D/TileMapDefs2D.h

@@ -103,6 +103,9 @@ enum TileMapObjectType2D
 /// Property set.
 /// Property set.
 class ATOMIC_API PropertySet2D : public RefCounted
 class ATOMIC_API PropertySet2D : public RefCounted
 {
 {
+
+    REFCOUNTED(PropertySet2D)
+
 public:
 public:
     PropertySet2D();
     PropertySet2D();
     virtual ~PropertySet2D();
     virtual ~PropertySet2D();
@@ -122,6 +125,8 @@ protected:
 /// Tile define.
 /// Tile define.
 class ATOMIC_API Tile2D : public RefCounted
 class ATOMIC_API Tile2D : public RefCounted
 {
 {
+    REFCOUNTED(Tile2D)
+
 public:
 public:
     /// Construct.
     /// Construct.
     Tile2D();
     Tile2D();
@@ -157,6 +162,8 @@ private:
 /// Tile map object.
 /// Tile map object.
 class ATOMIC_API TileMapObject2D : public RefCounted
 class ATOMIC_API TileMapObject2D : public RefCounted
 {
 {
+    REFCOUNTED(TileMapObject2D)
+
 public:
 public:
     TileMapObject2D();
     TileMapObject2D();
 
 

+ 8 - 0
Source/Atomic/Atomic2D/TmxFile2D.h

@@ -37,6 +37,8 @@ class XMLFile;
 /// Tmx layer.
 /// Tmx layer.
 class TmxLayer2D : public RefCounted
 class TmxLayer2D : public RefCounted
 {
 {
+    REFCOUNTED(TmxLayer2D)
+
 public:
 public:
     TmxLayer2D(TmxFile2D* tmxFile, TileMapLayerType2D type);
     TmxLayer2D(TmxFile2D* tmxFile, TileMapLayerType2D type);
     virtual ~TmxLayer2D();
     virtual ~TmxLayer2D();
@@ -90,6 +92,8 @@ protected:
 /// Tmx tile layer.
 /// Tmx tile layer.
 class TmxTileLayer2D : public TmxLayer2D
 class TmxTileLayer2D : public TmxLayer2D
 {
 {
+    REFCOUNTED(TmxTileLayer2D)
+
 public:
 public:
     TmxTileLayer2D(TmxFile2D* tmxFile);
     TmxTileLayer2D(TmxFile2D* tmxFile);
 
 
@@ -106,6 +110,8 @@ protected:
 /// Tmx image layer.
 /// Tmx image layer.
 class TmxObjectGroup2D : public TmxLayer2D
 class TmxObjectGroup2D : public TmxLayer2D
 {
 {
+    REFCOUNTED(TmxObjectGroup2D)
+
 public:
 public:
     TmxObjectGroup2D(TmxFile2D* tmxFile);
     TmxObjectGroup2D(TmxFile2D* tmxFile);
 
 
@@ -126,6 +132,8 @@ private:
 /// Tmx image layer.
 /// Tmx image layer.
 class TmxImageLayer2D : public TmxLayer2D
 class TmxImageLayer2D : public TmxLayer2D
 {
 {
+    REFCOUNTED(TmxImageLayer2D)
+
 public:
 public:
     TmxImageLayer2D(TmxFile2D* tmxFile);
     TmxImageLayer2D(TmxFile2D* tmxFile);
 
 

+ 2 - 0
Source/Atomic/Atomic3D/AnimationState.h

@@ -59,6 +59,8 @@ struct AnimationStateTrack
 /// %Animation instance.
 /// %Animation instance.
 class ATOMIC_API AnimationState : public RefCounted
 class ATOMIC_API AnimationState : public RefCounted
 {
 {
+    REFCOUNTED(AnimationState)
+
 public:
 public:
     /// Construct with animated model and animation pointers.
     /// Construct with animated model and animation pointers.
     AnimationState(AnimatedModel* model, Animation* animation);
     AnimationState(AnimatedModel* model, Animation* animation);

+ 2 - 0
Source/Atomic/Audio/SoundStream.h

@@ -30,6 +30,8 @@ namespace Atomic
 /// Base class for sound streams.
 /// Base class for sound streams.
 class ATOMIC_API SoundStream : public RefCounted
 class ATOMIC_API SoundStream : public RefCounted
 {
 {
+    REFCOUNTED(SoundStream)
+
 public:
 public:
     /// Construct.
     /// Construct.
     SoundStream();
     SoundStream();

+ 17 - 0
Source/Atomic/Container/RefCounted.h

@@ -25,6 +25,18 @@
 namespace Atomic
 namespace Atomic
 {
 {
 
 
+// ATOMIC BEGIN
+
+typedef const void* ClassID;
+
+/// Macro to be included in RefCounted derived classes for efficient RTTI
+#define REFCOUNTED(typeName) \
+    public: \
+        virtual ClassID GetClassID() const { return GetClassIDStatic(); } \
+        static ClassID GetClassIDStatic() { static const int typeID = 0; return (ClassID) &typeID; }
+
+// ATOMIC END
+
 /// Reference count structure.
 /// Reference count structure.
 struct RefCount
 struct RefCount
 {
 {
@@ -70,10 +82,15 @@ public:
     /// Return pointer to the reference count structure.
     /// Return pointer to the reference count structure.
     RefCount* RefCountPtr() { return refCount_; }
     RefCount* RefCountPtr() { return refCount_; }
 
 
+    // ATOMIC BEGIN
     virtual bool IsObject() const { return false; }
     virtual bool IsObject() const { return false; }
 
 
+    virtual ClassID GetClassID() const  = 0;
+    static ClassID GetClassIDStatic() { static const int typeID = 0; return (ClassID) &typeID; }
+
     inline void* JSGetHeapPtr() const { return jsHeapPtr_; }
     inline void* JSGetHeapPtr() const { return jsHeapPtr_; }
     inline void  JSSetHeapPtr(void* heapptr) { jsHeapPtr_ = heapptr; }
     inline void  JSSetHeapPtr(void* heapptr) { jsHeapPtr_ = heapptr; }
+    // ATOMIC END
 
 
 private:
 private:
     /// Prevent copy construction.
     /// Prevent copy construction.

+ 2 - 0
Source/Atomic/Core/Attribute.h

@@ -52,6 +52,8 @@ class Serializable;
 /// Abstract base class for invoking attribute accessors.
 /// Abstract base class for invoking attribute accessors.
 class ATOMIC_API AttributeAccessor : public RefCounted
 class ATOMIC_API AttributeAccessor : public RefCounted
 {
 {
+    REFCOUNTED(AttributeAccessor)
+
 public:
 public:
     /// Get the attribute.
     /// Get the attribute.
     virtual void Get(const Serializable* ptr, Variant& dest) const = 0;
     virtual void Get(const Serializable* ptr, Variant& dest) const = 0;

+ 2 - 0
Source/Atomic/Core/Context.h

@@ -46,6 +46,8 @@ class ATOMIC_API Context : public RefCounted
 {
 {
     friend class Object;
     friend class Object;
 
 
+    REFCOUNTED(Context)
+
 public:
 public:
     /// Construct.
     /// Construct.
     Context();
     Context();

+ 5 - 0
Source/Atomic/Core/Object.h

@@ -40,6 +40,8 @@ class EventHandler;
         virtual const Atomic::String& GetTypeName() const { return GetTypeNameStatic(); } \
         virtual const Atomic::String& GetTypeName() const { return GetTypeNameStatic(); } \
         static Atomic::StringHash GetTypeStatic() { static const Atomic::StringHash typeStatic(#typeName); return typeStatic; } \
         static Atomic::StringHash GetTypeStatic() { static const Atomic::StringHash typeStatic(#typeName); return typeStatic; } \
         static const Atomic::String& GetTypeNameStatic() { static const Atomic::String typeNameStatic(#typeName); return typeNameStatic; } \
         static const Atomic::String& GetTypeNameStatic() { static const Atomic::String typeNameStatic(#typeName); return typeNameStatic; } \
+        virtual ClassID GetClassID() const { return GetClassIDStatic(); } \
+        static ClassID GetClassIDStatic() { static const int typeID = 0; return (ClassID) &typeID; }
 
 
 #define BASEOBJECT(typeName) \
 #define BASEOBJECT(typeName) \
     public: \
     public: \
@@ -111,6 +113,7 @@ public:
     const String& GetCategory() const;
     const String& GetCategory() const;
 
 
     virtual bool IsObject() const { return true; }
     virtual bool IsObject() const { return true; }
+    static ClassID GetClassIDStatic() { static const int typeID = 0; return (ClassID) &typeID; }
     static const Atomic::String& GetTypeNameStatic() { static const Atomic::String typeNameStatic("Object"); return typeNameStatic; }
     static const Atomic::String& GetTypeNameStatic() { static const Atomic::String typeNameStatic("Object"); return typeNameStatic; }
     
     
 protected:
 protected:
@@ -136,6 +139,8 @@ template <class T> T* Object::GetSubsystem() const { return static_cast<T*>(GetS
 /// Base class for object factories.
 /// Base class for object factories.
 class ATOMIC_API ObjectFactory : public RefCounted
 class ATOMIC_API ObjectFactory : public RefCounted
 {
 {
+    REFCOUNTED(ObjectFactory)
+
 public:
 public:
     /// Construct.
     /// Construct.
     ObjectFactory(Context* context) :
     ObjectFactory(Context* context) :

+ 2 - 0
Source/Atomic/Core/WorkQueue.cpp

@@ -34,6 +34,8 @@ namespace Atomic
 /// Worker thread managed by the work queue.
 /// Worker thread managed by the work queue.
 class WorkerThread : public Thread, public RefCounted
 class WorkerThread : public Thread, public RefCounted
 {
 {
+    REFCOUNTED(WorkerThread)
+
 public:
 public:
     /// Construct.
     /// Construct.
     WorkerThread(WorkQueue* owner, unsigned index) :
     WorkerThread(WorkQueue* owner, unsigned index) :

+ 2 - 0
Source/Atomic/Core/WorkQueue.h

@@ -40,6 +40,8 @@ class WorkerThread;
 /// Work queue item.
 /// Work queue item.
 struct WorkItem : public RefCounted
 struct WorkItem : public RefCounted
 {
 {
+    REFCOUNTED(WorkItem)
+
     friend class WorkQueue;
     friend class WorkQueue;
 
 
 public:
 public:

+ 2 - 0
Source/Atomic/Graphics/Material.h

@@ -70,6 +70,8 @@ struct TechniqueEntry
 /// Material's shader parameter animation instance.
 /// Material's shader parameter animation instance.
 class ShaderParameterAnimationInfo : public ValueAnimationInfo
 class ShaderParameterAnimationInfo : public ValueAnimationInfo
 {
 {
+    REFCOUNTED(ShaderParameterAnimationInfo)
+
 public:
 public:
     /// Construct.
     /// Construct.
     ShaderParameterAnimationInfo
     ShaderParameterAnimationInfo

+ 2 - 0
Source/Atomic/Graphics/OpenGL/OGLRenderSurface.h

@@ -38,6 +38,8 @@ class ATOMIC_API RenderSurface : public RefCounted
     friend class Texture2D;
     friend class Texture2D;
     friend class TextureCube;
     friend class TextureCube;
 
 
+    REFCOUNTED(RenderSurface)
+
 public:
 public:
     /// Construct with parent texture.
     /// Construct with parent texture.
     RenderSurface(Texture* parentTexture);
     RenderSurface(Texture* parentTexture);

+ 2 - 0
Source/Atomic/Graphics/OpenGL/OGLShaderProgram.h

@@ -54,6 +54,8 @@ struct ShaderParameter
 /// Linked shader program on the GPU.
 /// Linked shader program on the GPU.
 class ATOMIC_API ShaderProgram : public RefCounted, public GPUObject
 class ATOMIC_API ShaderProgram : public RefCounted, public GPUObject
 {
 {
+    REFCOUNTED(ShaderProgam)
+
 public:
 public:
     /// Construct.
     /// Construct.
     ShaderProgram(Graphics* graphics, ShaderVariation* vertexShader, ShaderVariation* pixelShader);
     ShaderProgram(Graphics* graphics, ShaderVariation* vertexShader, ShaderVariation* pixelShader);

+ 2 - 0
Source/Atomic/Graphics/OpenGL/OGLShaderVariation.h

@@ -36,6 +36,8 @@ class ShaderProgram;
 /// Vertex or pixel shader on the GPU.
 /// Vertex or pixel shader on the GPU.
 class ATOMIC_API ShaderVariation : public RefCounted, public GPUObject
 class ATOMIC_API ShaderVariation : public RefCounted, public GPUObject
 {
 {
+    REFCOUNTED(ShaderVariation)
+
 public:
 public:
     /// Construct.
     /// Construct.
     ShaderVariation(Shader* owner, ShaderType type);
     ShaderVariation(Shader* owner, ShaderType type);

+ 2 - 0
Source/Atomic/Graphics/RenderPath.h

@@ -204,6 +204,8 @@ struct RenderPathCommand
 /// Rendering path definition.
 /// Rendering path definition.
 class ATOMIC_API RenderPath : public RefCounted
 class ATOMIC_API RenderPath : public RefCounted
 {
 {
+    REFCOUNTED(RenderPath)
+
 public:
 public:
     /// Construct.
     /// Construct.
     RenderPath();
     RenderPath();

+ 2 - 0
Source/Atomic/Graphics/Technique.h

@@ -41,6 +41,8 @@ enum PassLightingMode
 /// %Material rendering pass, which defines shaders and render state.
 /// %Material rendering pass, which defines shaders and render state.
 class ATOMIC_API Pass : public RefCounted
 class ATOMIC_API Pass : public RefCounted
 {
 {
+    REFCOUNTED(Pass)
+
 public:
 public:
     /// Construct.
     /// Construct.
     Pass(const String& passName);
     Pass(const String& passName);

+ 2 - 0
Source/Atomic/Network/HttpRequest.h

@@ -43,6 +43,8 @@ enum HttpRequestState
 /// An HTTP connection with response data stream.
 /// An HTTP connection with response data stream.
 class HttpRequest : public RefCounted, public Deserializer, public Thread
 class HttpRequest : public RefCounted, public Deserializer, public Thread
 {
 {
+    REFCOUNTED(HttpRequest)
+
 public:
 public:
     /// Construct with parameters.
     /// Construct with parameters.
     HttpRequest(const String& url, const String& verb, const Vector<String>& headers, const String& postData);
     HttpRequest(const String& url, const String& verb, const Vector<String>& headers, const String& postData);

+ 7 - 0
Source/Atomic/Physics/CollisionShape.h

@@ -62,11 +62,14 @@ enum ShapeType
 /// Base class for collision shape geometry data.
 /// Base class for collision shape geometry data.
 struct CollisionGeometryData : public RefCounted
 struct CollisionGeometryData : public RefCounted
 {
 {
+    REFCOUNTED(CollisionGeometryData)
 };
 };
 
 
 /// Triangle mesh geometry data.
 /// Triangle mesh geometry data.
 struct TriangleMeshData : public CollisionGeometryData
 struct TriangleMeshData : public CollisionGeometryData
 {
 {
+    REFCOUNTED(TriangleMeshData)
+
     /// Construct from a model.
     /// Construct from a model.
     TriangleMeshData(Model* model, unsigned lodLevel);
     TriangleMeshData(Model* model, unsigned lodLevel);
     /// Construct from a custom geometry.
     /// Construct from a custom geometry.
@@ -85,6 +88,8 @@ struct TriangleMeshData : public CollisionGeometryData
 /// Convex hull geometry data.
 /// Convex hull geometry data.
 struct ConvexData : public CollisionGeometryData
 struct ConvexData : public CollisionGeometryData
 {
 {
+    REFCOUNTED(ConvexData)
+
     /// Construct from a model.
     /// Construct from a model.
     ConvexData(Model* model, unsigned lodLevel);
     ConvexData(Model* model, unsigned lodLevel);
     /// Construct from a custom geometry.
     /// Construct from a custom geometry.
@@ -108,6 +113,8 @@ struct ConvexData : public CollisionGeometryData
 /// Heightfield geometry data.
 /// Heightfield geometry data.
 struct HeightfieldData : public CollisionGeometryData
 struct HeightfieldData : public CollisionGeometryData
 {
 {
+    REFCOUNTED(HeightfieldData)
+
     /// Construct from a terrain.
     /// Construct from a terrain.
     HeightfieldData(Terrain* terrain, unsigned lodLevel);
     HeightfieldData(Terrain* terrain, unsigned lodLevel);
     /// Destruct. Free geometry data.
     /// Destruct. Free geometry data.

+ 2 - 0
Source/Atomic/Resource/BackgroundLoader.h

@@ -52,6 +52,8 @@ struct BackgroundLoadItem
 /// Background loader of resources. Owned by the ResourceCache.
 /// Background loader of resources. Owned by the ResourceCache.
 class BackgroundLoader : public RefCounted, public Thread
 class BackgroundLoader : public RefCounted, public Thread
 {
 {
+    REFCOUNTED(BackgroundLoader);
+
 public:
 public:
     /// Construct.
     /// Construct.
     BackgroundLoader(ResourceCache* owner);
     BackgroundLoader(ResourceCache* owner);

+ 2 - 0
Source/Atomic/Scene/ValueAnimationInfo.h

@@ -35,6 +35,8 @@ struct VAnimEventFrame;
 /// Base class for a value animation instance, which includes animation runtime information and updates the target object's value automatically.
 /// Base class for a value animation instance, which includes animation runtime information and updates the target object's value automatically.
 class ValueAnimationInfo : public RefCounted
 class ValueAnimationInfo : public RefCounted
 {
 {
+    REFCOUNTED(ValueAnimationInfo)
+
 public:
 public:
     /// Construct without target object.
     /// Construct without target object.
     ValueAnimationInfo(ValueAnimation* animation, WrapMode wrapMode, float speed);
     ValueAnimationInfo(ValueAnimation* animation, WrapMode wrapMode, float speed);

+ 2 - 0
Source/Atomic/UI/UIPreferredSize.h

@@ -28,6 +28,8 @@ class UIPreferredSize : public RefCounted
 {
 {
     friend class UIWidget;
     friend class UIWidget;
 
 
+    REFCOUNTED(UIPreferredSize)
+
 public:
 public:
 
 
     UIPreferredSize(int w = 0, int h = 0);
     UIPreferredSize(int w = 0, int h = 0);

+ 32 - 41
Source/AtomicJS/Javascript/JSAPI.cpp

@@ -58,23 +58,27 @@ void js_class_declare_internal(JSVM* vm, void* uniqueClassID, const char* packag
 {
 {
     duk_context* ctx = vm->GetJSContext();
     duk_context* ctx = vm->GetJSContext();
 
 
-    // stash a lookup from the uniqueID to the package name
-    // (NULL) == non-object, so core "Atomic" package
+    // uniqueClassID must be non-null
+    assert(uniqueClassID);
 
 
-    if (uniqueClassID)
-    {
-        duk_push_heap_stash(ctx);
-        duk_push_pointer(ctx, uniqueClassID);
-        duk_push_string(ctx, package);
-        duk_put_prop(ctx, -3);
-        duk_pop(ctx);
-    }
-    else
-    {
-        // RefCounted only supported in Atomic package
-        assert(String("Atomic") == package );
-    }
+    // stash a lookup from the uniqueID to the package and class name
 
 
+    duk_push_heap_stash(ctx);
+    duk_push_pointer(ctx, uniqueClassID);
+
+    duk_push_object(ctx);
+    duk_push_string(ctx, package);
+    duk_put_prop_index(ctx, -2, 0);
+    duk_push_string(ctx, classname);
+    duk_put_prop_index(ctx, -2, 1);
+
+    // store class object into uniqueClassID key
+    duk_put_prop(ctx, -3);
+
+    // pop heap stash
+    duk_pop(ctx);
+
+    // store the constructor
     duk_get_global_string(ctx, package);
     duk_get_global_string(ctx, package);
     duk_push_c_function(ctx, constructor, DUK_VARARGS);
     duk_push_c_function(ctx, constructor, DUK_VARARGS);
     duk_put_prop_string(ctx, -2, classname);
     duk_put_prop_string(ctx, -2, classname);
@@ -372,15 +376,11 @@ void js_push_variant(duk_context *ctx, const Variant& v)
 {
 {
     VariantType type = v.GetType();
     VariantType type = v.GetType();
     RefCounted* ref;
     RefCounted* ref;
-    Object* object;
     Vector2 vector2 = Vector2::ZERO;
     Vector2 vector2 = Vector2::ZERO;
     Vector3 vector3 = Vector3::ZERO;
     Vector3 vector3 = Vector3::ZERO;
     Vector4 vector4 = Vector4::ZERO;
     Vector4 vector4 = Vector4::ZERO;
     Color color = Color::BLACK;
     Color color = Color::BLACK;
 
 
-    void* uniqueClassID = NULL;
-    const char* package = NULL;
-
     switch (type)
     switch (type)
     {
     {
     case VAR_NONE:
     case VAR_NONE:
@@ -394,38 +394,29 @@ void js_push_variant(duk_context *ctx, const Variant& v)
 
 
         ref = v.GetPtr();
         ref = v.GetPtr();
 
 
-        if (!ref || !ref->IsObject() || !ref->Refs())
+        // if we're null or don't have any refs, return null
+        if (!ref || !ref->Refs())
         {
         {
             duk_push_null(ctx);
             duk_push_null(ctx);
             break;
             break;
         }
         }
 
 
-        object = (Object*) ref;
-
-
         // check that class is supported
         // check that class is supported
-        uniqueClassID = (void *) object->GetTypeName().CString();
         duk_push_heap_stash(ctx);
         duk_push_heap_stash(ctx);
-        duk_push_pointer(ctx, uniqueClassID);
+        duk_push_pointer(ctx, (void*) ref->GetClassID());
         duk_get_prop(ctx, -2);
         duk_get_prop(ctx, -2);
-        package = duk_to_string(ctx, -1);
-        duk_pop_2(ctx);
 
 
-        // check that class is supported
-        duk_get_global_string(ctx, package);
-
-        // will not handle renamed classes!
-        duk_get_prop_string(ctx, -1, object->GetTypeName().CString());
-
-        if (!duk_is_function(ctx, -1))
-            object = NULL;
-
-        duk_pop_n(ctx, 2);
-
-        if (object)
-            js_push_class_object_instance(ctx, object);
-        else
+        if (!duk_is_object(ctx, -1))
+        {
+            duk_pop_2(ctx);
             duk_push_undefined(ctx);
             duk_push_undefined(ctx);
+        }
+        else
+        {
+            duk_pop_2(ctx);
+            js_push_class_object_instance(ctx, ref);
+        }
+
         break;
         break;
 
 
     case VAR_BOOL:
     case VAR_BOOL:

+ 1 - 2
Source/AtomicJS/Javascript/JSAPI.h

@@ -28,8 +28,7 @@ void js_class_declare_internal(JSVM* vm, void* uniqueClassID, const char* packag
 template<typename T>
 template<typename T>
 void js_class_declare(JSVM* vm, const char* package, const char* classname, duk_c_function constructor)
 void js_class_declare(JSVM* vm, const char* package, const char* classname, duk_c_function constructor)
 {
 {
-    void* uniqueID = (void*) T::GetTypeNameStatic().CString();
-    js_class_declare_internal(vm, uniqueID, package, classname, constructor);
+    js_class_declare_internal(vm, (void*) T::GetClassIDStatic(), package, classname, constructor);
 }
 }
 
 
 void js_constructor_basecall(duk_context* ctx, const char* package, const char* baseclass);
 void js_constructor_basecall(duk_context* ctx, const char* package, const char* baseclass);

+ 14 - 18
Source/AtomicJS/Javascript/JSVM.h

@@ -225,26 +225,22 @@ inline bool js_push_class_object_instance(duk_context* ctx, const RefCounted *in
         return true;
         return true;
     }
     }
 
 
-    // will not handle renamed classes
-    if (instance->IsObject())
-    {
-        Object *obj = (Object*) instance;
+    duk_push_heap_stash(ctx);
+    duk_push_pointer(ctx, (void*) instance->GetClassID());
+    duk_get_prop(ctx, -2);
 
 
-        void* uniqueClassID = (void *) obj->GetTypeName().CString();
-        duk_push_heap_stash(ctx);
-        duk_push_pointer(ctx, uniqueClassID);
-        duk_get_prop(ctx, -2);
-        const char* package = duk_require_string(ctx, -1);
-        duk_pop_2(ctx);
+    // if this is tripped, means the class hasn't been registered and shouldn't be trying to push it
+    assert(duk_is_object(ctx, -1));
 
 
-        duk_get_global_string(ctx, package);
-        duk_get_prop_string(ctx, -1, ((Object*)instance)->GetTypeName().CString());
-    }
-    else
-    {
-        duk_get_global_string(ctx, "Atomic");
-        duk_get_prop_string(ctx, -1, classname);
-    }
+    duk_get_prop_index(ctx, -1, 0);
+    const char* package = duk_require_string(ctx, -1);
+    duk_get_prop_index(ctx, -2, 1);
+    const char* jclassname = duk_require_string(ctx, -1);
+
+    duk_set_top(ctx, top);
+
+    duk_get_global_string(ctx, package);
+    duk_get_prop_string(ctx, -1, jclassname);
 
 
     duk_push_pointer(ctx, (void*) instance);
     duk_push_pointer(ctx, (void*) instance);
     duk_new(ctx, 1);
     duk_new(ctx, 1);

+ 1 - 5
Source/ToolCore/JSBind/JSBModuleWriter.cpp

@@ -52,11 +52,7 @@ void JSBModuleWriter::WriteClassDeclaration(String& source)
         if (klass->IsNumberArray())
         if (klass->IsNumberArray())
             continue;
             continue;
 
 
-        if (klass->IsObject())
-            source.AppendWithFormat("   js_class_declare<%s>(vm, \"%s\", \"%s\", jsb_constructor_%s);\n", klass->GetNativeName().CString(), packageName.CString(), klass->GetName().CString(), klass->GetName().CString());
-        else
-            source.AppendWithFormat("   js_class_declare_internal(vm, NULL, \"%s\", \"%s\", jsb_constructor_%s);\n", packageName.CString(), klass->GetName().CString(), klass->GetName().CString());
-
+        source.AppendWithFormat("   js_class_declare<%s>(vm, \"%s\", \"%s\", jsb_constructor_%s);\n", klass->GetNativeName().CString(), packageName.CString(), klass->GetName().CString(), klass->GetName().CString());
 
 
         if (klass->HasProperties())
         if (klass->HasProperties())
         {
         {