From: Daniel Karbach Date: Mon, 5 Oct 2015 15:32:01 +0000 (+0200) Subject: read preferences from user config file X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=78dcbeb7a905c4c153cb1b20e23f5adc1efc6d7e;p=blank.git read preferences from user config file --- diff --git a/src/app/Runtime.hpp b/src/app/Runtime.hpp index 2d169d0..1e660e0 100644 --- a/src/app/Runtime.hpp +++ b/src/app/Runtime.hpp @@ -48,11 +48,14 @@ public: Runtime() noexcept; - void ReadArgs(int argc, const char *const *argv); + void Initialize(int argc, const char *const *argv); int Execute(); private: + void ReadArgs(int argc, const char *const *argv); + void ReadPreferences(); + void RunStandalone(); void RunServer(); void RunClient(); diff --git a/src/app/runtime.cpp b/src/app/runtime.cpp index 780a063..22ca920 100644 --- a/src/app/runtime.cpp +++ b/src/app/runtime.cpp @@ -106,10 +106,10 @@ void Config::Save(std::ostream &out) { out << "player.name = \"" << player.name << "\";" << std::endl; out << "video.dblbuf = " << (video.dblbuf ? "on" : "off") << ';' << std::endl; out << "video.vsync = " << (video.vsync ? "on" : "off") << ';' << std::endl; - out << "video.msaa = " << net.port << ';' << std::endl; + out << "video.msaa = " << video.msaa << ';' << std::endl; out << "video.hud = " << (video.hud ? "on" : "off") << ';' << std::endl; out << "video.world = " << (video.world ? "on" : "off") << ';' << std::endl; - out << "video.debug = " << (video.world ? "on" : "off") << ';' << std::endl; + out << "video.debug = " << (video.debug ? "on" : "off") << ';' << std::endl; } @@ -169,6 +169,13 @@ Runtime::Runtime() noexcept } +void Runtime::Initialize(int argc, const char *const *argv) { + ReadArgs(argc, argv); + if (mode == ERROR) return; + ReadPreferences(); + ReadArgs(argc, argv); +} + void Runtime::ReadArgs(int argc, const char *const *argv) { if (argc <= 0) return; name = argv[0]; @@ -324,9 +331,20 @@ void Runtime::ReadArgs(int argc, const char *const *argv) { if (error) { mode = ERROR; - return; + } else if (n > 0) { + if (t > 0) { + mode = FIXED_FRAME_LIMIT; + } else { + mode = FRAME_LIMIT; + } + } else if (t > 0) { + mode = TIME_LIMIT; + } else { + mode = NORMAL; } +} +void Runtime::ReadPreferences() { if (config.env.asset_path.empty()) { config.env.asset_path = default_asset_path(); } else if ( @@ -344,16 +362,14 @@ void Runtime::ReadArgs(int argc, const char *const *argv) { config.env.save_path += '/'; } - if (n > 0) { - if (t > 0) { - mode = FIXED_FRAME_LIMIT; - } else { - mode = FRAME_LIMIT; - } - } else if (t > 0) { - mode = TIME_LIMIT; + string prefs_path = config.env.save_path + "prefs.conf"; + if (is_file(prefs_path)) { + ifstream file(prefs_path); + config.game.Load(file); } else { - mode = NORMAL; + make_dirs(config.env.save_path); + ofstream file(prefs_path); + config.game.Save(file); } } diff --git a/src/blank.cpp b/src/blank.cpp index d11ee9b..2c3c40d 100644 --- a/src/blank.cpp +++ b/src/blank.cpp @@ -4,6 +4,6 @@ using namespace blank; int main(int argc, char *argv[]) { Runtime rt; - rt.ReadArgs(argc, argv); + rt.Initialize(argc, argv); return rt.Execute(); }