1 /* guile-irrlicht --- GNU Guile bindings for Irrlicht Engine
3 Copyright (C) 2020 Javier Sancho <jsf@jsancho.org>
5 This file is part of guile-irrlicht.
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.
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.
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/>.
22 #include <irrlicht/irrlicht.h>
26 #include "file-archive.h"
27 #include "file-system.h"
29 #include "gui-environment.h"
30 #include "scene-manager.h"
35 init_file_system (void)
37 init_file_system_type ();
38 DEFINE_GSUBR ("add-file-archive!", 2, 0, 1, irr_io_addFileArchive);
39 DEFINE_GSUBR ("get-file-system", 1, 0, 0, irr_getFileSystem);
42 DEFINE_WRAPPED_TYPE (irr::io::IFileSystem*, "file-system",
43 init_file_system_type, file_system_p,
44 wrap_file_system, unwrap_file_system);
47 irr_io_addFileArchive (SCM wrapped_file_system,
51 SCM ignore_case = SCM_BOOL_T;
52 SCM ignore_paths = SCM_BOOL_T;
53 SCM archive_type = scm_from_utf8_symbol ("unknown");
54 SCM password = scm_from_utf8_string ("");
55 SCM ret_archive = SCM_UNDEFINED;
57 scm_c_bind_keyword_arguments ("add-file-archive!", rest, (scm_t_keyword_arguments_flags)0,
58 scm_from_utf8_keyword ("ignore-case"), &ignore_case,
59 scm_from_utf8_keyword ("ignore-paths"), &ignore_paths,
60 scm_from_utf8_keyword ("archive-type"), &archive_type,
61 scm_from_utf8_keyword ("password"), &password,
62 scm_from_utf8_keyword ("ret-archive"), &ret_archive,
65 irr::io::IFileArchive** retArchiveReference = 0;
66 if (ret_archive != SCM_UNDEFINED)
68 irr::io::IFileArchive* retArchive = unwrap_file_archive (ret_archive);
69 retArchiveReference = &retArchive;
71 irr::io::IFileSystem* file_system = unwrap_file_system (wrapped_file_system);
73 (file_system->addFileArchive (scm_to_utf8_stringn (filename, NULL),
74 scm_to_bool (ignore_case),
75 scm_to_bool (ignore_paths),
76 scm_to_file_archive_type (archive_type),
77 scm_to_utf8_stringn (password, NULL),
78 retArchiveReference));
82 irr_getFileSystem (SCM wrapped_obj)
84 irr::io::IFileSystem* file_system;
85 if (gui_environment_p (wrapped_obj))
87 file_system = unwrap_gui_environment (wrapped_obj)->getFileSystem ();
89 else if (device_p (wrapped_obj))
91 file_system = unwrap_device (wrapped_obj)->getFileSystem ();
93 else if (scene_manager_p (wrapped_obj))
95 file_system = unwrap_scene_manager (wrapped_obj)->getFileSystem ();
99 scm_error (scm_arg_type_key, NULL, "Cannot get file system from object: ~S",
100 scm_list_1 (wrapped_obj), scm_list_1 (wrapped_obj));
102 return wrap_file_system (file_system);