Support game-specific minetest.conf
authorPerttu Ahola <celeron55@gmail.com>
Thu, 21 Mar 2013 19:42:23 +0000 (21:42 +0200)
committerPerttu Ahola <celeron55@gmail.com>
Thu, 21 Mar 2013 20:22:15 +0000 (22:22 +0200)
doc/lua_api.txt
src/defaultsettings.cpp
src/defaultsettings.h
src/server.cpp
src/subgame.cpp
src/subgame.h

index 19fa814738ccb953f617ba64c21b11e4698ed473..af8b1cc9a585a7a0db9f1cc3c07e84c2cc8983df 100644 (file)
@@ -57,6 +57,9 @@ eg.
 
 Common mods are loaded from the pseudo-game "common".
 
+The game directory can contain the file minetest.conf, which will be used
+to set default settings when running the particular game.
+
 Mod load path
 -------------
 Generic:
index b0ae271ce3fc478bc4b4fda27df932c4f366adbd..25edffe32571e3bed335ad3ea958ca741bd48f11 100644 (file)
@@ -243,3 +243,12 @@ void set_default_settings(Settings *settings)
 
 }
 
+void override_default_settings(Settings *settings, Settings *from)
+{
+       std::vector<std::string> names = from->getNames();
+       for(size_t i=0; i<names.size(); i++){
+               const std::string &name = names[i];
+               settings->setDefault(name, from->get(name));
+       }
+}
+
index 37e3f717f11232a675644815d8da944770f1bb3e..00aacad87f2d4dd142d163f7db8b1fcb55415936 100644 (file)
@@ -23,6 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 class Settings;
 
 void set_default_settings(Settings *settings);
+void override_default_settings(Settings *settings, Settings *from);
 
 #endif
 
index 2dcab63b8c2e1c6f225c4140af259e4af1ca8fde..f77ac6ad94906c1af98d1d3abb77484cb5f7940e 100644 (file)
@@ -58,6 +58,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "util/mathconstants.h"
 #include "rollback.h"
 #include "util/serialize.h"
+#include "defaultsettings.h"
 
 void * ServerThread::Thread()
 {
@@ -687,6 +688,13 @@ Server::Server(
        infostream<<"- config: "<<m_path_config<<std::endl;
        infostream<<"- game:   "<<m_gamespec.path<<std::endl;
 
+       // Initialize default settings and override defaults with those provided
+       // by the game
+       set_default_settings(g_settings);
+       Settings gamedefaults;
+       getGameMinetestConfig(gamespec.path, gamedefaults);
+       override_default_settings(g_settings, &gamedefaults);
+
        // Create biome definition manager
        m_biomedef = new BiomeDefManager(this);
 
index 8678ae37fd03fe3fa1ab3364ed7adceeb631bd66..19ad4e636be379fdd38171d175f72f42b49b455e 100644 (file)
@@ -24,6 +24,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "log.h"
 #include "util/string.h"
 
+bool getGameMinetestConfig(const std::string &game_path, Settings &conf)
+{
+       std::string conf_path = game_path + DIR_DELIM + "minetest.conf";
+       return conf.readConfigFile(conf_path.c_str());
+}
+
 bool getGameConfig(const std::string &game_path, Settings &conf)
 {
        std::string conf_path = game_path + DIR_DELIM + "game.conf";
index 996714be04accb6bb3c9ce285ec9990a7e8947a4..b120b75425482d8d5ee1e43dd54611734a63942b 100644 (file)
@@ -54,6 +54,9 @@ struct SubgameSpec
        }
 };
 
+// minetest.conf
+bool getGameMinetestConfig(const std::string &game_path, Settings &conf);
+// game.conf
 bool getGameConfig(const std::string &game_path, Settings &conf);
 
 std::string getGameName(const std::string &game_path);