From a59c8c830960e4937ea29584ce7500a6603ab428 Mon Sep 17 00:00:00 2001 From: Javier Sancho Date: Wed, 4 Mar 2020 17:07:27 +0100 Subject: [PATCH] get-video-driver --- Makefile.am | 3 +- irrlicht/device.scm | 1 + src/GuileIrrlicht.cpp | 4 ++- src/IVideoDriver.cpp | 63 ++++++++++++++++++++++++++++++++++++++++++ src/IVideoDriver.h | 44 +++++++++++++++++++++++++++++ src/IrrlichtDevice.cpp | 43 ++++++++++++++++++++-------- src/IrrlichtDevice.h | 14 ++++++++-- 7 files changed, 157 insertions(+), 15 deletions(-) create mode 100644 src/IVideoDriver.cpp create mode 100644 src/IVideoDriver.h diff --git a/Makefile.am b/Makefile.am index a82439d..8e87700 100644 --- a/Makefile.am +++ b/Makefile.am @@ -4,7 +4,8 @@ libguile_irrlicht_la_SOURCES = \ src/dimension2d.cpp \ src/EDriverTypes.cpp \ src/GuileIrrlicht.cpp \ - src/IrrlichtDevice.cpp + src/IrrlichtDevice.cpp \ + src/IVideoDriver.cpp libguile_irrlicht_la_CPPFLAGS = @GUILE_CFLAGS@ libguile_irrlicht_la_LDFLAGS = \ -version-info 0:1 \ diff --git a/irrlicht/device.scm b/irrlicht/device.scm index f359c49..8a7b30d 100644 --- a/irrlicht/device.scm +++ b/irrlicht/device.scm @@ -20,6 +20,7 @@ (define-module (irrlicht device) #:export (create-device + get-video-driver set-window-caption!)) (load-extension "libguile-irrlicht" "init_guile_irrlicht") diff --git a/src/GuileIrrlicht.cpp b/src/GuileIrrlicht.cpp index 6d2c5d7..3dd6c3a 100644 --- a/src/GuileIrrlicht.cpp +++ b/src/GuileIrrlicht.cpp @@ -21,13 +21,15 @@ #include #include "IrrlichtDevice.h" +#include "IVideoDriver.h" extern "C" { void init_guile_irrlicht (void) { - init_irrlicht_device (); + init_device (); + init_video_driver (); } } diff --git a/src/IVideoDriver.cpp b/src/IVideoDriver.cpp new file mode 100644 index 0000000..6f19e9f --- /dev/null +++ b/src/IVideoDriver.cpp @@ -0,0 +1,63 @@ +/* guile-irrlicht --- GNU Guile bindings for Irrlicht Engine + + Copyright (C) 2020 Javier Sancho + + This file is part of guile-irrlicht. + + guile-irrlicht is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 3 of the + License, or (at your option) any later version. + + guile-irrlicht is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with guile-irrlicht. If not, see + . +*/ + +#include +#include +#include "IVideoDriver.h" + +extern "C" { + + void + init_video_driver (void) + { + init_video_driver_type (); + } + + static SCM video_driver_type; + + void + init_video_driver_type (void) + { + SCM name, slots; + scm_t_struct_finalize finalizer; + + name = scm_from_utf8_symbol ("video-driver"); + slots = scm_list_1 (scm_from_utf8_symbol ("data")); + finalizer = NULL; + + video_driver_type = + scm_make_foreign_object_type (name, slots, finalizer); + } + + SCM + wrap_video_driver (irr::video::IVideoDriver* driver) + { + return scm_make_foreign_object_1 (video_driver_type, driver); + } + + irr::video::IVideoDriver* + unwrap_video_driver (SCM driver_obj) + { + scm_assert_foreign_object_type (video_driver_type, driver_obj); + return (irr::video::IVideoDriver*)scm_foreign_object_ref (driver_obj, 0); + } + +} diff --git a/src/IVideoDriver.h b/src/IVideoDriver.h new file mode 100644 index 0000000..eb91c02 --- /dev/null +++ b/src/IVideoDriver.h @@ -0,0 +1,44 @@ +/* guile-irrlicht --- GNU Guile bindings for Irrlicht Engine + + Copyright (C) 2020 Javier Sancho + + This file is part of guile-irrlicht. + + guile-irrlicht is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 3 of the + License, or (at your option) any later version. + + guile-irrlicht is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with guile-irrlicht. If not, see + . +*/ + +#ifndef __GUILE_I_VIDEO_DRIVER_INCLUDED__ +#define __GUILE_I_VIDEO_DRIVER_INCLUDED__ + +#include +#include + +extern "C" { + + void + init_video_driver (void); + + void + init_video_driver_type (void); + + SCM + wrap_video_driver (irr::video::IVideoDriver* driver); + + irr::video::IVideoDriver* + unwrap_video_driver (SCM driver_obj); + +} + +#endif diff --git a/src/IrrlichtDevice.cpp b/src/IrrlichtDevice.cpp index b3b33bd..66c8c54 100644 --- a/src/IrrlichtDevice.cpp +++ b/src/IrrlichtDevice.cpp @@ -22,24 +22,27 @@ #include #include #include + +#include "dimension2d.h" #include "EDriverTypes.h" #include "IrrlichtDevice.h" -#include "dimension2d.h" +#include "IVideoDriver.h" extern "C" { void - init_irrlicht_device (void) + init_device (void) { - init_irrlicht_device_object (); + init_device_type (); scm_c_define_gsubr ("create-device", 7, 0, 0, (scm_t_subr)irr_createDevice); + 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); } - static SCM irrlicht_device; + static SCM device_type; void - init_irrlicht_device_object (void) + init_device_type (void) { SCM name, slots; scm_t_struct_finalize finalizer; @@ -48,10 +51,23 @@ extern "C" { slots = scm_list_1 (scm_from_utf8_symbol ("data")); finalizer = NULL; - irrlicht_device = + device_type = scm_make_foreign_object_type (name, slots, finalizer); } + SCM + wrap_device (irr::IrrlichtDevice* device) + { + return scm_make_foreign_object_1 (device_type, device); + } + + irr::IrrlichtDevice* + unwrap_device (SCM device_obj) + { + scm_assert_foreign_object_type (device_type, device_obj); + return (irr::IrrlichtDevice*)scm_foreign_object_ref (device_obj, 0); + } + SCM irr_createDevice (SCM deviceType, SCM windowSize, @@ -68,20 +84,25 @@ extern "C" { scm_to_bool (fullscreen), scm_to_bool (stencilbuffer), scm_to_bool (vsync)); - return scm_make_foreign_object_1 (irrlicht_device, device); + return wrap_device (device); + } + + SCM + irr_getVideoDriver (SCM device_obj) + { + irr::IrrlichtDevice* device = unwrap_device (device_obj); + irr::video::IVideoDriver* driver = device->getVideoDriver(); + return wrap_video_driver (driver); } SCM irr_setWindowCaption (SCM device_obj, SCM text) { - irr::IrrlichtDevice* device; + irr::IrrlichtDevice* device = unwrap_device (device_obj); char* ctext; wchar_t* wtext; - scm_assert_foreign_object_type (irrlicht_device, device_obj); - device = (irr::IrrlichtDevice*)scm_foreign_object_ref (device_obj, 0); - ctext = scm_to_utf8_stringn (text, NULL); wtext = (wchar_t*)malloc ((strlen (ctext) + 1) * sizeof (wchar_t)); mbstowcs (wtext, ctext, strlen (ctext) + 1); diff --git a/src/IrrlichtDevice.h b/src/IrrlichtDevice.h index c364903..6f8afea 100644 --- a/src/IrrlichtDevice.h +++ b/src/IrrlichtDevice.h @@ -22,15 +22,22 @@ #ifndef __GUILE_IRRLICHT_DEVICE_INCLUDED__ #define __GUILE_IRRLICHT_DEVICE_INCLUDED__ +#include #include extern "C" { void - init_irrlicht_device (void); + init_device (void); void - init_irrlicht_device_object (void); + init_device_type (void); + + SCM + wrap_device (irr::IrrlichtDevice* device); + + irr::IrrlichtDevice* + unwrap_device (SCM device_obj); SCM irr_createDevice (SCM deviceType, @@ -41,6 +48,9 @@ extern "C" { SCM vsync, SCM receiver); + SCM + irr_getVideoDriver (SCM device_obj); + SCM irr_setWindowCaption (SCM device, SCM text); -- 2.39.5