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
feat(w3ddevice): fires and blasts light the ground, walls and units
Olcay Seygan4d21b76de216
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 2bf5a1cd3..03891765d 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -8,6 +8,10 @@ found and fixed, EA's own, not port damage.**---+## Fires light what stands around them++- Firelight, under Options, Effects, is a new setting, off by default until it has been played. A burning building, a wreck or a blast throws a flickering orange light on the ground around it, where before only the one-off flash of an explosion lit anything and a town could burn all night over unlit paving. On Dark Night the moonlit ground beside a fire goes from cold blue-grey to warm tan. Twelve fires at most are lit at once, the strongest in view, and with all twelve going in a battle of three armies and three superweapons they add about a millisecond to a frame already at 18. The Direct3D 9 picture and Classic Graphics keep the old light.+## The ground remembers the fight- Battle Marks, under Options, Effects, is a new setting, off by default until it has been looked at on more maps. Tank shells and missiles landing on open ground leave a burn, where only fifty of the game's 431 effects ever marked the ground and a tank shell was not one of them. A building that falls leaves a dark stain with cracks in it. A nuke, a MOAB or a Daisy Cutter burns a ring of scorched earth round its crater, and a tank's track stays dark for three quarters of its length instead of a quarter.diff --git a/GeneralsMD/Code/BuildFingerprint.manifest b/GeneralsMD/Code/BuildFingerprint.manifestindex e92cb0dc1..bb611f034 100644--- a/GeneralsMD/Code/BuildFingerprint.manifest+++ b/GeneralsMD/Code/BuildFingerprint.manifest@@ -1779,6 +1779,7 @@ GameEngineDevice/Include/W3DDevice/Common/W3DModuleFactory.hGameEngineDevice/Include/W3DDevice/Common/W3DRadar.hGameEngineDevice/Include/W3DDevice/Common/W3DThingFactory.hGameEngineDevice/Include/W3DDevice/GameClient/BaseHeightMap.h+GameEngineDevice/Include/W3DDevice/GameClient/FireLights.hGameEngineDevice/Include/W3DDevice/GameClient/FlatHeightMap.hGameEngineDevice/Include/W3DDevice/GameClient/GpuParticles.hGameEngineDevice/Include/W3DDevice/GameClient/GroundMarks.h@@ -3213,6 +3214,7 @@ Tests/test_ffvertex.cppTests/test_ffvertexcompile.cppTests/test_ffvertexd3d9.cppTests/test_fingerprint_manifest.sh+Tests/test_fire_lights.cppTests/test_first_launch_chooser.shTests/test_fontchars.cppTests/test_fpucontrol.cppdiff --git a/GeneralsMD/Code/CMakeLists.txt b/GeneralsMD/Code/CMakeLists.txtindex bcffef350..ad692dde1 100644--- a/GeneralsMD/Code/CMakeLists.txt+++ b/GeneralsMD/Code/CMakeLists.txt@@ -2226,6 +2226,8 @@ target_include_directories(test_audio_mix_policy PRIVATE ${CMAKE_CURRENT_SOURCE_# W3DDevice/GameClient/GroundMarks.h: the Battle Marks option's cap and fade.add_lib_test(test_ground_marks)target_include_directories(test_ground_marks PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/GameEngineDevice/Include)+add_lib_test(test_fire_lights)+target_include_directories(test_fire_lights PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/GameEngineDevice/Include)add_lib_test(test_hazard_cloud_policy)set_target_properties(test_hazard_cloud_policy PROPERTIES CXX_STANDARD 17)diff --git a/GeneralsMD/Code/Data/Patch.str b/GeneralsMD/Code/Data/Patch.strindex 09d2b6456..ea6428028 100644--- a/GeneralsMD/Code/Data/Patch.str+++ b/GeneralsMD/Code/Data/Patch.str@@ -1508,6 +1508,14 @@ TOOLTIP:GroundMarks"Shells and missiles leave burns on the ground, a fallen building leaves a dark stain with cracks in it, a nuke leaves a burnt ring, and tank treads stay dark for longer. They fade over about four minutes. Direct3D 11 only, and off under Classic Graphics. Applies when you press Accept."END+GUI:Firelight+"Firelight"+END++TOOLTIP:Firelight+"Burning buildings, wrecks and explosions throw a flickering orange light on the ground, the walls and the units around them. It shows most on night maps. Direct3D 11 only, and off under Classic Graphics. Applies when you press Accept."+END+GUI:FormationDrag"Drag Out A Formation"ENDdiff --git a/GeneralsMD/Code/Data/Turkish/Generals.str b/GeneralsMD/Code/Data/Turkish/Generals.strindex 83e77843c..fd3f98e0f 100644--- a/GeneralsMD/Code/Data/Turkish/Generals.str+++ b/GeneralsMD/Code/Data/Turkish/Generals.str@@ -15901,6 +15901,14 @@ TOOLTIP:GroundMarks"Mermiler ve füzeler yerde yanık bırakır, yıkılan bina çatlaklarla dolu koyu bir leke bırakır, nükleer patlama yanık bir halka bırakır, tank paletlerinin izi daha uzun süre koyu kalır. Yaklaşık dört dakikada silinirler. Yalnızca Direct3D 11 ile, Klasik Grafikler açıkken kapalıdır. Kabul Et'e basınca uygulanır."END+GUI:Firelight+"Ateş Işığı"+END++TOOLTIP:Firelight+"Yanan binalar, enkazlar ve patlamalar çevrelerindeki zemine, duvarlara ve birimlere titreyen turuncu bir ışık vurur. En çok gece haritalarında belli olur. Yalnızca Direct3D 11 ile, Klasik Grafikler açıkken kapalıdır. Kabul Et'e basınca uygulanır."+END+GUI:FormationDrag"Sürükleyerek Düzen Kur"ENDdiff --git a/GeneralsMD/Code/Data/Window/Menus/OptionsMenuClassic.wnd b/GeneralsMD/Code/Data/Window/Menus/OptionsMenuClassic.wndindex 01dc0318d..d2e08a734 100644--- a/GeneralsMD/Code/Data/Window/Menus/OptionsMenuClassic.wnd+++ b/GeneralsMD/Code/Data/Window/Menus/OptionsMenuClassic.wnd@@ -7643,6 +7643,53 @@ WINDOWWINDOWWINDOWTYPE = CHECKBOX;SCREENRECT = UPPERLEFT: 536 350, BOTTOMRIGHT: 760 374, CREATIONRESOLUTION: 800 600;+ NAME = "OptionsMenu.wnd:CheckFirelight";+ STATUS = ENABLED+IMAGE+BORDER;+ STYLE = CHECKBOX+MOUSETRACK;+ SYSTEMCALLBACK = "[None]";+ INPUTCALLBACK = "[None]";+ TOOLTIPCALLBACK = "[None]";+ DRAWCALLBACK = "[None]";+ FONT = NAME: "Arial", SIZE: 14, BOLD: 0;+ HEADERTEMPLATE = "MinorTitle";+ TOOLTIPTEXT = "TOOLTIP:Firelight";+ TOOLTIPDELAY = -1;+ TEXT = "GUI:Firelight";+ TEXTCOLOR = ENABLED: 255 255 255 255, ENABLEDBORDER: 0 0 0 255,+ DISABLED: 192 192 192 255, DISABLEDBORDER: 64 64 64 255,+ HILITE: 186 255 12 255, HILITEBORDER: 0 0 0 255;+ ENABLEDDRAWDATA = IMAGE: NoImage, COLOR: 255 0 0 255, BORDERCOLOR: 255 128 128 255,+ IMAGE: Active-Unchecked, COLOR: 255 255 255 0, BORDERCOLOR: 128 128 255 255,+ IMAGE: Active-Checked, COLOR: 0 0 255 255, BORDERCOLOR: 128 128 255 255,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0;+ DISABLEDDRAWDATA = IMAGE: NoImage, COLOR: 128 128 128 255, BORDERCOLOR: 192 192 192 255,+ IMAGE: Disabled-Unchecked, COLOR: 255 255 255 0, BORDERCOLOR: 192 192 192 255,+ IMAGE: Disabled-Checked, COLOR: 64 64 64 255, BORDERCOLOR: 254 254 254 255,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0;+ HILITEDRAWDATA = IMAGE: NoImage, COLOR: 0 255 0 255, BORDERCOLOR: 128 255 128 255,+ IMAGE: Active-HiLighted, COLOR: 255 255 255 0, BORDERCOLOR: 128 128 255 255,+ IMAGE: Active-Checked, COLOR: 255 255 0 255, BORDERCOLOR: 254 254 254 255,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0;+ END+ CHILD+ WINDOW+ WINDOWTYPE = CHECKBOX;+ SCREENRECT = UPPERLEFT: 536 378, BOTTOMRIGHT: 760 402, CREATIONRESOLUTION: 800 600;NAME = "OptionsMenu.wnd:CheckDebrisTrails";STATUS = ENABLED+IMAGE+BORDER;STYLE = CHECKBOX+MOUSETRACK;diff --git a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.hindex d84d66dc0..421bf5dcf 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h@@ -707,6 +707,7 @@ public:Bool m_teamGlow; ///< "TeamGlow": bright house colour glows (Direct3D 11, client only)Bool m_waterFoam; ///< "WaterFoam": foam, shore band and the sun's shadow on water (Direct3D 11, client only)Bool m_groundMarks; ///< "GroundMarks": craters, stains and longer treads that fade over minutes (Direct3D 11, client only)+ Bool m_firelight; ///< "Firelight": flames light the ground, walls and units around them (Direct3D 11, client only)Int m_maxParticleCount; ///< maximum number of particles that can existInt m_maxFieldParticleCount; ///< maximum number of field-type particles that can exist (roughly)diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cppindex 5d45f7fde..279970dff 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp@@ -1136,6 +1136,7 @@ GlobalData::GlobalData()m_teamGlow = FALSE;m_waterFoam = FALSE;m_groundMarks = FALSE;+ m_firelight = FALSE;m_horizontalScrollSpeedFactor = 1.0;m_verticalScrollSpeedFactor = 1.0;diff --git a/GeneralsMD/Code/GameEngine/Source/Common/OptionsCatalog.cpp b/GeneralsMD/Code/GameEngine/Source/Common/OptionsCatalog.cppindex a3fb69089..8ea4f158e 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/OptionsCatalog.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/OptionsCatalog.cpp@@ -143,6 +143,7 @@ OPTION_BOOL_ACCESSORS( m_mapLight )OPTION_BOOL_ACCESSORS( m_teamGlow )OPTION_BOOL_ACCESSORS( m_waterFoam )OPTION_BOOL_ACCESSORS( m_groundMarks )+OPTION_BOOL_ACCESSORS( m_firelight )OPTION_INT_ACCESSORS( m_shadowQuality )OPTION_INT_ACCESSORS( m_graphicsQuality )@@ -619,6 +620,13 @@ const OptionDef TheOptionCatalog[] =OPTION_BOOL, APPLY_LIVE, 0, 1,get_m_groundMarks, set_m_groundMarks },+ // Burning buildings, wrecks and blasts as flickering point lights on the ground, walls and units.+ // The particle draw asks every frame. Off under Classic graphics and -d3d9, which light nothing+ // per pixel, and no row in the quality table: an opt-in until it has been seen. On Options > Effects.+ { "Firelight", OPT_WND( "CheckFirelight" ), "GUI:Firelight",+ OPTION_BOOL, APPLY_LIVE, 0, 1,+ get_m_firelight, set_m_firelight },+// The size of the sun's depth map. The shadow pass asks for it every frame and the backend makes// the map again when the size changes, so a new level shows on the next frame. On Options >// Effects. Classic graphics and -d3d9 draw no map at all.diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cppindex 637c73bf1..59e940b59 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp@@ -2961,7 +2961,7 @@ void OptionsMenuInit( WindowLayout *layout, void *userData )// three looks only the Direct3D 11 picture draws; under -d3d9 their boxes keep the saved value, greyedif( !TheGlobalData->m_direct3D11 ){- static const char *const direct3D11Only[] = { "MapLight", "TeamGlow", "WaterFoam", "GroundMarks" };+ static const char *const direct3D11Only[] = { "MapLight", "TeamGlow", "WaterFoam", "GroundMarks", "Firelight" };for( Int i = 0; i < (Int)( sizeof( direct3D11Only ) / sizeof( direct3D11Only[ 0 ] ) ); ++i )findOptionWidget( *findOptionDef( direct3D11Only[ i ] ) )->winEnable( FALSE );}diff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/FireLights.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/FireLights.hnew file mode 100644index 000000000..5169ce032--- /dev/null+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/FireLights.h@@ -0,0 +1,187 @@+/*+** Command & Conquer Generals Zero Hour(tm)+** Copyright 2025 Electronic Arts Inc.+**+** This program is free software: you can redistribute it and/or modify+** it under the terms of the GNU General Public License as published by+** the Free Software Foundation, either version 3 of the License, or+** (at your option) any later version.+**+** This program is distributed in the hope that it will be useful,+** but WITHOUT ANY WARRANTY; without even the implied warranty of+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+** GNU General Public License for more details.+**+** You should have received a copy of the GNU General Public License+** along with this program. If not, see <http://www.gnu.org/licenses/>.+*/+// Modified 2026 by Olcay Seygan for Zero Hour Reforged; see the git history.++// FILE: FireLights.h+// The Firelight option: flames as point lights on the ground, walls and units, kept free of the engine+// so a test can hold the grouping and the cap. A burning building is a dozen systems, so flames near+// each other become one light, and the strongest MAX_LIGHTS in view go to the per pixel lights+// (BLAST_LIGHT_SAMPLING). Client only: nothing here reads or writes logic.++#pragma once++#include <math.h>++namespace FireLights {++enum {+ MAX_LIGHTS = 12, ///< a frame's fire lights, out of the 32 per pixel slots the pulses share+ MAX_GROUPS = 128 ///< flames in view; past this a new group is dropped+};++static const float MERGE_DISTANCE = 60.0f; ///< flames this close to a group's middle join it+static const float MIN_WEIGHT = 25.0f; ///< brightness x size under which flames light nothing: a muzzle flare+static const float FULL_WEIGHT = 300.0f; ///< and at which they are at full strength+static const float REACH = 90.0f; ///< a full fire's reach beyond its own spread+static const float SPREAD_SCALE = 2.0f; ///< times the flames' RMS spread, added to the reach+static const float MAX_REACH = 260.0f;+static const float INNER_REACH = 10.0f; ///< full strength inside this+static const float LIFT = 25.0f; ///< over the flames' middle, so the ground around them faces the light+static const float GAIN = 0.7f; ///< a full fire's light at the surface it faces+static const float AMBIENT_SHARE = 0.3f; ///< of that, on every surface it reaches whichever way it faces+static const float RED = 1.0f, GREEN = 0.5f, BLUE = 0.2f;++/// Weighted sums over a fire's particles: w the weight (brightness x size), then the weighted+/// position and the weighted square of it.+struct Flames {+ float w, x, y, z, sq;++ Flames() : w(0.0f), x(0.0f), y(0.0f), z(0.0f), sq(0.0f) {}++ void add(float weight, float px, float py, float pz)+ {+ w += weight;+ x += weight * px;+ y += weight * py;+ z += weight * pz;+ sq += weight * (px * px + py * py + pz * pz);+ }+ void add(const Flames &other)+ {+ w += other.w;+ x += other.x;+ y += other.y;+ z += other.z;+ sq += other.sq;+ }+ void scale(float by)+ {+ w *= by;+ x *= by;+ y *= by;+ z *= by;+ sq *= by;+ }+};++struct Light {+ float x, y, z, reach, inner;+ float red, green, blue; ///< the facing surface's light; the ambient is AMBIENT_SHARE of it+ float strength;+};++/// 0 at MIN_WEIGHT, so a fire comes on with no pop, and 1 from FULL_WEIGHT.+inline float strength(float weight)+{+ if (weight <= MIN_WEIGHT)+ return 0.0f;+ return weight >= FULL_WEIGHT ? 1.0f : (weight - MIN_WEIGHT) / (FULL_WEIGHT - MIN_WEIGHT);+}++/// A fire breathing on the particle clock, 0.78 to 1, each spot of the map out of step with the next.+/// The flames' own weight moves it too until it saturates, and a big fire's weight always has.+inline float flicker(unsigned int frame, float x, float y)+{+ const float f = (float)frame;+ const float phase = floorf(x / 64.0f) * 3.7f + floorf(y / 64.0f) * 5.3f;+ const float noise = 0.5f * sinf(0.21f * f + phase) + 0.3f * sinf(0.53f * f + 2.1f * phase) + 0.2f * sinf(1.07f * f + 3.7f * phase);+ return 0.89f + 0.11f * noise;+}++class Gather {+public:+ Gather() : m_count(0) {}++ void clear() { m_count = 0; }+ int count() const { return m_count; }++ /// Flames join the first group whose middle is near them, whose spread they then widen.+ void add(const Flames &flames)+ {+ if (flames.w <= 0.0f)+ return;+ const float inv = 1.0f / flames.w;+ const float px = flames.x * inv, py = flames.y * inv, pz = flames.z * inv;+ for (int i = 0; i < m_count; ++i) {+ const Flames &group = m_groups[i];+ const float groupInv = 1.0f / group.w;+ const float dx = group.x * groupInv - px, dy = group.y * groupInv - py, dz = group.z * groupInv - pz;+ if (dx * dx + dy * dy + dz * dz < MERGE_DISTANCE * MERGE_DISTANCE) {+ m_groups[i].add(flames);+ return;+ }+ }+ // ponytail: past MAX_GROUPS in view a late fire goes dark; pick by weight if a nuke's field ever gets here+ if (m_count < MAX_GROUPS)+ m_groups[m_count++] = flames;+ }++ /// The strongest MAX_LIGHTS whose reach touches the box, into out[MAX_LIGHTS]. Returns how many.+ int pick(const float center[3], const float extent[3], unsigned int frame, Light *out) const+ {+ int lit = 0;+ for (int i = 0; i < m_count; ++i) {+ Light light;+ if (!makeLight(m_groups[i], frame, light))+ continue;+ if (fabsf(light.x - center[0]) > extent[0] + light.reach+ || fabsf(light.y - center[1]) > extent[1] + light.reach+ || fabsf(light.z - center[2]) > extent[2] + light.reach)+ continue;+ int slot = lit;+ if (lit == MAX_LIGHTS) {+ slot = 0;+ for (int j = 1; j < lit; ++j)+ if (out[j].strength < out[slot].strength)+ slot = j;+ if (out[slot].strength >= light.strength)+ continue;+ } else+ ++lit;+ out[slot] = light;+ }+ return lit;+ }++private:+ static bool makeLight(const Flames &flames, unsigned int frame, Light &light)+ {+ light.strength = strength(flames.w);+ if (light.strength <= 0.0f)+ return false;+ const float inv = 1.0f / flames.w;+ light.x = flames.x * inv;+ light.y = flames.y * inv;+ light.z = flames.z * inv + LIFT;+ const float mz = flames.z * inv;+ const float variance = flames.sq * inv - (light.x * light.x + light.y * light.y + mz * mz);+ const float reach = REACH * (0.5f + 0.5f * light.strength) + SPREAD_SCALE * (variance > 0.0f ? sqrtf(variance) : 0.0f);+ light.reach = reach < MAX_REACH ? reach : MAX_REACH;+ light.inner = INNER_REACH;+ const float gain = light.strength * GAIN * flicker(frame, light.x, light.y);+ light.red = RED * gain;+ light.green = GREEN * gain;+ light.blue = BLUE * gain;+ return true;+ }++ Flames m_groups[MAX_GROUPS];+ int m_count;+};++} // namespace FireLightsdiff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DParticleSys.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DParticleSys.hindex 358572285..aa6038a83 100644--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DParticleSys.h+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DParticleSys.h@@ -48,6 +48,10 @@class TextureClass;+namespace FireLights { struct Light; }+/// The Firelight option's lights the last doParticles picked: none with the option off.+const FireLights::Light *getFirelights( Int *count );+//=============================================================================/** W3D implementation of the game display which is responsible for creating* all interaction with the screen and updating the display@@ -149,6 +153,8 @@ private:/// attachment that decide a fade change in the logic alone, or in doDrawModule before a pass's first/// refresh. Anything else that changes one of them mid-frame is not seen until the next logic frame.std::vector<SystemView> m_frameView;+ std::vector<ParticleSystem *> m_frameFires; ///< the additive and Emissive FireLook systems among them, for the Firelight option+ std::vector<Real> m_frameFireFades; ///< and their fadesstd::vector<ParticleSystem *> m_fieldSystems; ///< the contamination fields' systems, empty ones toostd::vector<SunMapCaster> m_sunMapCasters;Bool m_frameViewValid;diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DParticleSys.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DParticleSys.cppindex e292ab100..2438dda36 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DParticleSys.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DParticleSys.cpp@@ -32,6 +32,7 @@#include "Lib/Clock.h"#include "GameClient/Color.h"#include "W3DDevice/GameClient/W3DParticleSys.h"+#include "W3DDevice/GameClient/FireLights.h"#include "W3DDevice/GameClient/W3DAssetManager.h"#include "W3DDevice/GameClient/W3DDisplay.h"#include "W3DDevice/GameClient/HeightMap.h"@@ -271,12 +272,11 @@ static void addFireLight( Real w, Real x, Real y, Real z, Real sq, Real fade )s_fireLights.push_back( fire );}-/** One additive or Emissive system as a point light, if it is bright enough. An Emissive body's- * colour stays white while its flipbook cools to soot, so its weight falls with the life left. */-static void gatherFireLight( ParticleSystem *sys, Real fade )+/** A system's flames as weighted sums. An Emissive body's colour stays white while its flipbook cools+ * to soot, so its weight falls with the life left. */+static void sumFlames( ParticleSystem *sys, FireLights::Flames &flames ){const Bool emissive = sys->getTemplate()->isEmissive();- Real w = 0.0f, x = 0.0f, y = 0.0f, z = 0.0f, sq = 0.0f;for (Particle *p = sys->getFirstParticle(); p; p = p->m_systemNext){const RGBColor *c = p->getColor();@@ -286,13 +286,63 @@ static void gatherFireLight( ParticleSystem *sys, Real fade )if (pw <= 0.0f)continue;const Coord3D *pos = p->getPosition();- w += pw;- x += pw * pos->x;- y += pw * pos->y;- z += pw * pos->z;- sq += pw * (pos->x * pos->x + pos->y * pos->y + pos->z * pos->z);+ flames.add( pw, pos->x, pos->y, pos->z );+ }+}++/** One additive or Emissive system as a point light, if it is bright enough. */+static void gatherFireLight( ParticleSystem *sys, Real fade )+{+ FireLights::Flames flames;+ sumFlames( sys, flames );+ addFireLight( flames.w, flames.x, flames.y, flames.z, flames.sq, fade );+}++// The Firelight option's lights, picked by the last doParticles for the next frame's terrain and+// models: the scene takes them first and these cost nothing but the walk over the flames in view.+static FireLights::Gather s_firelightGroups;+static FireLights::Light s_firelights[ FireLights::MAX_LIGHTS ];+static Int s_firelightCount = 0;++const FireLights::Light *getFirelights( Int *count )+{+ *count = s_firelightCount;+ return s_firelights;+}++/** The flames in view, grouped, then the strongest as lights. A FireLook template that draws by+ * adding light is a flame or a blast; its smoke, FireLook or not, blends. A FireLook system is never+ * on the GPU path (isGpuEligible), so nothing here pays for a closed form, and the systems were filed+ * once a particle update (m_frameFires). */+static void gatherFirelights( const AABoxClass &view, UnsignedInt frame, const std::vector<ParticleSystem *> &systems, const std::vector<Real> &fades )+{+ s_firelightGroups.clear();+ for (size_t i = 0; i < systems.size(); ++i)+ {+ // the view is filed once a particle update and a system can run out of particles before the next+ Particle *first = systems[ i ]->getFirstParticle();+ if (first == NULL+ || WWMath::Fabs( first->getPosition()->x - view.Center.X ) > view.Extent.X + FireLights::MAX_REACH+ || WWMath::Fabs( first->getPosition()->y - view.Center.Y ) > view.Extent.Y + FireLights::MAX_REACH)+ continue;+ FireLights::Flames flames;+ sumFlames( systems[ i ], flames );+ flames.scale( fades[ i ] );+ s_firelightGroups.add( flames );}- addFireLight( w, x, y, z, sq, fade );+ const float center[3] = { view.Center.X, view.Center.Y, view.Center.Z };+ const float extent[3] = { view.Extent.X, view.Extent.Y, view.Extent.Z };+ s_firelightCount = s_firelightGroups.pick( center, extent, frame, s_firelights );++#ifdef DEBUG_LOGGING+ static UnsignedInt s_nextLog = 0;+ if (frame >= s_nextLog && s_firelightCount > 0)+ {+ s_nextLog = frame + 10 * LOGICFRAMES_PER_SECOND;+ DEBUG_LOG(( "FIRELIGHT frame %u: %d flame systems, %d groups in view, %d lit, strongest %.2f\n",+ frame, (Int)systems.size(), s_firelightGroups.count(), s_firelightCount, s_firelights[ 0 ].strength ));+ }+#endif}/** The same for a GPU system, from the spawns it keeps (ParticleSystem::getGpuSample) aged in closed@@ -1831,8 +1881,11 @@ void W3DParticleSystemManager::reset(){ParticleSystemManager::reset();s_fireLightsValid = FALSE;+ s_firelightCount = 0;m_frameViewValid = FALSE; // its systems are gonem_frameView.clear();+ m_frameFires.clear();+ m_frameFireFades.clear();m_fieldSystems.clear();m_sunMapCasters.clear();invalidateGroundFields(); // the object IDs it holds belong to the game that ended@@ -1892,6 +1945,8 @@ void W3DParticleSystemManager::refreshFrameView( void )return;m_frameView.clear();+ m_frameFires.clear();+ m_frameFireFades.clear();m_fieldSystems.clear();for (ParticleSystemListIt it = m_allParticleSystemList.begin(); it != m_allParticleSystemList.end(); ++it){@@ -1918,6 +1973,12 @@ void W3DParticleSystemManager::refreshFrameView( void )} else view.owner = sys->getAttachedObject();#endifm_frameView.push_back( view );+ if (sys->getTemplate()->isFireLook()+ && (sys->getShaderType() == ParticleSystemInfo::ADDITIVE || sys->getTemplate()->isEmissive()))+ {+ m_frameFires.push_back( sys );+ m_frameFireFades.push_back( fade );+ }}refreshGpuSystems();@@ -2150,6 +2211,13 @@ void W3DParticleSystemManager::doParticles(RenderInfoClass &rinfo)fillJob.extentY = beY;fillJob.extentZ = beZ;fillJob.lightCount = 0;+ // A reflecting water's mirror comes here first with its own, smaller box; the picks are the frame's.+ if (!ShaderClass::Is_Backface_Culling_Inverted())+ {+ s_firelightCount = 0;+ if (TheGlobalData->m_firelight && Direct3D11_Lights_Per_Pixel())+ gatherFirelights( bbox, m_lastLogicFrameUpdate, m_frameFires, m_frameFireFades );+ }// Only a CPU drawn smoke system takes a light (pickSmokeLights); with none, the walk over every// fire, a GPU one's samples aged in closed form, is a third of a frame thrown away.Bool smokeDrawn = FALSE;diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DScene.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DScene.cppindex 5830438ff..5d8ee327a 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DScene.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DScene.cpp@@ -55,6 +55,8 @@#include "W3DDevice/GameClient/HeightMap.h"#include "W3DDevice/GameClient/W3DScene.h"#include "W3DDevice/GameClient/W3DDynamicLight.h"+#include "W3DDevice/GameClient/W3DParticleSys.h"+#include "W3DDevice/GameClient/FireLights.h"#include "W3DDevice/GameClient/W3DGranny.h"#include "W3DDevice/GameClient/W3DShadow.h"#include "W3DDevice/GameClient/W3DVolumetricShadow.h"@@ -1400,6 +1402,20 @@ static void handBlastLights(RefRenderObjListClass &dynamicLights, const Vector3static float lights[BLAST_LIGHT_SLOTS][BLAST_LIGHT_FLOATS];unsigned count = 0;+ // The Firelight option's fires come first, so a barrage's muzzle flashes cannot take a burning base+ // off the ground for a frame and give it back the next; FireLights::MAX_LIGHTS leaves the pulses the rest.+ Int fireCount;+ const FireLights::Light *fires = getFirelights(&fireCount);+ for (Int i = 0; i < fireCount; ++i)+ {+ const FireLights::Light &fire = fires[i];+ float *slot = lights[count++];+ slot[0] = fire.x; slot[1] = fire.y; slot[2] = fire.z; slot[3] = fire.reach;+ slot[4] = fire.red / base[0]; slot[5] = fire.green / base[1]; slot[6] = fire.blue / base[2];+ slot[7] = fire.inner;+ slot[8] = slot[4] * FireLights::AMBIENT_SHARE; slot[9] = slot[5] * FireLights::AMBIENT_SHARE; slot[10] = slot[6] * FireLights::AMBIENT_SHARE;+ slot[11] = 0.0f;+ }for (size_t i = 0; i < nearest.size() && count < BLAST_LIGHT_SLOTS; ++i){W3DDynamicLight *light = nearest[i].second;diff --git a/GeneralsMD/Code/Tests/test_fire_lights.cpp b/GeneralsMD/Code/Tests/test_fire_lights.cppnew file mode 100644index 000000000..64186fdb1--- /dev/null+++ b/GeneralsMD/Code/Tests/test_fire_lights.cpp@@ -0,0 +1,81 @@+// test_fire_lights.cpp: the grouping and the cap of the Firelight option.++#include "test_harness.h"++#include "W3DDevice/GameClient/FireLights.h"++using namespace FireLights;++static Flames flamesAt(float weight, float x, float y, float z)+{+ Flames flames;+ flames.add(weight, x, y, z);+ return flames;+}++static const float VIEW_CENTER[3] = { 0.0f, 0.0f, 0.0f };+static const float VIEW_EXTENT[3] = { 1000.0f, 1000.0f, 1000.0f };++TEST(flames_near_each_other_are_one_light_and_far_ones_are_two)+{+ Gather gather;+ gather.add(flamesAt(FULL_WEIGHT, 0.0f, 0.0f, 0.0f));+ gather.add(flamesAt(FULL_WEIGHT, 20.0f, 0.0f, 0.0f));+ CHECK_EQ(gather.count(), 1);+ gather.add(flamesAt(FULL_WEIGHT, 500.0f, 0.0f, 0.0f));+ CHECK_EQ(gather.count(), 2);++ Light lights[MAX_LIGHTS];+ CHECK_EQ(gather.pick(VIEW_CENTER, VIEW_EXTENT, 0, lights), 2);+ CHECK_NEAR(lights[0].x, 10.0f, 0.01f);+ CHECK_NEAR(lights[0].z, LIFT, 0.01f);+ // two systems ten units either side of the middle widen the reach past a lone one's+ CHECK(lights[0].reach > lights[1].reach);+}++TEST(a_muzzle_flare_lights_nothing_and_a_fire_comes_on_from_nothing)+{+ CHECK_EQ(strength(MIN_WEIGHT), 0.0f);+ CHECK(strength(MIN_WEIGHT + 1.0f) < 0.01f);+ CHECK_EQ(strength(FULL_WEIGHT), 1.0f);+ CHECK_EQ(strength(FULL_WEIGHT * 10.0f), 1.0f);++ Gather gather;+ gather.add(flamesAt(MIN_WEIGHT - 1.0f, 0.0f, 0.0f, 0.0f));+ Light lights[MAX_LIGHTS];+ CHECK_EQ(gather.pick(VIEW_CENTER, VIEW_EXTENT, 0, lights), 0);+}++TEST(the_strongest_fires_take_the_capped_lights)+{+ Gather gather;+ for (int i = 0; i < MAX_LIGHTS * 2; ++i)+ gather.add(flamesAt(MIN_WEIGHT + 10.0f * (float)(i + 1), (float)i * 200.0f - 2000.0f, 0.0f, 0.0f));+ const float wide[3] = { 10000.0f, 10000.0f, 10000.0f };+ Light lights[MAX_LIGHTS];+ CHECK_EQ(gather.pick(VIEW_CENTER, wide, 0, lights), (int)MAX_LIGHTS);+ const float weakestKept = strength(MIN_WEIGHT + 10.0f * (float)(MAX_LIGHTS + 1));+ for (int i = 0; i < MAX_LIGHTS; ++i)+ CHECK(lights[i].strength >= weakestKept - 0.001f);+}++TEST(a_fire_out_of_reach_of_the_view_is_no_light)+{+ Gather gather;+ gather.add(flamesAt(FULL_WEIGHT, 5000.0f, 0.0f, 0.0f));+ Light lights[MAX_LIGHTS];+ CHECK_EQ(gather.pick(VIEW_CENTER, VIEW_EXTENT, 0, lights), 0);+}++TEST(the_flicker_stays_in_its_band_and_moves)+{+ float low = 2.0f, high = 0.0f;+ for (unsigned int frame = 0; frame < 2000; ++frame) {+ const float f = flicker(frame, 300.0f, 700.0f);+ low = f < low ? f : low;+ high = f > high ? f : high;+ }+ CHECK(low >= 0.78f - 0.001f);+ CHECK(high <= 1.0f + 0.001f);+ CHECK(high - low > 0.1f);+}diff --git a/GeneralsMD/Code/Tools/optionsmenu_layout.py b/GeneralsMD/Code/Tools/optionsmenu_layout.pyindex 8234e2777..df2b5550f 100644--- a/GeneralsMD/Code/Tools/optionsmenu_layout.py+++ b/GeneralsMD/Code/Tools/optionsmenu_layout.py@@ -239,6 +239,7 @@ NEW_CONTROLS = [(CHECK, "CheckTeamGlow", "GUI:TeamGlow"),(CHECK, "CheckWaterFoam", "GUI:WaterFoam"),(CHECK, "CheckGroundMarks", "GUI:GroundMarks"),+ (CHECK, "CheckFirelight", "GUI:Firelight"),(LABEL, "LabelGraphicsQuality", "GUI:GraphicsQuality"),(SLIDER, "SliderGraphicsQuality", None),]@@ -387,6 +388,7 @@ GROUP_LAYOUT = [setting("LabelSmoke", "ComboBoxSmoke"),("check", "CheckParticleBounce"),("check", "CheckSmokeFireLighting"),+ ("check", "CheckFirelight"),("check", "CheckDebrisTrails")])]),("PageAudio", [