From 9a256c6c6a756378cb53c89d42e362bbaa2fc5c0 Mon Sep 17 00:00:00 2001 From: Javier Sancho Date: Sun, 15 Mar 2020 10:42:45 +0100 Subject: [PATCH] refactor --- src/device.cpp | 30 ------------------------------ src/device.h | 9 --------- src/gui-environment.cpp | 18 ++++++++++++++++++ src/gui-environment.h | 3 +++ src/reference-counted.cpp | 5 +++++ src/scene-manager.cpp | 18 ++++++++++++++++++ src/scene-manager.h | 3 +++ src/video-driver.cpp | 19 +++++++++++++++++++ src/video-driver.h | 3 +++ 9 files changed, 69 insertions(+), 39 deletions(-) diff --git a/src/device.cpp b/src/device.cpp index bb43ddb..e578e05 100644 --- a/src/device.cpp +++ b/src/device.cpp @@ -25,9 +25,6 @@ #include "device.h" #include "dimension2d.h" #include "driver-types.h" -#include "gui-environment.h" -#include "scene-manager.h" -#include "video-driver.h" #include "wchar.h" #include "wrapped.h" @@ -38,9 +35,6 @@ extern "C" { { init_device_type (); scm_c_define_gsubr ("create-device", 7, 0, 0, (scm_t_subr)irr_createDevice); - scm_c_define_gsubr ("get-gui-environment", 1, 0, 0, (scm_t_subr)irr_getGUIEnvironment); - scm_c_define_gsubr ("get-scene-manager", 1, 0, 0, (scm_t_subr)irr_getSceneManager); - scm_c_define_gsubr ("get-video-driver", 1, 0, 0, (scm_t_subr)irr_getVideoDriver); scm_c_define_gsubr ("set-window-caption!", 2, 0, 0, (scm_t_subr)irr_setWindowCaption); } @@ -67,30 +61,6 @@ extern "C" { return wrap_device (device); } - SCM - irr_getGUIEnvironment (SCM wrapped_device) - { - irr::IrrlichtDevice* device = unwrap_device (wrapped_device); - irr::gui::IGUIEnvironment* gui_environment = device->getGUIEnvironment (); - return wrap_gui_environment (gui_environment); - } - - SCM - irr_getSceneManager (SCM wrapped_device) - { - irr::IrrlichtDevice* device = unwrap_device (wrapped_device); - irr::scene::ISceneManager* scene_manager = device->getSceneManager (); - return wrap_scene_manager (scene_manager); - } - - SCM - irr_getVideoDriver (SCM wrapped_device) - { - irr::IrrlichtDevice* device = unwrap_device (wrapped_device); - irr::video::IVideoDriver* driver = device->getVideoDriver (); - return wrap_video_driver (driver); - } - SCM irr_setWindowCaption (SCM wrapped_device, SCM text) diff --git a/src/device.h b/src/device.h index 0f3d243..8c9f8a1 100644 --- a/src/device.h +++ b/src/device.h @@ -43,15 +43,6 @@ extern "C" { SCM vsync, SCM receiver); - SCM - irr_getGUIEnvironment (SCM wrapped_device); - - SCM - irr_getSceneManager (SCM wrapped_device); - - SCM - irr_getVideoDriver (SCM wrapped_device); - SCM irr_setWindowCaption (SCM wrapped_device, SCM text); diff --git a/src/gui-environment.cpp b/src/gui-environment.cpp index 76dc57c..ca59a31 100644 --- a/src/gui-environment.cpp +++ b/src/gui-environment.cpp @@ -22,6 +22,7 @@ #include #include +#include "device.h" #include "gui-element.h" #include "gui-environment.h" #include "gui-static-text.h" @@ -36,12 +37,29 @@ extern "C" { { init_gui_environment_type (); scm_c_define_gsubr ("add-static-text!", 8, 0, 0, (scm_t_subr)irr_gui_addStaticText); + scm_c_define_gsubr ("get-gui-environment", 1, 0, 0, (scm_t_subr)irr_getGUIEnvironment); } DEFINE_WRAPPED_TYPE (irr::gui::IGUIEnvironment*, "gui-environment", init_gui_environment_type, gui_environment_p, wrap_gui_environment, unwrap_gui_environment); + SCM + irr_getGUIEnvironment (SCM wrapped_obj) + { + irr::gui::IGUIEnvironment* gui_environment; + if (device_p (wrapped_obj)) + { + gui_environment = unwrap_device (wrapped_obj)->getGUIEnvironment (); + } + else + { + scm_error (scm_arg_type_key, NULL, "Cannot get GUI environment from object: ~S", + scm_list_1 (wrapped_obj), scm_list_1 (wrapped_obj)); + } + return wrap_gui_environment (gui_environment); + } + SCM irr_gui_addStaticText (SCM wrappedGUIEnvironment, SCM text, diff --git a/src/gui-environment.h b/src/gui-environment.h index 9b8d636..caac2ee 100644 --- a/src/gui-environment.h +++ b/src/gui-environment.h @@ -34,6 +34,9 @@ extern "C" { DECLARE_WRAPPED_TYPE (irr::gui::IGUIEnvironment*, init_gui_environment_type, gui_environment_p, wrap_gui_environment, unwrap_gui_environment); + SCM + irr_getGUIEnvironment (SCM wrapped_obj); + SCM irr_gui_addStaticText (SCM guienv, SCM text, diff --git a/src/reference-counted.cpp b/src/reference-counted.cpp index 85634d4..58878d3 100644 --- a/src/reference-counted.cpp +++ b/src/reference-counted.cpp @@ -41,6 +41,11 @@ extern "C" { { result = unwrap_device (wrapped_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); } diff --git a/src/scene-manager.cpp b/src/scene-manager.cpp index 5e81de7..d4234e8 100644 --- a/src/scene-manager.cpp +++ b/src/scene-manager.cpp @@ -24,6 +24,7 @@ #include "animated-mesh.h" #include "animated-mesh-scene-node.h" +#include "device.h" #include "scene-manager.h" #include "scene-node.h" #include "vector3d.h" @@ -38,12 +39,29 @@ extern "C" { scm_c_define_gsubr ("add-animated-mesh-scene-node", 8, 0, 0, (scm_t_subr)irr_scene_addAnimatedMeshSceneNode); scm_c_define_gsubr ("get-mesh", 2, 0, 0, (scm_t_subr)irr_scene_getMesh); + scm_c_define_gsubr ("get-scene-manager", 1, 0, 0, (scm_t_subr)irr_getSceneManager); } DEFINE_WRAPPED_TYPE (irr::scene::ISceneManager*, "scene-manager", init_scene_manager_type, scene_manager_p, wrap_scene_manager, unwrap_scene_manager); + SCM + irr_getSceneManager (SCM wrapped_obj) + { + irr::scene::ISceneManager* scene_manager; + if (device_p (wrapped_obj)) + { + scene_manager = unwrap_device (wrapped_obj)->getSceneManager (); + } + else + { + scm_error (scm_arg_type_key, NULL, "Cannot get scene manager from object: ~S", + scm_list_1 (wrapped_obj), scm_list_1 (wrapped_obj)); + } + return wrap_scene_manager (scene_manager); + } + SCM irr_scene_addAnimatedMeshSceneNode (SCM wrapped_scene_manager, SCM mesh, diff --git a/src/scene-manager.h b/src/scene-manager.h index f52d299..961b963 100644 --- a/src/scene-manager.h +++ b/src/scene-manager.h @@ -34,6 +34,9 @@ extern "C" { DECLARE_WRAPPED_TYPE (irr::scene::ISceneManager*, init_scene_manager_type, scene_manager_p, wrap_scene_manager, unwrap_scene_manager); + SCM + irr_getSceneManager (SCM wrapped_obj); + SCM irr_scene_addAnimatedMeshSceneNode (SCM wrapped_scene_manager, SCM mesh, diff --git a/src/video-driver.cpp b/src/video-driver.cpp index c746db3..b768f58 100644 --- a/src/video-driver.cpp +++ b/src/video-driver.cpp @@ -21,6 +21,8 @@ #include #include + +#include "device.h" #include "video-driver.h" #include "wrapped.h" @@ -30,10 +32,27 @@ extern "C" { init_video_driver (void) { init_video_driver_type (); + scm_c_define_gsubr ("get-video-driver", 1, 0, 0, (scm_t_subr)irr_getVideoDriver); } DEFINE_WRAPPED_TYPE (irr::video::IVideoDriver*, "video-driver", init_video_driver_type, video_driver_p, wrap_video_driver, unwrap_video_driver); + SCM + irr_getVideoDriver (SCM wrapped_obj) + { + irr::video::IVideoDriver* driver; + if (device_p (wrapped_obj)) + { + driver = unwrap_device (wrapped_obj)->getVideoDriver (); + } + else + { + scm_error (scm_arg_type_key, NULL, "Cannot get video driver from object: ~S", + scm_list_1 (wrapped_obj), scm_list_1 (wrapped_obj)); + } + return wrap_video_driver (driver); + } + } diff --git a/src/video-driver.h b/src/video-driver.h index 1525edf..7e3f727 100644 --- a/src/video-driver.h +++ b/src/video-driver.h @@ -34,6 +34,9 @@ extern "C" { DECLARE_WRAPPED_TYPE (irr::video::IVideoDriver*, init_video_driver_type, video_driver_p, wrap_video_driver, unwrap_video_driver); + SCM + irr_getVideoDriver (SCM wrapped_obj); + } #endif -- 2.39.5