]> git.jsancho.org Git - dungeon-master.git/commitdiff
misc
authorJavier Sancho <jsf@jsancho.org>
Sat, 6 Jun 2020 06:19:51 +0000 (08:19 +0200)
committerJavier Sancho <jsf@jsancho.org>
Sat, 6 Jun 2020 06:19:51 +0000 (08:19 +0200)
Makefile.am
src/generators.h
src/main.cpp
src/mods.cpp
src/mods.h
src/paths.cpp
src/paths.h

index f17c5a5ffad968fe5d7cc0af48efbf342827503f..eb984b73ce2e7a4f3e185848c8c3cd075483ddc4 100644 (file)
@@ -1,11 +1,12 @@
 bin_PROGRAMS = dmaster
 dmaster_SOURCES = \
   src/main.cpp \
+  src/mods.cpp \
   src/paths.cpp
 dmaster_CPPFLAGS = \
   @GUILE_CFLAGS@ \
   -DDATA_PATH=\"$(pkgdatadir)\" \
   -DPROGRAM_NAME=\"$(PACKAGE)\"
-dmaster_LDFLAGS = @GUILE_LIBS@
+dmaster_LDADD = @GUILE_LIBS@
 adventuresdir = $(pkgdatadir)/adventures
 adventures_DATA = adventures/*
index e88309d65c742f1a88f2284010bdab564301932f..cc897707b87b5bc47d79ffc86f7a9dc59f4a8acb 100644 (file)
@@ -24,4 +24,4 @@ struct SceneGenerator
   SCM proc;
 };
 
-int register_generator(SceneGenerator generator);
+int register_generator (SceneGenerator generator);
index b86ab1e2cb0b35a42886f4bc597e7e7c65d9472c..4a522aacc1fe9ad8a9f8571bede47c5e9652fa51 100644 (file)
@@ -16,6 +16,7 @@
 */
 
 #include <irrlicht/irrlicht.h>
+#include "mods.h"
 
 using namespace irr;
 using namespace core;
