bin_PROGRAMS = dmaster
dmaster_SOURCES = \
+ src/generators.cpp \
src/main.cpp \
src/mods.cpp \
src/paths.cpp
--- /dev/null
+/* Dungeon Master --- RPG Adventure Generator
+ Copyright © 2019 Javier Sancho <jsf@jsancho.org>
+
+ Dungeon Master is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ Dungeon Master 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 General Public License
+ along with Dungeon Master. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <libguile.h>
+#include <list>
+#include <map>
+#include "generators.h"
+
+struct compare_strings
+{
+ bool operator() (const char* a, const char* b) const
+ {
+ return strcmp (a, b) < 0;
+ }
+};
+
+std::map<char*,
+ std::list<SceneGenerator*>,
+ compare_strings> registered_generators;
+
+SceneGenerator*
+register_generator (char* name,
+ char* type,
+ SCM proc)
+{
+ SceneGenerator* generator = (SceneGenerator*) malloc (sizeof (SceneGenerator));
+ generator->name = name;
+ generator->type = type;
+ generator->proc = proc;
+
+ registered_generators[type].push_back (generator);
+
+ return generator;
+}
#include <libguile.h>
-struct SceneGenerator
+typedef struct
{
- std::string name;
- std::string type;
+ char* name;
+ char* type;
SCM proc;
-};
+} SceneGenerator;
-int register_generator (SceneGenerator generator);
+SceneGenerator*
+register_generator (char* name,
+ char* type,
+ SCM proc);
using namespace video;
using namespace gui;
-int main ()
+int
+main ()
{
load_dmaster_mods ();
*/
#include <dirent.h>
-#include <iostream>
#include <libguile.h>
#include "generators.h"
#include "mods.h"
#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 =
+ register_generator (scm_to_utf8_string (name),
+ scm_to_utf8_string (scm_symbol_to_string (type)),
+ proc);
+ printf ("Register: %s (%s)\n", generator->name, generator->type);
+ scm_call_1 (generator->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);
}
-void scm_init_dungeon_master_module ()
+void
+scm_init_dungeon_master_module ()
{
scm_c_define_module ("dungeon-master", init_dungeon_master_module, NULL);
}
-void add_to_load_path (std::string path)
+void
+add_to_load_path (std::string path)
{
- // Add path to %load-path variable, needed for modules created in mods
+ // Add path to %load-path variable, needed for mods structured like modules
std::string exp = "(add-to-load-path \"" + path + "\")";
scm_c_eval_string (exp.c_str ());
}
-void load_dmaster_mods ()
+void
+load_dmaster_mods ()
{
scm_init_guile ();
scm_init_dungeon_master_module ();
along with Dungeon Master. If not, see <http://www.gnu.org/licenses/>.
*/
-void load_dmaster_mods ();
+void
+load_dmaster_mods ();
#include <unistd.h>
#include "paths.h"
-std::string get_exec_path ()
+std::string
+get_exec_path ()
{
char pBuf[256];
size_t len = sizeof (pBuf);
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;
}
-std::set<std::string> get_dmaster_paths () {
+std::set<std::string>
+get_dmaster_paths () {
std::set<std::string> paths;
paths.insert (get_exec_path ());
paths.insert (DATA_PATH);
#define PROGRAM_NAME "dmaster"
#endif
-std::set<std::string> get_dmaster_paths ();
+std::set<std::string>
+get_dmaster_paths ();