feat: engine skeleton (Build Order step 1) and siege_tests
Engine: - SdlContext and Window: RAII, throwing constructors, non-movable - FrameClock (real time, clamped dt) and SimClock (fixed 1/60 s steps, speed 0 = planning phase, backlog capped per frame) - Application owns them in lifetime order, exposes EngineContext, and runs the fixed-timestep loop; AppConfig::FromArgs parses --frames, --seed and --fullscreen - Temporary window-surface fill so Wayland maps the window until RenderDevice lands in step 2 Build: - Split into the siege_engine static lib and the siege_deck exe - check_engine_deps fails the build if Engine/ includes Game/ - ctest smoke test: siege_deck --frames 30 on the offscreen driver - siege_tests on Catch2 v3.15.3 (nixpkgs + CPM pin), with SimClock, FrameClock and AppConfig tests Docs: - Decision Log: error handling split, Catch2 for unit tests - Build Order step 1 done; Engine Overview, Main Loop and Time and README updated to match - AGENTS.md with build, conventions and gotchas for coding agents - .gitignore: .mcp.json (local CLion MCP port) and Obsidian's workspace.json (tab/pane state), now untracked Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+76
-7
@@ -115,21 +115,58 @@ list(APPEND LIBS EnTT::EnTT)
|
||||
include(ImGui)
|
||||
list(APPEND LIBS imgui::imgui)
|
||||
|
||||
# Unit tests (siege_tests only, not in LIBS).
|
||||
CPMAddPackage(
|
||||
NAME Catch2
|
||||
VERSION 3.15.3
|
||||
GITHUB_REPOSITORY catchorg/Catch2
|
||||
GIT_TAG v3.15.3
|
||||
FIND_PACKAGE_ARGUMENTS "CONFIG")
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Target
|
||||
# Targets
|
||||
#
|
||||
# siege_engine is game-agnostic; siege_deck is the game on top of it. Engine code
|
||||
# must never include anything from Source/Game (see Docs: Engine Overview).
|
||||
# Both share Source/ as their include root, so the compiler can't stop that on
|
||||
# its own; check_engine_deps does, on every build.
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
add_executable(${PROJECT_NAME}
|
||||
Source/Main.cpp
|
||||
add_library(siege_engine STATIC
|
||||
Source/Common.h
|
||||
Source/Pch.h)
|
||||
Source/Pch.h
|
||||
Source/Engine/Application.cpp
|
||||
Source/Engine/Application.h
|
||||
Source/Engine/Platform/SdlContext.cpp
|
||||
Source/Engine/Platform/SdlContext.h
|
||||
Source/Engine/Platform/Window.cpp
|
||||
Source/Engine/Platform/Window.h
|
||||
Source/Engine/Time/FrameClock.cpp
|
||||
Source/Engine/Time/FrameClock.h
|
||||
Source/Engine/Time/SimClock.cpp
|
||||
Source/Engine/Time/SimClock.h)
|
||||
|
||||
target_include_directories(${PROJECT_NAME} PRIVATE
|
||||
target_include_directories(siege_engine PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Source)
|
||||
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE ${LIBS})
|
||||
# PUBLIC: engine headers expose SDL, glm and Common.h types, so the game needs them too.
|
||||
target_link_libraries(siege_engine PUBLIC ${LIBS})
|
||||
|
||||
target_precompile_headers(${PROJECT_NAME} PRIVATE Source/Pch.h)
|
||||
# PUBLIC so siege_deck builds its own PCH from the same header: engine headers
|
||||
# rely on Common.h being there without including it.
|
||||
target_precompile_headers(siege_engine PUBLIC Source/Pch.h)
|
||||
|
||||
add_custom_target(check_engine_deps
|
||||
COMMAND ${CMAKE_COMMAND} -DENGINE_DIR=${CMAKE_CURRENT_SOURCE_DIR}/Source/Engine
|
||||
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/CheckEngineDeps.cmake
|
||||
COMMENT "Checking that Engine/ doesn't include Game/"
|
||||
VERBATIM)
|
||||
add_dependencies(siege_engine check_engine_deps)
|
||||
|
||||
add_executable(${PROJECT_NAME}
|
||||
Source/Main.cpp)
|
||||
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE siege_engine)
|
||||
|
||||
# Assets are looked up relative to the executable, so the same path works from
|
||||
# the build dir, from CLion's runner, and from an installed copy.
|
||||
@@ -137,3 +174,35 @@ add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Assets
|
||||
$<TARGET_FILE_DIR:${PROJECT_NAME}>/Assets)
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Tests
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
enable_testing()
|
||||
|
||||
# Boots the whole engine and runs 30 frames. The offscreen video driver needs no
|
||||
# display, so this runs unattended in CI: ctest --preset debug
|
||||
add_test(NAME smoke COMMAND ${PROJECT_NAME} --frames 30)
|
||||
set_tests_properties(smoke PROPERTIES
|
||||
ENVIRONMENT "SDL_VIDEO_DRIVER=offscreen"
|
||||
TIMEOUT 30)
|
||||
|
||||
# Unit tests: engine (and later game) logic, no window. Each TEST_CASE shows up in
|
||||
# ctest on its own, next to the smoke test.
|
||||
add_executable(siege_tests
|
||||
Tests/Engine/AppConfigTests.cpp
|
||||
Tests/Engine/Time/FrameClockTests.cpp
|
||||
Tests/Engine/Time/SimClockTests.cpp)
|
||||
|
||||
target_link_libraries(siege_tests PRIVATE siege_engine Catch2::Catch2WithMain)
|
||||
|
||||
# catch_discover_tests lives in Catch.cmake: under extras/ in a source checkout
|
||||
# (CPM download), next to Catch2Config.cmake in an installed one (nixpkgs).
|
||||
if (Catch2_SOURCE_DIR)
|
||||
list(APPEND CMAKE_MODULE_PATH ${Catch2_SOURCE_DIR}/extras)
|
||||
else ()
|
||||
list(APPEND CMAKE_MODULE_PATH ${Catch2_DIR})
|
||||
endif ()
|
||||
include(Catch)
|
||||
catch_discover_tests(siege_tests)
|
||||
|
||||
Reference in New Issue
Block a user