From 277044d60dbf148bbece209b966e42863f7a1f85 Mon Sep 17 00:00:00 2001 From: VodkaNET Date: Thu, 12 Nov 2026 02:00:08 +0500 Subject: [PATCH 1/4] Dynamic Weather Basic Support --- Core/GameEngine/Include/GameClient/Snow.h | 14 ++ Core/GameEngine/Source/GameClient/Snow.cpp | 10 ++ .../GameLogic/System/GameLogicDispatch.cpp | 8 + .../GameEngine/Source/GameNetwork/Network.cpp | 13 ++ .../Include/W3DDevice/GameClient/W3DSnow.h | 1 + .../Source/W3DDevice/GameClient/W3DSnow.cpp | 15 +- .../GameEngine/Include/Common/MessageStream.h | 1 + .../GameEngine/Include/GameLogic/GameLogic.h | 19 +++ .../GameNetwork/GeneralsOnline/NGMPGame.h | 3 + .../Source/Common/MessageStream.cpp | 1 + .../Source/GameLogic/System/GameLogic.cpp | 153 ++++++++++++++++++ .../GameNetwork/GeneralsOnline/NGMPGame.cpp | 1 + 12 files changed, 233 insertions(+), 6 deletions(-) diff --git a/Core/GameEngine/Include/GameClient/Snow.h b/Core/GameEngine/Include/GameClient/Snow.h index 862820eb520..83ba7359152 100644 --- a/Core/GameEngine/Include/GameClient/Snow.h +++ b/Core/GameEngine/Include/GameClient/Snow.h @@ -36,6 +36,15 @@ class WeatherSetting : public Overridable MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE( WeatherSetting, "WeatherSetting" ) public: + enum DynamicProfile + { + DYNAMIC_AUTO, + DYNAMIC_DRY, + DYNAMIC_SNOW, + DYNAMIC_RAIN + }; + + Int m_dynamicWeatherProfile = DYNAMIC_AUTO; AsciiString m_snowTexture; Real m_snowFrequencyScaleX; /// TheWeatherSetting = nullptr; +static const char *const dynamicWeatherProfiles[] = { "AUTO", "DRY", "SNOW", "RAIN", nullptr }; + // PRIVATE DATA /////////////////////////////////////////////////////////////////////////////////// const FieldParse WeatherSetting::m_weatherSettingFieldParseTable[] = { + { "DynamicWeatherProfile", INI::parseIndexList, dynamicWeatherProfiles, offsetof( WeatherSetting, m_dynamicWeatherProfile ) }, { "SnowTexture", INI::parseAsciiString,nullptr, offsetof( WeatherSetting, m_snowTexture ) }, { "SnowFrequencyScaleX", INI::parseReal,nullptr, offsetof( WeatherSetting, m_snowFrequencyScaleX ) }, { "SnowFrequencyScaleY", INI::parseReal,nullptr, offsetof( WeatherSetting, m_snowFrequencyScaleY ) }, diff --git a/Core/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp b/Core/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp index c9c7cbb7602..a33abd3b85d 100644 --- a/Core/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp +++ b/Core/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp @@ -367,6 +367,14 @@ void GameLogic::logicMessageDispatcher( GameMessage *msg, void *userData ) return; } +#if defined(GENERALS_ONLINE) + if (msg->getType() == GameMessage::MSG_START_DYNAMIC_WEATHER) + { + startDynamicWeather(msgPlayer); + return; + } +#endif + AIGroupPtr currentlySelectedGroup = nullptr; if (isInGame()) diff --git a/Core/GameEngine/Source/GameNetwork/Network.cpp b/Core/GameEngine/Source/GameNetwork/Network.cpp index a149bca7179..dccaa14a99a 100644 --- a/Core/GameEngine/Source/GameNetwork/Network.cpp +++ b/Core/GameEngine/Source/GameNetwork/Network.cpp @@ -52,6 +52,10 @@ #include "Common/Recorder.h" #include "GameClient/MessageBox.h" #include "../NGMP_include.h" +#if defined(GENERALS_ONLINE) +#include "GameNetwork/GeneralsOnline/NGMPGame.h" +#include "GameNetwork/GeneralsOnline/OnlineServices_LobbyInterface.h" +#endif #if defined(DEBUG_CRC) && !RETAIL_COMPATIBLE_NETWORKING @@ -545,6 +549,15 @@ Bool Network::processCommand(GameMessage* msg) m_localStatus = NETLOCALSTATUS_INGAME; NetCommandList *netcmdlist = m_conMgr->getFrameCommandList(0); // clear out frame 0 since we skipped it deleteInstance(netcmdlist); +#if defined(GENERALS_ONLINE) + if (TheNGMPGame && TheGameInfo == TheNGMPGame && TheNGMPGame->amIHost() + && !TheNGMPGame->isQMGame() && TheNGMPGame->getDynamicWeather()) + { + GameMessage *weather = newInstance(GameMessage)(GameMessage::MSG_START_DYNAMIC_WEATHER); + m_conMgr->sendLocalGameMessage(weather, getExecutionFrame()); + deleteInstance(weather); + } +#endif } else { return FALSE; } diff --git a/Core/GameEngineDevice/Include/W3DDevice/GameClient/W3DSnow.h b/Core/GameEngineDevice/Include/W3DDevice/GameClient/W3DSnow.h index c994c5a2758..5dfb661197f 100644 --- a/Core/GameEngineDevice/Include/W3DDevice/GameClient/W3DSnow.h +++ b/Core/GameEngineDevice/Include/W3DDevice/GameClient/W3DSnow.h @@ -38,6 +38,7 @@ class W3DSnowManager : public SnowManager virtual void reset() override; virtual void update () override; virtual void updateIniSettings() override; + void reloadWeather() override; void render(RenderInfoClass &rinfo); void renderAsQuads(RenderInfoClass &rinfo, Int cubeOriginX, Int cubeOriginY, Int cubeDimX, Int cubeDimY); diff --git a/Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DSnow.cpp b/Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DSnow.cpp index 62ece01ed24..133a1295bb8 100644 --- a/Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DSnow.cpp +++ b/Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DSnow.cpp @@ -154,6 +154,12 @@ void W3DSnowManager::reset() SnowManager::reset(); } +void W3DSnowManager::reloadWeather() +{ + SnowManager::updateIniSettings(); + ReleaseResources(); // Recreated by render() on the next visible frame. +} + void W3DSnowManager::update() { // TheSuperHackers @tweak The snow render update is now decoupled from the logic step. @@ -322,7 +328,7 @@ void W3DSnowManager::renderSubBox(RenderInfoClass &rinfo, Int originX, Int origi void W3DSnowManager::render(RenderInfoClass &rinfo) { - if (!TheWeatherSetting->m_snowEnabled || !m_isVisible) + if (!TheWeatherSetting->m_snowEnabled || !isWeatherVisible()) return; Int usePointSprites = DX8Wrapper::Get_Current_Caps()->Support_PointSprites() && TheWeatherSetting->m_usePointSprites; @@ -401,11 +407,8 @@ void W3DSnowManager::render(RenderInfoClass &rinfo) REF_PTR_RELEASE(vmat); //make sure we have all the resources we need - if (usePointSprites && !m_VertexBufferD3D) - ReAcquireResources(); - - if (!usePointSprites && !m_indexBuffer) - ReAcquireResources(); + if ((usePointSprites ? m_VertexBufferD3D == nullptr : m_indexBuffer == nullptr) && !ReAcquireResources()) + return; DX8Wrapper::Set_Texture(0,m_snowTexture); diff --git a/GeneralsMD/Code/GameEngine/Include/Common/MessageStream.h b/GeneralsMD/Code/GameEngine/Include/Common/MessageStream.h index bcecd9e7003..bba8b8ae0b5 100644 --- a/GeneralsMD/Code/GameEngine/Include/Common/MessageStream.h +++ b/GeneralsMD/Code/GameEngine/Include/Common/MessageStream.h @@ -619,6 +619,7 @@ class GameMessage : public MemoryPoolObject MSG_LOGIC_CRC, ///< CRC from the logic passed around in a network game :) MSG_SET_MINE_CLEARING_DETAIL, ///< CRC from the logic passed around in a network game :) MSG_ENABLE_RETALIATION_MODE, ///< Turn retaliation mode on or off. + MSG_START_DYNAMIC_WEATHER, ///< Start the host's weather cycle on a synchronized frame. MSG_BEGIN_DEBUG_NETWORK_MESSAGES = 1900, ///< network messages that exist only in debug/internal builds. all grouped separately. diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/GameLogic.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/GameLogic.h index c3a66f6c326..f7f1c9eec2d 100644 --- a/GeneralsMD/Code/GameEngine/Include/GameLogic/GameLogic.h +++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/GameLogic.h @@ -171,6 +171,9 @@ class GameLogic : public SubsystemInterface, public Snapshot // super hack void startNewGame(Bool loadSaveGame); void loadMapINI(AsciiString mapName); +#if defined(GENERALS_ONLINE) + void startDynamicWeather(const Player *sender); +#endif void updateLoadProgress( Int progress ); void deleteLoadScreen(); @@ -431,6 +434,22 @@ class GameLogic : public SubsystemInterface, public Snapshot Bool m_startNewGame; WindowLayout* m_background; +#if defined(GENERALS_ONLINE) + struct WeatherPhase + { + TimeOfDay time; + UnsignedInt duration; + Bool precipitation; + }; + + void updateDynamicWeather(); + WeatherPhase m_weatherCycle[TIME_OF_DAY_COUNT - TIME_OF_DAY_FIRST]; + UnsignedInt m_nextWeatherFrame = 0; + Int m_nextWeatherPhase = 0; + NameKeyType m_weatherHost = NAMEKEY_INVALID; + Bool m_schedulePrecipitation = FALSE; +#endif + Object* m_objList; ///< All of the objects in the world. // ObjectPtrHash m_objHash; ///< Used for ObjectID lookups ObjectPtrVector m_objVector; diff --git a/GeneralsMD/Code/GameEngine/Include/GameNetwork/GeneralsOnline/NGMPGame.h b/GeneralsMD/Code/GameEngine/Include/GameNetwork/GeneralsOnline/NGMPGame.h index 0d11c6a51b3..149fc4999b3 100644 --- a/GeneralsMD/Code/GameEngine/Include/GameNetwork/GeneralsOnline/NGMPGame.h +++ b/GeneralsMD/Code/GameEngine/Include/GameNetwork/GeneralsOnline/NGMPGame.h @@ -54,6 +54,7 @@ class NGMPGame : public GameInfo UnsignedInt m_exeCRC; UnsignedInt m_iniCRC; Bool m_isQM; + Bool m_dynamicWeather = FALSE; AsciiString m_ladderIP; AsciiString m_pingStr; @@ -166,6 +167,8 @@ class NGMPGame : public GameInfo AsciiString generateLadderGameResultsPacket(void); void markGameAsQM(void) { m_isQM = TRUE; } Bool isQMGame(void) { return m_isQM; } + Bool getDynamicWeather() const { return m_dynamicWeather; } + void setDynamicWeather(Bool enabled) { m_dynamicWeather = enabled; } virtual void init(void); virtual void resetAccepted(void); ///< Reset the accepted flag on all players diff --git a/GeneralsMD/Code/GameEngine/Source/Common/MessageStream.cpp b/GeneralsMD/Code/GameEngine/Source/Common/MessageStream.cpp index f46fe9d73ca..e1873b6ade8 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/MessageStream.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/MessageStream.cpp @@ -661,6 +661,7 @@ const char *GameMessage::getCommandTypeAsString(GameMessage::Type t) CASE_LABEL(MSG_LOGIC_CRC) CASE_LABEL(MSG_SET_MINE_CLEARING_DETAIL) CASE_LABEL(MSG_ENABLE_RETALIATION_MODE) + CASE_LABEL(MSG_START_DYNAMIC_WEATHER) CASE_LABEL(MSG_BEGIN_DEBUG_NETWORK_MESSAGES) #if defined(RTS_DEBUG) || defined(_ALLOW_DEBUG_CHEATS_IN_RELEASE) diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp index 1fa00d1b2e6..ddea7e39645 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp @@ -120,6 +120,10 @@ struct QuitGameException {}; #include "../NextGenMP_defines.h" +#if defined(GENERALS_ONLINE) +#include +#endif + DECLARE_PERF_TIMER(SleepyMaintenance) #include "Common/UnitTimings.h" //Contains the DO_UNIT_TIMINGS define jba. @@ -314,6 +318,10 @@ void GameLogic::setDefaults(Bool loadingSaveGame) { m_frame = 0; m_hasUpdated = FALSE; +#if defined(GENERALS_ONLINE) + m_nextWeatherFrame = 0; + m_weatherHost = NAMEKEY_INVALID; +#endif #if defined(GENERALS_ONLINE_HIGH_FPS_SERVER) m_frameLegacy = 0; m_frameLegacyLast = 0; @@ -558,6 +566,9 @@ void GameLogic::reset() // clear any table of contents we have m_objectTOC.clear(); +#if defined(GENERALS_ONLINE) + const Bool hadWeatherCycle = m_nextWeatherFrame != 0 && m_schedulePrecipitation; +#endif setDefaults(FALSE); m_isScoringEnabled = TRUE; @@ -573,6 +584,10 @@ void GameLogic::reset() // Clean up any weather overrides that were generated for this map. WeatherSetting* ws = (WeatherSetting*)TheWeatherSetting.getNonOverloadedPointer(); TheWeatherSetting = (WeatherSetting*)ws->deleteOverrides(); +#if defined(GENERALS_ONLINE) + if (hadWeatherCycle && TheSnowManager && TheWeatherSetting != nullptr) + TheSnowManager->reloadWeather(); +#endif m_rankPointsToAddAtGameStart = 0; } @@ -1393,6 +1408,29 @@ void GameLogic::tryStartNewGame( Bool loadingSaveGame ) } } +#if defined(GENERALS_ONLINE) + m_nextWeatherFrame = 0; + m_weatherHost = NAMEKEY_INVALID; + if (TheNetwork && TheNGMPGame && game == TheNGMPGame && !TheNGMPGame->isQMGame()) + { + auto *lobbyInterface = NGMP_OnlineServicesManager::GetInterface(); + if (lobbyInterface) + { + const LobbyEntry &lobby = lobbyInterface->GetCurrentLobby(); + for (const LobbyMemberEntry &member : lobby.members) + { + if (member.IsHuman() && member.user_id == lobby.owner && member.m_SlotIndex < MAX_SLOTS) + { + AsciiString name; + name.format("player%d", static_cast(member.m_SlotIndex)); + m_weatherHost = TheNameKeyGenerator->nameToKey(name); + break; + } + } + } + } +#endif + checkForDuplicateColors(game); Bool isSkirmishOrSkirmishReplay = FALSE; @@ -2604,6 +2642,117 @@ static void findAndSelectCommandCenter(Object *obj, void* alreadyFound) // ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------ +#if defined(GENERALS_ONLINE) +void GameLogic::startDynamicWeather(const Player *sender) +{ + if (!TheGameInfo || m_nextWeatherFrame != 0) + return; + + const Bool replay = TheRecorder && TheRecorder->isPlaybackMode(); + if (!replay && (m_weatherHost == NAMEKEY_INVALID || sender->getPlayerNameKey() != m_weatherHost)) + return; + + m_schedulePrecipitation = FALSE; + if (TheSnowManager && TheWeatherSetting != nullptr) + { + const AsciiString &texture = TheWeatherSetting->m_snowTexture; + const Bool rainTexture = texture.compareNoCase("EXRainDrop.tga") == 0 + || texture.compareNoCase("EXRainDrop.dds") == 0; + const Bool snowTexture = texture.compareNoCase("EXSnowFlake.tga") == 0 + || texture.compareNoCase("EXSnowFlake.dds") == 0 + || texture.compareNoCase("EXSnowFlake1.tga") == 0 + || texture.compareNoCase("EXSnowFlake1.dds") == 0; + Int profile = TheWeatherSetting->m_dynamicWeatherProfile; + if (profile == WeatherSetting::DYNAMIC_AUTO) + { + const AsciiString &mapPath = TheGlobalData->m_mapName; + const char *basename = mapPath.reverseFind('\\'); + if (!basename) + basename = mapPath.reverseFind('/'); + const AsciiString mapName = basename ? AsciiString(basename + 1) : mapPath; + if (TheGlobalData->m_weather == WEATHER_SNOWY + || mapName.compareNoCase("[RANK] Freezing Bursa ZH v1.map") == 0) + profile = WeatherSetting::DYNAMIC_SNOW; + else if (TheWeatherSetting->m_snowEnabled && rainTexture) + profile = WeatherSetting::DYNAMIC_RAIN; + else if (TheWeatherSetting->m_snowEnabled && snowTexture) + profile = WeatherSetting::DYNAMIC_SNOW; + } + + m_schedulePrecipitation = profile == WeatherSetting::DYNAMIC_SNOW + || profile == WeatherSetting::DYNAMIC_RAIN; + if (profile == WeatherSetting::DYNAMIC_DRY) + TheSnowManager->setDynamicWeatherVisible(FALSE); + + if (m_schedulePrecipitation && (!TheWeatherSetting->m_snowEnabled + || (profile == WeatherSetting::DYNAMIC_SNOW && rainTexture) + || (profile == WeatherSetting::DYNAMIC_RAIN && snowTexture))) + { + // A temporary override is removed by the existing map weather cleanup. + auto *weather = newInstance(WeatherSetting); + weather->m_snowEnabled = TRUE; + weather->m_snowBoxDimensions = 100.0f; + if (profile == WeatherSetting::DYNAMIC_RAIN) + { + // The stock Eastern Everglades precipitation preset. + weather->m_snowTexture = "EXRainDrop.tga"; + weather->m_snowFrequencyScaleX = 1.0f; + weather->m_snowFrequencyScaleY = 1.0f; + weather->m_snowAmplitude = 0.1f; + weather->m_snowVelocity = 25.0f; + weather->m_snowPointSize = 0.3f; + weather->m_snowQuadSize = 0.1f; + } + else + { + // Match the snow scale and fall speed used by stock winter maps. + weather->m_snowAmplitude = 4.0f; + weather->m_snowVelocity = 3.0f; + weather->m_snowPointSize = 0.16f; + weather->m_snowMaxPointSize = 10.0f; + } + weather->markAsOverride(); + auto *base = const_cast(TheWeatherSetting.getNonOverloadedPointer()); + base->friend_getFinalOverride()->setNextOverride(weather); + TheSnowManager->reloadWeather(); + } + } + + // Keep the weather roll independent from the simulation's random number stream. + std::mt19937 weatherRandom(static_cast(TheGameInfo->getSeed())); + const Int phaseCount = TIME_OF_DAY_COUNT - TIME_OF_DAY_FIRST; + const Int firstTime = weatherRandom() % phaseCount; + // Reserve the all-dry and all-wet masks so the cycle always changes precipitation. + const UnsignedInt wetPhases = 1 + weatherRandom() % ((1u << phaseCount) - 2); + for (Int i = 0; i < phaseCount; ++i) + { + WeatherPhase &phase = m_weatherCycle[i]; + phase.time = static_cast(TIME_OF_DAY_FIRST + (firstTime + i) % phaseCount); + phase.duration = (120 + weatherRandom() % 121) * LOGICFRAMES_PER_SECOND; + phase.precipitation = (wetPhases & (1u << i)) != 0; + } + + m_nextWeatherPhase = 0; + m_nextWeatherFrame = m_frame; + updateDynamicWeather(); +} + +void GameLogic::updateDynamicWeather() +{ + if (m_nextWeatherFrame == 0 || m_frame < m_nextWeatherFrame) + return; + + const WeatherPhase &phase = m_weatherCycle[m_nextWeatherPhase]; + if (TheWritableGlobalData->setTimeOfDay(phase.time)) + TheGameClient->setTimeOfDay(phase.time); + if (m_schedulePrecipitation && TheSnowManager) + TheSnowManager->setDynamicWeatherVisible(phase.precipitation); + + m_nextWeatherFrame += phase.duration; + m_nextWeatherPhase = (m_nextWeatherPhase + 1) % (TIME_OF_DAY_COUNT - TIME_OF_DAY_FIRST); +} +#endif + void GameLogic::loadMapINI(AsciiString mapName) { @@ -3987,6 +4136,10 @@ void GameLogic::update() if (TheFramePacer->isTimeFrozen()) return; +#if defined(GENERALS_ONLINE) + updateDynamicWeather(); +#endif + // Note - TerrainLogic update needs to happen after ScriptEngine update, but before object updates. jba. // This way changes in bridges are noted in the script engine before being cleared in TerrainLogic->update { diff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/NGMPGame.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/NGMPGame.cpp index 62f7b703cba..5d95aa14216 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/NGMPGame.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/NGMPGame.cpp @@ -582,6 +582,7 @@ void NGMPGame::reset(void) { GameInfo::reset(); m_isQM = FALSE; + m_dynamicWeather = FALSE; } void NGMPGame::StartCountdown() From 8a0645d99461adcdf4bee1f8220bcc0041fdd6bd Mon Sep 17 00:00:00 2001 From: VodkaNET Date: Fri, 13 Nov 2026 00:02:24 +0500 Subject: [PATCH 2/4] New Rain Cycles + Improved Logic Dynamic Weather --- Core/GameEngine/Include/GameClient/Snow.h | 14 +- .../GameClient/MessageStream/CommandXlat.cpp | 9 +- Core/GameEngine/Source/GameClient/Snow.cpp | 83 +++++- .../GameLogic/System/GameLogicDispatch.cpp | 11 +- .../Source/W3DDevice/GameClient/W3DSnow.cpp | 1 + .../GameEngine/Include/GameLogic/GameLogic.h | 17 +- .../GeneralsOnline/NextGenMP_defines.h | 5 + .../GUI/GUICallbacks/InGameChat.cpp | 45 +++- .../Source/GameLogic/System/GameLogic.cpp | 255 +++++++++++------- 9 files changed, 325 insertions(+), 115 deletions(-) diff --git a/Core/GameEngine/Include/GameClient/Snow.h b/Core/GameEngine/Include/GameClient/Snow.h index 83ba7359152..3fb798c75a0 100644 --- a/Core/GameEngine/Include/GameClient/Snow.h +++ b/Core/GameEngine/Include/GameClient/Snow.h @@ -41,7 +41,9 @@ class WeatherSetting : public Overridable DYNAMIC_AUTO, DYNAMIC_DRY, DYNAMIC_SNOW, - DYNAMIC_RAIN + DYNAMIC_RAIN, + DYNAMIC_HEAVY_RAIN, + DYNAMIC_STORM }; Int m_dynamicWeatherProfile = DYNAMIC_AUTO; @@ -100,10 +102,12 @@ class SnowManager : public SubsystemInterface virtual void init() override; virtual void reset() override; + virtual void update() override; virtual void updateIniSettings (); virtual void reloadWeather() { updateIniSettings(); } void setVisible(Bool showWeather); ///isInMultiplayerGame() && !TheGameLogic->isInReplayGame()) + if ((TheGameLogic->isInMultiplayerGame() +#if GENERALS_ONLINE_WEATHER_DEBUG + || TheGameLogic->isInSkirmishGame() +#endif + ) && !TheGameLogic->isInReplayGame()) { Player *localPlayer = ThePlayerList->getLocalPlayer(); // TheSuperHackers @tweak skyaero 19/07/2025 Observers can now chat @@ -5720,6 +5724,9 @@ static Bool isSystemMessage( const GameMessage *msg ) case GameMessage::MSG_DESTROY_SELECTED_GROUP: case GameMessage::MSG_LOGIC_CRC: case GameMessage::MSG_SET_REPLAY_CAMERA: +#if defined(GENERALS_ONLINE) + case GameMessage::MSG_START_DYNAMIC_WEATHER: +#endif case GameMessage::MSG_FRAME_TICK: case GameMessage::MSG_META_DEMO_INSTANT_QUIT: return TRUE; diff --git a/Core/GameEngine/Source/GameClient/Snow.cpp b/Core/GameEngine/Source/GameClient/Snow.cpp index 770d0ad82b6..cfce2cfcbba 100644 --- a/Core/GameEngine/Source/GameClient/Snow.cpp +++ b/Core/GameEngine/Source/GameClient/Snow.cpp @@ -30,6 +30,11 @@ #include "PreRTS.h" // This must go first in EVERY cpp file in the Game #include "GameClient/Snow.h" #include "GameClient/View.h" +#include "GameClient/Display.h" +#include "GameLogic/GameLogic.h" +#include "GameLogic/TerrainLogic.h" +#include "Common/AudioEventRTS.h" +#include "Common/AudioHandleSpecialValues.h" SnowManager *TheSnowManager=nullptr; @@ -91,14 +96,90 @@ void SnowManager::setDynamicWeatherVisible(Bool visible) m_dynamicVisible = visible; } +void SnowManager::stopDynamicRain() +{ + if (TheAudio) + { + TheAudio->removeAudioEvent(m_rainSound); + TheAudio->removeAudioEvent(m_thunderSound); + } + m_rainSound = AHSV_Error; + m_thunderSound = AHSV_Error; + m_nextLightningFrame = 0; + m_thunderFrame = 0; +} + +void SnowManager::setDynamicRain(Int profile, UnsignedInt seed) +{ + stopDynamicRain(); + if (TheAudio) + { + // Dynamic weather takes over the stock rain sounds from any map scripts. + TheAudio->removeAudioEvent(AsciiString("RainStereoLoop")); + TheAudio->removeAudioEvent(AsciiString("ThunderAmbienceStereo")); + TheAudio->removeAudioEvent(AsciiString("ThunderStrikesStereo")); + if (profile == WeatherSetting::DYNAMIC_HEAVY_RAIN || profile == WeatherSetting::DYNAMIC_STORM) + { + AudioEventRTS rain("RainStereoLoop"); + m_rainSound = TheAudio->addAudioEvent(&rain); + } + } + if (profile == WeatherSetting::DYNAMIC_STORM && TheGameLogic) + { + m_stormSeed = seed; + m_nextLightningFrame = TheGameLogic->getFrame() + 2 * LOGICFRAMES_PER_SECOND; + } +} + +void SnowManager::update() +{ + if (m_nextLightningFrame == 0 || !TheGameLogic) + return; + + const UnsignedInt frame = TheGameLogic->getFrame(); + if (m_thunderFrame != 0 && frame >= m_thunderFrame) + { + if (TheAudio) + { + TheAudio->removeAudioEvent(m_thunderSound); + AudioEventRTS thunder("ThunderStrikesStereo"); + m_thunderSound = TheAudio->addAudioEvent(&thunder); + } + m_thunderFrame = 0; + } + if (frame < m_nextLightningFrame) + return; + + if (TheDisplay && TheTerrainLogic) + { + Region3D extent; + TheTerrainLogic->getExtent(&extent); + const Coord3D position = { + (extent.lo.x + extent.hi.x) * 0.5f, + (extent.lo.y + extent.hi.y) * 0.5f, + extent.hi.z + 200.0f + }; + const RGBColor color = { 0.65f, 0.7f, 0.85f }; + const Real radius = max(extent.hi.x - extent.lo.x, extent.hi.y - extent.lo.y) + 500.0f; + TheDisplay->createLightPulse(&position, &color, radius, 100.0f, 1, LOGICFRAMES_PER_SECOND / 4); + } + + // Visual randomness stays separate from the simulation and is seeded by the shared weather roll. + m_stormSeed = m_stormSeed * 1664525u + 1013904223u; + m_thunderFrame = frame + LOGICFRAMES_PER_SECOND / 2 + m_stormSeed % LOGICFRAMES_PER_SECOND; + m_nextLightningFrame = frame + (8 + (m_stormSeed >> 16) % 11) * LOGICFRAMES_PER_SECOND; +} + void SnowManager::reset() { + stopDynamicRain(); m_isVisible = TRUE; //default to showing if it's enabled via INI. m_useDynamicVisibility = FALSE; } SnowManager::~SnowManager() { + stopDynamicRain(); delete [] m_startingHeights; m_startingHeights=nullptr; @@ -109,7 +190,7 @@ SnowManager::~SnowManager() OVERRIDE TheWeatherSetting = nullptr; -static const char *const dynamicWeatherProfiles[] = { "AUTO", "DRY", "SNOW", "RAIN", nullptr }; +static const char *const dynamicWeatherProfiles[] = { "AUTO", "DRY", "SNOW", "RAIN", "HEAVY_RAIN", "STORM", nullptr }; // PRIVATE DATA /////////////////////////////////////////////////////////////////////////////////// const FieldParse WeatherSetting::m_weatherSettingFieldParseTable[] = diff --git a/Core/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp b/Core/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp index a33abd3b85d..55ca08079d4 100644 --- a/Core/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp +++ b/Core/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp @@ -370,7 +370,16 @@ void GameLogic::logicMessageDispatcher( GameMessage *msg, void *userData ) #if defined(GENERALS_ONLINE) if (msg->getType() == GameMessage::MSG_START_DYNAMIC_WEATHER) { - startDynamicWeather(msgPlayer); + if (msg->getArgumentCount() == 0) + startDynamicWeather(msgPlayer); +#if GENERALS_ONLINE_WEATHER_DEBUG + else if (msg->getArgumentCount() == 1 && msg->getArgumentDataType(0) == ARGUMENTDATATYPE_INTEGER) + { + const Int profile = msg->getArgument(0)->integer; + if (profile >= 0 && profile <= 5) + startDynamicWeather(msgPlayer, profile); + } +#endif return; } #endif diff --git a/Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DSnow.cpp b/Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DSnow.cpp index 133a1295bb8..92032e273ac 100644 --- a/Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DSnow.cpp +++ b/Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DSnow.cpp @@ -162,6 +162,7 @@ void W3DSnowManager::reloadWeather() void W3DSnowManager::update() { + SnowManager::update(); // TheSuperHackers @tweak The snow render update is now decoupled from the logic step. m_time += WW3D::Get_Logic_Frame_Time_Seconds(); diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/GameLogic.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/GameLogic.h index f7f1c9eec2d..337e0fbf99d 100644 --- a/GeneralsMD/Code/GameEngine/Include/GameLogic/GameLogic.h +++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/GameLogic.h @@ -56,6 +56,7 @@ class AudioEventRTS; class Object; class Drawable; class Player; +class WeatherSetting; class ThingTemplate; class Team; class CommandList; @@ -172,7 +173,7 @@ class GameLogic : public SubsystemInterface, public Snapshot void startNewGame(Bool loadSaveGame); void loadMapINI(AsciiString mapName); #if defined(GENERALS_ONLINE) - void startDynamicWeather(const Player *sender); + void startDynamicWeather(const Player *sender, Int debugProfile = -1); #endif void updateLoadProgress( Int progress ); @@ -435,19 +436,9 @@ class GameLogic : public SubsystemInterface, public Snapshot WindowLayout* m_background; #if defined(GENERALS_ONLINE) - struct WeatherPhase - { - TimeOfDay time; - UnsignedInt duration; - Bool precipitation; - }; - - void updateDynamicWeather(); - WeatherPhase m_weatherCycle[TIME_OF_DAY_COUNT - TIME_OF_DAY_FIRST]; - UnsignedInt m_nextWeatherFrame = 0; - Int m_nextWeatherPhase = 0; + UnsignedInt m_weatherRoll = 0; + WeatherSetting *m_weatherOverride = nullptr; NameKeyType m_weatherHost = NAMEKEY_INVALID; - Bool m_schedulePrecipitation = FALSE; #endif Object* m_objList; ///< All of the objects in the world. diff --git a/GeneralsMD/Code/GameEngine/Include/GameNetwork/GeneralsOnline/NextGenMP_defines.h b/GeneralsMD/Code/GameEngine/Include/GameNetwork/GeneralsOnline/NextGenMP_defines.h index b78109bc4c4..56cdd152ab5 100644 --- a/GeneralsMD/Code/GameEngine/Include/GameNetwork/GeneralsOnline/NextGenMP_defines.h +++ b/GeneralsMD/Code/GameEngine/Include/GameNetwork/GeneralsOnline/NextGenMP_defines.h @@ -8,6 +8,11 @@ #define GENERALS_ONLINE_COMMUNITY_PATCH_CHANGES 1 +// Temporary weather testing through the in-game /weather command. Set to 0 to disable. +#ifndef GENERALS_ONLINE_WEATHER_DEBUG +#define GENERALS_ONLINE_WEATHER_DEBUG 1 +#endif + #define GENERALS_ONLINE_USE_PLUGINS_INTERFACE //#define USE_MAULLER_ONEDRIVE_FIX 1 diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/InGameChat.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/InGameChat.cpp index 61cf0d4f8a6..968108f0495 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/InGameChat.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/InGameChat.cpp @@ -32,6 +32,7 @@ #include "Common/Player.h" #include "Common/PlayerList.h" +#include "Common/MessageStream.h" #include "GameClient/DisconnectMenu.h" #include "GameClient/GameWindow.h" #include "GameClient/Gadget.h" @@ -42,6 +43,7 @@ #include "GameClient/GUICallbacks.h" #include "GameClient/InGameUI.h" #include "GameClient/LanguageFilter.h" +#include "GameClient/Snow.h" #include "GameLogic/GameLogic.h" #include "GameNetwork/GameInfo.h" #include "GameNetwork/NetworkInterface.h" @@ -177,6 +179,41 @@ Bool handleInGameSlashCommands(UnicodeString uText) remainder.nextToken(&token); token.toLower(); +#if GENERALS_ONLINE_WEATHER_DEBUG + if (token == "weather") + { + if (TheNetwork && (!TheNGMPGame || TheGameInfo != TheNGMPGame || !TheNGMPGame->amIHost())) + { + TheInGameUI->message(UnicodeString(L"Weather testing is available to the match host.")); + return TRUE; + } + + AsciiString option; + remainder.nextToken(&option); + option.toLower(); + Int profile = WeatherSetting::DYNAMIC_AUTO; + if (option == "rain") + profile = WeatherSetting::DYNAMIC_RAIN; + else if (option == "heavy") + profile = WeatherSetting::DYNAMIC_HEAVY_RAIN; + else if (option == "storm") + profile = WeatherSetting::DYNAMIC_STORM; + else if (option == "snow") + profile = WeatherSetting::DYNAMIC_SNOW; + else if (option == "dry") + profile = WeatherSetting::DYNAMIC_DRY; + else if (!option.isEmpty() && option != "auto") + { + TheInGameUI->message(UnicodeString(L"Weather testing: /weather [auto|rain|heavy|storm|snow|dry]")); + return TRUE; + } + + GameMessage *weather = TheMessageStream->appendMessage(GameMessage::MSG_START_DYNAMIC_WEATHER); + weather->appendIntegerArgument(profile); + return TRUE; + } +#endif + if (token == "host") { UnicodeString s; @@ -203,7 +240,11 @@ void ToggleInGameChat( Bool immediate ) return; #if defined(GENERALS_ONLINE) - if (TheNGMPGame == nullptr) + if (TheNGMPGame == nullptr +#if GENERALS_ONLINE_WEATHER_DEBUG + && !TheGameLogic->isInSkirmishGame() +#endif + ) #else if (!TheGameInfo->isMultiPlayer() && TheGlobalData->m_netMinPlayers) #endif @@ -221,7 +262,7 @@ void ToggleInGameChat( Bool immediate ) // Send what is there, clear it out, and hide the window UnicodeString msg = GadgetTextEntryGetText( chatTextEntry ); msg.trim(); - if (!msg.isEmpty() && !handleInGameSlashCommands(msg)) + if (!msg.isEmpty() && !handleInGameSlashCommands(msg) && TheNetwork) { const Player *localPlayer = ThePlayerList->getLocalPlayer(); AsciiString playerName; diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp index ddea7e39645..714583c46a1 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp @@ -55,6 +55,7 @@ #include "Common/ThingFactory.h" #include "Common/Team.h" #include "Common/ThingTemplate.h" +#include "Common/TerrainTypes.h" #include "GameClient/Water.h" #include "GameClient/Snow.h" #include "Common/WellKnownKeys.h" @@ -319,7 +320,8 @@ void GameLogic::setDefaults(Bool loadingSaveGame) m_frame = 0; m_hasUpdated = FALSE; #if defined(GENERALS_ONLINE) - m_nextWeatherFrame = 0; + m_weatherRoll = 0; + m_weatherOverride = nullptr; m_weatherHost = NAMEKEY_INVALID; #endif #if defined(GENERALS_ONLINE_HIGH_FPS_SERVER) @@ -567,7 +569,7 @@ void GameLogic::reset() m_objectTOC.clear(); #if defined(GENERALS_ONLINE) - const Bool hadWeatherCycle = m_nextWeatherFrame != 0 && m_schedulePrecipitation; + const Bool hadWeatherPreset = m_weatherOverride != nullptr; #endif setDefaults(FALSE); @@ -585,7 +587,7 @@ void GameLogic::reset() WeatherSetting* ws = (WeatherSetting*)TheWeatherSetting.getNonOverloadedPointer(); TheWeatherSetting = (WeatherSetting*)ws->deleteOverrides(); #if defined(GENERALS_ONLINE) - if (hadWeatherCycle && TheSnowManager && TheWeatherSetting != nullptr) + if (hadWeatherPreset && TheSnowManager && TheWeatherSetting != nullptr) TheSnowManager->reloadWeather(); #endif @@ -1409,7 +1411,8 @@ void GameLogic::tryStartNewGame( Bool loadingSaveGame ) } #if defined(GENERALS_ONLINE) - m_nextWeatherFrame = 0; + m_weatherRoll = 0; + m_weatherOverride = nullptr; m_weatherHost = NAMEKEY_INVALID; if (TheNetwork && TheNGMPGame && game == TheNGMPGame && !TheNGMPGame->isQMGame()) { @@ -2643,113 +2646,177 @@ static void findAndSelectCommandCenter(Object *obj, void* alreadyFound) // ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------ #if defined(GENERALS_ONLINE) -void GameLogic::startDynamicWeather(const Player *sender) +static Int getDynamicWeatherProfileFromTerrain() { - if (!TheGameInfo || m_nextWeatherFrame != 0) + if (TheGlobalData->m_weather == WEATHER_SNOWY) + return WeatherSetting::DYNAMIC_SNOW; + + Region3D extent; + TheTerrainLogic->getExtent(&extent); + if (!TheTerrainVisual || extent.hi.x <= extent.lo.x || extent.hi.y <= extent.lo.y) + return WeatherSetting::DYNAMIC_DRY; + + Int snow = 0; + Int desert = 0; + Int temperate = 0; + // A regular grid weights materials by their coverage instead of counting texture names. + const Int samplesPerAxis = 32; + for (Int y = 0; y < samplesPerAxis; ++y) + { + const Real worldY = extent.lo.y + (y + 0.5f) * (extent.hi.y - extent.lo.y) / samplesPerAxis; + for (Int x = 0; x < samplesPerAxis; ++x) + { + const Real worldX = extent.lo.x + (x + 0.5f) * (extent.hi.x - extent.lo.x) / samplesPerAxis; + TerrainType *terrain = TheTerrainVisual->getTerrainTile(worldX, worldY); + if (!terrain) + continue; + + switch (terrain->getClass()) + { + case TERRAIN_SNOW_1: + case TERRAIN_SNOW_2: + case TERRAIN_SNOW_3: + case TERRAIN_RUGGED_SNOW: + case TERRAIN_FLAT_SNOW: + ++snow; + break; + case TERRAIN_DESERT_1: + case TERRAIN_DESERT_2: + case TERRAIN_DESERT_3: + case TERRAIN_LIVE_DESERT: + case TERRAIN_DRY_DESERT: + case TERRAIN_ACCENT_SAND: + case TERRAIN_SAND: + ++desert; + break; + case TERRAIN_EASTERN_EUROPE_1: + case TERRAIN_EASTERN_EUROPE_2: + case TERRAIN_EASTERN_EUROPE_3: + case TERRAIN_SWISS_1: + case TERRAIN_SWISS_2: + case TERRAIN_SWISS_3: + case TERRAIN_DIRT: + case TERRAIN_GRASS: + case TERRAIN_TROPICAL_BEACH: + case TERRAIN_BEACH_PARK: + case TERRAIN_COBBLESTONE_GRASS: + case TERRAIN_ACCENT_GRASS: + case TERRAIN_RESIDENTIAL: + case TERRAIN_FIELD: + case TERRAIN_ASPHALT: + case TERRAIN_CONCRETE: + case TERRAIN_CHINA: + case TERRAIN_URBAN: + ++temperate; + break; + } + } + } + + if (snow > 0 && snow >= desert && snow >= temperate) + return WeatherSetting::DYNAMIC_SNOW; + if (temperate > desert) + return WeatherSetting::DYNAMIC_RAIN; + return WeatherSetting::DYNAMIC_DRY; +} + +void GameLogic::startDynamicWeather(const Player *sender, Int debugProfile) +{ + const Bool debugRoll = debugProfile >= WeatherSetting::DYNAMIC_AUTO; + if (!TheGameInfo || (m_weatherRoll != 0 && !debugRoll)) return; const Bool replay = TheRecorder && TheRecorder->isPlaybackMode(); - if (!replay && (m_weatherHost == NAMEKEY_INVALID || sender->getPlayerNameKey() != m_weatherHost)) - return; + if (!replay) + { + if (TheNetwork) + { + if (m_weatherHost == NAMEKEY_INVALID || sender->getPlayerNameKey() != m_weatherHost) + return; + } + else if (!isInSkirmishGame() || sender != ThePlayerList->getLocalPlayer()) + return; + } - m_schedulePrecipitation = FALSE; + // Each roll is reproducible in multiplayer and replays without consuming logic randomness. + std::mt19937 weatherRandom(static_cast(TheGameInfo->getSeed()) + m_weatherRoll); + ++m_weatherRoll; + const TimeOfDay time = static_cast( + TIME_OF_DAY_FIRST + weatherRandom() % (TIME_OF_DAY_COUNT - TIME_OF_DAY_FIRST)); + const Bool randomPrecipitation = (weatherRandom() & 1u) != 0; + Int profile = WeatherSetting::DYNAMIC_DRY; + Bool precipitation = FALSE; if (TheSnowManager && TheWeatherSetting != nullptr) { - const AsciiString &texture = TheWeatherSetting->m_snowTexture; - const Bool rainTexture = texture.compareNoCase("EXRainDrop.tga") == 0 - || texture.compareNoCase("EXRainDrop.dds") == 0; - const Bool snowTexture = texture.compareNoCase("EXSnowFlake.tga") == 0 - || texture.compareNoCase("EXSnowFlake.dds") == 0 - || texture.compareNoCase("EXSnowFlake1.tga") == 0 - || texture.compareNoCase("EXSnowFlake1.dds") == 0; - Int profile = TheWeatherSetting->m_dynamicWeatherProfile; + const Int configuredProfile = TheWeatherSetting->m_dynamicWeatherProfile; + profile = debugRoll && debugProfile != WeatherSetting::DYNAMIC_AUTO ? debugProfile : configuredProfile; if (profile == WeatherSetting::DYNAMIC_AUTO) + profile = getDynamicWeatherProfileFromTerrain(); + precipitation = profile != WeatherSetting::DYNAMIC_DRY + && (randomPrecipitation || (debugRoll && debugProfile != WeatherSetting::DYNAMIC_AUTO)); + if (precipitation && profile == WeatherSetting::DYNAMIC_RAIN + && !(debugRoll && debugProfile == WeatherSetting::DYNAMIC_RAIN)) { - const AsciiString &mapPath = TheGlobalData->m_mapName; - const char *basename = mapPath.reverseFind('\\'); - if (!basename) - basename = mapPath.reverseFind('/'); - const AsciiString mapName = basename ? AsciiString(basename + 1) : mapPath; - if (TheGlobalData->m_weather == WEATHER_SNOWY - || mapName.compareNoCase("[RANK] Freezing Bursa ZH v1.map") == 0) - profile = WeatherSetting::DYNAMIC_SNOW; - else if (TheWeatherSetting->m_snowEnabled && rainTexture) - profile = WeatherSetting::DYNAMIC_RAIN; - else if (TheWeatherSetting->m_snowEnabled && snowTexture) - profile = WeatherSetting::DYNAMIC_SNOW; - } - - m_schedulePrecipitation = profile == WeatherSetting::DYNAMIC_SNOW - || profile == WeatherSetting::DYNAMIC_RAIN; - if (profile == WeatherSetting::DYNAMIC_DRY) - TheSnowManager->setDynamicWeatherVisible(FALSE); - - if (m_schedulePrecipitation && (!TheWeatherSetting->m_snowEnabled - || (profile == WeatherSetting::DYNAMIC_SNOW && rainTexture) - || (profile == WeatherSetting::DYNAMIC_RAIN && snowTexture))) + profile = WeatherSetting::DYNAMIC_RAIN + weatherRandom() % 3; + } + + if (precipitation) { - // A temporary override is removed by the existing map weather cleanup. - auto *weather = newInstance(WeatherSetting); - weather->m_snowEnabled = TRUE; - weather->m_snowBoxDimensions = 100.0f; - if (profile == WeatherSetting::DYNAMIC_RAIN) + if (!m_weatherOverride) { - // The stock Eastern Everglades precipitation preset. - weather->m_snowTexture = "EXRainDrop.tga"; - weather->m_snowFrequencyScaleX = 1.0f; - weather->m_snowFrequencyScaleY = 1.0f; - weather->m_snowAmplitude = 0.1f; - weather->m_snowVelocity = 25.0f; - weather->m_snowPointSize = 0.3f; - weather->m_snowQuadSize = 0.1f; + // Reuse one temporary override for all debug rolls. Map cleanup owns it. + m_weatherOverride = newInstance(WeatherSetting); + m_weatherOverride->m_dynamicWeatherProfile = configuredProfile; + m_weatherOverride->markAsOverride(); + auto *base = const_cast(TheWeatherSetting.getNonOverloadedPointer()); + base->friend_getFinalOverride()->setNextOverride(m_weatherOverride); } - else + + WeatherSetting *weather = m_weatherOverride; + struct RainPreset { - // Match the snow scale and fall speed used by stock winter maps. - weather->m_snowAmplitude = 4.0f; - weather->m_snowVelocity = 3.0f; - weather->m_snowPointSize = 0.16f; - weather->m_snowMaxPointSize = 10.0f; - } - weather->markAsOverride(); - auto *base = const_cast(TheWeatherSetting.getNonOverloadedPointer()); - base->friend_getFinalOverride()->setNextOverride(weather); + Real density; + Real amplitude; + Real pointSize; + Real quadSize; + }; + static const RainPreset rainPresets[] = { + { 0.35f, 0.1f, 0.18f, 0.06f }, // Light rain + { 1.0f, 0.1f, 0.3f, 0.1f }, // Heavy rain + { 1.4f, 0.5f, 0.3f, 0.1f } // Storm + }; + const RainPreset *rain = profile >= WeatherSetting::DYNAMIC_RAIN + ? &rainPresets[profile - WeatherSetting::DYNAMIC_RAIN] : nullptr; + weather->m_snowEnabled = TRUE; + weather->m_snowTexture = rain ? "EXRainDrop.tga" : "EXSnowFlake.tga"; + weather->m_snowBoxDimensions = 100.0f; + weather->m_snowBoxDensity = rain ? rain->density : 1.0f; + weather->m_snowFrequencyScaleX = rain ? 1.0f : 0.0533f; + weather->m_snowFrequencyScaleY = rain ? 1.0f : 0.0275f; + weather->m_snowAmplitude = rain ? rain->amplitude : 4.0f; + weather->m_snowVelocity = rain ? 25.0f : 3.0f; + weather->m_snowPointSize = rain ? rain->pointSize : 0.16f; + weather->m_snowQuadSize = rain ? rain->quadSize : 0.5f; + weather->m_snowMaxPointSize = rain ? 64.0f : 10.0f; TheSnowManager->reloadWeather(); } + TheSnowManager->setDynamicWeatherVisible(precipitation); + TheSnowManager->setDynamicRain(precipitation ? profile : WeatherSetting::DYNAMIC_DRY, weatherRandom()); } - // Keep the weather roll independent from the simulation's random number stream. - std::mt19937 weatherRandom(static_cast(TheGameInfo->getSeed())); - const Int phaseCount = TIME_OF_DAY_COUNT - TIME_OF_DAY_FIRST; - const Int firstTime = weatherRandom() % phaseCount; - // Reserve the all-dry and all-wet masks so the cycle always changes precipitation. - const UnsignedInt wetPhases = 1 + weatherRandom() % ((1u << phaseCount) - 2); - for (Int i = 0; i < phaseCount; ++i) + if (TheWritableGlobalData->setTimeOfDay(time)) + TheGameClient->setTimeOfDay(time); + +#if GENERALS_ONLINE_WEATHER_DEBUG + if (debugRoll && TheInGameUI) { - WeatherPhase &phase = m_weatherCycle[i]; - phase.time = static_cast(TIME_OF_DAY_FIRST + (firstTime + i) % phaseCount); - phase.duration = (120 + weatherRandom() % 121) * LOGICFRAMES_PER_SECOND; - phase.precipitation = (wetPhases & (1u << i)) != 0; + static const char *const profileNames[] = { "AUTO", "DRY", "SNOW", "LIGHT RAIN", "HEAVY RAIN", "STORM" }; + UnicodeString message; + message.format(L"Weather #%u: %hs / %hs (profile %hs)", m_weatherRoll, + TimeOfDayNames[time], precipitation ? profileNames[profile] : "DRY", profileNames[profile]); + TheInGameUI->message(message); } - - m_nextWeatherPhase = 0; - m_nextWeatherFrame = m_frame; - updateDynamicWeather(); -} - -void GameLogic::updateDynamicWeather() -{ - if (m_nextWeatherFrame == 0 || m_frame < m_nextWeatherFrame) - return; - - const WeatherPhase &phase = m_weatherCycle[m_nextWeatherPhase]; - if (TheWritableGlobalData->setTimeOfDay(phase.time)) - TheGameClient->setTimeOfDay(phase.time); - if (m_schedulePrecipitation && TheSnowManager) - TheSnowManager->setDynamicWeatherVisible(phase.precipitation); - - m_nextWeatherFrame += phase.duration; - m_nextWeatherPhase = (m_nextWeatherPhase + 1) % (TIME_OF_DAY_COUNT - TIME_OF_DAY_FIRST); +#endif } #endif @@ -4136,10 +4203,6 @@ void GameLogic::update() if (TheFramePacer->isTimeFrozen()) return; -#if defined(GENERALS_ONLINE) - updateDynamicWeather(); -#endif - // Note - TerrainLogic update needs to happen after ScriptEngine update, but before object updates. jba. // This way changes in bridges are noted in the script engine before being cleared in TerrainLogic->update { From 8117362296a67702b7f3eb6e5fe01c1d906d05be Mon Sep 17 00:00:00 2001 From: VodkaNET Date: Thu, 26 Nov 2026 01:59:38 +0500 Subject: [PATCH 3/4] Check box "Dynamic Weather" to stock Generals UI --- .../GameNetwork/GeneralsOnline/NGMPGame.h | 2 +- .../GUICallbacks/Menus/WOLGameSetupMenu.cpp | 62 +++++++++++++++++++ .../GameNetwork/GeneralsOnline/NGMPGame.cpp | 2 +- 3 files changed, 64 insertions(+), 2 deletions(-) diff --git a/GeneralsMD/Code/GameEngine/Include/GameNetwork/GeneralsOnline/NGMPGame.h b/GeneralsMD/Code/GameEngine/Include/GameNetwork/GeneralsOnline/NGMPGame.h index 149fc4999b3..d3fdaaccf77 100644 --- a/GeneralsMD/Code/GameEngine/Include/GameNetwork/GeneralsOnline/NGMPGame.h +++ b/GeneralsMD/Code/GameEngine/Include/GameNetwork/GeneralsOnline/NGMPGame.h @@ -54,7 +54,7 @@ class NGMPGame : public GameInfo UnsignedInt m_exeCRC; UnsignedInt m_iniCRC; Bool m_isQM; - Bool m_dynamicWeather = FALSE; + Bool m_dynamicWeather = TRUE; AsciiString m_ladderIP; AsciiString m_pingStr; diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cpp index d8c0b2c2eba..6b28adbef69 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cpp @@ -212,6 +212,7 @@ static bool s_matchStartCountdownWasRunning = false; static NameKeyType windowMapSelectMapID = NAMEKEY_INVALID; static NameKeyType checkBoxUseStatsID = NAMEKEY_INVALID; static NameKeyType checkBoxLimitSuperweaponsID = NAMEKEY_INVALID; +static NameKeyType checkBoxRandomWeatherID = NAMEKEY_INVALID; static NameKeyType comboBoxStartingCashID = NAMEKEY_INVALID; static NameKeyType checkBoxLimitArmiesID = NAMEKEY_INVALID; @@ -225,6 +226,7 @@ static GameWindow *textEntryChat = NULL; static GameWindow *textEntryMapDisplay = NULL; static GameWindow *windowMap = NULL; static GameWindow *checkBoxUseStats = NULL; +static GameWindow *checkBoxRandomWeather = NULL; static GameWindow *checkBoxLimitSuperweapons = NULL; static GameWindow *comboBoxStartingCash = NULL; static GameWindow *checkBoxLimitArmies = NULL; @@ -961,10 +963,60 @@ static void handleLimitSuperweaponsClick() #endif } +static void createRandomWeatherCheckbox() +{ + checkBoxRandomWeatherID = NAMEKEY("GameSpyGameOptionsMenu.wnd:CheckBoxRandomWeather"); + checkBoxRandomWeather = TheWindowManager->winGetWindowFromId(parentWOLGameSetup, checkBoxRandomWeatherID); + if (!checkBoxRandomWeather) + { + Int width, height, chatWidth, chatHeight, chatX, chatY; + Int screenX, screenY, chatScreenX, chatScreenY, parentX, parentY; + checkBoxLimitSuperweapons->winGetSize(&width, &height); + listboxGameSetupChat->winGetSize(&chatWidth, &chatHeight); + listboxGameSetupChat->winGetPosition(&chatX, &chatY); + checkBoxLimitSuperweapons->winGetScreenPosition(&screenX, &screenY); + listboxGameSetupChat->winGetScreenPosition(&chatScreenX, &chatScreenY); + parentWOLGameSetup->winGetScreenPosition(&parentX, &parentY); + if (chatHeight <= height * 2) + return; + + // Reserve one row above the chat and reuse the active checkbox theme and scale. + checkBoxRandomWeather = TheWindowManager->gogoGadgetCheckbox(parentWOLGameSetup, + checkBoxLimitSuperweapons->winGetStatus(), screenX - parentX, chatScreenY - parentY, + width, height, checkBoxLimitSuperweapons->winGetInstanceData(), + checkBoxLimitSuperweapons->winGetFont(), FALSE); + if (!checkBoxRandomWeather) + return; + checkBoxRandomWeather->winSetWindowId(checkBoxRandomWeatherID); + listboxGameSetupChat->winSetPosition(chatX, chatY + height); + listboxGameSetupChat->winSetSize(chatWidth, chatHeight - height); + } + + WinInstanceData *data = checkBoxRandomWeather->winGetInstanceData(); + data->m_decoratedNameString = "GameSpyGameOptionsMenu.wnd:CheckBoxRandomWeather"; + data->m_textLabelString.clear(); + data->m_tooltipString.clear(); + checkBoxRandomWeather->winSetTooltip(UnicodeString::TheEmptyString); + GadgetCheckBoxSetText(checkBoxRandomWeather, UnicodeString(L"Random Weather")); +} + +static void refreshRandomWeatherCheckbox() +{ + if (!checkBoxRandomWeather || !TheNGMPGame) + return; + const Bool isHost = TheNGMPGame->amIHost(); + checkBoxRandomWeather->winHide(!isHost); + checkBoxRandomWeather->winEnable(isHost && !TheNGMPGame->IsCountdownStarted()); + if (GadgetCheckBoxIsChecked(checkBoxRandomWeather) != TheNGMPGame->getDynamicWeather()) + GadgetCheckBoxSetChecked(checkBoxRandomWeather, TheNGMPGame->getDynamicWeather()); +} + static void WOLLockSettings() { buttonBack->winEnable(false); checkBoxLimitSuperweapons->winEnable(false); + if (checkBoxRandomWeather) + checkBoxRandomWeather->winEnable(false); comboBoxStartingCash->winEnable(false); for (Int i = 0; i < MAX_SLOTS; ++i) @@ -1377,6 +1429,7 @@ void WOLDisplayGameOptions() Bool limitSuperweapons = (theGame->getSuperweaponRestriction() != 0); if ( limitSuperweapons != GadgetCheckBoxIsChecked(checkBoxLimitSuperweapons)) GadgetCheckBoxSetChecked( checkBoxLimitSuperweapons, limitSuperweapons ); + refreshRandomWeatherCheckbox(); Int itemCount = GadgetComboBoxGetLength(comboBoxStartingCash); Int index = 0; @@ -1655,6 +1708,7 @@ void InitWOLGameGadgets() #endif checkBoxLimitArmies = TheWindowManager->winGetWindowFromId( parentWOLGameSetup, checkBoxLimitArmiesID ); DEBUG_ASSERTCRASH(windowMap, ("Could not find the GameSpyGameOptionsMenu.wnd:CheckBoxLimitArmies" )); + createRandomWeatherCheckbox(); // Limit Armies can ONLY be set in the Host Game window (PopupHostGame.wnd) checkBoxLimitArmies->winEnable( false ); @@ -1851,6 +1905,7 @@ void DeinitWOLGameGadgets() windowMap = NULL; } checkBoxUseStats = NULL; + checkBoxRandomWeather = NULL; checkBoxLimitSuperweapons = NULL; comboBoxStartingCash = NULL; @@ -2472,6 +2527,7 @@ void WOLGameSetupMenuUpdate( WindowLayout * layout, void *userData) { // Refresh only the fast-changing connection indicators each frame. WOLRefreshConnectionIndicators(); + refreshRandomWeatherCheckbox(); // need to exit? if (NGMP_OnlineServicesManager::GetInstance() != nullptr && NGMP_OnlineServicesManager::GetInstance()->IsPendingFullTeardown()) @@ -4190,6 +4246,12 @@ WindowMsgHandledType WOLGameSetupMenuSystem( GameWindow *window, UnsignedInt msg { handleLimitSuperweaponsClick(); } + else if (controlID == checkBoxRandomWeatherID) + { + if (TheNGMPGame && TheNGMPGame->amIHost() && !TheNGMPGame->IsCountdownStarted()) + TheNGMPGame->setDynamicWeather(GadgetCheckBoxIsChecked(checkBoxRandomWeather)); + refreshRandomWeatherCheckbox(); + } else { NGMP_OnlineServices_LobbyInterface* pLobbyInterface = NGMP_OnlineServicesManager::GetInterface(); diff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/NGMPGame.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/NGMPGame.cpp index 5d95aa14216..265db65551a 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/NGMPGame.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/NGMPGame.cpp @@ -582,7 +582,7 @@ void NGMPGame::reset(void) { GameInfo::reset(); m_isQM = FALSE; - m_dynamicWeather = FALSE; + m_dynamicWeather = TRUE; } void NGMPGame::StartCountdown() From fd0cdbea735fb0343b885d8dd2d15a24c97005b2 Mon Sep 17 00:00:00 2001 From: VodkaNET Date: Thu, 26 Nov 2026 02:33:33 +0500 Subject: [PATCH 4/4] Disable Weather Debbuging --- .../Include/GameNetwork/GeneralsOnline/NextGenMP_defines.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GeneralsMD/Code/GameEngine/Include/GameNetwork/GeneralsOnline/NextGenMP_defines.h b/GeneralsMD/Code/GameEngine/Include/GameNetwork/GeneralsOnline/NextGenMP_defines.h index 56cdd152ab5..67a37e29ce0 100644 --- a/GeneralsMD/Code/GameEngine/Include/GameNetwork/GeneralsOnline/NextGenMP_defines.h +++ b/GeneralsMD/Code/GameEngine/Include/GameNetwork/GeneralsOnline/NextGenMP_defines.h @@ -10,7 +10,7 @@ // Temporary weather testing through the in-game /weather command. Set to 0 to disable. #ifndef GENERALS_ONLINE_WEATHER_DEBUG -#define GENERALS_ONLINE_WEATHER_DEBUG 1 +#define GENERALS_ONLINE_WEATHER_DEBUG 0 #endif #define GENERALS_ONLINE_USE_PLUGINS_INTERFACE