]> git.localhorst.tv Git - blank.git/commitdiff
configurable asset and save path
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Sun, 9 Aug 2015 16:26:20 +0000 (18:26 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Sun, 9 Aug 2015 18:18:40 +0000 (20:18 +0200)
.gitignore
Makefile
running
src/app/Environment.hpp
src/app/Runtime.hpp
src/app/runtime.cpp

index 4c408d07a9981a8d424fea5fb51cd1547939e4fc..eeb54651b6fc17257878a9a8ce4acb0206e1f3fc 100644 (file)
@@ -7,3 +7,4 @@ blank.test
 build
 cachegrind.out.*
 callgrind.out.*
+saves
index d2e76cadf7d3e3f2dfb426d9790edc5ada08183e..5989839db7a74d8935dd755e3c0c94a4b9dc2668 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -62,20 +62,20 @@ profile: $(PROFILE_BIN)
 tests: $(TEST_BIN)
 
 run: $(ASSET_DEP) blank
-       ./blank
+       ./blank --save-path saves/
 
 gdb: $(ASSET_DEP) blank.debug
        gdb ./blank.debug
 
 cachegrind: $(ASSET_DEP) blank.profile
-       valgrind ./blank.profile
+       valgrind ./blank.profile --save-path saves/
 
 callgrind: $(ASSET_DEP) blank.profile
        valgrind --tool=callgrind \
                --branch-sim=yes --cacheuse=yes --cache-sim=yes \
                --collect-bus=yes --collect-systime=yes --collect-jumps=yes \
                --dump-instr=yes --simulate-hwpref=yes --simulate-wb=yes \
-               ./blank.profile -n 128 -t 16 --no-keyboard --no-mouse -d --no-vsync
+               ./blank.profile -n 128 -t 16 --no-keyboard --no-mouse -d --no-vsync --save-path saves/
 
 test: blank.test
        ./blank.test
diff --git a/running b/running
index d4019d5675ad6fe0c890e00eba470a74a92b8977..d3a632e35501d20a600ba08135577a025c1813c2 100644 (file)
--- a/running
+++ b/running
@@ -13,6 +13,15 @@ Runtime
 if both n and t are given, terminate after n frames and
 assume <t> milliseconds pass each frame
 
+--asset-path <path>
+       load assets from given path
+       default is application dir + "assets"
+
+--save-path <path>
+       store and load saves at given path
+       default is whatever SDL thinks is good
+       (should be ~/.local/share/localhorst/blank/)
+
 Application
 -----------
 
@@ -45,8 +54,9 @@ Interface
 World
 -----
 
-blank -s <seed>
-       use <seed> (unsigned integer) as the world seed. default is 0
+-s <seed>
+       use <seed> (unsigned integer) as the world seed
+       default is 0
 
 
 Controls
index b465bfb48f19c88e7e157e68b3f5c9f2e10ca66d..b9dcc2900f97760f92e6948a7434619252756330 100644 (file)
@@ -7,6 +7,8 @@
 #include "../audio/Audio.hpp"
 #include "../graphics/Viewport.hpp"
 
+#include <string>
+
 
 namespace blank {
 
@@ -24,7 +26,7 @@ struct Environment {
        StateControl state;
 
 
-       explicit Environment(Window &win);
+       explicit Environment(Window &win, const std::string &asset_path);
 
 };
 
index 036b8dbfc635ef9078454036113626b2b79266b0..ac508b90677bf8fbe5d19e44c7111bc2c55456a5 100644 (file)
@@ -5,6 +5,7 @@
 #include "../world/World.hpp"
 
 #include <cstddef>
+#include <string>
 
 
 namespace blank {
@@ -31,6 +32,9 @@ public:
                bool doublebuf = true;
                int multisampling = 1;
 
+               std::string asset_path;
+               std::string save_path;
+
                Interface::Config interface = Interface::Config();
                World::Config world = World::Config();
        };
index eaeea8dd85c5c8940074fb4792e50e58271ec3e8..5dce72159a439203843581f84cb14fc86fdda08a 100644 (file)
@@ -16,7 +16,7 @@ using namespace std;
 
 namespace {
 
-string get_asset_path() {
+string default_asset_path() {
        char *base = SDL_GetBasePath();
        string assets(base);
        assets += "assets/";
@@ -24,15 +24,30 @@ string get_asset_path() {
        return assets;
 }
 
+string default_save_path() {
+#ifndef NDEBUG
+       char *base = SDL_GetBasePath();
+       string save(base);
+       save += "saves/";
+       SDL_free(base);
+       return save;
+#else
+       char *pref = SDL_GetPrefPath("localhorst", "blank");
+       string save(pref);
+       SDL_free(pref);
+       return save;
+#endif
+}
+
 }
 
 namespace blank {
 
-Environment::Environment(Window &win)
+Environment::Environment(Window &win, const string &asset_path)
 : audio()
 , viewport()
 , window(win)
-, assets(get_asset_path())
+, assets(asset_path)
 , counter() {
 
 }
@@ -69,17 +84,34 @@ void Runtime::ReadArgs(int argc, const char *const *argv) {
                                        // stopper
                                        options = false;
                                } else {
+                                       const char *param = arg + 2;
                                        // long option
-                                       if (strcmp(arg + 2, "no-vsync") == 0) {
+                                       if (strcmp(param, "no-vsync") == 0) {
                                                config.vsync = false;
-                                       } else if (strcmp(arg + 2, "no-keyboard") == 0) {
+                                       } else if (strcmp(param, "no-keyboard") == 0) {
                                                config.interface.keyboard_disabled = true;
-                                       } else if (strcmp(arg + 2, "no-mouse") == 0) {
+                                       } else if (strcmp(param, "no-mouse") == 0) {
                                                config.interface.mouse_disabled = true;
-                                       } else if (strcmp(arg + 2, "no-hud") == 0) {
+                                       } else if (strcmp(param, "no-hud") == 0) {
                                                config.interface.visual_disabled = true;
-                                       } else if (strcmp(arg + 2, "no-audio") == 0) {
+                                       } else if (strcmp(param, "no-audio") == 0) {
                                                config.interface.audio_disabled = true;
+                                       } else if (strcmp(param, "asset-path") == 0) {
+                                               ++i;
+                                               if (i >= argc || argv[i] == nullptr || argv[i][0] == '\0') {
+                                                       cerr << "missing argument to --asset-path" << endl;
+                                                       error = true;
+                                               } else {
+                                                       config.asset_path = argv[i];
+                                               }
+                                       } else if (strcmp(param, "save-path") == 0) {
+                                               ++i;
+                                               if (i >= argc || argv[i] == nullptr || argv[i][0] == '\0') {
+                                                       cerr << "missing argument to --save-path" << endl;
+                                                       error = true;
+                                               } else {
+                                                       config.save_path = argv[i];
+                                               }
                                        } else {
                                                cerr << "unknown option " << arg << endl;
                                                error = true;
@@ -152,6 +184,23 @@ void Runtime::ReadArgs(int argc, const char *const *argv) {
                return;
        }
 
+       if (config.asset_path.empty()) {
+               config.asset_path = default_asset_path();
+       } else if (
+               config.asset_path[config.asset_path.size() - 1] != '/' &&
+               config.asset_path[config.asset_path.size() - 1] != '\\'
+       ) {
+               config.asset_path += '/';
+       }
+       if (config.save_path.empty()) {
+               config.save_path = default_save_path();
+       } else if (
+               config.save_path[config.save_path.size() - 1] != '/' &&
+               config.save_path[config.save_path.size() - 1] != '\\'
+       ) {
+               config.save_path += '/';
+       }
+
        if (n > 0) {
                if (t > 0) {
                        mode = FIXED_FRAME_LIMIT;
@@ -172,7 +221,7 @@ int Runtime::Execute() {
 
        Init init(config.doublebuf, config.multisampling);
 
-       Environment env(init.window);
+       Environment env(init.window, config.asset_path);
        env.viewport.VSync(config.vsync);
 
        Application app(env);