Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.
C++ cmakecnccommand-and-conquercppdirectx11game-enginegame-preservationgeneralsrtssage-enginex64zero-hour
docs(hazard-clouds): direct3d 11 backend, rebake policy, device release
Olcay Seygan4a4852efe039
diff --git a/docs/hazard-clouds.md b/docs/hazard-clouds.mdindex 4fc64cbd7..de6077da9 100644--- a/docs/hazard-clouds.md+++ b/docs/hazard-clouds.md@@ -3,29 +3,50 @@**Options → Graphics → Cloud style** selects **Classic** or **Volumetric**. Classic, the originaltoxin and radiation ground effects, is the default; Volumetric is an opt-in. Switching applies liveand persists as `CloudStyle = 0` or `CloudStyle = 1` in Options.ini. The choice is independent of-the particle and smoke-shadow settings.+the particle and smoke-shadow settings. The Classic graphics setting overrides it: that is the+game's own picture, puddles included. The heat effects option takes the nuclear shimmer off.## How it is split- **Neutral core**, built on every platform: `Platform/HazardCloud.h` (the renderer API: field and- body types, palettes, the abstract `HazardCloud::Layer`, `HazardCloud::Supported()` and- `HazardCloud::CreateLayer()`), `Platform/HazardCloudPolicy.h` (which templates are which hazard,- build-up, validity), `HazardCloudFlow` (the planar smoke-transport simulation; no graphics device),- `HazardCloud.cpp` (approved palettes, cache estimate), and the field tracking in+ body types, palettes, the camera a cloud is drawn from, the abstract `HazardCloud::Layer`,+ `Supported()`, `CreateLayer()` and `ReleaseDevice()`), `Platform/HazardCloudPolicy.h` (which+ templates are which hazard, build-up, validity), `HazardCloudFlow` (the planar smoke-transport+ simulation), `HazardCloud.cpp` (approved palettes, cache estimate), and the field tracking in`W3DParticleSys.cpp`.+- **Device-free half of a layer**, also on every platform: `Platform/HazardCloudCore.h` with+ `HazardCloudCore.cpp` (`HazardCloud::LayerCore`: fields, wakes, palettes, terrain grids, the+ shader constants and when the atlases rebake) and `HazardCloudShader.cpp` (the HLSL text of the+ cloud passes and the nuclear embers). A backend derives from `LayerCore` and supplies the device+ half: `initialize`, `render`, `estimatedCacheBytes` and `shutdown`.- **SDL GPU backend**, built where the SDL GPU renderer is (Linux and macOS):`PosixDevice/Render/SdlHazardCloud*.cpp`. `Supported()` is true when the device in use is the SDLGPU device and it provides a sampleable scene depth plus the R16F/RGBA16F/RGBA32F formats theclouds use. Its shaders go through `SDL3_Create_Shader`, so Metal gets them transpiled from SPIR-V.-- **No backend**, everywhere else (Windows today): `HazardCloudUnsupported.cpp`, where `Supported()`- is false and `CreateLayer()` returns null. A Direct3D 11 backend replaces this file and implements- `HazardCloud::Layer`.+- **Direct3D 11 backend**, Windows: `W3DDevice/GameClient/DX11HazardCloud.cpp`. `Supported()` is+ true while the Direct3D 11 frame presents (not under `-d3d9` or `-headless`) on a feature level+ 11 device that renders and samples R16F and RGBA16F and samples RGBA32F and R32F. The same HLSL+ is compiled at shader model 5 without SDL's register spaces, through+ `DX11BackendClass::Compile_Program`, so the programs land in `Run/dx11shaders.cache` and a second+ run compiles nothing. `test_dx11backend` compiles every pass and fails if FXC refuses one.+- **No backend**: `HazardCloudUnsupported.cpp`, where `Supported()` is false and `CreateLayer()`+ returns null, linked only into the tests that carry no device.-Without a supported backend the selector is hidden and the ground fields behave exactly as before-this change: the extended field tracking (fields keyed by height and owner, owner binding for-nuclear pulses, the sparse-emitter grace rule, skipping systems still in their initial delay) runs-only when the backend supports clouds. The answer is taken once per device and cached; when it-changes, the field tables are cleared before their key ordering changes.+The Direct3D 11 passes run on the context between two of the backend's draws, from+`W3DParticleSystemManager::doParticles`, while the draws go into the scene's own target or into a+screen filter's texture over the scene's depth (black and white, motion blur, cross fade:+`DX11BackendClass::Scene_Target`); a mirror and the sun's map keep Classic. The scene's depth is+read through `DX11DeviceClass::Get_Depth_Texture`, so the composite binds that target with no depth+buffer. Afterwards the scene target, its depth and the viewport are+bound again and `Forget_Bindings` makes the backend's next draw bind everything it needs. The heat+haze bends a `CopyResource` of the scene taken after the smoke and embers. The embers are drawn+with the backend's half-pixel viewport offset, so they sit where Direct3D 9 would put them.++Classic, or no backend, tracks the ground fields as retail did. The extended tracking (fields keyed+by height and owner, owner binding for nuclear pulses, the sparse-emitter grace rule, skipping+systems still in their initial delay) runs only with a backend and the Volumetric style. The device+is asked once and the answer cached; the mode is decided at the sync point only, and when it changes+the field tables are cleared before their key ordering changes.## What Volumetric draws@@ -38,22 +59,39 @@ state: Classic and Volumetric runs of the same scenario give the same game-stateEverything the clouds read from the game (field owners and their remaining lifetime, infantrypositions, visibility and shroud) is taken in `updateGroundFields` at the sync point, through-`W3DParticleSystemManager::takeReadsForRender`; the draw reads only those copies and the render-terrain heights.+`W3DParticleSystemManager::takeReadsForRender`; the draw reads only those copies, the render+terrain heights and the scene camera, which the caller hands over from `rinfo.Camera` rather than+the device's transforms (those can be the last draw's until the next state flush).++Each field's density and light live in two atlases baked from the field's state. A camera move+never rebakes them. A structural change does at once: a palette, the terrain, the field's size, a+new field. A cloud that only ages or is stirred rebakes at most `BakesPerSecond` (20) times a+second, and a wake grid with no infantry moving and nothing left to heal is put at rest and not+uploaded again. `test_hazard_cloud_policy` holds both rules.The client admits at most eight visible cloud layers within a 192 MiB atlas-cache budget.Over-budget fields, unknown effects and missing GPU resources keep the Classic effect. Clouds drawafter opaque geometry and water in the main scene; reflection and custom passes leave the-main-view caches and wakes alone. Caches and wakes reset on map or device changes.+main-view caches and wakes alone. A map's end frees the layers; the programs and screen-sized+targets they share stay until `ReleaseDevice`, which `releaseCloudResources` calls at the display's+device sites (teardown, alt-tab reset, a resolution or window change).The support model follows height-map terrain or an elevated plane. Cliffs and crossing decks have nodedicated fixture or automatic geometry fallback: one height per XY sample cannot representseveral support surfaces within a field. Exactly coincident owners of the same palette cannot betold apart by position.+`HAZARDCLOUD:` in the Windows log says when a layer first draws on Direct3D 11, and why the clouds+stopped if a program or a texture was refused.+## Tests```shcmake --build build-linux --target generals test_hazard_cloud_policy test_gameengine sdl_gpu_frame_selfcheckctest --test-dir build-linux --output-on-failure -R '^(test_hazard_cloud_policy|test_gameengine|sdl_gpu_frame_selfcheck)$'```++On Windows `build.bat Release test` runs `test_hazard_cloud_policy` and `test_dx11backend`.+`Scenarios/toxinslope.txt` puts a Scud Storm field on the mound at 1075, 3775 on Twilight Flame;+with `CloudStyle = 1` in the run's Options.ini, `-camera 1075 3775 -turbo -screenshot 2200` shows+it.diff --git a/docs/porting/windows-impact.md b/docs/porting/windows-impact.mdindex b82708725..894f43994 100644--- a/docs/porting/windows-impact.md+++ b/docs/porting/windows-impact.md@@ -473,12 +473,24 @@ names and shader programs; macOS binds the legacy SDL programs. The Linux stylewidget is hidden on both platforms. Windows/macOS builds and runtime checks remainopen; Linux compilation and GPU tests do not establish their runtime compatibility.-## Volumetric hazard clouds (2026-10-22)+## Volumetric hazard clouds (2026-10-22, Direct3D 11 2026-10-23)Windows compiles the neutral cloud core (`Platform/HazardCloud.h`, `HazardCloudPolicy.h`,-`HazardCloudFlow`, `HazardCloud.cpp`) and links `HazardCloudUnsupported.cpp`, so-`HazardCloud::Supported()` is false there: the Cloud style selector is hidden and the ground fields-take upstream's original keys, owner choice, grace period and initial-delay behaviour, because every-extended rule in `W3DParticleSys.cpp` is conditioned on that capability. The SDL backend-(`SdlHazardCloud*.cpp`) is built only where the SDL GPU renderer is. A Direct3D 11 backend would-replace `HazardCloudUnsupported.cpp` and implement `HazardCloud::Layer`.+`HazardCloudFlow`, `HazardCloud.cpp`) and, since 2026-10-23, the device-free half of a layer+(`Platform/HazardCloudCore.h`, `HazardCloudCore.cpp`, `HazardCloudShader.cpp`) that the SDL backend+shares. `gameenginedevice` links `DX11HazardCloud.cpp` in place of `HazardCloudUnsupported.cpp`,+which only the device-less tests still link. `HazardCloud::Supported()` is true while the Direct3D+11 frame presents on a feature level 11 device, so the Cloud style selector shows on the default+renderer and stays hidden under `-d3d9` and `-headless`.++The extended field rules in `W3DParticleSys.cpp` (keys, owner choice, grace period, initial delay)+now need the Volumetric style as well as the capability, and the Classic graphics setting turns+them off, so a Classic player on any platform tracks the fields as upstream did. The cloud programs+are compiled by the backend's `Compile_Program` at shader model 5 and kept in+`Run/dx11shaders.cache`; the shipped cache (`dx11shaders.shipped`) holds none of them until it is+recorded again, so a player's first Volumetric hazard pays their compile once.++The Direct3D 11 path was built and run on Windows: `test_dx11backend` compiles all eight programs+with d3dcompiler_47, and a Twilight Flame Scud Storm field drew on the default renderer with no+refusal in the log. The SDL backend was moved onto the shared core in the same change and has not+been compiled since; Linux and macOS builds are owed.