From 6c1096fbb8432320d76027d731aa1f23a60928fe Mon Sep 17 00:00:00 2001 From: portersky <24420859+portersky@users.noreply.github.com> Date: Wed, 6 May 2026 00:50:09 +0200 Subject: [PATCH] refactor: move scenes to dedicated CMakeLists.txt + clean arg parsing help - Extract scenes_cube/scenes_sphere (and convenience 'scenes' interface) to scenes/CMakeLists.txt. - Main CMakeLists.txt now much cleaner (single add_subdirectory(scenes)). - Updated help text in cuber.cpp to clearly separate Flags vs Keys (less confusing 'S' section). - No behavior change; depth/viewport/state/post-processing fixes from earlier remain. Followed project conventions and AGENTS.md commit rules. --- CMakeLists.txt | 22 ++-------------------- cuber.cpp | 11 +++++++---- scenes/CMakeLists.txt | 17 +++++++++++++++++ 3 files changed, 26 insertions(+), 24 deletions(-) create mode 100644 scenes/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 152031e..f28ae54 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,25 +46,7 @@ target_compile_options(cbt_scene PRIVATE ${BASE_OPTIONS}) target_compile_definitions(cbt_scene PRIVATE ${BASE_DEFINITIONS}) target_link_libraries(cbt_scene PUBLIC cbt_opengl) -# Application scenes -add_library(scenes_cube STATIC - "scenes/cube.cpp" -) -target_include_directories(scenes_cube PRIVATE ".") -target_compile_features(scenes_cube PRIVATE cxx_std_23) -target_compile_options(scenes_cube PRIVATE ${BASE_OPTIONS}) -target_compile_definitions(scenes_cube PRIVATE ${BASE_DEFINITIONS}) -target_link_libraries(scenes_cube PUBLIC cbt_scene glm::glm) - -# Sphere scene -add_library(scenes_sphere STATIC - "scenes/sphere.cpp" -) -target_include_directories(scenes_sphere PRIVATE ".") -target_compile_features(scenes_sphere PRIVATE cxx_std_23) -target_compile_options(scenes_sphere PRIVATE ${BASE_OPTIONS}) -target_compile_definitions(scenes_sphere PRIVATE ${BASE_DEFINITIONS}) -target_link_libraries(scenes_sphere PUBLIC cbt_scene glm::glm) +add_subdirectory(scenes) # Main executable add_executable(cuber "cuber.cpp") @@ -72,4 +54,4 @@ target_include_directories(cuber PRIVATE ".") target_compile_features(cuber PRIVATE cxx_std_23) target_compile_options(cuber PRIVATE ${BASE_OPTIONS}) target_compile_definitions(cuber PRIVATE ${BASE_DEFINITIONS}) -target_link_libraries(cuber PRIVATE cbt_scene scenes_cube scenes_sphere asio::asio ${BASE_LIBRARIES}) +target_link_libraries(cuber PRIVATE cbt_scene scenes asio::asio ${BASE_LIBRARIES}) diff --git a/cuber.cpp b/cuber.cpp index 64a7c00..54d387a 100644 --- a/cuber.cpp +++ b/cuber.cpp @@ -17,18 +17,21 @@ auto main(int argc, char const* argv[]) -> int { float max_duration_seconds = 0.0f; - std::string_view scene_name = "cube"; + std::string scene_name = "cube"; // "cube", "sphere", or "2" (for compatibility with keys) bool take_screenshot = false; for (int i = 1; i < argc; ++i) { std::string_view arg = argv[i]; if (arg == "--help" || arg == "-h") { fmt::print("Usage: {} [options]\n", argv[0]); + fmt::print("Flags:\n"); fmt::print(" --duration Auto-terminate after N seconds (for testing/CI)\n"); fmt::print(" --scene Select initial scene (default: cube)\n"); fmt::print(" --screenshot Render one frame, save screenshot, and exit\n"); - fmt::print(" S key Take screenshot (saved as screenshot.png)\n"); - fmt::print(" 1/2 key Switch between cube/sphere scene\n"); + fmt::print("\nKeys (during runtime):\n"); + fmt::print(" S Take screenshot (saved as screenshot.png)\n"); + fmt::print(" 1/2 Switch between cube/sphere scene\n"); + fmt::print(" Q Quit\n"); return 0; } if (arg == "--duration" && i + 1 < argc) { @@ -36,7 +39,7 @@ auto main(int argc, char const* argv[]) -> int { continue; } if (arg == "--scene" && i + 1 < argc) { - scene_name = argv[++i]; + scene_name = argv[++i]; // std::string to avoid string_view lifetime gotchas with argv continue; } if (arg == "--screenshot") { diff --git a/scenes/CMakeLists.txt b/scenes/CMakeLists.txt new file mode 100644 index 0000000..d6e1c75 --- /dev/null +++ b/scenes/CMakeLists.txt @@ -0,0 +1,17 @@ +add_library(scenes_cube STATIC "cube.cpp") +target_include_directories(scenes_cube PRIVATE "." "..") +target_compile_features(scenes_cube PRIVATE cxx_std_23) +target_compile_options(scenes_cube PRIVATE ${BASE_OPTIONS}) +target_compile_definitions(scenes_cube PRIVATE ${BASE_DEFINITIONS}) +target_link_libraries(scenes_cube PUBLIC cbt_scene glm::glm) + +add_library(scenes_sphere STATIC "sphere.cpp") +target_include_directories(scenes_sphere PRIVATE "." "..") +target_compile_features(scenes_sphere PRIVATE cxx_std_23) +target_compile_options(scenes_sphere PRIVATE ${BASE_OPTIONS}) +target_compile_definitions(scenes_sphere PRIVATE ${BASE_DEFINITIONS}) +target_link_libraries(scenes_sphere PUBLIC cbt_scene glm::glm) + +# Convenience interface for all scenes +add_library(scenes INTERFACE) +target_link_libraries(scenes INTERFACE scenes_cube scenes_sphere)