aboutsummaryrefslogtreecommitdiffstats
path: root/src/engine
diff options
context:
space:
mode:
Diffstat (limited to 'src/engine')
-rw-r--r--src/engine/renderer.cpp34
1 files changed, 30 insertions, 4 deletions
diff --git a/src/engine/renderer.cpp b/src/engine/renderer.cpp
index 0be0e53..0ec6371 100644
--- a/src/engine/renderer.cpp
+++ b/src/engine/renderer.cpp
@@ -10,6 +10,35 @@
#include <cmath>
#include <vector>
#include <algorithm>
+#include <string>
+#include <filesystem>
+
+namespace {
+
+// Root of a bring-your-own Forts install, used to resolve "forts:REL" texture
+// paths. Tries known developer install locations first, then the FORTS_DATA
+// override, and returns the first that exists on disk. Resolved once, cached.
+const std::string& forts_data_root() {
+ static const std::string root = [] {
+ std::vector<std::string> candidates = {
+ "/opt/steam/steamapps/common/Forts/data", // Emil
+ "/mnt/games/SteamLibrary/steamapps/common/Forts/data", // Vaino
+ };
+ if (const char* env = std::getenv("FORTS_DATA")) {
+ candidates.emplace_back(env);
+ }
+ for (const auto& c : candidates) {
+ std::error_code ec;
+ if (std::filesystem::is_directory(c, ec)) return c;
+ }
+ // None present; return the override if set, else the first guess, so the
+ // failed-load message at least points somewhere meaningful.
+ return candidates.back();
+ }();
+ return root;
+}
+
+} // namespace
bool Renderer::init(SDL_Window* window, int width, int height) {
width_ = width;
@@ -140,10 +169,7 @@ SDL_Texture* Renderer::load_texture(const std::string& path) {
// files, like a Doom source port + WAD). Nothing is copied into the repo.
std::string file = path;
if (path.rfind("forts:", 0) == 0) {
- const char* env = std::getenv("FORTS_DATA");
- std::string root = env ? env
- : "/mnt/games/SteamLibrary/steamapps/common/Forts/data";
- file = root + "/" + path.substr(6);
+ file = forts_data_root() + "/" + path.substr(6);
}
int w = 0, h = 0, n = 0;