aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPerttu Ahola <celeron55@gmail.com>2013-03-21 21:42:23 +0200
committerPerttu Ahola <celeron55@gmail.com>2013-03-21 22:22:15 +0200
commitc2250d95c4da368d1535794a1c7f2092ce479d7a (patch)
tree3cb15d732e93b02986393eb005eeb3a3d7b3493d
parentadc52f3f3c041e5914f665b6f96d07f49bbb6487 (diff)
downloadminetest-c2250d95c4da368d1535794a1c7f2092ce479d7a.tar.gz
minetest-c2250d95c4da368d1535794a1c7f2092ce479d7a.tar.bz2
minetest-c2250d95c4da368d1535794a1c7f2092ce479d7a.zip
Support game-specific minetest.conf
-rw-r--r--doc/lua_api.txt3
-rw-r--r--src/defaultsettings.cpp9
-rw-r--r--src/defaultsettings.h1
-rw-r--r--src/server.cpp8
-rw-r--r--src/subgame.cpp6
-rw-r--r--src/subgame.h3
6 files changed, 30 insertions, 0 deletions
diff --git a/doc/lua_api.txt b/doc/lua_api.txt
index 19fa81473..af8b1cc9a 100644
--- a/doc/lua_api.txt
+++ b/doc/lua_api.txt
@@ -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:
diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp
index b0ae271ce..25edffe32 100644
--- a/src/defaultsettings.cpp
+++ b/src/defaultsettings.cpp
@@ -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));
+ }
+}
+
diff --git a/src/defaultsettings.h b/src/defaultsettings.h
index 37e3f717f..00aacad87 100644
--- a/src/defaultsettings.h
+++ b/src/defaultsettings.h
@@ -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
diff --git a/src/server.cpp b/src/server.cpp
index 2dcab63b8..f77ac6ad9 100644
--- a/src/server.cpp
+++ b/src/server.cpp
@@ -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);
diff --git a/src/subgame.cpp b/src/subgame.cpp
index 8678ae37f..19ad4e636 100644
--- a/src/subgame.cpp
+++ b/src/subgame.cpp
@@ -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";
diff --git a/src/subgame.h b/src/subgame.h
index 996714be0..b120b7542 100644
--- a/src/subgame.h
+++ b/src/subgame.h
@@ -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);