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.
This commit is contained in:
2026-05-06 00:50:09 +02:00
parent c83561c0fa
commit 6c1096fbb8
3 changed files with 26 additions and 24 deletions
+2 -20
View File
@@ -46,25 +46,7 @@ target_compile_options(cbt_scene PRIVATE ${BASE_OPTIONS})
target_compile_definitions(cbt_scene PRIVATE ${BASE_DEFINITIONS}) target_compile_definitions(cbt_scene PRIVATE ${BASE_DEFINITIONS})
target_link_libraries(cbt_scene PUBLIC cbt_opengl) target_link_libraries(cbt_scene PUBLIC cbt_opengl)
# Application scenes add_subdirectory(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)
# Main executable # Main executable
add_executable(cuber "cuber.cpp") add_executable(cuber "cuber.cpp")
@@ -72,4 +54,4 @@ target_include_directories(cuber PRIVATE ".")
target_compile_features(cuber PRIVATE cxx_std_23) target_compile_features(cuber PRIVATE cxx_std_23)
target_compile_options(cuber PRIVATE ${BASE_OPTIONS}) target_compile_options(cuber PRIVATE ${BASE_OPTIONS})
target_compile_definitions(cuber PRIVATE ${BASE_DEFINITIONS}) 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})
+7 -4
View File
@@ -17,18 +17,21 @@
auto main(int argc, char const* argv[]) -> int { auto main(int argc, char const* argv[]) -> int {
float max_duration_seconds = 0.0f; 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; bool take_screenshot = false;
for (int i = 1; i < argc; ++i) { for (int i = 1; i < argc; ++i) {
std::string_view arg = argv[i]; std::string_view arg = argv[i];
if (arg == "--help" || arg == "-h") { if (arg == "--help" || arg == "-h") {
fmt::print("Usage: {} [options]\n", argv[0]); fmt::print("Usage: {} [options]\n", argv[0]);
fmt::print("Flags:\n");
fmt::print(" --duration <seconds> Auto-terminate after N seconds (for testing/CI)\n"); fmt::print(" --duration <seconds> Auto-terminate after N seconds (for testing/CI)\n");
fmt::print(" --scene <cube|sphere> Select initial scene (default: cube)\n"); fmt::print(" --scene <cube|sphere> Select initial scene (default: cube)\n");
fmt::print(" --screenshot Render one frame, save screenshot, and exit\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("\nKeys (during runtime):\n");
fmt::print(" 1/2 key Switch between cube/sphere scene\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; return 0;
} }
if (arg == "--duration" && i + 1 < argc) { if (arg == "--duration" && i + 1 < argc) {
@@ -36,7 +39,7 @@ auto main(int argc, char const* argv[]) -> int {
continue; continue;
} }
if (arg == "--scene" && i + 1 < argc) { 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; continue;
} }
if (arg == "--screenshot") { if (arg == "--screenshot") {
+17
View File
@@ -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)