]> git.localhorst.tv Git - blank.git/commitdiff
config IO
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Tue, 29 Sep 2015 15:48:44 +0000 (17:48 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Tue, 29 Sep 2015 15:48:44 +0000 (17:48 +0200)
src/app/Config.hpp
src/app/runtime.cpp

index 4beb0627b6d609405e1ef0765b0553c68fff6918..5261a44281334c180b63b0889710c867a54d8c03 100644 (file)
@@ -2,6 +2,7 @@
 #define BLANK_APP_CONFIG_HPP_
 
 #include <cstdint>
+#include <iosfwd>
 #include <string>
 
 
@@ -50,6 +51,9 @@ struct Config {
 
        } video;
 
+       void Load(std::istream &);
+       void Save(std::ostream &);
+
 };
 
 }
index a7beeb0f64c0e7e732809e69ccafaa2e56fc5868..7a489e6e21e542d1cdf843685ca34e6c048cbb6e 100644 (file)
@@ -5,6 +5,7 @@
 #include "init.hpp"
 #include "../client/MasterState.hpp"
 #include "../io/filesystem.hpp"
+#include "../io/TokenStreamReader.hpp"
 #include "../io/WorldSave.hpp"
 #include "../server/ServerState.hpp"
 #include "../standalone/MasterState.hpp"
@@ -47,6 +48,71 @@ string default_save_path() {
 
 namespace blank {
 
+void Config::Load(std::istream &is) {
+       TokenStreamReader in(is);
+       std::string name;
+       while (in.HasMore()) {
+               if (in.Peek().type == Token::STRING) {
+                       in.ReadString(name);
+               } else {
+                       in.ReadIdentifier(name);
+               }
+               in.Skip(Token::EQUALS);
+               if (name == "audio.enabled") {
+                       in.ReadBoolean(audio.enabled);
+               } else if (name == "input.keyboard") {
+                       in.ReadBoolean(input.keyboard);
+               } else if (name == "input.mouse") {
+                       in.ReadBoolean(input.mouse);
+               } else if (name == "input.pitch_sensitivity") {
+                       in.ReadNumber(input.pitch_sensitivity);
+               } else if (name == "input.yaw_sensitivity") {
+                       in.ReadNumber(input.yaw_sensitivity);
+               } else if (name == "net.host") {
+                       in.ReadString(net.host);
+               } else if (name == "net.port") {
+                       int port;
+                       in.ReadNumber(port);
+                       net.port = port;
+               } else if (name == "player.name") {
+                       in.ReadString(player.name);
+               } else if (name == "video.dblbuf") {
+                       in.ReadBoolean(video.dblbuf);
+               } else if (name == "video.vsync") {
+                       in.ReadBoolean(video.vsync);
+               } else if (name == "video.msaa") {
+                       in.ReadNumber(video.msaa);
+               } else if (name == "video.hud") {
+                       in.ReadBoolean(video.hud);
+               } else if (name == "video.world") {
+                       in.ReadBoolean(video.world);
+               } else if (name == "video.debug") {
+                       in.ReadBoolean(video.debug);
+               }
+               if (in.HasMore() && in.Peek().type == Token::SEMICOLON) {
+                       in.Skip(Token::SEMICOLON);
+               }
+       }
+}
+
+void Config::Save(std::ostream &out) {
+       out << "audio.enabled = " << (audio.enabled ? "yes" : "no") << ';' << std::endl;
+       out << "input.keyboard = " << (input.keyboard ? "on" : "off") << ';' << std::endl;
+       out << "input.mouse = " << (input.keyboard ? "on" : "off") << ';' << std::endl;
+       out << "input.pitch_sensitivity = " << input.pitch_sensitivity << ';' << std::endl;
+       out << "input.yaw_sensitivity = " << input.yaw_sensitivity << ';' << std::endl;
+       out << "net.host = \"" << net.host << "\";" << std::endl;
+       out << "net.port = " << net.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.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;
+}
+
+
 HeadlessEnvironment::HeadlessEnvironment(const Config &config)
 : config(config)
 , loader(config.asset_path)