X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fapp%2Fruntime.cpp;h=c80fa765998069a185556e6ad2bdde046d73bc82;hb=4727825186798902f68df5b99a6a32f0ef618454;hp=7a489e6e21e542d1cdf843685ca34e6c048cbb6e;hpb=561047fd00bb427455a6d3a8dc02573c074b01ee;p=blank.git diff --git a/src/app/runtime.cpp b/src/app/runtime.cpp index 7a489e6..c80fa76 100644 --- a/src/app/runtime.cpp +++ b/src/app/runtime.cpp @@ -12,6 +12,7 @@ #include #include +#include #include #include #include @@ -106,10 +107,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; } @@ -117,8 +118,17 @@ HeadlessEnvironment::HeadlessEnvironment(const Config &config) : config(config) , loader(config.asset_path) , counter() -, state() { - +, state() +, rng( +#ifdef BLANK_PROFILING +0 +#else +std::time(nullptr) +#endif +){ + for (int i = 0; i < 4; ++i) { + rng.Next(); + } } string HeadlessEnvironment::Config::GetWorldPath(const string &world_name) const { @@ -135,7 +145,8 @@ Environment::Environment(Window &win, const Config &config) , audio() , viewport() , window(win) -, keymap() { +, keymap() +, msg_state(*this) { viewport.Clear(); window.Flip(); keymap.LoadDefault(); @@ -150,6 +161,12 @@ Environment::Environment(Window &win, const Config &config) } } +void Environment::ShowMessage(const char *msg) { + cout << msg << endl; + msg_state.SetMessage(msg); + state.Push(&msg_state); +} + Runtime::Runtime() noexcept : name("blank") @@ -162,6 +179,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]; @@ -317,9 +341,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 ( @@ -337,16 +372,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); } }