diff options
Diffstat (limited to 'src/engine.cpp')
| -rw-r--r-- | src/engine.cpp | 27 |
1 files changed, 11 insertions, 16 deletions
diff --git a/src/engine.cpp b/src/engine.cpp index a9991c4..1f57bd7 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -194,7 +194,7 @@ static void render_software(Renderer<FrameBuffer, Shaders>& renderer, const Matr #ifdef HAVE_NCURSES #define MKEY_ESC 27 -static int main_term(const std::filesystem::path& files_root, Scene& scene) { +static int main_term(const engine::path_utils::Paths& paths, Scene& scene) { // init std::setlocale(LC_ALL, ""); initscr(); @@ -206,7 +206,7 @@ static int main_term(const std::filesystem::path& files_root, Scene& scene) { curs_set(0); int texture_w, texture_h, texture_channels; - const auto texture_path = std::filesystem::path(files_root).append(ASSETS_TEXTURES_DIR "/viking_room.png"); + const auto texture_path = paths.assets_textures() / "viking_room.png"; #ifdef _WIN32 const auto texture_path_wcstr = texture_path.c_str(); const auto texture_path_cstr_size = stbi_convert_wchar_to_utf8(nullptr, 0, texture_path_wcstr); @@ -907,7 +907,7 @@ static void generate_mipmaps(VkCommandBuffer cmd_buf, VkPhysicalDevice physical_ } } -static int main_graphical(const std::filesystem::path& files_root, Scene& scene) { +static int main_graphical(const engine::path_utils::Paths& paths, Scene& scene) { // init window glfwInit(); glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); @@ -1581,7 +1581,7 @@ static int main_graphical(const std::filesystem::path& files_root, Scene& scene) // reading shader file auto shader_module = [&] { auto shader_code = [&] { - const auto shader_path = std::filesystem::path(files_root).append(SHADERS_DIR "/shader.spv"); + const auto shader_path = paths.spvshaders() / "shader.spv"; const auto shader_file_name = shader_path.c_str(); std::ifstream shader_file(shader_file_name, std::ios::ate | std::ios::binary); if (!shader_file.is_open()) { @@ -1832,7 +1832,7 @@ static int main_graphical(const std::filesystem::path& files_root, Scene& scene) // create texture image auto [texture_img, texture_mip_lvls, texture_img_device_mem, texture_w, texture_h, texture_pixels] = [&] { int w, h, channels; - const auto texture_path = std::filesystem::path(files_root).append(ASSETS_TEXTURES_DIR "/viking_room.png"); + const auto texture_path = paths.assets_textures() / "viking_room.png"; #ifdef _WIN32 const auto texture_path_wcstr = texture_path.c_str(); const auto texture_path_cstr_size = stbi_convert_wchar_to_utf8(nullptr, 0, texture_path_wcstr); @@ -2892,12 +2892,7 @@ static void parse_args(const std::vector<std::string_view>& args, Mode& mode) { } int main(int argc, char *argv[]) { - const auto exe_path_opt = engine::path_utils::exe_path(); - if (!exe_path_opt) { - std::cerr << "cannot find path of executable" << std::endl; - exit(1); - } - const auto files_root = (*exe_path_opt).parent_path(); + const auto paths = engine::path_utils::Paths(); Mode mode = Mode::graphical; parse_args(convert_args(argc, argv), mode); @@ -2920,7 +2915,7 @@ int main(int argc, char *argv[]) { case GameType::suzanne: return { { - engine::parse_object(std::filesystem::path(files_root).append(ASSETS_OBJS_DIR "/suzanne.obj")), + engine::parse_object(paths.assets_objs() / "suzanne.obj"), { Vector3(0.f, 0.f, 0.f), Quaternion::one(), @@ -2939,7 +2934,7 @@ int main(int argc, char *argv[]) { } }, { - engine::parse_object(std::filesystem::path(files_root).append(ASSETS_OBJS_DIR "/suzanne.obj")), + engine::parse_object(paths.assets_objs() / "suzanne.obj"), { Vector3(0.f, 1.f, 0.f), Quaternion::one(), @@ -2950,7 +2945,7 @@ int main(int argc, char *argv[]) { case GameType::test: return { { - engine::parse_object(std::filesystem::path(files_root).append(ASSETS_OBJS_DIR "/viking_room.obj")), + engine::parse_object(paths.assets_objs() / "viking_room.obj"), { Vector3(0.f, .5f, 0.f), Quaternion::look_towards({ -1.f, 0.f, 0.f }, { 0.f, 0.f, 1.f }).conjugate(), @@ -2969,13 +2964,13 @@ int main(int argc, char *argv[]) { return EXIT_SUCCESS; case Mode::term: #ifdef HAVE_NCURSES - return main_term(files_root, scene); + return main_term(paths, scene); #else std::cerr << "Error: ncurses was not enabled during compilation." << std::endl; return EXIT_FAILURE; #endif case Mode::graphical: - return main_graphical(files_root, scene); + return main_graphical(paths, scene); default: std::unreachable(); } |
