From 523b27e38c0978f6513c95f90582e7e5ab160e3d Mon Sep 17 00:00:00 2001 From: vimene Date: Mon, 16 Feb 2026 11:45:19 +0100 Subject: small improvements --- .gitignore | 1 + Makefile.am | 2 +- README.md | 2 +- src/Makefile.am | 3 ++- src/engine.cpp | 2 +- src/path_utils.cpp | 19 ++++++++++++------- src/path_utils.hpp | 8 ++++++-- src/spvshaders/Makefile.am | 4 ++-- 8 files changed, 26 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index ec09064..243bc3d 100644 --- a/.gitignore +++ b/.gitignore @@ -28,5 +28,6 @@ Makefile.in /autoscan.log # vim +.vimrc .*.swp *~ diff --git a/Makefile.am b/Makefile.am index 6e7a500..ab4961a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,4 +1,4 @@ -include common.am +include $(top_srcdir)/common.am SUBDIRS = src src/spvshaders EXTRA_DIST = m4/NOTES diff --git a/README.md b/README.md index 2141e3f..717aebf 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Small graphics engine. ## Usage :::text - Usage: ./engine [-htg] [--help] [--term] [--graphical] + Usage: engine [-htg] [--help] [--term] [--graphical] -h, --help show usage (this) -t, --term terminal mode -g, --graphical graphical mode (default) diff --git a/src/Makefile.am b/src/Makefile.am index 00e76ac..1239928 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,4 +1,4 @@ -include ../common.am +include $(top_srcdir)/common.am bin_PROGRAMS = engine @@ -46,6 +46,7 @@ engine_CPPFLAGS = -std=gnu++23 -Wall -Wextra -I'$(srcdir)/src' \ -DBINDIR='"$(BINDIR_CXX)"' \ -DPKGDATADIR='"$(PKGDATADIR_CXX)"' \ -DSPVSHADERSDIR='"$(SPVSHADERSDIR_CXX)"' \ + -DEXENAME='"engine$(EXEEXT)"' \ $(GLFW3_CFLAGS) $(VULKAN_CFLAGS) if !DEBUG engine_CPPFLAGS += -DNDEBUG diff --git a/src/engine.cpp b/src/engine.cpp index 1f57bd7..0876932 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -100,7 +100,7 @@ enum class GameType { constexpr GameType game_type { GameType::test }; static void print_usage(std::ostream& output_stream) { - output_stream << "Usage: ./engine [-htg] [--help] [--term] [--graphical]\n" + output_stream << "Usage: " EXENAME " [-htg] [--help] [--term] [--graphical]\n" << " -h, --help show usage (this)\n" << " -t, --term terminal mode\n" << " -g, --graphical graphical mode (default)\n" diff --git a/src/path_utils.cpp b/src/path_utils.cpp index 94bbba5..50c70cd 100644 --- a/src/path_utils.cpp +++ b/src/path_utils.cpp @@ -7,7 +7,7 @@ # include #endif -std::optional engine::path_utils::exe_path() noexcept { +std::optional engine::path_utils::exe() noexcept { #if defined(_WIN32) TCHAR filename[MAX_PATH]; if (!GetModuleFileName(NULL, filename, MAX_PATH)) @@ -21,14 +21,19 @@ std::optional engine::path_utils::exe_path() noexcept { } engine::path_utils::Paths::Paths() noexcept { - const auto exe_path_opt = engine::path_utils::exe_path(); - if (!exe_path_opt) { + const auto exe_opt = engine::path_utils::exe(); + if (!exe_opt) { std::cerr << "cannot find path of executable" << std::endl; exit(1); } - const auto files_root = (*exe_path_opt).parent_path(); + m_exe = *exe_opt; - m_assets_objs = files_root / std::filesystem::relative(PKGDATADIR "/assets/objs", BINDIR); - m_assets_textures = files_root / std::filesystem::relative(PKGDATADIR "/assets/textures", BINDIR); - m_spvshaders = files_root / std::filesystem::relative(SPVSHADERSDIR, BINDIR); + const auto files_root = m_exe.parent_path(); + const auto bin = std::filesystem::weakly_canonical(BINDIR); + const std::filesystem::path pkgdata { PKGDATADIR }; + const auto assets = pkgdata / "assets"; + + m_assets_objs = std::filesystem::canonical(files_root / std::filesystem::weakly_canonical(assets / "objs") .lexically_relative(bin)); + m_assets_textures = std::filesystem::canonical(files_root / std::filesystem::weakly_canonical(assets / "textures").lexically_relative(bin)); + m_spvshaders = std::filesystem::canonical(files_root / std::filesystem::weakly_canonical(SPVSHADERSDIR) .lexically_relative(bin)); } diff --git a/src/path_utils.hpp b/src/path_utils.hpp index 76567bc..2594206 100644 --- a/src/path_utils.hpp +++ b/src/path_utils.hpp @@ -6,12 +6,16 @@ namespace engine::path_utils { -std::optional exe_path() noexcept; +std::optional exe() noexcept; class Paths { public: Paths() noexcept; + const std::filesystem::path& exe() const & noexcept { + return m_exe; + } + const std::filesystem::path& assets_objs() const & noexcept { return m_assets_objs; } @@ -25,7 +29,7 @@ class Paths { } private: - std::filesystem::path m_assets_objs, m_assets_textures, m_spvshaders; + std::filesystem::path m_exe, m_assets_objs, m_assets_textures, m_spvshaders; }; } diff --git a/src/spvshaders/Makefile.am b/src/spvshaders/Makefile.am index 5a5a362..c707798 100644 --- a/src/spvshaders/Makefile.am +++ b/src/spvshaders/Makefile.am @@ -1,7 +1,7 @@ -include ../../common.am +include $(top_srcdir)/common.am spvshaders_DATA = shader.spv -CLEANFILES = shader.spv +CLEANFILES = $(spvshaders_DATA) shader_spv_SLANGFLAGS = -target spirv -profile spirv_1_4 -emit-spirv-directly -fvk-use-entrypoint-name -entry vert_main -entry frag_main -- cgit v1.2.3