From 652177d7027e9a9fe6c6b8394042bdaabf5ada76 Mon Sep 17 00:00:00 2001 From: Javier Sancho Date: Sat, 6 Jun 2020 08:19:51 +0200 Subject: [PATCH] misc --- Makefile.am | 3 ++- src/generators.h | 2 +- src/main.cpp | 3 +++ src/mods.cpp | 55 +++++++++++++++++++++++++----------------------- src/mods.h | 2 +- src/paths.cpp | 22 +++++++++---------- src/paths.h | 2 +- 7 files changed, 48 insertions(+), 41 deletions(-) diff --git a/Makefile.am b/Makefile.am index f17c5a5..eb984b7 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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/* diff --git a/src/generators.h b/src/generators.h index e88309d..cc89770 100644 --- a/src/generators.h +++ b/src/generators.h @@ -24,4 +24,4 @@ struct SceneGenerator SCM proc; }; -int register_generator(SceneGenerator generator); +int register_generator (SceneGenerator generator); diff --git a/src/main.cpp b/src/main.cpp index b86ab1e..4a522aa 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -16,6 +16,7 @@ */ #include +#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 (640, 480)); diff --git a/src/mods.cpp b/src/mods.cpp index 06a5b2f..abdf472 100644 --- a/src/mods.cpp +++ b/src/mods.cpp @@ -23,49 +23,52 @@ #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 paths = get_dm_paths(); + std::set 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); - } } diff --git a/src/mods.h b/src/mods.h index 59da012..e5fd4a5 100644 --- a/src/mods.h +++ b/src/mods.h @@ -15,4 +15,4 @@ along with Dungeon Master. If not, see . */ -void load_mods(); +void load_dmaster_mods (); diff --git a/src/paths.cpp b/src/paths.cpp index a175232..02aee3f 100644 --- a/src/paths.cpp +++ b/src/paths.cpp @@ -18,32 +18,32 @@ #include #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 get_data_paths() { +std::set get_dmaster_paths () { std::set 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; } diff --git a/src/paths.h b/src/paths.h index 2325eae..38cb13a 100644 --- a/src/paths.h +++ b/src/paths.h @@ -28,4 +28,4 @@ #define PROGRAM_NAME "dmaster" #endif -std::set get_data_paths(); +std::set get_dmaster_paths (); -- 2.39.5