Skip to content

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.

feat(w3ddevice): weather option, rain, sand, snow and a wind

Olcay Seyganb747d51245fe
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b0aff9280..71a832f4e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,10 @@ found and fixed, EA's own, not port damage.**
---
+## Weather, if you want it
+
+- Weather, under Options, Effects, is a new setting, off by default until it has been played. A green map gets rain, and a desert map gets blowing sand over a still tan haze. A snowy map with no flakes of its own gets them. The trees lean and sway harder and smoke drifts downwind; a map that already rains or snows, Flooded Plains or Bitter Winter, keeps what EA gave it and takes only the wind. No part of the game reads any of this: what a unit sees and hits stays what the map says, so you and your opponent can have different weather in one match. A sandstorm over a battle of three armies and three superweapons takes the graphics card's frame from about 7.9 to 8.5 ms. Direct3D 11 only, and off under Classic Graphics.
+
## Fire keeps its colour
- Internal HDR Tone Mapping, under Options, Effects, is a new setting, off by default until it has been played. The name is exact: the game's picture has held light past white for a long time, then squeezed nearly all of it into one white on the way out, so a Strategy Center going up was a blown patch with no shape. With this on that fireball stays orange and yellow, a night fire shows its flame tongue, and the white heart of a nuke shrinks, about 54,000 near-white pixels down to about 24,000 in the same shot. Team colours hold a little more colour, and ground lit by a blast leans more orange. Ground and walls away from a fire do not change. Your monitor still gets a normal image: an HDR screen gets no HDR signal, and no HDR screen has seen this. In a battle of three armies and three superweapons the graphics card's frame reads 7.95 ms on and 7.78 and 8.12 ms off, which is no cost anyone can measure. The Direct3D 9 picture and Classic Graphics keep the old look.
diff --git a/GeneralsMD/Code/Data/Patch.str b/GeneralsMD/Code/Data/Patch.str
index bd39dbd5d..4c39404db 100644
--- a/GeneralsMD/Code/Data/Patch.str
+++ b/GeneralsMD/Code/Data/Patch.str
@@ -1540,6 +1540,14 @@ TOOLTIP:InternalHdr
"Fire, blasts and lasers past white keep their colour on the way to your screen instead of ending in one flat white, and team colours hold a little more of theirs. Ground and walls away from a fire stay as they were. This is inside the game's picture: your monitor still gets a normal image, and an HDR monitor gets no HDR signal. Direct3D 11 only, and off under Classic Graphics. Applies when you press Accept."
END
+GUI:Weather
+"Weather"
+END
+
+TOOLTIP:Weather
+"Rain falls, or sand blows on a desert map and snow on a snowy one, and a wind bends the trees and leans the smoke. A map with its own rain or snow keeps it and takes only the wind. Only your picture changes: what units see and hit stays the same, and other players see their own setting. Direct3D 11 only, and off under Classic Graphics. Applies when you press Accept."
+END
+
GUI:FormationDrag
"Drag Out A Formation"
END
diff --git a/GeneralsMD/Code/Data/Turkish/Generals.str b/GeneralsMD/Code/Data/Turkish/Generals.str
index 402557a9c..7128c6731 100644
--- a/GeneralsMD/Code/Data/Turkish/Generals.str
+++ b/GeneralsMD/Code/Data/Turkish/Generals.str
@@ -15933,6 +15933,14 @@ TOOLTIP:InternalHdr
"Ateş, patlama ve lazerler beyazı geçince ekrana düz beyaz olarak gelmek yerine renklerini korur, takım renkleri de rengini biraz daha iyi tutar. Ateşten uzak zemin ve duvarlar olduğu gibi kalır. Bu oyunun kendi görüntüsünün içindedir: monitörünüz yine normal görüntü alır, HDR monitöre HDR sinyali gitmez. Yalnızca Direct3D 11 ile, Klasik Grafikler açıkken kapalıdır. Kabul Et'e basınca uygulanır."
END
+GUI:Weather
+"Hava Durumu"
+END
+
+TOOLTIP:Weather
+"Yağmur yağar, çöl haritasında kum, karlı haritada kar savrulur; rüzgâr ağaçları büker, dumanı yana yatırır. Kendi yağmuru ya da karı olan harita onu korur, yalnızca rüzgârı alır. Değişen sadece sizin görüntünüzdür: birliklerin gördüğü ve vurduğu aynı kalır, diğer oyuncular kendi ayarını görür. 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"
END
diff --git a/GeneralsMD/Code/Data/Window/Menus/OptionsMenuClassic.wnd b/GeneralsMD/Code/Data/Window/Menus/OptionsMenuClassic.wnd
index 6cb564e46..dfbd4ebd6 100644
--- a/GeneralsMD/Code/Data/Window/Menus/OptionsMenuClassic.wnd
+++ b/GeneralsMD/Code/Data/Window/Menus/OptionsMenuClassic.wnd
@@ -7874,6 +7874,53 @@ WINDOW
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 406, BOTTOMRIGHT: 760 430, CREATIONRESOLUTION: 800 600;
+ NAME = "OptionsMenu.wnd:CheckWeather";
+ 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:Weather";
+ TOOLTIPDELAY = -1;
+ TEXT = "GUI:Weather";
+ 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
ENDALLCHILDREN
END
CHILD
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h
index cf6c305b4..9550f347b 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h
@@ -710,6 +710,7 @@ public:
Bool m_firelight; ///< "Firelight": flames light the ground, walls and units around them (Direct3D 11, client only)
Bool m_hemiAmbient; ///< "HemiAmbient": models take the ambient from the sky above and the ground below (Direct3D 11, client only)
Bool m_ambientOcclusion; ///< "AmbientOcclusion": corners and the ground under what stands on it darken, half size in world units (Direct3D 11, client only)
+ Bool m_weatherEffects; ///< "Weather": rain, blowing sand or snow by the map's ground, and a wind on trees and smoke (Direct3D 11, client only)
Bool m_internalHdr; ///< "InternalHdr": what passes white in the half float scene keeps its colour on the way to eight bits; no HDR monitor output (Direct3D 11, client only)
Int m_maxParticleCount; ///< maximum number of particles that can exist
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/ParticleSys.h b/GeneralsMD/Code/GameEngine/Include/GameClient/ParticleSys.h
index 8ea9aeec3..24fee4ae9 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/ParticleSys.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/ParticleSys.h
@@ -714,6 +714,7 @@ public:
void setSkipParentXfrm(Bool enable) { m_skipParentXfrm = enable; } ///<disable transforming particle system with parent matrix.
const Coord3D *getDriftVelocity( void ) { return &m_driftVelocity; } ///< get the drift velocity of the system
+ Coord3D getDriftWithWeather( void ) const; ///< that, plus the Weather option's wind on what it leans
Bool isGroundCollision( void ) const { return m_groundCollision; } ///< do this system's particles hit the terrain?
Real getGroundBounce( void ) const { return m_groundBounce; } ///< restitution against the terrain
Real getGroundFriction( void ) const { return m_groundFriction; } ///< drag along the terrain
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/Snow.h b/GeneralsMD/Code/GameEngine/Include/GameClient/Snow.h
index b50ec4d48..2a035fb5f 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/Snow.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/Snow.h
@@ -81,6 +81,40 @@ EMPTY_DTOR(WeatherSetting)
extern OVERRIDE<WeatherSetting> TheWeatherSetting;
+struct BreezeInfo;
+
+/** What the Weather option falls on a map. NONE on a map with a Weather block of its own: that is
+ what EA's maps rain or snow with (EXRainDrop.tga on Flooded Plains, Winding River and two more),
+ and the option adds only its wind there. */
+enum WeatherKind
+{
+ WEATHER_KIND_NONE = 0,
+ WEATHER_KIND_RAIN,
+ WEATHER_KIND_SAND,
+ WEATHER_KIND_SNOW,
+ WEATHER_KIND_COUNT
+};
+
+/// A map's own Weather block wins, a snowy map snows, more than two fifths of desert ground blows sand.
+inline WeatherKind weatherKindForMap(Bool mapHasWeather, Bool snowyMap, Int sandCells, Int cells)
+{
+ if (mapHasWeather)
+ return WEATHER_KIND_NONE;
+ if (snowyMap)
+ return WEATHER_KIND_SNOW;
+ return (sandCells * 5 > cells * 2) ? WEATHER_KIND_SAND : WEATHER_KIND_RAIN;
+}
+
+/// x brought into [origin, origin + size), so a drop stays put in the world while the tile follows the camera.
+inline Real weatherWrap(Real x, Real origin, Real size)
+{
+ const Real along = (x - origin) / size;
+ return origin + (along - (Real)floor(along)) * size;
+}
+
+/// The script's breeze, or the Weather option's stronger one while it is on. Trees read this.
+const BreezeInfo &weatherBreezeInfo(void);
+
class SnowManager : public SubsystemInterface
{
public :
@@ -97,8 +131,20 @@ class SnowManager : public SubsystemInterface
virtual void updateIniSettings (void);
void setVisible(Bool showWeather); ///<enable/disable rendering of weather - assuming it's available on map.
+ Bool isWeatherOn(void) const { return m_weatherOn; } ///< the Weather option is on and this device draws it.
+ Bool isVisible(void) const { return m_isVisible; } ///< a script has not hidden the weather.
+ WeatherKind getWeatherKind(void) const { return m_weatherKind; } ///< NONE while the option is off.
+ const Coord3D &getWeatherWind(void) const { return m_weatherWind; } ///< what the option's wind adds to smoke per update.
+ void getWeatherHaze(float colour[3], Real *strength) const; ///< the still ground haze that goes with the kind.
+
protected :
+ void setWeatherWind(Real strength); ///< the option's breeze and smoke drift, along the script's breeze direction.
+
+ Bool m_weatherOn;
+ WeatherKind m_weatherKind;
+ Coord3D m_weatherWind;
+
Real *m_startingHeights;
Real m_time; ///<time elapsed since it started snowing.
Real m_velocity; ///<positive velocity of falling snow
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp
index 7fee9075f..0a27c0d2d 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp
@@ -1139,6 +1139,7 @@ GlobalData::GlobalData()
m_firelight = FALSE;
m_hemiAmbient = FALSE;
m_ambientOcclusion = FALSE;
+ m_weatherEffects = FALSE;
m_internalHdr = 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.cpp
index 54a4be747..8e91676a8 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/OptionsCatalog.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/OptionsCatalog.cpp
@@ -146,6 +146,7 @@ OPTION_BOOL_ACCESSORS( m_groundMarks )
OPTION_BOOL_ACCESSORS( m_firelight )
OPTION_BOOL_ACCESSORS( m_hemiAmbient )
OPTION_BOOL_ACCESSORS( m_ambientOcclusion )
+OPTION_BOOL_ACCESSORS( m_weatherEffects )
OPTION_BOOL_ACCESSORS( m_internalHdr )
OPTION_INT_ACCESSORS( m_shadowQuality )
OPTION_INT_ACCESSORS( m_graphicsQuality )
@@ -644,6 +645,13 @@ const OptionDef TheOptionCatalog[] =
OPTION_BOOL, APPLY_LIVE, 0, 1,
get_m_ambientOcclusion, set_m_ambientOcclusion },
+ // Rain, blowing sand or snow by the map's ground, and a wind on trees and smoke. Read every frame, and
+ // no sim reads it, so two players may differ. Off under Classic graphics and -d3d9, and no row in the
+ // quality table: an opt-in until it has been seen. On Options > Effects.
+ { "Weather", OPT_WND( "CheckWeather" ), "GUI:Weather",
+ OPTION_BOOL, APPLY_LIVE, 0, 1,
+ get_m_weatherEffects, set_m_weatherEffects },
+
// What passes white keeps its colour on the way to the eight bit screen; no HDR monitor output. The
// post chain is told every frame. Classic graphics has no half float scene and -d3d9 no chain, and
// no row in the quality table: an opt-in until it has been seen. On Options > Effects.
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable/Update/SwayClientUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable/Update/SwayClientUpdate.cpp
index a589130d8..f2fd81d75 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable/Update/SwayClientUpdate.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable/Update/SwayClientUpdate.cpp
@@ -32,6 +32,7 @@
#include "GameClient/Drawable.h"
#include "GameClient/Module/SwayClientUpdate.h"
+#include "GameClient/Snow.h"
#include "Common/Player.h"
#include "Common/PlayerList.h"
#include "Common/ThingFactory.h"
@@ -80,8 +81,8 @@ SwayClientUpdate::~SwayClientUpdate( void )
//-------------------------------------------------------------------------------------------------
void SwayClientUpdate::updateSway()
{
- const BreezeInfo& info = TheScriptEngine->getBreezeInfo();
- if (info.m_randomness == 0.0f)
+ const BreezeInfo& info = weatherBreezeInfo();
+ if (info.m_randomness == 0.0f)
{
m_curValue = 0;
}
@@ -107,8 +108,8 @@ void SwayClientUpdate::clientUpdate( void )
// if breeze changes, always process the full update, even if not visible,
// so that things offscreen won't 'pop' when first viewed
- const BreezeInfo& info = TheScriptEngine->getBreezeInfo();
- if (info.m_breezeVersion != m_curVersion)
+ const BreezeInfo& info = weatherBreezeInfo();
+ if (info.m_breezeVersion != m_curVersion)
{
updateSway();
}
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp
index ededad83d..31233e745 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, greyed
if( !TheGlobalData->m_direct3D11 )
{
- static const char *const direct3D11Only[] = { "MapLight", "TeamGlow", "WaterFoam", "GroundMarks", "Firelight", "HemiAmbient", "AmbientOcclusion", "InternalHdr" };
+ static const char *const direct3D11Only[] = { "MapLight", "TeamGlow", "WaterFoam", "GroundMarks", "Firelight", "HemiAmbient", "AmbientOcclusion", "InternalHdr", "Weather" };
for( Int i = 0; i < (Int)( sizeof( direct3D11Only ) / sizeof( direct3D11Only[ 0 ] ) ); ++i )
findOptionWidget( *findOptionDef( direct3D11Only[ i ] ) )->winEnable( FALSE );
}
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/Snow.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/Snow.cpp
index 6940caec3..724905447 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/Snow.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/Snow.cpp
@@ -31,6 +31,7 @@
#include "PreRTS.h" // This must go first in EVERY cpp file int the Game
#include "GameClient/Snow.h"
#include "GameClient/View.h"
+#include "GameLogic/ScriptEngine.h"
#ifdef _INTERNAL
// for occasional debugging...
@@ -45,6 +46,9 @@ SnowManager::SnowManager()
m_time = 0;
m_velocity = 1;
m_isVisible = TRUE; //default to showing if it's enabled via INI.
+ m_weatherOn = FALSE;
+ m_weatherKind = WEATHER_KIND_NONE;
+ m_weatherWind.zero();
}
void SnowManager::init( void )
@@ -86,6 +90,53 @@ void SnowManager::updateIniSettings(void)
m_fullTimePeriod = m_boxDimensions/m_velocity;
}
+/* The Weather option's wind. Strength 1 is a sandstorm. Sway and lean are radians over the default
+ breeze's 0.055 of each, the smoke's drift is world units per particle update; a smoke column rises
+ about twice that, so it leans by some 25 degrees. */
+static const Real WEATHER_SWAY = 0.11f;
+static const Real WEATHER_LEAN = 0.16f;
+static const Real WEATHER_SMOKE_DRIFT = 0.5f;
+static const Short WEATHER_BREEZE_PERIOD = LOGICFRAMES_PER_SECOND * 3;
+static const Short WEATHER_BREEZE_VERSION = 0x2000; // past any count a map's scripts reach, so trees notice the switch
+static BreezeInfo s_weatherBreeze;
+
+const BreezeInfo &weatherBreezeInfo(void)
+{
+ return (TheSnowManager != NULL && TheSnowManager->isWeatherOn()) ? s_weatherBreeze : TheScriptEngine->getBreezeInfo();
+}
+
+void SnowManager::setWeatherWind(Real strength)
+{
+ const BreezeInfo &script = TheScriptEngine->getBreezeInfo();
+ s_weatherBreeze = script;
+ s_weatherBreeze.m_intensity = max(script.m_intensity, WEATHER_SWAY * strength);
+ s_weatherBreeze.m_lean = max(script.m_lean, WEATHER_LEAN * strength);
+ s_weatherBreeze.m_breezePeriod = min(script.m_breezePeriod, WEATHER_BREEZE_PERIOD);
+ // the kind too: a tree buffer outlives its map, and the next map may blow harder
+ s_weatherBreeze.m_breezeVersion = script.m_breezeVersion + WEATHER_BREEZE_VERSION + (Short)m_weatherKind;
+ m_weatherWind.x = script.m_directionVec.x * WEATHER_SMOKE_DRIFT * strength;
+ m_weatherWind.y = script.m_directionVec.y * WEATHER_SMOKE_DRIFT * strength;
+ m_weatherWind.z = 0.0f;
+}
+
+/* Strength is the most of the colour a pixel takes before the haze's own cap of a half. The colour
+ takes the map's light channel by channel and the strength its brightness: a tan veil at full strength
+ took the blue out of Dark Night's moonlight. */
+void SnowManager::getWeatherHaze(float colour[3], Real *strength) const
+{
+ static const float COLOURS[WEATHER_KIND_COUNT][3] = {
+ { 0.0f, 0.0f, 0.0f }, { 0.50f, 0.54f, 0.60f }, { 0.74f, 0.58f, 0.38f }, { 0.82f, 0.86f, 0.92f } };
+ static const Real STRENGTHS[WEATHER_KIND_COUNT] = { 0.0f, 0.24f, 0.70f, 0.28f };
+ const GlobalData::TerrainLighting &sun = TheGlobalData->m_terrainLighting[TheGlobalData->m_timeOfDay][0];
+ const Real red = min(sun.ambient.red + sun.diffuse.red, 1.0f);
+ const Real green = min(sun.ambient.green + sun.diffuse.green, 1.0f);
+ const Real blue = min(sun.ambient.blue + sun.diffuse.blue, 1.0f);
+ colour[0] = COLOURS[m_weatherKind][0] * red;
+ colour[1] = COLOURS[m_weatherKind][1] * green;
+ colour[2] = COLOURS[m_weatherKind][2] * blue;
+ *strength = STRENGTHS[m_weatherKind] * (0.299f * red + 0.587f * green + 0.114f * blue);
+}
+
void SnowManager::setVisible(Bool showWeather)
{
m_isVisible = showWeather;
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/System/ParticleSys.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/System/ParticleSys.cpp
index fee50320d..d36883486 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/System/ParticleSys.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/System/ParticleSys.cpp
@@ -53,6 +53,7 @@
#include "GameClient/InGameUI.h"
#include "GameClient/ParticleSys.h"
#include "GameClient/Shadow.h"
+#include "GameClient/Snow.h"
#include "GameLogic/GameLogic.h"
#include "GameLogic/Object.h"
@@ -2627,9 +2628,24 @@ Bool ParticleSystem::updateEmission( Int localPlayerIndex, Bool *keepSystem )
// ------------------------------------------------------------------------------------------------
/** What every particle of this system reads during this update. */
// ------------------------------------------------------------------------------------------------
+Coord3D ParticleSystem::getDriftWithWeather( void ) const
+{
+ Coord3D drift = m_driftVelocity;
+ // The Weather option's wind leans what rises and hangs in the air. A flame's additive and a mark
+ // laid on the ground stay put, and so does an area effect, which shows where a hazard really is.
+ if (TheSnowManager != NULL && TheSnowManager->isWeatherOn() && m_shaderType == ParticleSystemInfo::ALPHA
+ && !m_isGroundAligned && m_priority != AREA_EFFECT)
+ {
+ const Coord3D &wind = TheSnowManager->getWeatherWind();
+ drift.x += wind.x;
+ drift.y += wind.y;
+ }
+ return drift;
+}
+
void ParticleSystem::makeUpdateContext( ParticleUpdateContext *context ) const
{
- context->driftVelocity = m_driftVelocity;
+ context->driftVelocity = getDriftWithWeather();
context->gravity = m_gravity;
context->clientFrame = TheGameClient->getFrame();
context->shaderType = m_shaderType;
@@ -2839,6 +2855,7 @@ void ParticleSystem::addGpuSamplesToShadowBlob( ParticleShadowBlob *blob ) const
{
const UnsignedInt now = ParticleSystemManager::getParticleFrame();
const UnsignedInt samples = getGpuSampleCount();
+ const Coord3D drift = getDriftWithWeather();
for (UnsignedInt i = 0; i < samples; ++i)
{
const GpuSpawnSample &sample = getGpuSample( i );
@@ -2848,8 +2865,8 @@ void ParticleSystem::addGpuSamplesToShadowBlob( ParticleShadowBlob *blob ) const
continue;
const Real travel = info.m_velDamping * particleDampedSum( info.m_velDamping, k );
- const Real x = info.m_pos.x + k * m_driftVelocity.x + info.m_vel.x * travel;
- const Real y = info.m_pos.y + k * m_driftVelocity.y + info.m_vel.y * travel;
+ const Real x = info.m_pos.x + k * drift.x + info.m_vel.x * travel;
+ const Real y = info.m_pos.y + k * drift.y + info.m_vel.y * travel;
const Real size = info.m_size + info.m_sizeRate * particleDampedSum( info.m_sizeRateDamping, k );
Real alpha = info.m_alphaKey[ 0 ].value;
diff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DSnow.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DSnow.h
index 7223088c0..f94f3703b 100644
--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DSnow.h
+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DSnow.h
@@ -48,6 +48,21 @@ class W3DSnowManager : public SnowManager
Bool ReAcquireResources(void);
private:
+ void updateWeather(void);
+ void renderWeather(RenderInfoClass &rinfo);
+ void drawWeatherLayer(RenderInfoClass &rinfo, Int layer, Real light);
+
+ // The Weather option. None of it is allocated, loaded or read while the option is off.
+ struct WeatherDrop { Real x, y, phase; }; ///< a drop's place in its tile and in its fall, 0 to 1
+ WeatherDrop *m_weatherDrops;
+ TextureClass *m_weatherTextures[2];
+ double m_weatherTime; ///< seconds; double, because it is multiplied by a speed and wrapped by the tile
+ const void *m_weatherMap; ///< the map m_weatherSandCells was counted on, with its samples: see W3DShaderManager's haze
+ const void *m_weatherMapData;
+ Int m_weatherMapWidth;
+ Int m_weatherSandCells;
+ Int m_weatherCells;
+
DX8IndexBufferClass *m_indexBuffer;
TextureClass *m_snowTexture;
IDirect3DVertexBuffer9* m_VertexBufferD3D;
diff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/WorldHeightMap.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/WorldHeightMap.h
index 574dc8ae7..512a90be6 100644
--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/WorldHeightMap.h
+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/WorldHeightMap.h
@@ -242,6 +242,7 @@ public: // height map info.
Int getTextureClassNoBlend(Int xIndex, Int yIndex, Bool baseClass=false);
Int getTextureClass(Int xIndex, Int yIndex, Bool baseClass=false);
+ void countSandCells(Int *sandCells, Int *cells);
TXTextureClass getTextureFromIndex( Int textureIndex );
public: // tile and texture info.
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DParticleSys.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DParticleSys.cpp
index 2438dda36..34058ac76 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DParticleSys.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DParticleSys.cpp
@@ -2677,6 +2677,10 @@ UnsignedInt W3DParticleSystemManager::gpuSlotFor( ParticleSystem *system )
taken.reuseFrame = 0;
ParticleGpuSystemEntry &entry = m_gpuEntries[ slot ];
particleGpuSystemEntryBuild( *system, &entry );
+ // taken once a slot, so the Weather option switched in a match reaches the systems made after it
+ const Coord3D drift = system->getDriftWithWeather();
+ entry.m_drift[ 0 ] = drift.x;
+ entry.m_drift[ 1 ] = drift.y;
entry.m_textureSlice = slice;
entry.m_flags = PARTICLE_GPU_ALIVE | ( system->isGpuGroundClamped() ? PARTICLE_GPU_GROUND_CLAMPED : 0u );
// the fade is taken at the sync point (refreshGpuSystems), which runs before the next draw
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DShaderManager.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DShaderManager.cpp
index d1d215ce3..50cdf1001 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DShaderManager.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DShaderManager.cpp
@@ -67,6 +67,7 @@
#include "W3DDevice/GameClient/W3DCustomScene.h"
#include "W3DDevice/GameClient/W3DSmudge.h"
#include "GameClient/View.h"
+#include "GameClient/Snow.h"
#include "GameClient/CommandXlat.h"
#include "GameClient/Display.h"
#include "GameClient/Water.h"
@@ -399,14 +400,38 @@ static void pushShroudFrame(void)
Direct3D11_Set_Haze_Shroud(NULL, wholeRect);
}
}
+
+// The Weather option's haze: the same still layer, over all the ground, in the kind's colour.
+static void pushWeatherHaze(void)
+{
+ float colour[3];
+ Real strength;
+ TheSnowManager->getWeatherHaze(colour, &strength);
+ const float up[3] = { 0.0f, 0.0f, 1.0f };
+ DX11Post_Set_Haze(colour, 1.0e5f, 1.0f, strength, PROTO_HAZE_REACH, -1.0e6f, up, 0.0f);
+}
#endif
void W3DShaderManager::pushProtoHaze(void)
{
#if defined(_WIN32)
- if (TheGlobalData->m_mapLight && Direct3D11_Is_Active())
+ // The kind is NONE unless the option is on and Direct3D 11 presents. Weather's haze takes the place
+ // of the Warm Light one while it lasts. Either option goes off live, and the haze holds what it was
+ // last handed.
+ const Bool weatherHaze = TheSnowManager != NULL && TheSnowManager->getWeatherKind() != WEATHER_KIND_NONE
+ && TheSnowManager->isVisible();
+ static Bool s_hazed = FALSE;
+ if (weatherHaze)
+ pushWeatherHaze();
+ else if (TheGlobalData->m_mapLight && Direct3D11_Is_Active())
pushProtoHazeFrame();
- if ((TheGlobalData->m_mapLight || TheGlobalData->m_ambientOcclusion) && Direct3D11_Is_Active())
+ else if (s_hazed)
+ {
+ const float none[3] = { 0.0f, 0.0f, 0.0f };
+ DX11Post_Set_Haze(none, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, none, 0.0f);
+ }
+ s_hazed = weatherHaze || TheGlobalData->m_mapLight;
+ if ((TheGlobalData->m_mapLight || TheGlobalData->m_ambientOcclusion || weatherHaze) && Direct3D11_Is_Active())
pushShroudFrame();
#endif
}
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DSnow.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DSnow.cpp
index f0e99adf7..3243ac4d6 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DSnow.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DSnow.cpp
@@ -22,7 +22,9 @@
#include "W3DDevice/GameClient/W3DSnow.h"
#include "W3DDevice/GameClient/HeightMap.h"
+#include "Common/GlobalData.h"
#include "GameClient/View.h"
+#include "GameLogic/ScriptEngine.h"
#include "WW3D2/dx8wrapper.h"
#include "WW3D2/rinfo.h"
#include "WW3D2/camera.h"
@@ -50,11 +52,21 @@ W3DSnowManager::W3DSnowManager(void)
m_indexBuffer=NULL;
m_snowTexture=NULL;
m_VertexBufferD3D=NULL;
+ m_weatherDrops=NULL;
+ m_weatherTextures[0]=NULL;
+ m_weatherTextures[1]=NULL;
+ m_weatherTime=0.0;
+ m_weatherMap=NULL;
+ m_weatherMapData=NULL;
+ m_weatherMapWidth=0;
+ m_weatherSandCells=0;
+ m_weatherCells=0;
}
W3DSnowManager::~W3DSnowManager()
{
ReleaseResources();
+ delete [] m_weatherDrops;
}
// Direct3D 11 has no point sprites at all: the fixed-function primitive that expands one vertex
@@ -89,6 +101,8 @@ void W3DSnowManager::init( void )
void W3DSnowManager::ReleaseResources(void)
{
REF_PTR_RELEASE(m_snowTexture);
+ REF_PTR_RELEASE(m_weatherTextures[0]);
+ REF_PTR_RELEASE(m_weatherTextures[1]);
if (m_VertexBufferD3D)
m_VertexBufferD3D->Release();
@@ -103,7 +117,7 @@ Bool W3DSnowManager::ReAcquireResources(void)
{
ReleaseResources();
- if (!TheWeatherSetting->m_snowEnabled)
+ if (!TheWeatherSetting->m_snowEnabled && m_weatherKind == WEATHER_KIND_NONE)
return TRUE; //no need for resources if snow is disabled.
if (snowUsesPointSprites())
@@ -192,6 +206,223 @@ void W3DSnowManager::update(void)
//find current time offset, adjusting for overflow
m_time=fmod(m_time,m_fullTimePeriod);
+
+ m_weatherOn = TheGlobalData->m_weatherEffects && !TheGlobalData->m_classicGraphics && Direct3D11_Present_Is_Enabled();
+ if (m_weatherOn)
+ updateWeather();
+ else
+ m_weatherKind = WEATHER_KIND_NONE;
+}
+
+/* The Weather option (Options > Effects, Direct3D 11, off under Classic). A client's picture and no
+ more: quads, a wind on the trees and on rising smoke, the still haze. Nothing here reaches logic,
+ sight or the shroud, so two players may see different weather in one match.
+
+ Each layer keeps a fixed number of quads in a square tile that follows the camera; a quad wraps
+ round the tile, which leaves it where it is in the world while the camera pans. So the cost is the
+ count, whatever the zoom. A quad covers no pixel the texture would not, and the program is the one
+ EA's snow draws with. */
+struct WeatherLayer
+{
+ const char *texture;
+ Int count; // quads on a tile of WEATHER_TILE_STEP; a smaller tile takes fewer
+ Real along; // world units a second down the wind
+ Real down; // and toward the ground
+ Real length; // a streak's length along its flight, or a card's height
+ Real width;
+ UnsignedInt colour; // taken down with the map's light
+ Real height; // the layer's depth over the ground the camera looks at; 0 falls from the camera
+ Bool facesCamera; // a card instead of a streak along the flight
+};
+
+static const WeatherLayer WEATHER_LAYERS[WEATHER_KIND_COUNT][2] =
+{
+ { { NULL }, { NULL } },
+ { { "EXRainDrop.tga", 8000, 180.0f, 1100.0f, 44.0f, 3.4f, 0xe0d8e4f0, 0.0f, FALSE }, { NULL } },
+ { { "EXRainDrop.tga", 6000, 520.0f, 25.0f, 72.0f, 3.2f, 0xb0ecd4a4, 150.0f, FALSE },
+ { "EXCloud01.tga", 200, 260.0f, 4.0f, 260.0f, 260.0f, 0x40d0ac7c, 170.0f, TRUE } },
+ { { "EXSnowFlake1.tga", 7000, 34.0f, 46.0f, 2.4f, 2.4f, 0xe0e8eef4, 0.0f, TRUE }, { NULL } }
+};
+
+static const Real WEATHER_WIND_STRENGTH[WEATHER_KIND_COUNT] = { 0.5f, 0.8f, 1.0f, 0.35f };
+static const Int WEATHER_MAX_DROPS = 8192;
+static const Real WEATHER_TILE_STEP = 2048.0f;
+static const Real WEATHER_TILE_MIN = 512.0f;
+static const Real WEATHER_TILE_MAX = 4096.0f;
+static const Real WEATHER_FALL_PER_TILE = 0.75f; // how far a falling layer reaches, by the tile
+static const Real WEATHER_EYE_CLEARANCE = 0.55f; // of the eye's height: nothing falls against the lens, where a streak would cross the screen
+
+void W3DSnowManager::updateWeather(void)
+{
+ m_weatherTime = fmod(m_weatherTime + WW3D::Get_Frame_Time() / 1000.0, 3600.0);
+
+ WorldHeightMap *map = TheTerrainRenderObject != NULL ? TheTerrainRenderObject->getMap() : NULL;
+ if (map != NULL && (map != m_weatherMap || map->getDataPtr() != m_weatherMapData || map->getXExtent() != m_weatherMapWidth))
+ {
+ m_weatherMap = map;
+ m_weatherMapData = map->getDataPtr();
+ m_weatherMapWidth = map->getXExtent();
+ map->countSandCells(&m_weatherSandCells, &m_weatherCells);
+ DEBUG_LOG(("WEATHER map is %d sand of %d cells\n", m_weatherSandCells, m_weatherCells));
+ }
+
+ const WeatherKind kind = map == NULL ? WEATHER_KIND_NONE : weatherKindForMap(TheWeatherSetting->m_snowEnabled,
+ TheGlobalData->m_weather == WEATHER_SNOWY, m_weatherSandCells, m_weatherCells);
+ if (kind != m_weatherKind)
+ {
+ m_weatherKind = kind;
+ REF_PTR_RELEASE(m_weatherTextures[0]);
+ REF_PTR_RELEASE(m_weatherTextures[1]);
+ }
+ setWeatherWind(WEATHER_WIND_STRENGTH[kind]);
+}
+
+void W3DSnowManager::renderWeather(RenderInfoClass &rinfo)
+{
+ if (m_weatherDrops == NULL)
+ {
+ m_weatherDrops = NEW WeatherDrop[WEATHER_MAX_DROPS];
+ for (Int i = 0; i < WEATHER_MAX_DROPS; ++i)
+ {
+ m_weatherDrops[i].x = rand() / (Real)RAND_MAX;
+ m_weatherDrops[i].y = rand() / (Real)RAND_MAX;
+ m_weatherDrops[i].phase = rand() / (Real)RAND_MAX;
+ }
+ }
+ if (!m_indexBuffer)
+ ReAcquireResources();
+
+ Matrix4x4 identity(true);
+ DX8Wrapper::Set_Transform(D3DTS_WORLD, identity);
+ Matrix3D view;
+ rinfo.Camera.Get_View_Matrix(&view);
+ DX8Wrapper::Set_Transform(D3DTS_VIEW, view);
+ VertexMaterialClass *vmat = VertexMaterialClass::Get_Preset(VertexMaterialClass::PRELIT_DIFFUSE);
+ DX8Wrapper::Set_Material(vmat);
+ REF_PTR_RELEASE(vmat);
+ DX8Wrapper::Set_Index_Buffer(m_indexBuffer, 0);
+
+ const GlobalData::TerrainLighting &sun = TheGlobalData->m_terrainLighting[TheGlobalData->m_timeOfDay][0];
+ const Real light = WWMath::Clamp(0.299f * (sun.ambient.red + sun.diffuse.red) + 0.587f * (sun.ambient.green + sun.diffuse.green)
+ + 0.114f * (sun.ambient.blue + sun.diffuse.blue), 0.3f, 1.0f);
+
+ // No sun's shadow on what falls: with it every pixel of every quad pays the blocker search, for a
+ // shade nobody could see on a streak.
+ Direct3D11_Set_Emissive(true);
+ drawWeatherLayer(rinfo, 0, light);
+ if (WEATHER_LAYERS[m_weatherKind][1].texture != NULL)
+ drawWeatherLayer(rinfo, 1, light);
+ Direct3D11_Set_Emissive(false);
+}
+
+void W3DSnowManager::drawWeatherLayer(RenderInfoClass &rinfo, Int layerIndex, Real light)
+{
+ const WeatherLayer &layer = WEATHER_LAYERS[m_weatherKind][layerIndex];
+ if (m_weatherTextures[layerIndex] == NULL)
+ m_weatherTextures[layerIndex] = WW3DAssetManager::Get_Instance()->Get_Texture(layer.texture);
+ DX8Wrapper::Set_Texture(0, m_weatherTextures[layerIndex]);
+ // A card wider than a unit would cut a hard line where it meets the ground, so it takes no depth:
+ // a cloud between the eye and the ground goes over all of it anyway.
+ ShaderClass shader(ShaderClass::_PresetAlphaShader);
+ if (layer.height > 0.0f && layer.facesCamera)
+ shader.Set_Depth_Compare(ShaderClass::PASS_ALWAYS);
+ // A near vertical streak past the point under the camera turns its back to it at a steep tilt.
+ shader.Set_Cull_Mode(ShaderClass::CULL_MODE_DISABLE);
+ DX8Wrapper::Set_Shader(shader);
+
+ CameraClass &camera = rinfo.Camera;
+ const Vector3 eye = camera.Get_Position();
+
+ // The tile: a power of two times the step, so it holds through a pan and only a change of zoom
+ // moves the drops, and centred ahead of the camera as far as it may go and still hold the near ground.
+ AABoxClass visible;
+ TheTerrainRenderObject->getMaximumVisibleBox(camera.Get_Frustum(), &visible, TRUE);
+ const Real wanted = 2.0f * max(visible.Extent.X, visible.Extent.Y);
+ Real tile = WEATHER_TILE_MIN;
+ while (tile < wanted && tile < WEATHER_TILE_MAX)
+ tile *= 2.0f;
+ Vector2 ahead(visible.Center.X - eye.X, visible.Center.Y - eye.Y);
+ const Real farthest = tile * 0.45f;
+ if (ahead.Length() > farthest)
+ ahead *= farthest / ahead.Length();
+ const Real centreX = eye.X + ahead.X;
+ const Real centreY = eye.Y + ahead.Y;
+ const Real originX = centreX - tile * 0.5f;
+ const Real originY = centreY - tile * 0.5f;
+
+ const Real ground = TheTerrainRenderObject->getHeightMapHeight(centreX, centreY, NULL);
+ const Real depth = layer.height > 0.0f ? layer.height : tile * WEATHER_FALL_PER_TILE;
+ const Real top = layer.height > 0.0f ? ground + layer.height : eye.Z - (eye.Z - ground) * WEATHER_EYE_CLEARANCE;
+
+ const Coord2D &wind = weatherBreezeInfo().m_directionVec;
+ const Real shiftX = (Real)fmod(m_weatherTime * wind.x * layer.along, (double)tile);
+ const Real shiftY = (Real)fmod(m_weatherTime * wind.y * layer.along, (double)tile);
+ const Real fallen = (Real)fmod(m_weatherTime * layer.down / depth, 1.0);
+
+ // A streak lies along its flight and takes its width across the view, so it never turns edge on.
+ const Matrix3D &eyeFrame = camera.Get_Transform();
+ Vector3 axis;
+ Vector3 side;
+ if (layer.facesCamera)
+ {
+ axis = eyeFrame.Get_Y_Vector() * -1.0f;
+ side = eyeFrame.Get_X_Vector();
+ }
+ else
+ {
+ axis.Set(wind.x * layer.along, wind.y * layer.along, -layer.down);
+ axis.Normalize();
+ Vector3::Cross_Product(eyeFrame.Get_Z_Vector(), axis, &side);
+ side.Normalize();
+ }
+ axis *= layer.length * 0.5f;
+ side *= layer.width * 0.5f;
+ const Vector3 corners[4] = { -axis - side, axis - side, axis + side, -axis + side };
+ static const Real CORNER_U[4] = { 0.0f, 0.0f, 1.0f, 1.0f };
+ static const Real CORNER_V[4] = { 0.0f, 1.0f, 1.0f, 0.0f };
+
+ const UnsignedInt colour = (layer.colour & 0xff000000)
+ | ((UnsignedInt)(((layer.colour >> 16) & 0xff) * light) << 16)
+ | ((UnsignedInt)(((layer.colour >> 8) & 0xff) * light) << 8)
+ | (UnsignedInt)((layer.colour & 0xff) * light);
+
+ const Int count = min((Int)(layer.count * tile * tile / (WEATHER_TILE_STEP * WEATHER_TILE_STEP)), layer.count);
+ Int done = 0;
+ while (done < count)
+ {
+ const Int batch = min(count - done, (Int)SNOW_BATCH_SIZE);
+ DynamicVBAccessClass vb_access(BUFFER_TYPE_DYNAMIC_DX8, dynamic_fvf_type, batch * 4);
+ {
+ DynamicVBAccessClass::WriteLockClass lock(&vb_access);
+ VertexFormatXYZNDUV2 *verts = lock.Get_Formatted_Vertex_Array();
+ for (Int i = 0; i < batch; ++i)
+ {
+ const WeatherDrop &drop = m_weatherDrops[done + i];
+ const Real x = weatherWrap(drop.x * tile + shiftX, originX, tile);
+ const Real y = weatherWrap(drop.y * tile + shiftY, originY, tile);
+ const Real phase = drop.phase + fallen;
+ const Real z = top - (phase - (Int)phase) * depth;
+ for (Int corner = 0; corner < 4; ++corner)
+ {
+ verts->x = x + corners[corner].X;
+ verts->y = y + corners[corner].Y;
+ verts->z = z + corners[corner].Z;
+ verts->nx = 0; //keep AGP write-combining active
+ verts->ny = 0;
+ verts->nz = 0;
+ verts->diffuse = colour;
+ verts->u1 = CORNER_U[corner];
+ verts->v1 = CORNER_V[corner];
+ verts->u2 = 0;
+ verts->v2 = 0;
+ verts++;
+ }
+ }
+ }
+ DX8Wrapper::Set_Vertex_Buffer(vb_access);
+ DX8Wrapper::Draw_Triangles(0, batch * 2, 0, batch * 4);
+ done += batch;
+ }
}
#define MAXIMUM_CAMERA_DISTANCE 100000 //maximum distance of camera position from world origin.
@@ -353,6 +584,12 @@ flush_particles:
void W3DSnowManager::render(RenderInfoClass &rinfo)
{
+ if (m_weatherKind != WEATHER_KIND_NONE && m_isVisible)
+ {
+ renderWeather(rinfo);
+ return;
+ }
+
if (!TheWeatherSetting->m_snowEnabled || !m_isVisible)
return;
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DTreeBuffer.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DTreeBuffer.cpp
index 5ea95f69b..1aa6208b9 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DTreeBuffer.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DTreeBuffer.cpp
@@ -71,6 +71,7 @@ enum
#include "Common/Player.h"
#include "Common/PlayerList.h"
#include "GameLogic/ScriptEngine.h"
+#include "GameClient/Snow.h"
#include "GameLogic/GameLogic.h"
#include "GameLogic/Object.h"
#include "GameLogic/PartitionManager.h"
@@ -2287,7 +2288,7 @@ void W3DTreeBuffer::drawTrees(CameraClass * camera, RefRenderObjListIterator *pD
// if breeze changes, always process the full update, even if not visible,
// so that things offscreen won't 'pop' when first viewed
- const BreezeInfo& info = TheScriptEngine->getBreezeInfo();
+ const BreezeInfo& info = weatherBreezeInfo();
Bool pause = TheScriptEngine->isTimeFrozenScript() || TheScriptEngine->isTimeFrozenDebug();
if (TheGameLogic && TheGameLogic->isGamePaused()) {
pause = true;
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/WorldHeightMap.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/WorldHeightMap.cpp
index 2fe794e70..d7360eea8 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/WorldHeightMap.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/WorldHeightMap.cpp
@@ -1834,8 +1834,37 @@ Int WorldHeightMap::getTextureClass(Int xIndex, Int yIndex, Bool baseClass)
+/** How much of the playable ground, every second cell each way, is laid in a desert or sand class of
+Terrain.ini. Once a map, for the Weather option. */
+void WorldHeightMap::countSandCells(Int *sandCells, Int *cells)
+{
+ Bool sandy[NUM_TEXTURE_CLASSES];
+ for (Int i = 0; i < m_numTextureClasses; i++) {
+ TerrainType *terrain = TheTerrainTypes->findTerrain(m_textureClasses[i].name); // a map may name one its data lacks
+ const TerrainClass terrainClass = terrain != NULL ? terrain->getClass() : TERRAIN_NONE;
+ sandy[i] = terrainClass == TERRAIN_DESERT_1 || terrainClass == TERRAIN_DESERT_2 || terrainClass == TERRAIN_DESERT_3
+ || terrainClass == TERRAIN_DRY_DESERT || terrainClass == TERRAIN_LIVE_DESERT || terrainClass == TERRAIN_SAND
+ || terrainClass == TERRAIN_ACCENT_SAND;
+ }
+ *sandCells = 0;
+ *cells = 0;
+ for (Int y = m_borderSize; y < m_height - m_borderSize; y += 2) {
+ for (Int x = m_borderSize; x < m_width - m_borderSize; x += 2) {
+ const Int tile = m_tileNdxes[x + y * m_width] >> 2;
+ for (Int i = 0; i < m_numTextureClasses; i++) {
+ if (tile >= m_textureClasses[i].firstTile && tile < m_textureClasses[i].firstTile + m_textureClasses[i].numTiles) {
+ if (sandy[i])
+ ++*sandCells;
+ break;
+ }
+ }
+ ++*cells;
+ }
+ }
+}
+
/** Gets global texture class. */
-Int WorldHeightMap::getTextureClassFromNdx(Int tileNdx)
+Int WorldHeightMap::getTextureClassFromNdx(Int tileNdx)
{
Int i;
tileNdx = tileNdx>>2;
diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cpp
index cc41e0b5c..cbb892ab6 100644
--- a/GeneralsMD/Code/Tests/test_gameengine.cpp
+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp
@@ -20520,6 +20520,29 @@ TEST(save_older_than_60hz_loads_only_as_mission_save)
#include "test_map_ini_rollback.inc"
#include "test_hostile_map.inc"
+#include "GameClient/Snow.h"
+
+TEST(weather_kind_goes_by_the_map)
+{
+ CHECK_EQ( (Int)weatherKindForMap( TRUE, TRUE, 100, 100 ), (Int)WEATHER_KIND_NONE );
+ CHECK_EQ( (Int)weatherKindForMap( TRUE, FALSE, 0, 100 ), (Int)WEATHER_KIND_NONE );
+ CHECK_EQ( (Int)weatherKindForMap( FALSE, TRUE, 100, 100 ), (Int)WEATHER_KIND_SNOW );
+ CHECK_EQ( (Int)weatherKindForMap( FALSE, FALSE, 41, 100 ), (Int)WEATHER_KIND_SAND );
+ CHECK_EQ( (Int)weatherKindForMap( FALSE, FALSE, 40, 100 ), (Int)WEATHER_KIND_RAIN );
+ CHECK_EQ( (Int)weatherKindForMap( FALSE, FALSE, 0, 0 ), (Int)WEATHER_KIND_RAIN );
+}
+
+TEST(a_weather_drop_keeps_its_world_place_as_the_tile_follows_the_camera)
+{
+ CHECK_NEAR( weatherWrap( 100.0f, 0.0f, 1024.0f ), 100.0f, 0.001f );
+ CHECK_NEAR( weatherWrap( 1124.0f, 0.0f, 1024.0f ), 100.0f, 0.001f );
+ CHECK_NEAR( weatherWrap( -100.0f, 0.0f, 1024.0f ), 924.0f, 0.001f );
+ // a pan that leaves the drop inside the tile does not move it
+ CHECK_NEAR( weatherWrap( 700.0f, 300.0f, 1024.0f ), weatherWrap( 700.0f, 500.0f, 1024.0f ), 0.001f );
+ // one it leaves behind comes round a whole tile on
+ CHECK_NEAR( weatherWrap( 700.0f, 800.0f, 1024.0f ), 1724.0f, 0.001f );
+}
+
#include "GameLogic/AI.h"
/* An AI seat's personality rides on its slot entry as an optional sixth field. The whole options
diff --git a/GeneralsMD/Code/Tools/optionsmenu_layout.py b/GeneralsMD/Code/Tools/optionsmenu_layout.py
index 43a1fde14..7cb82ca9e 100644
--- a/GeneralsMD/Code/Tools/optionsmenu_layout.py
+++ b/GeneralsMD/Code/Tools/optionsmenu_layout.py
@@ -243,6 +243,7 @@ NEW_CONTROLS = [
(CHECK, "CheckHemiAmbient", "GUI:HemiAmbient"),
(CHECK, "CheckAmbientOcclusion", "GUI:AmbientOcclusion"),
(CHECK, "CheckInternalHdr", "GUI:InternalHdr"),
+ (CHECK, "CheckWeather", "GUI:Weather"),
(LABEL, "LabelGraphicsQuality", "GUI:GraphicsQuality"),
(SLIDER, "SliderGraphicsQuality", None),
]
@@ -395,7 +396,8 @@ GROUP_LAYOUT = [
("check", "CheckParticleBounce"),
("check", "CheckSmokeFireLighting"),
("check", "CheckFirelight"),
- ("check", "CheckDebrisTrails")])]),
+ ("check", "CheckDebrisTrails"),
+ ("check", "CheckWeather")])]),
("PageAudio", [
("GUI:OptionsGroupVolume", [