]> git.jsancho.org Git - guile-irrlicht.git/blob - src/device.cpp
call remote procs from guile code
[guile-irrlicht.git] / src / device.cpp
1 /* guile-irrlicht --- GNU Guile bindings for Irrlicht Engine
2
3    Copyright (C) 2020 Javier Sancho <jsf@jsancho.org>
4
5    This file is part of guile-irrlicht.
6
7    guile-irrlicht is free software; you can redistribute it and/or modify
8    it under the terms of the GNU Lesser General Public License as
9    published by the Free Software Foundation; either version 3 of the
10    License, or (at your option) any later version.
11
12    guile-irrlicht is distributed in the hope that it will be useful, but
13    WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15    General Public License for more details.
16
17    You should have received a copy of the GNU Lesser General Public
18    License along with guile-irrlicht. If not, see
19    <http://www.gnu.org/licenses/>.
20 */
21
22 #include <irrlicht/irrlicht.h>
23 #include <libguile.h>
24 #include "device.h"
25 #include "dimension2d.h"
26 #include "driver-types.h"
27 #include "gsubr.h"
28 #include "wchar.h"
29
30
31 using namespace irr;
32
33
34 SCM
35 irr_createDevice (SCM device_type,
36                   SCM window_size,
37                   SCM bits,
38                   SCM fullscreen,
39                   SCM stencilbuffer,
40                   SCM vsync,
41                   SCM receiver)
42 {
43   IrrlichtDevice* device =
44     createDevice (scm_to_driver_type (device_type),
45                   scm_to_dimension2d_u32 (window_size),
46                   scm_to_uint32 (bits),
47                   scm_to_bool (fullscreen),
48                   scm_to_bool (stencilbuffer),
49                   scm_to_bool (vsync),
50                   (IEventReceiver*)scm_to_pointer (receiver));
51   return scm_from_pointer ((void*)device, NULL);
52 }
53
54
55 SCM
56 IrrlichtDevice_getCursorControl (SCM device)
57 {
58   gui::ICursorControl* cursor_control =
59     ((IrrlichtDevice*)scm_to_pointer (device))->getCursorControl ();
60   return scm_from_pointer ((void*)cursor_control, NULL);
61 }
62
63
64 SCM
65 IrrlichtDevice_getFileSystem (SCM device)
66 {
67   io::IFileSystem* file_system =
68     ((IrrlichtDevice*)scm_to_pointer (device))->getFileSystem ();
69   return scm_from_pointer ((void*)file_system, NULL);
70 }
71
72
73 SCM
74 IrrlichtDevice_getGUIEnvironment (SCM device)
75 {
76   gui::IGUIEnvironment* gui_env =
77     ((IrrlichtDevice*)scm_to_pointer (device))->getGUIEnvironment ();
78   return scm_from_pointer ((void*)gui_env, NULL);
79 }
80
81
82 SCM
83 IrrlichtDevice_getSceneManager (SCM device)
84 {
85   scene::ISceneManager* manager =
86     ((IrrlichtDevice*)scm_to_pointer (device))->getSceneManager ();
87   return scm_from_pointer ((void*)manager, NULL);
88 }
89
90
91 SCM
92 IrrlichtDevice_getTimer (SCM device)
93 {
94   ITimer* timer =
95     ((IrrlichtDevice*)scm_to_pointer (device))->getTimer ();
96   return scm_from_pointer ((void*)timer, NULL);
97 }
98
99
100 SCM
101 IrrlichtDevice_getVideoDriver (SCM device)
102 {
103   video::IVideoDriver* driver =
104     ((IrrlichtDevice*)scm_to_pointer (device))->getVideoDriver ();
105   return scm_from_pointer ((void*)driver, NULL);
106 }
107
108
109 SCM
110 IrrlichtDevice_isWindowActive (SCM device)
111 {
112   return scm_from_bool
113     (((IrrlichtDevice*)scm_to_pointer (device))->isWindowActive ());
114 }
115
116
117 SCM
118 IrrlichtDevice_run (SCM device)
119 {
120   return scm_from_bool
121     (((IrrlichtDevice*)scm_to_pointer (device))->run ());
122 }
123
124
125 template <typename TEventReceiver>
126 SCM
127 IrrlichtDevice_setEventReceiver (SCM device,
128                                  SCM receiver)
129 {
130   ((IrrlichtDevice*)scm_to_pointer (device))->
131     setEventReceiver ((TEventReceiver)scm_to_pointer (receiver));
132   return SCM_UNSPECIFIED;
133 }
134
135
136 SCM
137 IrrlichtDevice_setResizable (SCM device,
138                              SCM resize)
139 {
140   ((IrrlichtDevice*)scm_to_pointer (device))->
141     setResizable (scm_to_bool (resize));
142   return SCM_UNSPECIFIED;
143 }
144
145
146 SCM
147 IrrlichtDevice_setWindowCaption (SCM device,
148                                  SCM text)
149 {
150   ((IrrlichtDevice*)scm_to_pointer (device))->
151     setWindowCaption (scm_to_wide_char_string (text));
152   return SCM_UNSPECIFIED;
153 }
154
155
156 SCM
157 IrrlichtDevice_yield (SCM device)
158 {
159   ((IrrlichtDevice*)scm_to_pointer (device))->yield ();
160   return SCM_UNSPECIFIED;
161 }
162
163
164 extern "C" {
165
166   void
167   init_device (void)
168   {
169     DEFINE_GSUBR ("createDevice", 7, 0, 0, irr_createDevice);
170     DEFINE_GSUBR ("IrrlichtDevice_getCursorControl", 1, 0, 0, IrrlichtDevice_getCursorControl);
171     DEFINE_GSUBR ("IrrlichtDevice_getFileSystem", 1, 0, 0, IrrlichtDevice_getFileSystem);
172     DEFINE_GSUBR ("IrrlichtDevice_getGUIEnvironment", 1, 0, 0, IrrlichtDevice_getGUIEnvironment);
173     DEFINE_GSUBR ("IrrlichtDevice_getSceneManager", 1, 0, 0, IrrlichtDevice_getSceneManager);
174     DEFINE_GSUBR ("IrrlichtDevice_getTimer", 1, 0, 0, IrrlichtDevice_getTimer);
175     DEFINE_GSUBR ("IrrlichtDevice_getVideoDriver", 1, 0, 0, IrrlichtDevice_getVideoDriver);
176     DEFINE_GSUBR ("IrrlichtDevice_isWindowActive", 1, 0, 0, IrrlichtDevice_isWindowActive);
177     DEFINE_GSUBR ("IrrlichtDevice_run", 1, 0, 0, IrrlichtDevice_run);
178     DEFINE_GSUBR ("IrrlichtDevice_setEventReceiver_IEventReceiver", 2, 0, 0,
179                   IrrlichtDevice_setEventReceiver<IEventReceiver*>);
180     DEFINE_GSUBR ("IrrlichtDevice_setResizable", 2, 0, 0, IrrlichtDevice_setResizable);
181     DEFINE_GSUBR ("IrrlichtDevice_setWindowCaption", 2, 0, 0, IrrlichtDevice_setWindowCaption);
182     DEFINE_GSUBR ("IrrlichtDevice_yield", 1, 0, 0, IrrlichtDevice_yield);
183   }
184
185 }