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
fix(w3ddevice): build hazard cloud programs at match start, end clouds with their field
Olcay Seyganc44c0aa60f1c
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex d75a9537d..be0584157 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -22,6 +22,7 @@ found and fixed — EA's own, not port damage.**- Options has a Cloud Style box. Volumetric draws toxin, anthrax and nuclear fields as moving smoke at the size and for the time the hazard really lasts: low smoke hugs the ground and curls around infantry walking through it, and a nuclear field fades in across its whole width with dark billows and embers rising through the heat shimmer. The damage is exactly what it was. Classic stays the default until the cost in a big battle is measured.- Windows draws them too, on the default renderer, and so do Linux and macOS. The Direct3D 9 renderer and the Classic graphics setting keep the original puddles whatever the box says, and turning heat effects off takes the shimmer off a nuclear field as well. A cloud that only drifts redraws its smoke twenty times a second rather than every frame, and the second match of a session no longer stalls on the first toxin shell while the clouds' shaders are built again.+- The first toxin cloud of a fresh install no longer freezes the game for three and a half seconds: the clouds' shaders come with the game now, and are made ready when a match starts or the box is switched rather than when the first field opens. A toxin field also no longer comes back at full strength for ten seconds after it has run out; it fades with the hazard.## A rank ladder for every armydiff --git a/GeneralsMD/Code/Data/dx11shaders.shipped b/GeneralsMD/Code/Data/dx11shaders.shippedindex bf646875a..6cfe3d32b 100644Binary files a/GeneralsMD/Code/Data/dx11shaders.shipped and b/GeneralsMD/Code/Data/dx11shaders.shipped differdiff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/DX11HazardCloud.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/DX11HazardCloud.cppindex 8014aa2ba..4f993fe2a 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/DX11HazardCloud.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/DX11HazardCloud.cpp@@ -6,6 +6,7 @@#include "dx11backend.h"#include "dx11device.h"#include "dx11runtime.h"+#include "dx11resource.h"#include <d3d11.h>#include <algorithm>@@ -141,6 +142,7 @@ bool compile(DX11BackendClass *backend, ID3D11Device *device, const std::stringbool makeShared(DX11BackendClass *backend, ID3D11Device *device){if (shared.device == device) return !shared.refused;+ const double started = DX11Resource_Milliseconds_Now();releaseShared();shared.device = device;static const char *const names[PassCount] = {@@ -200,6 +202,9 @@ bool makeShared(DX11BackendClass *backend, ID3D11Device *device)shared.device = device;shared.refused = true;}+ // A program the shader cache lacks costs seconds of FXC here; the field tracking asks for+ // this at the first frame with Volumetric clouds, never on the frame a hazard opens.+ DEBUG_LOG(("HAZARDCLOUD: Direct3D 11 cloud programs made in %.1f ms\n", DX11Resource_Milliseconds_Now() - started));return made;}diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DParticleSys.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DParticleSys.cppindex db49d09ec..30c47334b 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DParticleSys.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DParticleSys.cpp@@ -791,13 +791,20 @@ static unsigned s_fieldCollectionPass = 0;static bool fieldCloudsSupported(){- if (!s_fieldCloudCapabilityKnown) {+ const bool newDevice = !s_fieldCloudCapabilityKnown;+ if (newDevice) {s_fieldCloudCapability = HazardCloud::Supported();s_fieldCloudCapabilityKnown = true;}// The Classic graphics setting is the game's own picture, and its clouds.const bool volumetric = s_fieldCloudCapability && TheGlobalData&& TheGlobalData->m_cloudStyle == 1 && !TheGlobalData->m_classicGraphics;+ // The programs every layer shares are built here, on the shell map or a match's first frame,+ // or the frame the style is switched: built by the first hazard instead, a program the shader+ // cache lacked froze that frame for three and a half seconds of FXC.+ if (volumetric && (newDevice || !s_fieldCloudsSupported))+ if (std::unique_ptr<HazardCloud::Layer> layer = HazardCloud::CreateLayer())+ layer->initialize();// A new device, or the style switched: destroy keys before changing their// comparator's mode.if (volumetric != s_fieldCloudsSupported) {@@ -876,6 +883,21 @@ static ObjectID findFieldObject( const Coord3D ¢re, Int palette = -1 )return found;}+/** The owner of the hazard cloud already standing at this place, living or not. A field's object+ * fires its weapon on the frame it dies, and that last system finds no living owner: left alone it+ * started a fresh cloud at full strength over the ended one, ten seconds of smoke after the hazard+ * was gone. It belongs to the field it was fired into. */+static ObjectID standingFieldOwner( Int x, Int y, Int z, Int palette )+{+ for (std::map<FieldKey, FieldState>::const_iterator st = s_fieldStates.begin(); st != s_fieldStates.end(); ++st)+ {+ const FieldKey &key = st->first;+ if (key.owner != INVALID_ID && key.palette == palette && key.x == x && key.y == y && key.z == z)+ return key.owner;+ }+ return INVALID_ID;+}+/** The middle of a random range. */static inline Real midValue( const GameClientRandomVariable &v ){@@ -1200,7 +1222,12 @@ static void updateGroundFields( const std::vector<ParticleSystem *> &systems )if (palette >= 0 && binding != s_fieldSystemOwners.end()) owner = binding->second.object;if (owner == INVALID_ID) {auto ownerEntry = fieldOwners.find(ownerKey);- if (ownerEntry == fieldOwners.end()) ownerEntry = fieldOwners.emplace(ownerKey, findFieldObject(pos, palette)).first;+ if (ownerEntry == fieldOwners.end()) {+ ObjectID found = findFieldObject(pos, palette);+ if (found == INVALID_ID && palette >= 0)+ found = standingFieldOwner(std::get<0>(ownerKey), std::get<1>(ownerKey), std::get<2>(ownerKey), palette);+ ownerEntry = fieldOwners.emplace(ownerKey, found).first;+ }owner = ownerEntry->second;}if (palette >= 0) {diff --git a/docs/hazard-clouds.md b/docs/hazard-clouds.mdindex de6077da9..8df540c6e 100644--- a/docs/hazard-clouds.md+++ b/docs/hazard-clouds.md@@ -46,7 +46,16 @@ Classic, or no backend, tracks the ground fields as retail did. The extended traby height and owner, owner binding for nuclear pulses, the sparse-emitter grace rule, skippingsystems still in their initial delay) runs only with a backend and the Volumetric style. The deviceis 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.+the field tables are cleared before their key ordering changes. The first sync point with Volumetric+on (or a new device) also initializes a throwaway layer, which builds the programs every layer+shares: built by the first hazard, a program missing from the shader cache froze that frame for 3.6+to 5.5 s on Direct3D 11.++A field's object fires its weapon on the frame it dies, so one last system turns up with no living+owner. It joins the bound field already standing at the same place and palette, the dead owner's,+and fades with it. Without that it started a new unbound cloud at full strength, about ten seconds+of smoke after the hazard ended (a Toxin Tractor's contamination: owner gone at frame 3850, the+second cloud drawn until 4436).## What Volumetric draws