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): toxin pools lie on the terrain as a steady field
Olcay Seygand30bf9e33cb1
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 6dbdc0888..48bb99d28 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -1303,7 +1303,7 @@ The whole HUD is on the hardware. Four colours carry it, and they mean the same- An explosion lights everything around it, smoothly. On the default renderer the light of a blast reaches every tank, soldier, building and patch of ground it can see, fading out with distance, where the ground used to brighten in blocky squares and a model took only four lights at once, so in a big fight half the tanks next to a burning wreck stayed dark. The 32 blasts nearest the camera light at the same time, and a wall with its back to the fire stays in shadow. The light brightens what it falls on by three quarters at most: a nuke's took the ground to white within a few frames until it was held there.- A bright cloud no longer shows what is behind it as a line drawing. Inside a nuke's white cloud, or a falling War Factory's fireball, every tree and wreck under it used to come out as a thin grey outline, and the picture's sharpening ringed each dark piece in white. Both stop where the frame is bright.- Smoke and fire no longer end on a straight line where they meet the ground or a building. A puff that sinks into a hillside or drifts against a wall thins out over its last few metres, softly enough that a nuke's haze and a Scud's grey smoke no longer come out as stacked, stair-stepped terraces, and a toxin cloud lying low over the ground keeps its body instead of breaking into hard-edged green islands. This is the default renderer; Classic and the old renderer keep the hard edge they had in 2003.-- Toxin, anthrax and radiation pools lie on the ground. A pool is a carpet of puddle pictures spread up to 140 paces from where the shell or the spray came down, and every one of them was drawn dead flat at the height of that one spot: on a hillside the uphill half of the pool disappeared into the slope and the downhill half hung in the air above it. Each puddle now bends over the ground underneath it, on both renderers, and a pool on a bridge stays on the deck. The pool also stains the ground it covers, darker and tinted toward its own colour, green for toxin and the anthrax colours for anthrax, so it looks spilled rather than shone onto the grass.+- Toxin, anthrax and radiation pools lie on the ground. A pool is a carpet of puddle pictures spread up to 140 paces from where the shell or the spray came down, and every one of them was drawn dead flat at the height of that one spot: on a hillside the uphill half of the pool disappeared into the slope and the downhill half hung in the air above it. Each puddle now bends over the ground underneath it, on both renderers, and a pool on a bridge stays on the deck. The pool also holds still. It used to throb twice a second, because every half second the pool's poison fired a fresh batch of puddles that swelled out of black to full green and back to black in two seconds, each batch somewhere new. Now it comes up in half a second, stays one steady pool at full colour for as long as it does damage, and fades over its last three seconds, or over three seconds from the moment the fog of war closes over it. Four Scud warheads landing on one spot used to stack into a white-hot blotch in the middle; overlapping pools now share their light and the middle stays toxin green. The ground under it takes on its colour, green for toxin and the anthrax colours for anthrax, so it looks spilled rather than shone onto the grass.- A Scud Storm or a carpet bomb shakes the screen as hard as it should. The game cut a pile of heavy shakes back to a mild one, so a run of missiles or bombs landing together shook less than one of them alone. Each now shakes a step lighter and the run builds up. Demo traps and Aurora bombs shake now, and a falling building shakes harder the bigger it was.- The shake knows how close you are. A shell landing in the middle of the screen kicks the camera half as hard again as it used to, one at the edge of the range barely moves it, and a heavy hit settles over about a second instead of stopping dead after half of one. The cut that put a pile of shakes back to a mild one is gone too: past the limit the camera holds at full shake.- A damaged building's fires burn bigger, and its smoke runs darker and longer, the closer it gets to falling.diff --git a/GeneralsMD/Code/BuildFingerprint.manifest b/GeneralsMD/Code/BuildFingerprint.manifestindex 4f0a8e778..02a6bbb2e 100644--- a/GeneralsMD/Code/BuildFingerprint.manifest+++ b/GeneralsMD/Code/BuildFingerprint.manifest@@ -176,6 +176,7 @@ Data/Scenarios/statues.txtData/Scenarios/sweep.txtData/Scenarios/techrespawn.txtData/Scenarios/towncross.txt+Data/Scenarios/toxinslope.txtData/Scenarios/trailer_arrival.txtData/Scenarios/trailer_chaos.txtData/Scenarios/trailer_clash.txtdiff --git a/GeneralsMD/Code/Data/Scenarios/toxinslope.txt b/GeneralsMD/Code/Data/Scenarios/toxinslope.txtnew file mode 100644index 000000000..30a01585a--- /dev/null+++ b/GeneralsMD/Code/Data/Scenarios/toxinslope.txt@@ -0,0 +1,27 @@+# Toxin pools on uneven ground, for a picture of the puddles lying on the terrain: a Scud Storm's+# large field on the mound at 1075,3775 on Twilight Flame (the ground 140 out, the field's edge, is+# 15 to 17 lower on every side), and a Toxin Tractor spraying a power plant on the slope south of+# 1550,3650, its small pools at the impact points. The Scud fires at frame 300 and its field lasts+# 45 seconds, so 900 to 1400 is the window; the tractor's pools come and go from about 200 on.+#+# generals.exe -win -xres 1920 -yres 1080 -msaa 0 -fps 120 -noFPSLimit -quickstart -noshellmap+# -observer -multiInstance -map "Maps\Twilight Flame\Twilight Flame.map" -autoskirmish 3+# -takeover -side 0 FactionAmerica -side 1 FactionChina -side 2 FactionGLA -seed 7+# -camera 1075 3775 -screenshot 1100 -maxframes 1180 -scenario toxinslope -logPrefix toxinslope_+#+# -d3d9 on the same line is the other device. generals_base.exe (an older build) on the same line+# shows the flat pools: the outer puddles in the air over the mound's flanks.++# the Scud Storm, back at its start and powered by the verb+10 spawn 2 GLAScudStorm 1 start2:0:200++# the power plant on the slope and the tractor that sprays it+20 spawn 0 AmericaPowerPlant 1 1550 3600+40 spawn 2 GLAVehicleToxinTruck 1 1420 3650+60 attack 2 GLAVehicleToxinTruck 0 AmericaPowerPlant++# the Scud Storm on the mound+300 power 2 GLAScudStorm 1075 3775++200 tally 0 *+900 tally 0 *diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DParticleSys.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DParticleSys.cppindex f722c1cd6..ed4f8a3b3 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DParticleSys.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DParticleSys.cpp@@ -43,6 +43,12 @@#include "WW3D2/dx8wrapper.h"#include "WW3D2/dx11runtime.h"#include "Common/JobSystem.h"+#include "GameLogic/GameLogic.h"+#include "GameLogic/Object.h"+#include "GameLogic/Module/LifetimeUpdate.h"+#include "GameLogic/PartitionManager.h"+#include "GameClient/ObserverCamera.h"+#include <map>#ifdef _INTERNAL// for occasional debugging...@@ -448,6 +454,575 @@ static void fillBillboards( Int index, void *context )fill.glow = job->glowAfterShade && lightCount > 0;}+//-------------------------------------------------------------------------------------------------+// A contamination field - toxin, anthrax, radiation - is ground-aligned AREA_EFFECT particles:+// squares up to 170 units across, every one at the emitter's height, which UseCallersRadius spreads+// over the weapon's damage radius (140 for a large toxin field). Drawn flat, on anything but level+// ground the uphill side of a square sank into the terrain and the downhill side hung in the air.+// Each puddle square is a grid here instead, every vertex set on the terrain under it, so the field+// lies on the hill. A field whose emitter stands clear of the terrain, on a bridge deck, keeps its+// height. Which squares a field draws is collectGroundFields' business, below.+//+// Before the glow, the same grid takes light off the ground under the bright part of the texture,+// mostly from the channels the field's hue lacks, so the ground under the field turns the field's+// colour and the pool reads as liquid and not as light laid on the ground. The hue is the+// template's own, so anthrax keeps its colour. Every field's stain goes down before any field's+// glow: drawn system by system, a later system's stain darkened the glow already laid by the ones+// before it, and the overlaps came out as black-green blotches through the pool. Both passes are+// plain DX8Wrapper draws in world space and both devices draw them.+//-------------------------------------------------------------------------------------------------++static const Real FIELD_GRID_SPACING = 5.0f; ///< world units between grid vertices; a terrain cell is ten+static const Int FIELD_GRID_MAX_STEPS = 16; ///< per side; the largest squares get a coarser grid+static const Real FIELD_LIFT = 1.0f; ///< over the terrain, for the chords between vertices+static const Real FIELD_ON_GROUND = 10.0f; ///< an emitter higher than this over the terrain is on a deck+static const Real FIELD_STAIN_DARKEN = 0.05f; ///< share of the ground's light the stain takes in every channel+static const Real FIELD_STAIN_TINT = 0.25f; ///< further share taken from the channels the hue lacks+static const Int FIELD_CHUNK_VERTICES = 8192; ///< one draw's worth; a 16 step square is 289++/** Is this system a field to be laid on the terrain? The same pair the field particle count uses.+ * A system attached to a drawable or an object is not: its position is an offset in that model's+ * space (the damaged oil tank's ToxinTankPuddle hangs off a bone), and it moves with it, so it keeps+ * the ordinary particle path. */+static Bool isGroundField( ParticleSystem *sys )+{+ return sys->getPriority() == AREA_EFFECT && sys->m_isGroundAligned+ && !sys->isUsingStreak() && sys->getVolumeParticleDepth() <= 1+ && sys->getAttachedDrawable() == INVALID_DRAWABLE_ID && sys->getAttachedObject() == INVALID_ID;+}++struct FieldChunk+{+ Int firstVertex, vertexCount;+ Int firstIndex, indexCount;+};++static std::vector<Vector3> s_fieldPos;+static std::vector<Vector2> s_fieldUV;+static std::vector<unsigned> s_fieldGlow;+static std::vector<unsigned> s_fieldStain;+static std::vector<unsigned short> s_fieldIndex;+static std::vector<FieldChunk> s_fieldChunks;++/** One field system's chunks and how it draws. */+struct FieldBatch+{+ TextureClass *texture; ///< a reference held until the frame's fields are drawn+ ShaderClass glow, stain;+ Bool stained;+ Int firstChunk, chunkCount;+};++static std::vector<FieldBatch> s_fieldBatches;++/** Writes one pass of a chunk and draws it; the index buffer is already set. */+static void drawFieldPass( const FieldChunk &chunk, const std::vector<unsigned> &colors, const ShaderClass &shader )+{+ DynamicVBAccessClass vbAccess( BUFFER_TYPE_DYNAMIC_DX8, DX8_FVF_XYZNDUV2, (unsigned short)chunk.vertexCount );+ {+ DynamicVBAccessClass::WriteLockClass lock( &vbAccess );+ VertexFormatXYZNDUV2 *vb = lock.Get_Formatted_Vertex_Array();+ for (Int i = 0; i < chunk.vertexCount; ++i)+ {+ const Int v = chunk.firstVertex + i;+ vb[i].x = s_fieldPos[ v ].X;+ vb[i].y = s_fieldPos[ v ].Y;+ vb[i].z = s_fieldPos[ v ].Z;+ vb[i].nx = 0.0f;+ vb[i].ny = 0.0f;+ vb[i].nz = 1.0f;+ vb[i].diffuse = colors[ v ];+ vb[i].u1 = s_fieldUV[ v ].X;+ vb[i].v1 = s_fieldUV[ v ].Y;+ vb[i].u2 = 0.0f;+ vb[i].v2 = 0.0f;+ }+ }+ DX8Wrapper::Set_Shader( shader );+ DX8Wrapper::Set_Vertex_Buffer( vbAccess );+ DX8Wrapper::Draw_Triangles( 0, (unsigned short)(chunk.indexCount / 3), 0, (unsigned short)chunk.vertexCount );+}++/** One puddle square laid on the terrain as a grid, into the chunk being filled. */+static void addFieldPuddle( FieldChunk &chunk, Real cx, Real cy, Real flatZ, Bool onGround, Real size, Real angle,+ unsigned glowColor, unsigned stainColor )+{+ Int steps = (Int)ceilf( 2.0f * size / FIELD_GRID_SPACING );+ steps = steps < 1 ? 1 : (steps > FIELD_GRID_MAX_STEPS ? FIELD_GRID_MAX_STEPS : steps);+ const Int side = steps + 1;+ const Int vertices = side * side;++ if (chunk.vertexCount + vertices > FIELD_CHUNK_VERTICES)+ {+ s_fieldChunks.push_back( chunk );+ chunk.firstVertex += chunk.vertexCount;+ chunk.firstIndex += chunk.indexCount;+ chunk.vertexCount = 0;+ chunk.indexCount = 0;+ }++ // the square's half axes: PointGroupClass laid a ground quad out to size on either side+ const Real c = WWMath::Cos( angle ) * size;+ const Real s = WWMath::Sin( angle ) * size;+ const Real step = 2.0f / steps;+ for (Int j = 0; j < side; ++j)+ {+ const Real b = -1.0f + j * step;+ for (Int i = 0; i < side; ++i)+ {+ const Real a = -1.0f + i * step;+ const Real x = cx + a * c - b * s;+ const Real y = cy + a * s + b * c;+ const Real z = onGround ? TheTerrainRenderObject->getHeightMapHeight( x, y, NULL ) + FIELD_LIFT : flatZ;+ s_fieldPos.push_back( Vector3( x, y, z ) );+ s_fieldUV.push_back( Vector2( (1.0f - a) * 0.5f, (1.0f - b) * 0.5f ) );+ s_fieldGlow.push_back( glowColor );+ s_fieldStain.push_back( stainColor );+ }+ }++ const Int base = chunk.vertexCount;+ for (Int j = 0; j < steps; ++j)+ {+ for (Int i = 0; i < steps; ++i)+ {+ const unsigned short v = (unsigned short)(base + j * side + i);+ s_fieldIndex.push_back( v );+ s_fieldIndex.push_back( (unsigned short)(v + 1) );+ s_fieldIndex.push_back( (unsigned short)(v + side) );+ s_fieldIndex.push_back( (unsigned short)(v + 1) );+ s_fieldIndex.push_back( (unsigned short)(v + side + 1) );+ s_fieldIndex.push_back( (unsigned short)(v + side) );+ }+ }+ chunk.vertexCount += vertices;+ chunk.indexCount += steps * steps * 6;+}++//-------------------------------------------------------------------------------------------------+// A field does not draw its particles. The object behind it fires its field weapon every half+// second, and each shot's FX starts a new system whose particles swell from black to the field's+// colour and back to black in two seconds, at fresh random places: drawn as they are, the pool+// throbbed, its patches came and went, and past MaxFieldParticleCount new ones were refused and it+// thinned out. The systems only say where a field is. Every system of one template at one place+// is one field, and it is drawn as a fixed scatter of puddles over the emission radius, placed by a+// hash of the place so the scatter is the same every frame, at the template's brightest colour. It+// fades in over FIELD_FADE_IN and out over the last FIELD_FADE_OUT frames of the field object's+// life, read off its LifetimeUpdate; a field with no such object (a one-off contamination) fades+// with its last particle instead. This reads the logic's objects and writes nothing back.+//-------------------------------------------------------------------------------------------------++static const Real FIELD_COVER = 2.0f; ///< puddles per (radius / puddle size) squared+static const Int FIELD_MAX_PUDDLES = 48;+static const Real FIELD_GAIN = 0.7f; ///< of the template's brightest colour, a puddle+static const Int FIELD_FADE_IN = 15; ///< logic frames+static const Int FIELD_FADE_OUT = 90; ///< logic frames before the field object dies+static const Int FIELD_FADE_GONE = FIELD_FADE_OUT; ///< logic frames, a field fogged over or whose object went early+static const Real FIELD_OBJECT_REACH = 5.0f; ///< how near the field's centre its object stands++struct FieldKey+{+ const ParticleSystemTemplate *tmpl;+ Int x, y;+ bool operator<( const FieldKey &o ) const+ {+ if (tmpl != o.tmpl) return tmpl < o.tmpl;+ if (x != o.x) return x < o.x;+ return y < o.y;+ }+};++/** A field as it is drawn, kept between frames: a shot whose particles the LOD refused leaves a+ * half second with no system at the place, and the pool stays through it. */+struct FieldState+{+ Int born; ///< logic frame it was first seen+ Int seen; ///< logic frame a system was last seen at it+ ObjectID object; ///< the object whose life it fades with, or INVALID_ID+ Int gone; ///< logic frame it began going out (fog, or its object gone), or -1+ Real goneFade; ///< the fade it had then+ Real shown; ///< the fade it was last drawn at+ Int particleEnd; ///< logic frame its last particle ends, for a field with no object+ Coord3D centre;+ Real radius; ///< the emission radius, which UseCallersRadius set from the weapon+ Real size; ///< a puddle's half width+ RGBColor color; ///< the template's brightest keyframe+ ParticleSystemInfo::ParticleShaderType shader;+ AsciiString texture;+};++static const Int FIELD_GRACE = 30; ///< logic frames a field with no object outlives its systems+static const Real FIELD_STACK = 2.5f; ///< puddles' worth of cover a spot may add up to+static const Real FIELD_SATURATE = 0.6f; ///< share of the weakest channel taken out of the colour++static std::map<FieldKey, FieldState> s_fieldStates;++/** One puddle of this frame's fields, before it is laid. */+struct FieldPuddle+{+ Real x, y, size, angle;+ Real bright; ///< its own share of the field's colour+ Real fade; ///< its field's fade+ Real overlap; ///< how many puddles, itself included, cover its middle+};++/** One field of this frame, before it is laid. */+struct FieldDraw+{+ FieldBatch batch;+ Coord3D centre;+ Bool onGround;+ Real fade;+ Bool visible; ///< inside the view; one outside is collected only for its overlap+ RGBColor color;+ AsciiString texture;+ Int firstPuddle, puddleCount;+};++static std::vector<FieldPuddle> s_fieldPuddles;+static std::vector<FieldDraw> s_fieldDraws;++/** The CLEANUP_HAZARD object with a LifetimeUpdate standing on a field's centre, if there is one. */+static ObjectID findFieldObject( const Coord3D ¢re )+{+ static NameKeyType key_LifetimeUpdate = NAMEKEY( "LifetimeUpdate" );+ ObjectID found = INVALID_ID;+ Real best = FIELD_OBJECT_REACH * FIELD_OBJECT_REACH;+ for (Object *obj = TheGameLogic->getFirstObject(); obj; obj = obj->getNextObject())+ {+ if (!obj->isKindOf( KINDOF_CLEANUP_HAZARD ))+ continue;+ const Coord3D *pos = obj->getPosition();+ const Real dx = pos->x - centre.x, dy = pos->y - centre.y;+ const Real d = dx * dx + dy * dy;+ if (d <= best && obj->findUpdateModule( key_LifetimeUpdate ) != NULL)+ {+ best = d;+ found = obj->getID();+ }+ }+ return found;+}++/** The middle of a random range. */+static inline Real midValue( const GameClientRandomVariable &v )+{+ return 0.5f * (v.getMinimumValue() + v.getMaximumValue());+}++/** A field's fade this frame, from its object's remaining life or its particles'.+ *+ * Under the fog the pool goes out, as the retail one did: FXList::doFXPos plays nothing where the+ * watcher's cell is not clear, so no new puddles came and the old ones died off in two seconds.+ * A Scud Storm's reveal running out over its own fields did exactly that 32 seconds into their+ * 45. It is asked here of the cell directly rather than read off the systems stopping, which+ * left the pool at full strength for the 30 frames the systems were given to come back. */+static Real fieldFade( FieldState &state, Int now )+{+ static NameKeyType key_LifetimeUpdate = NAMEKEY( "LifetimeUpdate" );+ Bool lost = now - state.seen > FIELD_GRACE+ || ThePartitionManager->getShroudStatusForPlayer( TheObserverCamera.getShroudPlayerIndex(), &state.centre ) != CELLSHROUD_CLEAR;+ Int remaining = state.particleEnd - now;+ if (!lost && state.object != INVALID_ID)+ {+ Object *obj = TheGameLogic->findObjectByID( state.object );+ LifetimeUpdate *life = obj ? (LifetimeUpdate *)obj->findUpdateModule( key_LifetimeUpdate ) : NULL;+ if (life)+ remaining = (Int)life->getDieFrame() - now;+ else+ lost = TRUE; // cleaned up early, or died+ }+ if (lost)+ {+ // the pool goes out over the same three seconds as at the end of its life, from where it was+ if (state.gone < 0)+ {+ state.gone = now;+ state.goneFade = state.shown;+ }+ const Real left = 1.0f - (Real)(now - state.gone) / FIELD_FADE_GONE;+ state.shown = WWMath::Max( left, 0.0f ) * state.goneFade;+ return state.shown;+ }+ if (state.gone >= 0)+ {+ // out of the fog again: up from where it had got to+ state.born = now - REAL_TO_INT_FLOOR( state.shown * FIELD_FADE_IN );+ state.gone = -1;+ }+ const Real fadeIn = WWMath::Clamp( (Real)(now - state.born) / FIELD_FADE_IN, 0.0f, 1.0f );+ const Real fadeOut = WWMath::Clamp( (Real)remaining / FIELD_FADE_OUT, 0.0f, 1.0f );+ state.shown = fadeIn * fadeOut;+ return state.shown;+}++/** Collects this frame's fields from their systems and lays them on the terrain into the field+ * buffers; drawGroundFields draws them. Returns the puddles laid. */+static Int collectGroundFields( ParticleSystemManager::ParticleSystemList &systems, const AABoxClass &view )+{+ const Int now = (Int)TheGameLogic->getFrame();+ s_fieldPuddles.clear();+ s_fieldDraws.clear();++ // where the fields are this frame, and what each one looks like+ for (ParticleSystemManager::ParticleSystemListIt it = systems.begin(); it != systems.end(); ++it)+ {+ ParticleSystem *sys = *it;+ if (!sys || sys->isUsingDrawables() || !isGroundField( sys ))+ continue;++ Coord3D pos;+ sys->getPosition( &pos );+ FieldKey key = { sys->getTemplate(), REAL_TO_INT_FLOOR( pos.x + 0.5f ), REAL_TO_INT_FLOOR( pos.y + 0.5f ) };+ const ParticleSystemInfo::EmissionVolumeType volume = sys->getEmisionVolumeType();+ const Real radius = volume == ParticleSystemInfo::SPHERE ? sys->m_emissionVolume.sphere.radius+ : (volume == ParticleSystemInfo::CYLINDER ? sys->m_emissionVolume.cylinder.radius : 0.0f);+ Int life = sys->isSystemForever() ? FIELD_FADE_OUT : (Int)sys->getSystemLifetimeLeft();+ life += REAL_TO_INT_CEIL( sys->m_lifetime.getMaximumValue() );+ for (Particle *p = sys->getFirstParticle(); p; p = p->m_systemNext)+ life = WWMath::Max( life, (Int)p->getLifetimeLeft() );++ std::map<FieldKey, FieldState>::iterator st = s_fieldStates.find( key );+ if (st == s_fieldStates.end() || st->second.seen != now)+ {+ if (st == s_fieldStates.end())+ {+ FieldState fresh;+ fresh.born = now;+ fresh.seen = now;+ fresh.object = findFieldObject( pos );+ fresh.gone = -1;+ fresh.goneFade = 0.0f;+ fresh.shown = 0.0f;+ st = s_fieldStates.insert( std::make_pair( key, fresh ) ).first;+ }+ FieldState &state = st->second;+ state.seen = now;+ state.particleEnd = now + life;+ state.centre = pos;+ state.radius = radius;++ // a puddle the size a particle reaches halfway through its life+ const Real half = 0.5f * midValue( sys->m_lifetime );+ const Real rate = midValue( sys->m_sizeRate );+ const Real damping = midValue( sys->m_sizeRateDamping );+ const Real growth = damping < 1.0f ? rate * (1.0f - powf( damping, half )) / (1.0f - damping) : rate * half;+ state.size = WWMath::Max( midValue( sys->m_startSize ) + growth, 1.0f );++ // the template's brightest keyframe is the field's colour+ state.color = sys->m_colorKey[ 0 ].color;+ for (Int k = 1; k < MAX_KEYFRAMES; ++k)+ {+ const RGBColor &c = sys->m_colorKey[ k ].color;+ if (c.red + c.green + c.blue > state.color.red + state.color.green + state.color.blue)+ state.color = c;+ }+ state.shader = sys->getShaderType();+ state.texture = sys->getParticleTypeName();+ }+ else+ {+ FieldState &state = st->second;+ state.radius = WWMath::Max( state.radius, radius );+ state.particleEnd = WWMath::Max( state.particleEnd, now + life );+ }+ }++ Int laid = 0;+ for (std::map<FieldKey, FieldState>::iterator st = s_fieldStates.begin(); st != s_fieldStates.end(); )+ {+ const FieldKey &key = st->first;+ FieldState &state = st->second;++ // Kept while its systems are, even faded out: the systems outlive the object by a few+ // seconds, and a field forgotten under them would be found again as a new one.+ const Real fade = fieldFade( state, now );+ const Bool stale = now - state.seen > FIELD_GRACE;+ if ((stale && fade <= 0.0f) || now < state.seen)+ {+ // out, or a frame count from before a load+ s_fieldStates.erase( st++ );+ continue;+ }+ ++st;+ if (fade <= 0.0f)+ continue;++ // a field off screen is still collected, as its puddles dim the ones it overlaps on screen+ const Real size = state.size;+ const Real reach = state.radius + size;+ const Bool visible = WWMath::Fabs( state.centre.x - view.Center.X ) <= view.Extent.X + reach+ && WWMath::Fabs( state.centre.y - view.Center.Y ) <= view.Extent.Y + reach+ && WWMath::Fabs( state.centre.z - view.Center.Z ) <= view.Extent.Z + reach;++ FieldBatch batch;+ if (!particlePresetShader( state.shader, &batch.glow ))+ continue;+ batch.glow.Set_Cull_Mode( ShaderClass::CULL_MODE_DISABLE );+ batch.glow.Set_Primary_Gradient( ShaderClass::GRADIENT_MODULATE );+ batch.glow.Set_Texturing( ShaderClass::TEXTURING_ENABLE );+ // dst * (1 - texel * colour): black texels leave the ground alone, as they add nothing to it+ batch.stain = batch.glow;+ batch.stain.Set_Src_Blend_Func( ShaderClass::SRCBLEND_ZERO );+ batch.stain.Set_Dst_Blend_Func( ShaderClass::DSTBLEND_ONE_MINUS_SRC_COLOR );+ batch.stained = state.shader == ParticleSystemInfo::ADDITIVE;+ batch.texture = NULL;++ FieldDraw draw;+ draw.batch = batch;+ draw.centre = state.centre;+ draw.onGround = state.centre.z+ - TheTerrainRenderObject->getHeightMapHeight( state.centre.x, state.centre.y, NULL ) < FIELD_ON_GROUND;+ draw.fade = fade;+ draw.visible = visible;+ draw.texture = state.texture;++ // More saturated than the keyframe: pulling the weakest channel down keeps the hue and keeps+ // the pool from going mint where the puddles overlap.+ const RGBColor &key_color = state.color;+ const Real low = WWMath::Min( key_color.red, WWMath::Min( key_color.green, key_color.blue ) ) * FIELD_SATURATE;+ const Real peak = WWMath::Max( key_color.red, WWMath::Max( key_color.green, key_color.blue ) );+ const Real lift = peak > low ? peak / (peak - low) : 1.0f;+ draw.color.red = (key_color.red - low) * lift;+ draw.color.green = (key_color.green - low) * lift;+ draw.color.blue = (key_color.blue - low) * lift;++ const Real spread = state.radius / size;+ const Int count = WWMath::Clamp_Int( (Int)ceilf( FIELD_COVER * spread * spread ), 1, FIELD_MAX_PUDDLES );++ // the same scatter every frame: a little generator seeded by the place+ UnsignedInt seed = (UnsignedInt)key.x * 73856093u ^ (UnsignedInt)key.y * 19349663u ^ 0x9E3779B9u;+ draw.firstPuddle = (Int)s_fieldPuddles.size();+ draw.puddleCount = count;+ for (Int i = 0; i < count; ++i)+ {+ Real u[ 4 ];+ for (Int k = 0; k < 4; ++k)+ {+ seed = seed * 1664525u + 1013904223u;+ u[ k ] = (Real)(seed >> 8) * (1.0f / 16777216.0f);+ }+ const Real r = count == 1 ? 0.0f : state.radius * sqrtf( u[ 0 ] );+ const Real a = u[ 1 ] * 2.0f * PI;+ FieldPuddle puddle;+ puddle.x = state.centre.x + r * WWMath::Cos( a );+ puddle.y = state.centre.y + r * WWMath::Sin( a );+ puddle.size = size;+ puddle.angle = u[ 2 ] * 2.0f * PI;+ puddle.bright = 0.8f + 0.2f * u[ 3 ];+ puddle.fade = fade;+ puddle.overlap = 0.0f;+ s_fieldPuddles.push_back( puddle );+ }+ s_fieldDraws.push_back( draw );+ }++ // How many puddles cover each one's middle, over every field: four Scud fields on one spot and the+ // thick middle of each, added up, went past white. Each puddle is dimmed by how far its cover+ // goes over FIELD_STACK, so the whole pool tops out at about that many puddles' worth. A+ // neighbour counts at its own fade, so a field coming up or going out dims the others with it+ // rather than in one frame.+ // ponytail: every pair, a few hundred puddles on the map at most; a grid when a map holds more+ const Int puddleCount = (Int)s_fieldPuddles.size();+ for (Int i = 0; i < puddleCount; ++i)+ {+ FieldPuddle &p = s_fieldPuddles[ i ];+ p.overlap = 1.0f;+ for (Int j = 0; j < puddleCount; ++j)+ {+ const FieldPuddle &q = s_fieldPuddles[ j ];+ const Real reach = p.size + q.size;+ const Real dx = p.x - q.x, dy = p.y - q.y;+ const Real t = 1.0f - (dx * dx + dy * dy) / (reach * reach);+ if (j != i && t > 0.0f)+ p.overlap += t * t * q.fade;+ }+ }++ for (size_t d = 0; d < s_fieldDraws.size(); ++d)+ {+ FieldDraw &draw = s_fieldDraws[ d ];+ if (!draw.visible)+ continue;+ FieldBatch &batch = draw.batch;+ batch.firstChunk = (Int)s_fieldChunks.size();+ FieldChunk chunk = { (Int)s_fieldPos.size(), 0, (Int)s_fieldIndex.size(), 0 };+ for (Int i = draw.firstPuddle; i < draw.firstPuddle + draw.puddleCount; ++i)+ {+ const FieldPuddle &puddle = s_fieldPuddles[ i ];+ const Real stack = puddle.overlap > FIELD_STACK ? FIELD_STACK / puddle.overlap : 1.0f;+ const Real bright = FIELD_GAIN * draw.fade * puddle.bright * stack;+ const Real red = draw.color.red * bright, green = draw.color.green * bright, blue = draw.color.blue * bright;+ const unsigned glowColor = DX8Wrapper::Convert_Color_Clamp( Vector4( red, green, blue, 1.0f ) );+ unsigned stainColor = 0;+ const Real peak = WWMath::Max( red, WWMath::Max( green, blue ) );+ if (batch.stained && peak > 0.0f)+ {+ // once more by the fade, so the stain is gone with the glow and not after it+ const Real inv = 1.0f / peak;+ const Real k = peak * draw.fade;+ stainColor = DX8Wrapper::Convert_Color_Clamp( Vector4(+ k * (FIELD_STAIN_DARKEN + FIELD_STAIN_TINT * (1.0f - red * inv)),+ k * (FIELD_STAIN_DARKEN + FIELD_STAIN_TINT * (1.0f - green * inv)),+ k * (FIELD_STAIN_DARKEN + FIELD_STAIN_TINT * (1.0f - blue * inv)),+ 1.0f ) );+ }+ addFieldPuddle( chunk, puddle.x, puddle.y, draw.centre.z, draw.onGround, puddle.size, puddle.angle,+ glowColor, stainColor );+ ++laid;+ }+ s_fieldChunks.push_back( chunk );++ batch.chunkCount = (Int)s_fieldChunks.size() - batch.firstChunk;+ batch.texture = W3DDisplay::m_assetManager->Get_Texture( draw.texture.str() );+ s_fieldBatches.push_back( batch );+ }+ return laid;+}++/** Draws every field the frame collected: all their stains, then all their glows. */+static void drawGroundFields( void )+{+ if (s_fieldBatches.empty())+ return;++ VertexMaterialClass *material = VertexMaterialClass::Get_Preset( VertexMaterialClass::PRELIT_DIFFUSE );+ Matrix4x4 identity( true );+ DX8Wrapper::Set_Transform( D3DTS_WORLD, identity );+ DX8Wrapper::Set_Material( material );+ REF_PTR_RELEASE( material );++ for (Int pass = 0; pass < 2; ++pass)+ {+ const Bool stainPass = pass == 0;+ for (size_t b = 0; b < s_fieldBatches.size(); ++b)+ {+ const FieldBatch &batch = s_fieldBatches[ b ];+ if (stainPass && !batch.stained)+ continue;+ DX8Wrapper::Set_Texture( 0, batch.texture );+ for (Int k = batch.firstChunk; k < batch.firstChunk + batch.chunkCount; ++k)+ {+ const FieldChunk &fc = s_fieldChunks[ k ];+ DynamicIBAccessClass ibAccess( BUFFER_TYPE_DYNAMIC_DX8, (unsigned short)fc.indexCount );+ {+ DynamicIBAccessClass::WriteLockClass lock( &ibAccess );+ memcpy( lock.Get_Index_Array(), &s_fieldIndex[ fc.firstIndex ], fc.indexCount * sizeof( unsigned short ) );+ }+ DX8Wrapper::Set_Index_Buffer( ibAccess, 0 );+ if (stainPass)+ drawFieldPass( fc, s_fieldStain, batch.stain );+ else+ drawFieldPass( fc, s_fieldGlow, batch.glow );+ }+ }+ }++ for (size_t b = 0; b < s_fieldBatches.size(); ++b)+ s_fieldBatches[ b ].texture->Release_Ref(); // the draw state holds its own reference to the last one+ s_fieldBatches.clear();+}+W3DParticleSystemManager::W3DParticleSystemManager(){m_pointGroup = NULL;@@ -493,6 +1068,7 @@ void W3DParticleSystemManager::reset(){ParticleSystemManager::reset();s_fireLightsValid = FALSE;+ s_fieldStates.clear(); // the object IDs it holds belong to the game that ended}/**@@ -634,6 +1210,22 @@ void W3DParticleSystemManager::doParticles(RenderInfoClass &rinfo)}fillJob.glowAfterShade = Direct3D11_Present_Is_Enabled();JobSystem::parallel_for( (Int)m_billboardFills.size(), BILLBOARD_FILLS_PER_CLAIM, fillBillboards, &fillJob );++ s_fieldPos.clear();+ s_fieldUV.clear();+ s_fieldGlow.clear();+ s_fieldStain.clear();+ s_fieldIndex.clear();+ s_fieldChunks.clear();+ {+ const Int puddles = collectGroundFields( particleSysList, bbox );+ // counted as field particles on purpose: past MaxFieldParticleCount the field systems keep+ // one particle each, and that one is all the steady pool needs from them+ m_fieldParticleCount += puddles;+ m_onScreenParticleCount += puddles;+ }+ drawGroundFields();+size_t nextFill = 0;for( ParticleSystemManager::ParticleSystemListIt it = particleSysList.begin(); it != particleSysList.end(); ++it){@@ -695,6 +1287,9 @@ void W3DParticleSystemManager::doParticles(RenderInfoClass &rinfo)continue;}+ if (isGroundField( sys ))+ continue; // drawn above, every field at once+/// @todo lorenzen sez: declare these outside the sys loop, and put some in registers// initialize them here still, of course// build W3D particle bufferdiff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11backend.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11backend.cppindex 2ba64a39a..def24a3d7 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11backend.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11backend.cpp@@ -1880,6 +1880,9 @@ bool DX11BackendClass::Shadow_Receiving() const|| destination == D3DBLEND_DESTCOLOR || source == D3DBLEND_DESTCOLOR) {return false; // additive and multiplicative passes: fire, glow, the shadows themselves}+ if (destination == D3DBLEND_INVSRCCOLOR) {+ return false; // the toxin field's stain: its colour is light taken away, and shaded it ran backwards+ }}return true;}