]> git.jsancho.org Git - guile-irrlicht.git/commitdiff
device
authorJavier Sancho <jsf@jsancho.org>
Thu, 7 May 2020 11:15:42 +0000 (13:15 +0200)
committerJavier Sancho <jsf@jsancho.org>
Thu, 7 May 2020 11:15:42 +0000 (13:15 +0200)
src/device.cpp
src/device.h

index 1b06a48c59cb551d204f4991e52fea6627fcd93a..4ff21a56aa38a32e671f751a0535a1c52e459f72 100644 (file)
 
 #include <irrlicht/irrlicht.h>
 #include <libguile.h>
-
 #include "device.h"
 #include "dimension2d.h"
 #include "driver-types.h"
-#include "event-receiver.h"
 #include "gsubr.h"
-#include "timer.h"
 #include "wchar.h"
-#include "wrapped.h"
+
 
 using namespace irr;
 
+
+template <typename TEventReceiver>
+SCM
+irr_createDevice (SCM device_type,
+                  SCM window_size,
+                  SCM bits,
+                  SCM fullscreen,
+                  SCM stencilbuffer,
+                  SCM vsync,
+                  SCM receiver)
+{
+  IrrlichtDevice* device =
+    createDevice (scm_to_driver_type (device_type),
+                  scm_to_dimension2d_u32 (window_size),
+                  scm_to_uint32 (bits),
+                  scm_to_bool (fullscreen),
+                  scm_to_bool (stencilbuffer),
+                  scm_to_bool (vsync),
+                  (TEventReceiver)scm_to_pointer (receiver));
+  return scm_from_pointer ((void*)device, NULL);
+}
+
+
+SCM
+irr_IrrlichtDevice_getCursorControl (SCM device)
+{
+  gui::ICursorControl* cursor_control =
+    ((IrrlichtDevice*)scm_to_pointer (device))->getCursorControl ();
+  return scm_from_pointer ((void*)cursor_control, NULL);
+}
+
+
+SCM
+irr_IrrlichtDevice_getGUIEnvironment (SCM device)
+{
+  gui::IGUIEnvironment* gui_env =
+    ((IrrlichtDevice*)scm_to_pointer (device))->getGUIEnvironment ();
+  return scm_from_pointer ((void*)gui_env, NULL);
+}
+
+
+SCM
+irr_IrrlichtDevice_getSceneManager (SCM device)
+{
+  scene::ISceneManager* manager =
+    ((IrrlichtDevice*)scm_to_pointer (device))->getSceneManager ();
+  return scm_from_pointer ((void*)manager, NULL);
+}
+
+
+SCM
+irr_IrrlichtDevice_getTimer (SCM device)
+{
+  ITimer* timer =
+    ((IrrlichtDevice*)scm_to_pointer (device))->getTimer ();
+  return scm_from_pointer ((void*)timer, NULL);
+}
+
+
+SCM
+irr_IrrlichtDevice_getVideoDriver (SCM device)
+{
+  video::IVideoDriver* driver =
+    ((IrrlichtDevice*)scm_to_pointer (device))->getVideoDriver ();
+  return scm_from_pointer ((void*)driver, NULL);
+}
+
+
+SCM
+irr_IrrlichtDevice_isWindowActive (SCM device)
+{
+  return scm_from_bool
+    (((IrrlichtDevice*)scm_to_pointer (device))->isWindowActive ());
+}
+
+
+SCM
+irr_IrrlichtDevice_run (SCM device)
+{
+  return scm_from_bool
+    (((IrrlichtDevice*)scm_to_pointer (device))->run ());
+}
+
+
+template <typename TEventReceiver>
+SCM
+irr_IrrlichtDevice_setEventReceiver (SCM device,
+                                     SCM receiver)
+{
+  ((IrrlichtDevice*)scm_to_pointer (device))->
+    setEventReceiver ((TEventReceiver)scm_to_pointer (receiver));
+  return SCM_UNSPECIFIED;
+}
+
+
+SCM
+irr_IrrlichtDevice_setResizable (SCM device,
+                                 SCM resize)
+{
+  ((IrrlichtDevice*)scm_to_pointer (device))->
+    setResizable (scm_to_bool (resize));
+  return SCM_UNSPECIFIED;
+}
+
+
+SCM
+irr_IrrlichtDevice_setWindowCaption (SCM device,
+                                     SCM text)
+{
+  ((IrrlichtDevice*)scm_to_pointer (device))->
+    setWindowCaption (scm_to_wide_char_string (text));
+  return SCM_UNSPECIFIED;
+}
+
+
+SCM
+irr_IrrlichtDevice_yield (SCM device)
+{
+  ((IrrlichtDevice*)scm_to_pointer (device))->yield ();
+  return SCM_UNSPECIFIED;
+}
+
+
 extern "C" {
 
   void
   init_device (void)
   {
     init_device_type ();
-    DEFINE_GSUBR ("irr_createDevice", 7, 0, 0, irr_createDevice);
+    DEFINE_GSUBR ("irr_createDevice_IEventReceiver", 7, 0, 0,
+                  irr_createDevice<IEventReceiver*>);
+    DEFINE_GSUBR ("irr_IrrlichtDevice_getCursorControl", 1, 0, 0,
+                  irr_IrrlichtDevice_getCursorControl);
     DEFINE_GSUBR ("irr_IrrlichtDevice_getGUIEnvironment", 1, 0, 0,
                   irr_IrrlichtDevice_getGUIEnvironment);
     DEFINE_GSUBR ("irr_IrrlichtDevice_getSceneManager", 1, 0, 0,
                   irr_IrrlichtDevice_getSceneManager);
+    DEFINE_GSUBR ("irr_IrrlichtDevice_getTimer", 1, 0, 0,
+                  irr_IrrlichtDevice_getTimer);
     DEFINE_GSUBR ("irr_IrrlichtDevice_getVideoDriver", 1, 0, 0,
                   irr_IrrlichtDevice_getVideoDriver);
+    DEFINE_GSUBR ("irr_IrrlichtDevice_isWindowActive", 1, 0, 0,
+                  irr_IrrlichtDevice_isWindowActive);
+    DEFINE_GSUBR ("irr_IrrlichtDevice_run", 1, 0, 0,
+                  irr_IrrlichtDevice_run);
+    DEFINE_GSUBR ("irr_IrrlichtDevice_setEventReceiver_IEventReceiver", 2, 0, 0,
+                  irr_IrrlichtDevice_setEventReceiver<IEventReceiver*>);
+    DEFINE_GSUBR ("irr_IrrlichtDevice_setResizable", 2, 0, 0,
+                  irr_IrrlichtDevice_setResizable);
     DEFINE_GSUBR ("irr_IrrlichtDevice_setWindowCaption", 2, 0, 0,
                   irr_IrrlichtDevice_setWindowCaption);
-    DEFINE_GSUBR ("get-timer", 1, 0, 0, irr_getTimer);
-    DEFINE_GSUBR ("is-window-active?", 1, 0, 0, irr_isWindowActive);
-    DEFINE_GSUBR ("run", 1, 0, 0, irr_run);
-    DEFINE_GSUBR ("set-event-receiver!", 2, 0, 0, irr_setEventReceiver);
-    DEFINE_GSUBR ("set-resizable!", 2, 0, 0, irr_setResizable);
-    DEFINE_GSUBR ("yield", 1, 0, 0, irr_yield);
-  }
-
-  DEFINE_WRAPPED_TYPE (irr::IrrlichtDevice*, "device",
-                       init_device_type, device_p,
-                       wrap_device, unwrap_device);
-
-  SCM
-  irr_createDevice (SCM device_type,
-                    SCM window_size,
-                    SCM bits,
-                    SCM fullscreen,
-                    SCM stencilbuffer,
-                    SCM vsync,
-                    SCM receiver)
-  {
-    IrrlichtDevice* device =
-      createDevice (scm_to_driver_type (device_type),
-                    scm_to_dimension2d_u32 (window_size),
-                    scm_to_uint32 (bits),
-                    scm_to_bool (fullscreen),
-                    scm_to_bool (stencilbuffer),
-                    scm_to_bool (vsync),
-                    (IEventReceiver*)scm_to_pointer (receiver));
-    return scm_from_pointer ((void*)device, NULL);
-  }
-
-  SCM
-  irr_IrrlichtDevice_getGUIEnvironment (SCM device){
-    gui::IGUIEnvironment* gui_env =
-      ((IrrlichtDevice*)scm_to_pointer (device))->getGUIEnvironment ();
-    return scm_from_pointer ((void*)gui_env, NULL);
-  }
-
-  SCM
-  irr_IrrlichtDevice_getSceneManager (SCM device)
-  {
-    scene::ISceneManager* manager =
-      ((IrrlichtDevice*)scm_to_pointer (device))->getSceneManager ();
-    return scm_from_pointer ((void*)manager, NULL);
-  }
-
-  SCM
-  irr_IrrlichtDevice_getVideoDriver (SCM device)
-  {
-    video::IVideoDriver* driver =
-      ((IrrlichtDevice*)scm_to_pointer (device))->getVideoDriver ();
-    return scm_from_pointer ((void*)driver, NULL);
-  }
-
-  SCM
-  irr_IrrlichtDevice_setWindowCaption (SCM device,
-                                       SCM text)
-  {
-    ((IrrlichtDevice*)scm_to_pointer (device))->
-      setWindowCaption (scm_to_wide_char_string (text));
-    return SCM_UNSPECIFIED;
-  }
-
-  SCM
-  irr_getTimer (SCM wrapped_device)
-  {
-    irr::IrrlichtDevice* device = unwrap_device (wrapped_device);
-    return wrap_timer (device->getTimer ());
-  }
-
-  SCM
-  irr_isWindowActive (SCM wrapped_device)
-  {
-    irr::IrrlichtDevice* device = unwrap_device (wrapped_device);
-    return scm_from_bool (device->isWindowActive ());
-  }
-
-  SCM
-  irr_run (SCM wrapped_device)
-  {
-    irr::IrrlichtDevice* device = unwrap_device (wrapped_device);
-    return scm_from_bool (device->run ());
-  }
-
-  SCM
-  irr_setEventReceiver (SCM wrapped_device,
-                        SCM receiver)
-  {
-    irr::IrrlichtDevice* device = unwrap_device (wrapped_device);
-    device->setEventReceiver (unwrap_event_receiver (receiver));
-    return SCM_UNSPECIFIED;
-  }
-
-  SCM
-  irr_setResizable (SCM wrapped_device,
-                    SCM resize)
-  {
-    irr::IrrlichtDevice* device = unwrap_device (wrapped_device);
-    device->setResizable (scm_to_bool (resize));
-    return SCM_UNSPECIFIED;
-  }
-
-  SCM
-  irr_yield (SCM wrapped_device)
-  {
-    irr::IrrlichtDevice* device = unwrap_device (wrapped_device);
-    device->yield ();
-    return SCM_UNSPECIFIED;
+    DEFINE_GSUBR ("irr_IrrlichtDevice_yield", 1, 0, 0,
+                  irr_IrrlichtDevice_yield);
   }
 
 }
