X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fapp%2Fruntime.cpp;h=f51a0cd620d48921fa01c9bd1b53070a0a5ed925;hb=fd86376a8e7d3f1b09be3d018f772ef884937238;hp=780a063fc1c3b27e1f15599dd47c32bfcbc37393;hpb=78a290bd642c5578c9dd17481c8164ff50889ca2;p=blank.git diff --git a/src/app/runtime.cpp b/src/app/runtime.cpp index 780a063..f51a0cd 100644 --- a/src/app/runtime.cpp +++ b/src/app/runtime.cpp @@ -12,6 +12,7 @@ #include #include +#include #include #include #include @@ -74,6 +75,10 @@ void Config::Load(std::istream &is) { int port; in.ReadNumber(port); net.port = port; + } else if (name == "net.cmd_port") { + int port; + in.ReadNumber(port); + net.cmd_port = port; } else if (name == "player.name") { in.ReadString(player.name); } else if (name == "video.dblbuf") { @@ -103,13 +108,14 @@ void Config::Save(std::ostream &out) { out << "input.yaw_sensitivity = " << input.yaw_sensitivity << ';' << std::endl; out << "net.host = \"" << net.host << "\";" << std::endl; out << "net.port = " << net.port << ';' << std::endl; + out << "net.cmd_port = " << net.cmd_port << ';' << std::endl; 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 +175,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]; @@ -232,6 +245,14 @@ void Runtime::ReadArgs(int argc, const char *const *argv) { } else { config.game.net.port = strtoul(argv[i], nullptr, 10); } + } else if (strcmp(param, "cmd-port") == 0) { + ++i; + if (i >= argc || argv[i] == nullptr || argv[i][0] == '\0') { + cerr << "missing argument to --cmd-port" << endl; + error = true; + } else { + config.game.net.cmd_port = strtoul(argv[i], nullptr, 10); + } } else if (strcmp(param, "player-name") == 0) { ++i; if (i >= argc || argv[i] == nullptr || argv[i][0] == '\0') { @@ -324,36 +345,45 @@ 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; } if (config.env.asset_path.empty()) { config.env.asset_path = default_asset_path(); } else if ( - config.env.asset_path[config.env.asset_path.size() - 1] != '/' && - config.env.asset_path[config.env.asset_path.size() - 1] != '\\' + config.env.asset_path.back() != '/' && + config.env.asset_path.back() != '\\' ) { config.env.asset_path += '/'; } if (config.env.save_path.empty()) { config.env.save_path = default_save_path(); } else if ( - config.env.save_path[config.env.save_path.size() - 1] != '/' && - config.env.save_path[config.env.save_path.size() - 1] != '\\' + config.env.save_path.back() != '/' && + config.env.save_path.back() != '\\' ) { 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; +void Runtime::ReadPreferences() { + 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); } }