]> git.jsancho.org Git - guile-irrlicht.git/commitdiff
get-file-system add-file-archive!
authorJavier Sancho <jsf@jsancho.org>
Fri, 20 Mar 2020 15:47:31 +0000 (16:47 +0100)
committerJavier Sancho <jsf@jsancho.org>
Fri, 20 Mar 2020 15:47:31 +0000 (16:47 +0100)
Makefile.am
src/file-archive.cpp [new file with mode: 0644]
src/file-archive.h [new file with mode: 0644]
src/file-system.cpp [new file with mode: 0644]
src/file-system.h [new file with mode: 0644]
src/guile-irrlicht.cpp

index 576c75ebf310426d49a45d668da1f50258a0f244..4918fc260086d9e5bb3b94299e29c8221337f1f4 100644 (file)
@@ -31,6 +31,8 @@ libguile_irrlicht_la_SOURCES = \
   src/device.cpp \
   src/dimension2d.cpp \
   src/driver-types.cpp \
+  src/file-archive.cpp \
+  src/file-system.cpp \
   src/gui-element.cpp \
   src/gui-environment.cpp \
   src/gui-static-text.cpp \
diff --git a/src/file-archive.cpp b/src/file-archive.cpp
new file mode 100644 (file)
index 0000000..97d842b
--- /dev/null
@@ -0,0 +1,81 @@
+/* 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 "file-archive.h"
+
+extern "C" {
+
+  void
+  init_file_archive (void)
+  {
+    init_file_archive_type ();
+  }
+
+  DEFINE_WRAPPED_TYPE (irr::io::IFileArchive*, "file-archive",
+                       init_file_archive_type, file_archive_p,
+                       wrap_file_archive, unwrap_file_archive);
+
+  irr::io::E_FILE_ARCHIVE_TYPE
+  scm_to_file_archive_type (SCM file_archive_type)
+  {
+    char* type = scm_to_utf8_stringn (scm_symbol_to_string (file_archive_type), NULL);
+    if (!strcmp (type, "zip"))
+      {
+        return irr::io::EFAT_ZIP;
+      }
+    else if (!strcmp (type, "gzip"))
+      {
+        return irr::io::EFAT_GZIP;
+      }
+    else if (!strcmp (type, "folder"))
+      {
+        return irr::io::EFAT_FOLDER;
+      }
+    else if (!strcmp (type, "pak"))
+      {
+        return irr::io::EFAT_PAK;
+      }
+    else if (!strcmp (type, "npk"))
+      {
+        return irr::io::EFAT_NPK;
+      }
+    else if (!strcmp (type, "tar"))
+      {
+        return irr::io::EFAT_TAR;
+      }
+    else if (!strcmp (type, "wad"))
+      {
+        return irr::io::EFAT_WAD;
+      }
+    else if (!strcmp (type, "unknown"))
+      {
+        return irr::io::EFAT_UNKNOWN;
+      }
+    else
+      {
+        scm_error (scm_arg_type_key, NULL, "Wrong file archive type: ~S",
+                   scm_list_1 (file_archive_type), scm_list_1 (file_archive_type));
+      }
+  }
+
+}
diff --git a/src/file-archive.h b/src/file-archive.h
new file mode 100644 (file)
index 0000000..1679ad1
--- /dev/null
@@ -0,0 +1,42 @@
+/* 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/>.
+*/
+
+#ifndef __GUILE_IRRLICHT_FILE_ARCHIVE_H_INCLUDED__
+#define __GUILE_IRRLICHT_FILE_ARCHIVE_H_INCLUDED__
+
+#include <irrlicht/irrlicht.h>
+#include <libguile.h>
+#include "wrapped.h"
+
+extern "C" {
+
+  void
+  init_file_archive (void);
+
+  DECLARE_WRAPPED_TYPE (irr::io::IFileArchive*, init_file_archive_type,
+                        file_archive_p, wrap_file_archive, unwrap_file_archive);
+
+  irr::io::E_FILE_ARCHIVE_TYPE
+  scm_to_file_archive_type (SCM file_archive_type);
+
+}
+
+#endif
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);
+  }
+
+}
diff --git a/src/file-system.h b/src/file-system.h
new file mode 100644 (file)
index 0000000..35a0627
--- /dev/null
@@ -0,0 +1,47 @@
+/* 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/>.
+*/
+
+#ifndef __GUILE_IRRLICHT_FILE_SYSTEM_H_INCLUDED__
+#define __GUILE_IRRLICHT_FILE_SYSTEM_H_INCLUDED__
+
+#include <irrlicht/irrlicht.h>
+#include <libguile.h>
+#include "wrapped.h"
+
+extern "C" {
+
+  void
+  init_file_system (void);
+
+  DECLARE_WRAPPED_TYPE (irr::io::IFileSystem*, 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
+  irr_getFileSystem (SCM wrapped_obj);
+
+}
+
+#endif
index fd4515fd136f0f416044af41195cdd9cdd6ad6fd..daa314d5f68e6bdebc3d8849f14ba8140a045f10 100644 (file)
@@ -25,6 +25,8 @@
 #include "animated-mesh-scene-node.h"
 #include "camera-scene-node.h"
 #include "device.h"
+#include "file-archive.h"
+#include "file-system.h"
 #include "gui-element.h"
 #include "gui-environment.h"
 #include "gui-static-text.h"
@@ -45,6 +47,8 @@ extern "C" {
     init_animated_mesh_scene_node ();
     init_camera_scene_node ();
     init_device ();
+    init_file_archive ();
+    init_file_system ();
     init_gui_element ();
     init_gui_environment ();
     init_gui_static_text ();