]> git.jsancho.org Git - guile-irrlicht.git/commitdiff
reference counted refactor
authorJavier Sancho <jsf@jsancho.org>
Thu, 16 Apr 2020 11:26:39 +0000 (13:26 +0200)
committerJavier Sancho <jsf@jsancho.org>
Thu, 16 Apr 2020 11:26:39 +0000 (13:26 +0200)
src/reference-counted.cpp
src/reference-counted.h

index 1060df4b56c9d657216ace980e44190719c7df89..b13cbb02f799c656c7c65a652147209d90a4837e 100644 (file)
 
 extern "C" {
 
+  DEFINE_WRAPPED_TYPE (irr::IReferenceCounted*, "reference-counted",
+                       init_reference_counted_type, reference_counted_p,
+                       wrap_reference_counted, unwrap_reference_counted);
+
   void
   init_reference_counted (void)
   {
+    init_reference_counted_type ();
     DEFINE_GSUBR ("drop!", 1, 0, 0, irr_drop);
   }
 
+  bool
+  is_reference_counted_object (SCM wrapped_obj)
+  {
+    return
+      device_p (wrapped_obj) ||
+      reference_counted_p (wrapped_obj) ||
+      scene_node_animator_p (wrapped_obj);
+  }
+
   SCM
   irr_drop (SCM wrapped_obj)
   {
-    bool result = 0;
-    if (device_p (wrapped_obj))
-      {
-        result = unwrap_device (wrapped_obj)->drop ();
-      }
-    else if (scene_node_animator_p (wrapped_obj))
+    if (is_reference_counted_object (wrapped_obj))
       {
-        result = unwrap_scene_node_animator (wrapped_obj)->drop ();
+        irr::IReferenceCounted* obj = unwrap_reference_counted (wrapped_obj, false);
+        return scm_from_bool (obj->drop ());
       }
     else
       {
         scm_error (scm_arg_type_key, NULL, "Object cannot be dropped: ~S",
                    scm_list_1 (wrapped_obj), scm_list_1 (wrapped_obj));
       }
-    return scm_from_bool (result);
   }
 
 }
index f2a261315983051dc1f1cf3409d3017a05126daf..a4ccfa798ef9ef3a3c7da7ba905a010f21997208 100644 (file)
 
 extern "C" {
 
+  DECLARE_WRAPPED_TYPE (irr::IReferenceCounted*, init_reference_counted_type,
+                        reference_counted_p, wrap_reference_counted, unwrap_reference_counted);
+
   void
   init_reference_counted (void);
 
+  bool
+  is_reference_counted_object (SCM wrapped_obj);
+
   SCM
   irr_drop (SCM wrapped_obj);