From 04c771564681f5e43838e4bff48ad906053136ec Mon Sep 17 00:00:00 2001 From: dingo Date: Thu, 1 Oct 2026 16:58:46 -0400 Subject: [PATCH] Implement M9.2 native client lifecycle and immutable render boundary --- CMakeLists.txt | 3 +- CMakePresets.json | 3 + README.md | 3 +- apps/evo-client/main.cpp | 61 +++++++ cmake/ClientProbe.cmake | 66 ++++++-- deploy/docker/Dockerfile | 11 +- docs/ROADMAP.md | 8 +- docs/STATUS.md | 18 +- .../0077-scoped-native-client-dependencies.md | 3 +- docs/adr/0078-native-client-lifecycle.md | 50 ++++++ docs/adr/README.md | 1 + docs/architecture/CLIENT_ARCHITECTURE.md | 47 +++++ docs/architecture/SYSTEM_OVERVIEW.md | 4 + docs/engineering/CLIENT.md | 51 ++++++ docs/engineering/CLIENT_DEPENDENCIES.md | 10 +- docs/engineering/VALIDATION.md | 53 ++++++ include/evo/client/application.hpp | 50 ++++++ include/evo/render/frame.hpp | 36 ++++ src/client/platform/application.cpp | 160 ++++++++++++++++++ src/render/frame.cpp | 17 ++ src/render/sdl_renderer.cpp | 32 ++++ src/render/sdl_renderer.hpp | 12 ++ tests/client_lifecycle.cpp | 160 ++++++++++++++++++ tools/windows-check.ps1 | 2 +- 24 files changed, 827 insertions(+), 34 deletions(-) create mode 100644 apps/evo-client/main.cpp create mode 100644 docs/adr/0078-native-client-lifecycle.md create mode 100644 docs/architecture/CLIENT_ARCHITECTURE.md create mode 100644 docs/engineering/CLIENT.md create mode 100644 include/evo/client/application.hpp create mode 100644 include/evo/render/frame.hpp create mode 100644 src/client/platform/application.cpp create mode 100644 src/render/frame.cpp create mode 100644 src/render/sdl_renderer.cpp create mode 100644 src/render/sdl_renderer.hpp create mode 100644 tests/client_lifecycle.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 8969541..5abcd9b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,6 +25,7 @@ option(EVO_BUILD_FUZZER "Build the Clang libFuzzer snapshot target" OFF) option(EVO_BUILD_ECS_EXPERIMENT "Build the isolated EnTT comparison (explicit preparation required)" OFF) option(EVO_BUILD_POSTGRES "Build the isolated Linux PostgreSQL persistence adapter" OFF) option(EVO_BUILD_CLIENT_PROBE "Build the isolated M9.1 SDL dependency probe" OFF) +option(EVO_BUILD_CLIENT "Build the native M9 engineering client" OFF) set(EVO_SANITIZER "none" CACHE STRING "none, address (ASan/UBSan), or thread") set_property(CACHE EVO_SANITIZER PROPERTY STRINGS none address thread) include(cmake/ProjectOptions.cmake) @@ -91,7 +92,7 @@ target_link_libraries(evo_region_checkpoint PUBLIC evo::region_lease evo::proces evo_owned_target(evo_region_checkpoint) include(CTest) -if(EVO_BUILD_CLIENT_PROBE) +if(EVO_BUILD_CLIENT_PROBE OR EVO_BUILD_CLIENT) include(cmake/ClientProbe.cmake) endif() if(EVO_BUILD_POSTGRES) diff --git a/CMakePresets.json b/CMakePresets.json index d62fef2..ee7d4d2 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -8,6 +8,7 @@ {"name": "analysis", "inherits": "debug", "cacheVariables": {"EVO_ENABLE_TIDY": "ON"}}, {"name": "asan", "inherits": "debug", "cacheVariables": {"EVO_SANITIZER": "address"}}, {"name": "tsan", "inherits": "debug", "cacheVariables": {"EVO_SANITIZER": "thread"}}, + {"name": "client", "inherits": "release", "cacheVariables": {"EVO_BUILD_CLIENT": "ON"}}, {"name": "client-probe", "inherits": "release", "cacheVariables": {"EVO_BUILD_CLIENT_PROBE": "ON"}} ], "buildPresets": [ @@ -16,6 +17,7 @@ {"name": "analysis", "configurePreset": "analysis"}, {"name": "asan", "configurePreset": "asan"}, {"name": "tsan", "configurePreset": "tsan"}, + {"name": "client", "configurePreset": "client", "targets": ["evo-client", "evo-client-lifecycle-tests"]}, {"name": "client-probe", "configurePreset": "client-probe", "targets": ["evo-client-probe"]} ], "testPresets": [ @@ -24,6 +26,7 @@ {"name": "analysis", "configurePreset": "analysis", "output": {"outputOnFailure": true}}, {"name": "asan", "configurePreset": "asan", "output": {"outputOnFailure": true}}, {"name": "tsan", "configurePreset": "tsan", "output": {"outputOnFailure": true}}, + {"name": "client", "configurePreset": "client", "filter": {"include": {"label": "client"}}, "output": {"outputOnFailure": true}}, {"name": "client-probe", "configurePreset": "client-probe", "filter": {"include": {"label": "client"}}, "output": {"outputOnFailure": true}} ] } diff --git a/README.md b/README.md index 85bba85..a8963d8 100644 --- a/README.md +++ b/README.md @@ -168,4 +168,5 @@ The default simulation build does not require PostgreSQL. The optional SDL3 probe is separate from the headless targets. See [client dependency preparation and checks](docs/engineering/CLIENT_DEPENDENCIES.md). -M9.2 will build the actual client platform/render boundary. +M9.2 supplies the [native engineering client](docs/engineering/CLIENT.md), with +an immutable frame boundary and tested window/resource lifecycle. diff --git a/apps/evo-client/main.cpp b/apps/evo-client/main.cpp new file mode 100644 index 0000000..64175a0 --- /dev/null +++ b/apps/evo-client/main.cpp @@ -0,0 +1,61 @@ +#include "evo/client/application.hpp" +#include +#include +#include +#include +#include +#include +#include + +int main(int argc, char** argv) try { + evo::client::Config config; + unsigned frames = 0; + for (int i = 1; i < argc; ++i) { + const std::string_view arg{argv[i]}; + if (arg == "--hidden") + config.hidden = true; + else if (arg == "--renderer" && i + 1 < argc) + config.renderer = argv[++i]; + else if (arg == "--frames" && i + 1 < argc) { + const std::string_view value{argv[++i]}; + const auto [end, error] = + std::from_chars(value.data(), value.data() + value.size(), frames); + if (error != std::errc{} || end != value.data() + value.size() || frames == 0 || + frames > 100000) + return 2; + } else { + std::fputs("usage: evo-client [--renderer NAME] [--hidden] [--frames 1..100000]\n", + stderr); + return 2; + } + } + auto app = evo::client::Application::open(config); + if (!app) { + std::fprintf(stderr, "client initialization error=%d\n", static_cast(app.error())); + return 1; + } + // Presentation fixture only. No simulated organisms or world state. + const std::array boxes{{{24, 24, 160, 96, {64, 180, 140, 255}}}}; + const auto frame = evo::render::Frame::create(boxes, {16, 20, 28, 255}); + if (!frame) + return 1; + unsigned count = 0; + while (frames == 0 || count < frames) { + const auto result = (*app)->step(*frame); + if (!result) { + std::fprintf(stderr, "client frame error=%d\n", static_cast(result.error())); + return 1; + } + if (*result == evo::client::Step::closed) + break; + ++count; + std::this_thread::sleep_for(std::chrono::milliseconds{16}); + } + return 0; +} catch (const std::exception& e) { + std::fprintf(stderr, "client exception: %.200s\n", e.what()); + return 1; +} catch (...) { + std::fputs("client exception\n", stderr); + return 1; +} diff --git a/cmake/ClientProbe.cmake b/cmake/ClientProbe.cmake index 06ab256..ebbd440 100644 --- a/cmake/ClientProbe.cmake +++ b/cmake/ClientProbe.cmake @@ -14,23 +14,61 @@ set(SDL_TEST_LIBRARY OFF CACHE BOOL "" FORCE) set(SDL_TESTS OFF CACHE BOOL "" FORCE) set(SDL_EXAMPLES OFF CACHE BOOL "" FORCE) set(SDL_INSTALL OFF CACHE BOOL "" FORCE) +if(CMAKE_SYSTEM_NAME STREQUAL "Linux") + # Keep Xlib process-lifetime caches reachable across SDL init/quit cycles. + # Dynamic unloading leaked in the repeated M9.2 lifecycle test (ADR-0078). + set(SDL_X11_SHARED OFF CACHE BOOL "Link X11 directly for the native client" FORCE) +endif() foreach(feature AUDIO CAMERA JOYSTICK HAPTIC SENSOR GPU) set(SDL_${feature} OFF CACHE BOOL "M9.1 scoped subset" FORCE) endforeach() add_subdirectory("${sdl_source}" "${PROJECT_BINARY_DIR}/sdl3" EXCLUDE_FROM_ALL SYSTEM) -add_executable(evo-client-probe experiments/client/main.cpp) -target_link_libraries(evo-client-probe PRIVATE SDL3::SDL3) -evo_owned_target(evo-client-probe) -if(WIN32) - add_custom_command(TARGET evo-client-probe POST_BUILD - COMMAND "${CMAKE_COMMAND}" -E copy_if_different - "$" "$" VERBATIM) +function(evo_client_runtime target) + if(WIN32) + add_custom_command(TARGET ${target} POST_BUILD + COMMAND "${CMAKE_COMMAND}" -E copy_if_different + "$" "$" VERBATIM) + endif() +endfunction() +if(EVO_BUILD_CLIENT_PROBE) + add_executable(evo-client-probe experiments/client/main.cpp) + target_link_libraries(evo-client-probe PRIVATE SDL3::SDL3) + evo_owned_target(evo-client-probe) + evo_client_runtime(evo-client-probe) + if(BUILD_TESTING) + add_test(NAME client-probe-software COMMAND evo-client-probe --renderer software) + set_tests_properties(client-probe-software PROPERTIES + ENVIRONMENT "SDL_VIDEO_DRIVER=dummy" TIMEOUT 20 LABELS "client") + add_test(NAME client-probe-invalid-driver COMMAND evo-client-probe --renderer evo-invalid) + set_tests_properties(client-probe-invalid-driver PROPERTIES + ENVIRONMENT "SDL_VIDEO_DRIVER=dummy" WILL_FAIL TRUE TIMEOUT 20 LABELS "client") + endif() endif() -if(BUILD_TESTING) - add_test(NAME client-probe-software COMMAND evo-client-probe --renderer software) - set_tests_properties(client-probe-software PROPERTIES - ENVIRONMENT "SDL_VIDEO_DRIVER=dummy" TIMEOUT 20 LABELS "client") - add_test(NAME client-probe-invalid-driver COMMAND evo-client-probe --renderer evo-invalid) - set_tests_properties(client-probe-invalid-driver PROPERTIES - ENVIRONMENT "SDL_VIDEO_DRIVER=dummy" WILL_FAIL TRUE TIMEOUT 20 LABELS "client") + +if(EVO_BUILD_CLIENT) + add_library(evo_render_frame STATIC src/render/frame.cpp) + target_include_directories(evo_render_frame PUBLIC "${PROJECT_SOURCE_DIR}/include") + evo_owned_target(evo_render_frame) + add_library(evo_client_platform STATIC src/client/platform/application.cpp src/render/sdl_renderer.cpp) + target_include_directories(evo_client_platform PRIVATE "${PROJECT_SOURCE_DIR}/src") + target_link_libraries(evo_client_platform PUBLIC evo_render_frame PRIVATE SDL3::SDL3) + evo_owned_target(evo_client_platform) + add_executable(evo-client apps/evo-client/main.cpp) + target_link_libraries(evo-client PRIVATE evo_client_platform) + evo_owned_target(evo-client) + evo_client_runtime(evo-client) + if(BUILD_TESTING) + add_executable(evo-client-lifecycle-tests tests/client_lifecycle.cpp) + target_include_directories(evo-client-lifecycle-tests PRIVATE "${PROJECT_SOURCE_DIR}/src") + target_link_libraries(evo-client-lifecycle-tests PRIVATE evo_client_platform SDL3::SDL3) + evo_owned_target(evo-client-lifecycle-tests) + evo_client_runtime(evo-client-lifecycle-tests) + add_test(NAME client-lifecycle COMMAND evo-client-lifecycle-tests) + add_test(NAME client-smoke COMMAND evo-client --renderer software --frames 3) + add_test(NAME client-init-failure COMMAND evo-client --frames 1) + set_tests_properties(client-lifecycle client-smoke PROPERTIES + ENVIRONMENT "SDL_VIDEO_DRIVER=dummy" TIMEOUT 30 LABELS "client") + set_tests_properties(client-init-failure PROPERTIES + ENVIRONMENT "SDL_VIDEO_DRIVER=evo-invalid" WILL_FAIL TRUE TIMEOUT 20 LABELS "client") + endif() endif() diff --git a/deploy/docker/Dockerfile b/deploy/docker/Dockerfile index fb63332..d721cb5 100644 --- a/deploy/docker/Dockerfile +++ b/deploy/docker/Dockerfile @@ -40,10 +40,15 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ && rm -rf /var/lib/apt/lists/* RUN cmake -P tools/prepare-sdl3.cmake \ && cmake --preset client-probe -DCMAKE_CXX_COMPILER=clang++-19 \ - -DEVO_ENABLE_TIDY=ON -DSDL_X11=ON -DSDL_WAYLAND=OFF \ - && cmake --build --preset client-probe --parallel 2 \ + -DEVO_BUILD_CLIENT=ON -DEVO_ENABLE_TIDY=ON -DSDL_X11=ON -DSDL_WAYLAND=OFF \ + && cmake --build build/client-probe --target evo-client-probe evo-client evo-client-lifecycle-tests --parallel 2 \ && ctest --preset client-probe --no-tests=error \ - && xvfb-run -a env SDL_VIDEO_DRIVER=x11 ./build/client-probe/evo-client-probe --renderer software + && xvfb-run -a env SDL_VIDEO_DRIVER=x11 ./build/client-probe/evo-client-probe --renderer software \ + && xvfb-run -a env SDL_VIDEO_DRIVER=x11 ./build/client-probe/evo-client-lifecycle-tests \ + && cmake --preset client-probe -DEVO_BUILD_CLIENT=ON -DEVO_SANITIZER=address -DEVO_ENABLE_TIDY=OFF \ + && cmake --build build/client-probe --target evo-client evo-client-lifecycle-tests --parallel 2 \ + && ctest --preset client-probe --no-tests=error \ + && xvfb-run -a env SDL_VIDEO_DRIVER=x11 ./build/client-probe/evo-client-lifecycle-tests FROM ci-source AS ci-ecs # Explicit experiment preparation; normal configure/runtime remains dependency-free. diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md index 846c30d..346ae9c 100644 --- a/docs/ROADMAP.md +++ b/docs/ROADMAP.md @@ -392,7 +392,13 @@ JetStream is adopted only for a demonstrated delivery workload, not as lease aut **M9.1 status (2026-10-01):** implemented and locally validated; scoped SDL3 decision in ADR-0077, explicit pinned preparation, Windows native and Linux X11 software probes. Evidence and platform limits are in engineering/VALIDATION.md. -The added Gitea client job awaits remote execution. Next gate: M9.2. +The added Gitea client job awaits remote verification. + +**M9.2 status (2026-10-01):** native application, immutable frame boundary and +surface/resource lifecycle implemented under ADR-0078; Windows/Linux tests, +analysis, ASan/UBSan and headless replay evidence in engineering/VALIDATION.md. +Physical DPI/input and real GPU loss remain hardware qualification, not claims +from injected events. Next gate: M9.3. **Goal:** a native desktop cellular viewer/controller with input, camera, renderer, readable organism/environment views and a real development-server connection. diff --git a/docs/STATUS.md b/docs/STATUS.md index 07ad444..5378afb 100644 --- a/docs/STATUS.md +++ b/docs/STATUS.md @@ -2,15 +2,17 @@ ## Current gate — 2026-10-01 -M9.1 supplies the opt-in native dependency probe and scoped SDL3 decision in -[ADR-0077](adr/0077-scoped-native-client-dependencies.md). SDL 3.4.16 is pinned by -archive hash; the headless build remains independent. Windows native backends and -Linux software/X11 validation are recorded in [VALIDATION.md](engineering/VALIDATION.md). -The new isolated Gitea client gate has not yet run remotely. +M9.2 adds an opt-in native `evo-client`, immutable presentation frame contract and +RAII platform/renderer lifecycle ([ADR-0078](adr/0078-native-client-lifecycle.md)). +Resize/pixel scale, focus, minimized/hidden windows, reset/loss and orderly close +are covered by Windows/Linux tests. Direct X11 linking resolves the observed +M9.1 unload allocation issue in repeated sanitizer checks. See +[CLIENT.md](engineering/CLIENT.md) and [VALIDATION.md](engineering/VALIDATION.md). +Updated remote Gitea client execution remains unverified locally. -Next: **M9.2**, the real native application lifecycle and immutable-view renderer -boundary, including resize/DPI/focus and failure handling. The probe is not a -playable client. No deployment or persistent-world state changed in M9.1. +Next: **M9.3**, camera and bounded input intentions. The window displays a static +presentation fixture, not organisms or a connected world. No deployment, +simulation rules, persistent formats or world state changed in M9.2. The sections below retain earlier milestone delivery history. diff --git a/docs/adr/0077-scoped-native-client-dependencies.md b/docs/adr/0077-scoped-native-client-dependencies.md index b2acd97..2d068c7 100644 --- a/docs/adr/0077-scoped-native-client-dependencies.md +++ b/docs/adr/0077-scoped-native-client-dependencies.md @@ -14,7 +14,8 @@ Use SDL **3.4.16**, zlib licensed, for window/events and `SDL_Renderer`. Build a shared library from an explicitly prepared SHA-256-pinned upstream source archive. `tools/sdl3-pin.cmake` is the machine-readable pin. Normal CMake configuration never downloads it. The dependency and `evo-client-probe` are opt-in; only the -probe links SDL. M9.2 will introduce the actual platform/render boundary. +probe links SDL at M9.1. ADR-0078 extends this to the M9.2 platform adapter and +its native tests, with direct X11 linking on Linux for lifecycle correctness. Select SDL's small 2D abstraction rather than direct Vulkan for this scope. Retain its platform renderer selection and allow the probe to explicitly request Vulkan, diff --git a/docs/adr/0078-native-client-lifecycle.md b/docs/adr/0078-native-client-lifecycle.md new file mode 100644 index 0000000..c73e545 --- /dev/null +++ b/docs/adr/0078-native-client-lifecycle.md @@ -0,0 +1,50 @@ +# ADR-0078: Native client lifecycle and immutable presentation frames + +## Status +Accepted for M9.2 engineering client; no gameplay or protocol decision. + +## Context +SDL requires main-thread window/render ownership. A renderer must not retain +mutable simulation stores, and DPI changes must not reinterpret world units. + +## Decision +Use one RAII application with a private SDL implementation, typed expected errors, +and a synchronous bounded immutable frame of copied presentation primitives. +Separate logical/drawable dimensions and content scale. Suspend rendering for +hidden/minimized surfaces. Recreate on recoverable device reset; fail closed on +device loss or adapter errors. Document the single-main-thread precondition. +The executable owns pacing and exception handling. See CLIENT_ARCHITECTURE.md. + +Linux X11 builds set SDL's supported `SDL_X11_SHARED=OFF`: link X11 libraries +directly rather than repeatedly dlopen/dlclose them with SDL. Repeated init/quit +with dynamic loading left 1,700,544 bytes reported by LeakSanitizer over this +fixture (32 repeated lifecycles, a hidden window and failed renderer initialization). Preloading +libX11 avoided the report; direct linking makes library lifetime explicit without +a preload requirement or sanitizer suppression. This adds system X11 runtime +dependencies when that backend is enabled; headless targets remain unaffected. + +## Alternatives considered +- Public SDL handles: simple but leaks backend lifetime into callers; rejected. +- Render thread / queued scene graph: unnecessary synchronization and lifetime + complexity for this gate; defer until profiling justifies it. +- Renderer directly reads world stores: violates the immutable view boundary. +- Retry every failed frame: risks busy loops and hides fatal failures; rejected. + +## Benefits +Bounded memory and work, release-active failure tests, no graphical dependencies +in headless targets. SDL can be replaced behind private source files. + +## Costs +Frame copy (bounded), one window, simple rectangles only. Native library/global +state precludes embedding another SDL owner in the same process for this scope. + +## Risks +Synthetic events do not prove a real GPU reset or physical multi-monitor DPI. +System driver allocations remain outside owned-code instrumentation. Direct +linking addresses the observed unload/lifecycle case, not every platform library +leak or arbitrary GPU driver. Re-run repeated native lifecycle checks on upgrades. + +## Consequences +M9.3 adds camera and input intentions; M9.4/5 add biology-derived projections. +No current simulation interfaces, rules or formats change. Desktop packaging, +hardware matrix and native driver recovery remain explicit qualification work. diff --git a/docs/adr/README.md b/docs/adr/README.md index 76a497a..c407f72 100644 --- a/docs/adr/README.md +++ b/docs/adr/README.md @@ -89,3 +89,4 @@ design. No unadopted candidate is a link dependency of the proof. - [ADR-0076: Upgrade rehearsal on clones, version barrier in dev/stage, and node growth](0076-upgrade-and-growth.md) - accepted for M8.9 accelerated clone runs compared state-for-state before a build change, failed-migration recovery, guarded in-cluster barrier, stores/compute node labels with policy-checked placement. - [ADR-0077: Scoped native client dependencies](0077-scoped-native-client-dependencies.md) - SDL 3.4.16 window/events and 2D renderer for the opt-in M9.1 probe; no simulation dependency. +- [ADR-0078: Native client lifecycle](0078-native-client-lifecycle.md) - main-thread RAII application, immutable presentation frames and explicit surface/device failure handling. diff --git a/docs/architecture/CLIENT_ARCHITECTURE.md b/docs/architecture/CLIENT_ARCHITECTURE.md new file mode 100644 index 0000000..aa7456b --- /dev/null +++ b/docs/architecture/CLIENT_ARCHITECTURE.md @@ -0,0 +1,47 @@ +# Native client boundary (M9.2) + +Implemented scope: desktop lifecycle and primitive presentation, not gameplay. +ADR-0077 selects SDL; ADR-0078 defines its ownership and view boundary. + +```mermaid +flowchart LR + App[evo-client main thread] --> Platform[Application / private SDL adapter] + App --> Frame[Owned immutable render Frame] + Platform --> Render[Private SDL renderer] + Frame --> Render + Future[Later M9.4 view projection] -. copied presentation values .-> Frame +``` + +`include/evo/client/application.hpp` and `include/evo/render/frame.hpp` contain +no SDL, world-store, network or database types. The application owns one SDL +runtime, window and renderer on the process main thread; concurrent application +instances are rejected. Destruction releases renderer, window, then SDL. Partial +initialization releases everything acquired. No application object may outlive +main or be used/destroyed on another thread. + +`Frame::create` validates and copies at most 4096 rectangles. Its const span is +valid until frame destruction/assignment. `Application::step(const Frame&)` +borrows it for the call only; there is no queue, stored pointer or simulation +mutation. Coordinates are logical window units, top-left origin, +Y down. They +are presentation units, never world millimetres. M9.3 owns world-screen mapping; +M9.4 projects environment samples. In particular, do not retain M6 validation +tokens/store pointers in a renderer or serialize them as a client protocol. + +Window state records logical size, drawable pixel size and display content scale +separately. Resizes/display changes query SDL rather than trust event payloads. +Drawing scales independently by pixel/logical width and height; content scale is +for future UI sizing, not a second pixel multiplier. Hidden/minimized/zero-area +windows skip rendering. Focus loss disables the future input admission flag; +there are no held gameplay inputs in M9.2. Close is terminal. + +Each step consumes at most 256 events, filters window-specific events and renders +one frame. Target reset needs only redraw (no cached textures). Device reset +recreates the renderer from CPU frame data. Device loss, recreation/query/draw +failure latch an error until destruction; no silent backend substitution or busy +recovery loop. Typed errors reach the process boundary. The host paces frames +outside the renderer and catches allocation/standard-library exceptions. + +Failure tests inject actual SDL events, including foreign window IDs, with no +test-only production hooks. Real device failures and physical DPI/input require +manual hardware qualification at M9.8. The native client is opt-in and never +enters a server container. Headless configuration does not prepare/load SDL. diff --git a/docs/architecture/SYSTEM_OVERVIEW.md b/docs/architecture/SYSTEM_OVERVIEW.md index 5ca2359..16151a6 100644 --- a/docs/architecture/SYSTEM_OVERVIEW.md +++ b/docs/architecture/SYSTEM_OVERVIEW.md @@ -43,6 +43,10 @@ headers expose values and bounded commands, not third-party ECS/storage types. No Steam ID, socket, Kubernetes API, logger clock or storage handle belongs in the simulation state. Durable account references live in orchestration mapping. +M9.2 implements the opt-in [native client boundary](CLIENT_ARCHITECTURE.md): +copied immutable presentation frames and one main-thread platform owner. It does +not yet project biological views or connect to a region server. + | Boundary | Owns | Must not own | |---|---|---| | core | Value types, deterministic algorithms, explicit version constants | Global state, threads, I/O | diff --git a/docs/engineering/CLIENT.md b/docs/engineering/CLIENT.md new file mode 100644 index 0000000..92a21ba --- /dev/null +++ b/docs/engineering/CLIENT.md @@ -0,0 +1,51 @@ +# Native engineering client (M9.2) + +This opens a resizable native window containing a static presentation fixture. +It does not simulate a world, connect to a server or implement cellular gameplay. +Contract: [client architecture](../architecture/CLIENT_ARCHITECTURE.md), ADR-0078. + +## Build and run + +After [explicit SDL preparation](CLIENT_DEPENDENCIES.md), in a compiler shell: + +```sh +cmake --preset client +cmake --build --preset client --parallel 4 +ctest --preset client --no-tests=error +./build/client/evo-client +``` + +Windows: `tools/windows-check.ps1 -Preset client -Action check` configures the +MSVC environment. Use `.exe` for executable paths. Linux requires the X11 or +Wayland development packages described in the dependency guide; the Docker +`ci-client` stage supplies the tested X11 subset. + +Close the window to exit. `--renderer software` or `--renderer vulkan` requests +one explicit backend, without fallback. `--frames N` exits after N bounded steps +(including paused steps), maximum 100000; `--hidden` opens without showing the +window and pauses drawing. These options permit unattended smoke checks. +Usage errors exit 2, lifecycle failures exit 1, orderly exit returns 0. + +For native X11 regression on a CI host: + +```sh +xvfb-run -a env SDL_VIDEO_DRIVER=x11 ./build/client/evo-client-lifecycle-tests +``` + +CTest uses the dummy driver. The lifecycle suite runs 32 open/destroy rounds, +resize/scale queries, non-unit drawable-scale pixel checks, minimize/restore, +show/hide, focus/foreign events, reset/loss and close. Separate process checks +exercise initialization failure. Tests stay active under NDEBUG. Synthetic +events and software rendering do not qualify physical DPI, keyboard, GPU loss +or compositor behavior; those remain a hardware matrix at M9.8. + +Analysis/sanitizers use the existing options, for example configure `--preset +asan -B build/client-asan -DEVO_BUILD_CLIENT=ON` with Clang 19. This instruments +owned frame/platform/app/test code, not SDL/system libraries. Linux X11 builds +link X11 directly (`SDL_X11_SHARED=OFF`) to preserve library lifetime across SDL +cycles. No preload or leak suppression is required. The diagnosed M9.1 dynamic +unload behavior and qualification evidence are documented in VALIDATION.md. + +Headless defaults keep both `EVO_BUILD_CLIENT` and `EVO_BUILD_CLIENT_PROBE` OFF. +No prepared SDL sources, display or client runtime are needed for `evo-sim` or +server tests. No Kubernetes deployment change belongs to this desktop gate. diff --git a/docs/engineering/CLIENT_DEPENDENCIES.md b/docs/engineering/CLIENT_DEPENDENCIES.md index fba6f21..ae51894 100644 --- a/docs/engineering/CLIENT_DEPENDENCIES.md +++ b/docs/engineering/CLIENT_DEPENDENCIES.md @@ -54,16 +54,18 @@ it explicitly for a clean rebuild. No network access occurs during configuration upstream archive retains bundled component notices. No claim is made that SDL license review licenses the game itself. Binary release packaging must retain applicable third-party notices and audit enabled backend/system dependencies. -- Shared SDL is linked only by `evo-client-probe`; no SDL includes/link dependencies - enter `include/evo`, simulation, world, biology or server targets. It is disabled +- Shared SDL is linked only by the opt-in probe/client platform and native tests; + no SDL includes enter public headers or simulation, world, biology or server + targets. It is disabled by default. Windows copies SDL3.dll beside the probe; Linux uses the build RPATH. - Size reports are build artifacts, not performance rankings. No representative creature/terrain workload exists yet, so no renderer throughput claim is made. ## Follow-up boundary -M9.2 owns the real application lifecycle, immutable-view renderer interface, -resize/DPI/focus/device failures and resource limits. M9.3 owns camera/intentions. +M9.2 implements the real application lifecycle, immutable-view renderer interface, +resize/DPI/focus/device failures and resource limits. See +[client operation and validation](CLIENT.md). M9.3 owns camera/intentions. M9.8 owns distributable packaging. Xvfb verifies the Linux X11 window path; real desktop input, focus, DPI, Wayland and GPU qualification remain later gate work. See VALIDATION.md for executed measurements and limitations. diff --git a/docs/engineering/VALIDATION.md b/docs/engineering/VALIDATION.md index aee0614..7b4a1aa 100644 --- a/docs/engineering/VALIDATION.md +++ b/docs/engineering/VALIDATION.md @@ -3187,3 +3187,56 @@ remote Gitea run or Kubernetes action was performed for this gate. The new clien CI job performs analysis, dummy pixel/error tests and an Xvfb window probe; remote execution remains pending. M9.1 selects a scoped dependency, not a production-ready renderer or packaged client. + +## M9.2 native application and renderer boundary — 2026-10-01 + +Implemented ADR-0078, opt-in `evo-client`, bounded immutable presentation frames, +private main-thread SDL ownership, logical/drawable size separation, focus and +visibility/minimize handling, recoverable reset and terminal device-loss policy. +No camera, gameplay, protocol, simulation-state or deployment changes. + +Executed: + +- Fresh Windows Release: `tools/windows-check.ps1 -Preset client -Action check` + configured and built with MSVC 19.44; **3/3 client CTests passed** under NDEBUG. + Also ran `build/client/evo-client-lifecycle-tests.exe` with native Windows video, + then `evo-client.exe --frames 3` (default renderer) and `--renderer vulkan + --frames 3`; all returned success. Earlier combined probe/client configuration + passed 5/5 labeled tests. +- Linux GCC 14 Release in `build/client-probe-linux`: **5/5 combined probe/client + CTests passed**, as did native X11 lifecycle checks under Xvfb. The new suite executes 32 + window/app destroy/recreate rounds, plus partial renderer initialization failure + and hidden-window/quit behavior. It covers copied-frame independence, finite + geometry/primitive limits, foreign events, focus, resize/scale queries, + non-unit anisotropic scale pixel readback, hide/minimize/resume, renderer + reset/loss and terminal close/error behavior. +- Clang 19 Debug ASan/UBSan: `cmake --preset asan -B build/client-asan + -DEVO_BUILD_CLIENT=ON -DCMAKE_CXX_COMPILER=clang++-19 + -DCMAKE_C_COMPILER=clang-19 -DSDL_X11=ON -DSDL_WAYLAND=OFF`, built application + and lifecycle tests, **3/3 CTests passed**. Xvfb/X11 lifecycle executable also + passed with default leak detection, **no LD_PRELOAD or suppressions** after + adopting direct X11 linkage. Owned libraries, app and tests are instrumented; + SDL and system libraries are not comprehensively sanitizer-instrumented. +- Investigated M9.1's X11 unload issue: dynamically loaded X11 configuration left + 1,700,544 bytes / 31,008 allocations reported at process exit in the repeated + fixture. Preloading libX11 avoided the report. SDL's supported + `SDL_X11_SHARED=OFF` fixes the observed repeated-lifecycle case by retaining the + linked system libraries for process lifetime. `ldd` confirms libX11 and libXext + dependencies; normal X11 sanitizer run passes. This is an adopted Linux build + constraint, not a claim to have repaired upstream Xlib or all native drivers. +- `clang-tidy-19 -p build/client-asan` on all five new C++ translation units: + passed with warnings-as-errors. Initial enum-size and multi-level pointer + conversion diagnostics were corrected. Repository `format-check` passed. +- Headless Release configured with **both client options OFF**, built `evo-sim` + and replayed seed 123456, eight entities, 1000 ticks: unchanged hash + `d61ad5bf0c928c76`, `replay_verified=true`. No SDL acquisition is part of this + configure/build path. + +CI's isolated client stage now builds the actual app, runs static analysis and +labeled checks, exercises X11 lifecycles, then instruments owned code and repeats +software/X11 checks. No Docker build or remote Gitea execution was verified here. +No full headless suite rerun or TSan run: headless source did not change, and this +boundary requires single-main-thread use. Tests do not establish physical +multi-monitor DPI, real keyboard/focus behavior, Wayland, hardware GPU loss or +human visual acceptance. Those remain M9.3/M9.8 qualification work. No cluster +operation was performed. diff --git a/include/evo/client/application.hpp b/include/evo/client/application.hpp new file mode 100644 index 0000000..8bd56e4 --- /dev/null +++ b/include/evo/client/application.hpp @@ -0,0 +1,50 @@ +#pragma once +#include "evo/render/frame.hpp" +#include +#include +#include +#include + +namespace evo::client { +enum class Error : std::uint8_t { + invalid_config, + already_open, + initialization, + window, + renderer, + surface, + draw, + device_lost +}; +enum class Step : std::uint8_t { rendered, paused, closed }; +struct Config { + int width{960}, height{640}; + bool hidden{false}; + std::string renderer; // Empty selects SDL's supported default; explicit names must succeed. +}; +struct WindowState { + int logical_width{}, logical_height{}, pixel_width{}, pixel_height{}; + float content_scale{1}; + bool focused{}, minimized{}, hidden{}, closed{}, failed{}; + [[nodiscard]] bool accepts_input() const noexcept { + return focused && !minimized && !hidden && !closed && !failed; + } +}; +// One owner, process main thread only (including destruction). No SDL owner may coexist. +class Application { + public: + [[nodiscard]] static std::expected, Error> + open(const Config& config); + ~Application(); + Application(const Application&) = delete; + Application& operator=(const Application&) = delete; + [[nodiscard]] WindowState state() const noexcept; + // Borrows the immutable frame for this call only. Errors latch until destruction. + [[nodiscard]] std::expected step(const render::Frame& frame); + + private: + struct Impl; + explicit Application(std::unique_ptr impl); + std::unique_ptr impl_; +}; +} // namespace evo::client diff --git a/include/evo/render/frame.hpp b/include/evo/render/frame.hpp new file mode 100644 index 0000000..f8d3ee1 --- /dev/null +++ b/include/evo/render/frame.hpp @@ -0,0 +1,36 @@ +#pragma once +#include +#include +#include +#include +#include + +namespace evo::render { +inline constexpr std::size_t max_rectangles = 4096; +struct Color { + std::uint8_t red{}, green{}, blue{}, alpha{255}; +}; +struct Rectangle { + float x{}, y{}, width{}, height{}; + Color color; +}; +enum class FrameError : std::uint8_t { too_many_primitives, invalid_geometry }; +// Owns copied logical-window coordinates; never stores simulation/native handles. +class Frame { + public: + [[nodiscard]] static std::expected + create(std::span rectangles, Color background = {}); + [[nodiscard]] std::span rectangles() const noexcept { + return rectangles_; + } + [[nodiscard]] Color background() const noexcept { + return background_; + } + + private: + Frame(std::span rectangles, Color background) + : rectangles_(rectangles.begin(), rectangles.end()), background_{background} {} + std::vector rectangles_; + Color background_; +}; +} // namespace evo::render diff --git a/src/client/platform/application.cpp b/src/client/platform/application.cpp new file mode 100644 index 0000000..c66c520 --- /dev/null +++ b/src/client/platform/application.cpp @@ -0,0 +1,160 @@ +#include "evo/client/application.hpp" +#include "render/sdl_renderer.hpp" +#define SDL_MAIN_HANDLED +#include +#include +#include +#include + +namespace evo::client { +namespace { +bool runtime_owned = false; // Process main-thread-only contract; no hidden threads. +struct Runtime { + bool acquired{false}; + ~Runtime() { + if (acquired) { + SDL_Quit(); + runtime_owned = false; + } + } +}; +} // namespace +struct Application::Impl { + Runtime runtime; + std::unique_ptr window{nullptr, SDL_DestroyWindow}; + detail::Renderer renderer{nullptr, SDL_DestroyRenderer}; + std::string renderer_name; + WindowState state; + std::optional failure; + + std::expected refresh() { + if (!SDL_GetWindowSize(window.get(), &state.logical_width, &state.logical_height) || + !SDL_GetWindowSizeInPixels(window.get(), &state.pixel_width, &state.pixel_height)) + return std::unexpected(Error::surface); + state.content_scale = SDL_GetWindowDisplayScale(window.get()); + if (!std::isfinite(state.content_scale) || state.content_scale <= 0 || + state.logical_width < 0 || state.logical_height < 0 || state.pixel_width < 0 || + state.pixel_height < 0 || state.logical_width > 32768 || state.logical_height > 32768 || + state.pixel_width > 32768 || state.pixel_height > 32768) + return std::unexpected(Error::surface); + return {}; + } +}; +Application::Application(std::unique_ptr impl) : impl_{std::move(impl)} {} +Application::~Application() = default; +WindowState Application::state() const noexcept { + auto result = impl_->state; + result.failed = impl_->failure.has_value(); + return result; +} +std::expected, Error> Application::open(const Config& config) { + if (config.width <= 0 || config.height <= 0 || config.width > 32768 || config.height > 32768 || + config.renderer.size() > 64 || config.renderer.find('\0') != std::string::npos) + return std::unexpected(Error::invalid_config); + if (runtime_owned || SDL_WasInit(0) != 0) + return std::unexpected(Error::already_open); + auto impl = std::make_unique(); + SDL_SetMainReady(); + impl->runtime.acquired = true; + runtime_owned = true; + if (!SDL_Init(SDL_INIT_VIDEO)) + return std::unexpected(Error::initialization); + const auto flags = SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIGH_PIXEL_DENSITY | + (config.hidden ? SDL_WINDOW_HIDDEN : 0); + impl->window.reset(SDL_CreateWindow("Aeternalis Evolution - engineering client", config.width, + config.height, flags)); + if (!impl->window) + return std::unexpected(Error::window); + impl->renderer_name = config.renderer; + auto renderer = detail::make_renderer(impl->window.get(), impl->renderer_name); + if (!renderer) + return std::unexpected(renderer.error()); + impl->renderer = std::move(*renderer); + const auto window_flags = SDL_GetWindowFlags(impl->window.get()); + impl->state.focused = (window_flags & SDL_WINDOW_INPUT_FOCUS) != 0; + impl->state.minimized = (window_flags & SDL_WINDOW_MINIMIZED) != 0; + impl->state.hidden = (window_flags & SDL_WINDOW_HIDDEN) != 0; + if (auto result = impl->refresh(); !result) + return std::unexpected(result.error()); + return std::unique_ptr{new Application{std::move(impl)}}; +} +std::expected Application::step(const render::Frame& frame) { + auto& p = *impl_; + if (p.failure) + return std::unexpected(*p.failure); + if (p.state.closed) + return Step::closed; + const auto id = SDL_GetWindowID(p.window.get()); + bool reset = false; + SDL_Event event{}; + for (int count = 0; count < 256 && SDL_PollEvent(&event); ++count) { + if (event.type == SDL_EVENT_QUIT) + p.state.closed = true; + if (event.type >= SDL_EVENT_WINDOW_FIRST && event.type <= SDL_EVENT_WINDOW_LAST && + event.window.windowID == id) { + switch (event.type) { + case SDL_EVENT_WINDOW_CLOSE_REQUESTED: + p.state.closed = true; + break; + case SDL_EVENT_WINDOW_FOCUS_GAINED: + p.state.focused = true; + break; + case SDL_EVENT_WINDOW_FOCUS_LOST: + p.state.focused = false; + break; + case SDL_EVENT_WINDOW_MINIMIZED: + p.state.minimized = true; + break; + case SDL_EVENT_WINDOW_RESTORED: + case SDL_EVENT_WINDOW_MAXIMIZED: + p.state.minimized = false; + break; + case SDL_EVENT_WINDOW_HIDDEN: + p.state.hidden = true; + break; + case SDL_EVENT_WINDOW_SHOWN: + p.state.hidden = false; + break; + default: + break; + } + } + if (event.type >= SDL_EVENT_RENDER_TARGETS_RESET && + event.type <= SDL_EVENT_RENDER_DEVICE_LOST && event.render.windowID == id) { + if (event.type == SDL_EVENT_RENDER_DEVICE_LOST) + p.failure = Error::device_lost; + else if (event.type == SDL_EVENT_RENDER_DEVICE_RESET) + reset = true; + } + } + if (p.failure) + return std::unexpected(*p.failure); + if (p.state.closed) + return Step::closed; + if (reset) { + p.renderer.reset(); + auto renderer = detail::make_renderer(p.window.get(), p.renderer_name); + if (!renderer) { + p.failure = renderer.error(); + return std::unexpected(*p.failure); + } + p.renderer = std::move(*renderer); + } + if (auto result = p.refresh(); !result) { + p.failure = result.error(); + return std::unexpected(*p.failure); + } + if (p.state.hidden || p.state.minimized || p.state.logical_width == 0 || + p.state.logical_height == 0 || p.state.pixel_width == 0 || p.state.pixel_height == 0) + return Step::paused; + if (auto result = detail::draw(p.renderer.get(), frame, p.state); !result) { + p.failure = result.error(); + return std::unexpected(*p.failure); + } + if (!SDL_RenderPresent(p.renderer.get())) { + p.failure = Error::draw; + return std::unexpected(*p.failure); + } + return Step::rendered; +} +} // namespace evo::client diff --git a/src/render/frame.cpp b/src/render/frame.cpp new file mode 100644 index 0000000..46387c4 --- /dev/null +++ b/src/render/frame.cpp @@ -0,0 +1,17 @@ +#include "evo/render/frame.hpp" +#include + +namespace evo::render { +std::expected Frame::create(std::span rectangles, + Color background) { + if (rectangles.size() > max_rectangles) + return std::unexpected(FrameError::too_many_primitives); + for (const auto& r : rectangles) { + if (!std::isfinite(r.x) || !std::isfinite(r.y) || !std::isfinite(r.width) || + !std::isfinite(r.height) || std::abs(r.x) > 32768 || std::abs(r.y) > 32768 || + r.width < 0 || r.height < 0 || r.width > 32768 || r.height > 32768) + return std::unexpected(FrameError::invalid_geometry); + } + return Frame{rectangles, background}; +} +} // namespace evo::render diff --git a/src/render/sdl_renderer.cpp b/src/render/sdl_renderer.cpp new file mode 100644 index 0000000..a32efef --- /dev/null +++ b/src/render/sdl_renderer.cpp @@ -0,0 +1,32 @@ +#include "sdl_renderer.hpp" + +namespace evo::client::detail { +std::expected make_renderer(SDL_Window* window, const std::string& name) { + Renderer result{SDL_CreateRenderer(window, name.empty() ? nullptr : name.c_str()), + SDL_DestroyRenderer}; + if (!result) + return std::unexpected(Error::renderer); + if (!SDL_SetRenderDrawBlendMode(result.get(), SDL_BLENDMODE_BLEND)) + return std::unexpected(Error::renderer); + return result; +} +std::expected draw(SDL_Renderer* renderer, const render::Frame& frame, + const WindowState& state) { + const auto bg = frame.background(); + if (!SDL_SetRenderScale( + renderer, + static_cast(state.pixel_width) / static_cast(state.logical_width), + static_cast(state.pixel_height) / static_cast(state.logical_height)) || + !SDL_SetRenderDrawColor(renderer, bg.red, bg.green, bg.blue, bg.alpha) || + !SDL_RenderClear(renderer)) + return std::unexpected(Error::draw); + for (const auto& r : frame.rectangles()) { + const SDL_FRect box{r.x, r.y, r.width, r.height}; + if (!SDL_SetRenderDrawColor(renderer, r.color.red, r.color.green, r.color.blue, + r.color.alpha) || + !SDL_RenderFillRect(renderer, &box)) + return std::unexpected(Error::draw); + } + return {}; +} +} // namespace evo::client::detail diff --git a/src/render/sdl_renderer.hpp b/src/render/sdl_renderer.hpp new file mode 100644 index 0000000..c0d8e77 --- /dev/null +++ b/src/render/sdl_renderer.hpp @@ -0,0 +1,12 @@ +#pragma once +#include "evo/client/application.hpp" +#include +#include + +namespace evo::client::detail { +using Renderer = std::unique_ptr; +[[nodiscard]] std::expected make_renderer(SDL_Window* window, + const std::string& name); +[[nodiscard]] std::expected draw(SDL_Renderer* renderer, const render::Frame& frame, + const WindowState& state); +} // namespace evo::client::detail diff --git a/tests/client_lifecycle.cpp b/tests/client_lifecycle.cpp new file mode 100644 index 0000000..149b598 --- /dev/null +++ b/tests/client_lifecycle.cpp @@ -0,0 +1,160 @@ +#include "evo/client/application.hpp" +#include "render/sdl_renderer.hpp" +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace { +using namespace evo::client; +void check(bool ok, std::source_location at = std::source_location::current()) { + if (!ok) + throw std::runtime_error("client lifecycle line " + std::to_string(at.line())); +} +#define CHECK(...) check(static_cast(__VA_ARGS__)) +template bool refused(const std::expected& result, E error) { + return !result && result.error() == error; +} +evo::render::Frame fixture() { + const std::array rectangles{{{0, 0, 32, 32, {255, 0, 0, 255}}}}; + auto result = evo::render::Frame::create(rectangles); + CHECK(result); + return std::move(result.value()); +} +SDL_Window* window() { + int count{}; + SDL_Window** windows = SDL_GetWindows(&count); + SDL_Window* result = count == 1 ? windows[0] : nullptr; + SDL_free(static_cast(windows)); + CHECK(result); + return result; +} +void send(SDL_EventType type, SDL_WindowID id) { + SDL_Event event{}; + event.type = type; + if (type >= SDL_EVENT_RENDER_TARGETS_RESET && type <= SDL_EVENT_RENDER_DEVICE_LOST) + event.render.windowID = id; + else + event.window.windowID = id; + CHECK(SDL_PushEvent(&event)); +} +void frame_contract() { + using namespace evo::render; + std::array r{{{1, 2, 3, 4, {5, 6, 7, 255}}}}; + const auto frame = Frame::create(r); + CHECK(frame); + r[0].x = 100; + CHECK(frame->rectangles()[0].x == 1); // Owns copy; caller mutation cannot alter it. + r[0].x = std::numeric_limits::quiet_NaN(); + CHECK(refused(Frame::create(r), FrameError::invalid_geometry)); + r[0].x = 0; + r[0].width = -1; + CHECK(refused(Frame::create(r), FrameError::invalid_geometry)); + r[0].width = std::numeric_limits::infinity(); + CHECK(refused(Frame::create(r), FrameError::invalid_geometry)); + std::vector full(max_rectangles); + CHECK(Frame::create(full)); + full.emplace_back(); + CHECK(refused(Frame::create(full), FrameError::too_many_primitives)); +} +void pixels(SDL_Window* native, const evo::render::Frame& frame, WindowState state) { + auto* renderer = SDL_GetRenderer(native); + CHECK(renderer); + // Exercise non-unit, anisotropic drawable scaling without requiring a HiDPI monitor. + state.logical_width = state.pixel_width / 2; + state.logical_height = state.pixel_height; + CHECK(detail::draw(renderer, frame, state)); + const std::unique_ptr surface{ + SDL_RenderReadPixels(renderer, nullptr), SDL_DestroySurface}; + CHECK(surface); + Uint8 r{}, g{}, b{}, a{}; + CHECK(SDL_ReadSurfacePixel(surface.get(), 48, 8, &r, &g, &b, &a)); + CHECK(r == 255 && g == 0 && b == 0 && a == 255); + CHECK(SDL_ReadSurfacePixel(surface.get(), 80, 8, &r, &g, &b, &a)); + CHECK(r == 0 && g == 0 && b == 0 && a == 255); + CHECK(SDL_ReadSurfacePixel(surface.get(), 8, 48, &r, &g, &b, &a)); + CHECK(r == 0 && g == 0 && b == 0 && a == 255); +} +void lifecycle() { + const auto frame = fixture(); + CHECK(refused(Application::open({0, 64, false, "software"}), Error::invalid_config)); + CHECK(refused(Application::open({64, 64, false, "evo-invalid"}), Error::renderer)); + CHECK(SDL_WasInit(0) == 0); // Failed partial initialization released SDL. + for (int round = 0; round < 32; ++round) { + auto result = Application::open({160, 120, false, "software"}); + CHECK(result); + auto app = std::move(result.value()); + CHECK(refused(Application::open({}), Error::already_open)); + CHECK(app->step(frame) == Step::rendered); + auto* native = window(); + pixels(native, frame, app->state()); + const auto id = SDL_GetWindowID(native); + // Foreign close/reset must not affect the one owned window. + send(SDL_EVENT_WINDOW_CLOSE_REQUESTED, id + 1); + send(SDL_EVENT_RENDER_DEVICE_LOST, id + 1); + send(SDL_EVENT_WINDOW_FOCUS_GAINED, id); + CHECK(app->step(frame) == Step::rendered); + CHECK(app->state().accepts_input()); + send(SDL_EVENT_WINDOW_FOCUS_LOST, id); + CHECK(app->step(frame) == Step::rendered); + CHECK(!app->state().accepts_input()); + send(SDL_EVENT_WINDOW_MINIMIZED, id); + CHECK(app->step(frame) == Step::paused); + send(SDL_EVENT_WINDOW_RESTORED, id); + CHECK(app->step(frame) == Step::rendered); + CHECK(SDL_SetWindowSize(native, 240, 180)); + send(SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED, id); + send(SDL_EVENT_WINDOW_DISPLAY_SCALE_CHANGED, id); + CHECK(app->step(frame) == Step::rendered); + int lw{}, lh{}, pw{}, ph{}; + CHECK(SDL_GetWindowSize(native, &lw, &lh)); + CHECK(SDL_GetWindowSizeInPixels(native, &pw, &ph)); + const auto state = app->state(); + CHECK(state.logical_width == lw && state.logical_height == lh); + CHECK(state.pixel_width == pw && state.pixel_height == ph); + CHECK(std::isfinite(state.content_scale) && state.content_scale > 0); + send(SDL_EVENT_RENDER_TARGETS_RESET, id); + CHECK(app->step(frame) == Step::rendered); + send(SDL_EVENT_RENDER_DEVICE_RESET, id); + CHECK(app->step(frame) == Step::rendered); + CHECK(SDL_HideWindow(native)); + send(SDL_EVENT_WINDOW_HIDDEN, id); + CHECK(app->step(frame) == Step::paused); + CHECK(SDL_ShowWindow(native)); + send(SDL_EVENT_WINDOW_SHOWN, id); + CHECK(app->step(frame) == Step::rendered); + if (round % 2 == 0) { + send(SDL_EVENT_RENDER_DEVICE_LOST, id); + CHECK(refused(app->step(frame), Error::device_lost)); + CHECK(refused(app->step(frame), Error::device_lost)); + CHECK(app->state().failed && !app->state().accepts_input()); + } else { + send(SDL_EVENT_WINDOW_CLOSE_REQUESTED, id); + CHECK(app->step(frame) == Step::closed); + CHECK(app->step(frame) == Step::closed); + } + app.reset(); + CHECK(SDL_WasInit(0) == 0); + } + auto hidden = Application::open({64, 64, true, "software"}); + CHECK(hidden); + CHECK((*hidden)->step(frame) == Step::paused); + send(SDL_EVENT_QUIT, 0); + CHECK((*hidden)->step(frame) == Step::closed); +} +} // namespace +int main() try { + frame_contract(); + lifecycle(); + return 0; +} catch (const std::exception& e) { + std::fprintf(stderr, "%s: %s\n", e.what(), SDL_GetError()); + return 1; +} catch (...) { + return 1; +} diff --git a/tools/windows-check.ps1 b/tools/windows-check.ps1 index 2fb3590..5ca075e 100644 --- a/tools/windows-check.ps1 +++ b/tools/windows-check.ps1 @@ -1,5 +1,5 @@ param( - [ValidateSet('debug', 'release', 'analysis', 'asan', 'tsan')] + [ValidateSet('debug', 'release', 'analysis', 'asan', 'tsan', 'client', 'client-probe')] [string]$Preset = 'debug', [ValidateSet('configure', 'build', 'test', 'format', 'check')] [string]$Action = 'check'