]> git.jsancho.org Git - guile-irrlicht.git/blobdiff - src/file-system.cpp
get-file-system add-file-archive!
[guile-irrlicht.git] / src / file-system.cpp
diff --git a/src/file-system.cpp b/src/file-system.cpp
new file mode 100644 (file)
index 0000000..da856f4
--- /dev/null
@@ -0,0 +1,105 @@
+/* guile-irrlicht --- GNU Guile bindings for Irrlicht Engine
+
+   Copyright (C) 2020 Javier Sancho <jsf@jsancho.org>
+
+   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
+   <http://www.gnu.org/licenses/>.
+*/
+
+#include <irrlicht/irrlicht.h>
+#include <libguile.h>
+
+#include "device.h"
+#include "file-archive.h"
+#include "file-system.h"
+#include "gui-environment.h"
+#include "scene-manager.h"
+
+extern "C" {
+
+  void
+  init_file_system (void)
+  {
+    init_file_system_type ();
+    scm_c_define_gsubr ("add-file-archive!", 2, 0, 1, (scm_t_subr)irr_io_addFileArchive);
+    scm_c_define_gsubr ("get-file-system", 1, 0, 0, (scm_t_subr)irr_getFileSystem);
+    scm_c_export ("add-file-archive!", "get-file-system", NULL);
+  }
+
+  DEFINE_WRAPPED_TYPE (irr::io::IFileSystem*, "file-system",
+                       init_file_system_type, file_system_p,
+                       wrap_file_system, unwrap_file_system);
+
+  SCM
+  irr_io_addFileArchive (SCM wrapped_file_system,
+                         SCM filename,
+                         SCM rest)
+  {
+    SCM ignore_case = scm_from_bool (1);
+    SCM ignore_paths = scm_from_bool (1);
+    SCM archive_type = scm_from_utf8_symbol ("unknown");
+    SCM password = scm_from_utf8_string ("");
+    SCM ret_archive = scm_from_bool (0);
+
+    scm_c_bind_keyword_arguments ("add-file-archive!", rest, (scm_t_keyword_arguments_flags)0,
+                                  scm_from_utf8_keyword ("ignore-case"), &ignore_case,
+                                  scm_from_utf8_keyword ("ignore-paths"), &ignore_paths,
+                                  scm_from_utf8_keyword ("archive-type"), &archive_type,
+                                  scm_from_utf8_keyword ("password"), &password,
+                                  scm_from_utf8_keyword ("ret-archive"), &ret_archive,
+                                  SCM_UNDEFINED);
+
+    irr::io::IFileArchive** retArchiveReference = 0;
+    if (!scm_is_false (ret_archive))
+      {
+        irr::io::IFileArchive* retArchive = unwrap_file_archive (ret_archive);
+        retArchiveReference = &retArchive;
+      }
+    irr::io::IFileSystem* file_system = unwrap_file_system (wrapped_file_system);
+    return scm_from_bool
+      (file_system->addFileArchive (scm_to_utf8_stringn (filename, NULL),
+                                    scm_to_bool (ignore_case),
+                                    scm_to_bool (ignore_paths),
+                                    scm_to_file_archive_type (archive_type),
+                                    scm_to_utf8_stringn (password, NULL),
+                                    retArchiveReference));
+  }
+
+  SCM
+  irr_getFileSystem (SCM wrapped_obj)
+  {
+    irr::io::IFileSystem* file_system;
+    if (gui_environment_p (wrapped_obj))
+      {
+        file_system = unwrap_gui_environment (wrapped_obj)->getFileSystem ();
+      }
+    else if (device_p (wrapped_obj))
+      {
+        file_system = unwrap_device (wrapped_obj)->getFileSystem ();
+      }
+    else if (scene_manager_p (wrapped_obj))
+      {
+        file_system = unwrap_scene_manager (wrapped_obj)->getFileSystem ();
+      }
+    else
+      {
+        scm_error (scm_arg_type_key, NULL, "Cannot get file system from object: ~S",
+                   scm_list_1 (wrapped_obj), scm_list_1 (wrapped_obj));
+      }
+    return wrap_file_system (file_system);
+  }
+
+}