1 /* Dungeon Master --- RPG Adventure Generator
2 Copyright © 2019 Javier Sancho <jsf@jsancho.org>
4 Dungeon Master is free software; you can redistribute it and/or modify it
5 under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
9 Dungeon Master is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with Dungeon Master. If not, see <http://www.gnu.org/licenses/>.
20 #include "generators.h"
25 register_scene_generator (SCM name,
29 SceneGenerator* generator =
30 register_generator (scm_to_utf8_string (name),
31 scm_to_utf8_string (scm_symbol_to_string (type)),
33 printf ("Register: %s (%s)\n", generator->name, generator->type);
34 scm_call_1 (generator->proc, scm_from_int (-1));
35 return SCM_UNSPECIFIED;
39 init_dungeon_master_module (void *unused)
41 scm_c_define_gsubr ("register-scene-generator", 3, 0, 0, (scm_t_subr) register_scene_generator);
42 scm_c_export ("register-scene-generator", NULL);
46 scm_init_dungeon_master_module ()
48 scm_c_define_module ("dungeon-master", init_dungeon_master_module, NULL);
52 add_to_load_path (std::string path)
54 // Add path to %load-path variable, needed for modules loading
55 std::string exp = "(add-to-load-path \"" + path + "\")";
56 scm_c_eval_string (exp.c_str ());
60 load_dmaster_modules ()
63 scm_init_dungeon_master_module ();
65 std::set<std::string> paths = get_dmaster_paths ();
67 struct dirent* module;
72 for (const std::string &path : paths)
74 modules_path = path + PATH_DELIM + "modules";
75 add_to_load_path (modules_path);
76 modules_dir = opendir (modules_path.c_str ());
77 if (modules_dir != NULL)
79 while (module = readdir (modules_dir))
81 if (strstr (module->d_name, ".scm") != NULL) {
82 module_main = modules_path + PATH_DELIM + module->d_name;
83 scm_primitive_load (scm_from_locale_string (module_main.c_str ()));
87 closedir (modules_dir);