@@ -24,6 +25,8 @@ using namespace gui;
 
 int main ()
 {
+  load_dmaster_mods ();
+
   IrrlichtDevice* device =
     createDevice (video::EDT_OPENGL, core::dimension2d<u32> (640, 480));
 
index 06a5b2fc67244e76eeda8296fb355410165ac159..abdf472bfd8ff25c4c1a6519f1761a11773f94b7 100644 (file)
 #include "paths.h"
 
 
-SCM register_scene_generator(SCM name, SCM type, SCM proc)
+SCM register_scene_generator (SCM name, SCM type, SCM proc)
 {
-  SceneGenerator generator {scm_to_locale_string(name), scm_to_locale_string(type), proc };
-  register_generator(generator);
-  printf ("Register: %s (%s)\n", generator.name.c_str(), generator.type.c_str());
-  scm_call_1(proc, scm_from_int(-1));
+  SceneGenerator generator {scm_to_locale_string (name), scm_to_locale_string (type), proc };
+  //register_generator (generator);
+  printf ("Register: %s (%s)\n", generator.name.c_str (), generator.type.c_str ());
+  scm_call_1 (proc, scm_from_int (-1));
   return SCM_UNSPECIFIED;
 }
 
-void init_dungeon_master_module(void *unused)
+void init_dungeon_master_module (void *unused)
 {
-  scm_c_define_gsubr("register-scene-generator", 3, 0, 0, (scm_t_subr)register_scene_generator);
-  scm_c_export("register-scene-generator", NULL);
+  scm_c_define_gsubr ("register-scene-generator", 3, 0, 0, (scm_t_subr) register_scene_generator);
+  scm_c_export ("register-scene-generator", NULL);
 }
 
-void scm_init_dungeon_master_module()
+void scm_init_dungeon_master_module ()
 {
-  scm_c_define_module("dungeon-master", init_dungeon_master_module, NULL);
+  scm_c_define_module ("dungeon-master", init_dungeon_master_module, NULL);
 }
 
-void load_mods()
+void load_dmaster_mods ()
 {
-  scm_init_guile();
-  scm_init_dungeon_master_module();
+  scm_init_guile ();
+  scm_init_dungeon_master_module ();
 
-  std::set<std::string> paths = get_dm_paths();
+  std::set<std::string> paths = get_dmaster_paths ();
   DIR* mods_dir;
   struct dirent* mod;
   std::string
     mods_path,
     mod_main;
 
-  for (const std::string &path : paths) {
-    mods_path = path + DIR_DELIM + "mods";
-    mods_dir = opendir(mods_path.c_str());
-    if (mods_dir != NULL) {
-      while (mod = readdir(mods_dir)) {
-       if (strcmp(mod->d_name, ".") != 0 && strcmp(mod->d_name, "..") != 0) {
-         mod_main = mods_path + DIR_DELIM + mod->d_name + DIR_DELIM + "main.scm";
-         scm_primitive_load(scm_from_locale_string(mod_main.c_str()));
-       }
-      }
+  for (const std::string &path : paths)
+    {
+      mods_path = path + PATH_DELIM + "mods";
+      mods_dir = opendir (mods_path.c_str ());
+      if (mods_dir != NULL)
+        {
+          while (mod = readdir (mods_dir))
+            {
+              if (strstr (mod->d_name, ".scm") != NULL) {
+                mod_main = mods_path + PATH_DELIM + mod->d_name;
+                scm_primitive_load (scm_from_locale_string (mod_main.c_str ()));
+              }
+            }
+        }
+      closedir (mods_dir);
     }
-    closedir(mods_dir);
-  }
 }
index 59da0123d25d9a2c21039c6dce64497b4bade454..e5fd4a5980ae5cbbc9824f9d45ad71ac62190397 100644 (file)
@@ -15,4 +15,4 @@
    along with Dungeon Master. If not, see <http://www.gnu.org/licenses/>.
 */
 
-void load_mods();
+void load_dmaster_mods ();
index a1752328abcd5a736c76ad8f54e7b9397f6705df..02aee3f28264a1be1ceac9849dd5238ba6a676f2 100644 (file)
 #include <unistd.h>
 #include "paths.h"
 
-std::string get_exec_path()
+std::string get_exec_path ()
 {
   char pBuf[256];
-  size_t len = sizeof(pBuf);
+  size_t len = sizeof (pBuf);
   char szTmp[32];
 
-  sprintf(szTmp, "/proc/%d/exe", getpid());
-  int bytes = readlink(szTmp, pBuf, len);
+  sprintf (szTmp, "/proc/%d/exe", getpid ());
+  int bytes = readlink (szTmp, pBuf, len);
   if (bytes > len - 1)
     bytes = len - 1;
   if (bytes >= 0)
     pBuf[bytes] = '\0';
 
   std::string exec_path = pBuf;
-  return exec_path.substr(0, exec_path.rfind(PATH_DELIM) + 1);
+  return exec_path.substr (0, exec_path.rfind (PATH_DELIM) + 1);
 }
 
-std::string get_home_path()
+std::string get_home_path ()
 {
-  return (std::string)getenv("HOME") + PATH_DELIM + "." + PROGRAM_NAME;
+  return (std::string) getenv ("HOME") + PATH_DELIM + "." + PROGRAM_NAME;
 }
 
-std::set<std::string> get_data_paths() {
+std::set<std::string> get_dmaster_paths () {
   std::set<std::string> paths;
-  paths.insert(get_exec_path());
-  paths.insert(DATA_PATH);
-  paths.insert(get_home_path());
+  paths.insert (get_exec_path ());
+  paths.insert (DATA_PATH);
+  paths.insert (get_home_path ());
   return paths;
 }
index 2325eae09cd163d573115b09c4b388aa3f7ee647..38cb13aa1a05337f1ef3ac045f026a0df430b1a7 100644 (file)
@@ -28,4 +28,4 @@
 #define PROGRAM_NAME "dmaster"
 #endif
 
-std::set<std::string> get_data_paths();
+std::set<std::string> get_dmaster_paths ();