diff options
| author | hachem <im@hachem.wtf> | 2026-09-22 06:57:16 +0200 |
|---|---|---|
| committer | hachem <im@hachem.wtf> | 2026-09-22 06:57:16 +0200 |
| commit | d7c1ced08d5d78fcb239550404db4e67d4357a19 (patch) | |
| tree | 9c0e218b096d138075cbf6a48e2562d33a8f94ed /src/main.cpp | |
| parent | 270eda6f558c972ec86ad0580f1d3d18afc83a94 (diff) | |
Diffstat (limited to 'src/main.cpp')
| -rw-r--r-- | src/main.cpp | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/src/main.cpp b/src/main.cpp index a59cf8b..c813278 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,8 +1,30 @@ #include "core/application.h" -int main() +#include <filesystem> + +// every asset path is relative to the repo root, but a double-clicked exe (or a +// ./bin/<cfg>/donut from elsewhere) starts wherever the launcher put it. walk up +// from `start` until assets/shaders shows up and run from there. +static auto chdir_to_project_root(std::filesystem::path start) -> bool +{ + namespace fs = std::filesystem; + std::error_code ec; + for (fs::path p = start; !p.empty(); p = p.parent_path()) + { + if (fs::exists(p / "assets" / "shaders", ec)) { fs::current_path(p, ec); return !ec; } + if (p == p.root_path()) break; + } + return false; +} + +int main(int /*argc*/, char** argv) { + // the cwd first (the normal case), then wherever the exe itself lives. if both + // miss, the loaders complain with the cwd in the message. + std::error_code ec; + if (!chdir_to_project_root(std::filesystem::current_path(ec)) && argv && argv[0]) + chdir_to_project_root(std::filesystem::absolute(argv[0], ec).parent_path()); Donut::Application* app = new Donut::Application("Donut Engine - Black Hole Simulation", 1280, 720); app->run(); delete app; -}
\ No newline at end of file +} |