index d95e458fecf120b1ae9b2aa16eddab30fdbda2ea..3e0e27b0dc96af4b13234622f0bcedf6c36a7f17 100644 (file)
 
 #include <irrlicht/irrlicht.h>
 #include <libguile.h>
-#include "wrapped.h"
 
-extern "C" {
-
-  void
-  init_device (void);
+template <typename TEventReceiver>
+SCM
+irr_createDevice (SCM device_type,
+                  SCM window_size,
+                  SCM bits,
+                  SCM fullscreen,
+                  SCM stencilbuffer,
+                  SCM vsync,
+                  SCM receiver);
 
-  DECLARE_WRAPPED_TYPE (irr::IrrlichtDevice*, init_device_type,
-                        device_p, wrap_device, unwrap_device);
+SCM
+irr_IrrlichtDevice_getCursorControl (SCM device);
 
-  SCM
-  irr_createDevice (SCM device_type,
-                    SCM window_size,
-                    SCM bits,
-                    SCM fullscreen,
-                    SCM stencilbuffer,
-                    SCM vsync,
-                    SCM receiver);
+SCM
+irr_IrrlichtDevice_getGUIEnvironment (SCM device);
 
-  SCM
-  irr_IrrlichtDevice_getGUIEnvironment (SCM device);
+SCM
+irr_IrrlichtDevice_getSceneManager (SCM device);
 
-  SCM
-  irr_IrrlichtDevice_getSceneManager (SCM device);
+SCM
+irr_IrrlichtDevice_getTimer (SCM device);
 
-  SCM
-  irr_IrrlichtDevice_getVideoDriver (SCM device);
+SCM
+irr_IrrlichtDevice_getVideoDriver (SCM device);
 
-  SCM
-  irr_IrrlichtDevice_setWindowCaption (SCM device,
-                                       SCM text);
+SCM
+irr_IrrlichtDevice_isWindowActive (SCM device);
 
-  SCM
-  irr_getTimer (SCM wrapped_device);
+SCM
+irr_IrrlichtDevice_run (SCM device);
 
-  SCM
-  irr_isWindowActive (SCM wrapped_device);
+template <typename TEventReceiver>
+SCM
+irr_IrrlichtDevice_setEventReceiver (SCM device,
+                                     SCM receiver);
 
-  SCM
-  irr_run (SCM wrapped_device);
+SCM
+irr_IrrlichtDevice_setResizable (SCM device,
+                                 SCM resize);
 
-  SCM
-  irr_setEventReceiver (SCM wrapped_device,
-                        SCM receiver);
+SCM
+irr_IrrlichtDevice_setWindowCaption (SCM device,
+                                     SCM text);
 
-  SCM
-  irr_setResizable (SCM wrapped_device,
-                    SCM resize);
-
-  SCM
-  irr_yield (SCM wrapped_device);
+SCM
+irr_IrrlichtDevice_yield (SCM device);
 
+extern "C" {
+  void
+  init_device (void);
 }
 
 #endif