Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions Core/GameEngine/Include/GameClient/Snow.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ class WeatherSetting : public Overridable
MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE( WeatherSetting, "WeatherSetting" )

public:
enum DynamicProfile
{
DYNAMIC_AUTO,
DYNAMIC_DRY,
DYNAMIC_SNOW,
DYNAMIC_RAIN,
DYNAMIC_HEAVY_RAIN,
DYNAMIC_STORM
};

Int m_dynamicWeatherProfile = DYNAMIC_AUTO;
AsciiString m_snowTexture;
Real m_snowFrequencyScaleX; ///<used to adjust snow position.
Real m_snowFrequencyScaleY; ///<used to adjust snow position.
Expand Down Expand Up @@ -91,10 +102,15 @@ 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); ///<enable/disable rendering of weather - assuming it's available on map.
void setDynamicWeatherVisible(Bool visible);
void setDynamicRain(Int profile, UnsignedInt seed);

protected :
Bool isWeatherVisible() const { return m_useDynamicVisibility ? m_dynamicVisible : m_isVisible; }

Real *m_startingHeights;
Real m_time; ///<time elapsed since it started snowing.
Expand All @@ -110,6 +126,16 @@ class SnowManager : public SubsystemInterface
Real m_boxDimensions; ///<used to set dimensions of box surrounding camera.
Real m_emitterSpacing; ///<used to control how many emitters are present per world unit
Bool m_isVisible; ///<used to prevent map weather (if defined) from rendering.
Bool m_useDynamicVisibility = FALSE;
Bool m_dynamicVisible = FALSE;

private:
void stopDynamicRain();
UnsignedInt m_rainSound = 0;
UnsignedInt m_thunderSound = 0;
UnsignedInt m_stormSeed = 0;
UnsignedInt m_nextLightningFrame = 0;
UnsignedInt m_thunderFrame = 0;
};

extern SnowManager *TheSnowManager; ///< the ray effects singleton external
Original file line number Diff line number Diff line change
Expand Up @@ -3269,7 +3269,11 @@ GameMessageDisposition CommandTranslator::translateGameMessage(const GameMessage

//-----------------------------------------------------------------------------------------
case GameMessage::MSG_META_CHAT_EVERYONE:
if (TheGameLogic->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
Expand Down Expand Up @@ -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;
Expand Down
91 changes: 91 additions & 0 deletions Core/GameEngine/Source/GameClient/Snow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -85,13 +90,96 @@ void SnowManager::setVisible(Bool showWeather)
m_isVisible = showWeather;
}

void SnowManager::setDynamicWeatherVisible(Bool visible)
{
m_useDynamicVisibility = TRUE;
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;

Expand All @@ -102,9 +190,12 @@ SnowManager::~SnowManager()

OVERRIDE<WeatherSetting> TheWeatherSetting = nullptr;

static const char *const dynamicWeatherProfiles[] = { "AUTO", "DRY", "SNOW", "RAIN", "HEAVY_RAIN", "STORM", 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 ) },
Expand Down
17 changes: 17 additions & 0 deletions Core/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,23 @@ void GameLogic::logicMessageDispatcher( GameMessage *msg, void *userData )
return;
}

#if defined(GENERALS_ONLINE)
if (msg->getType() == GameMessage::MSG_START_DYNAMIC_WEATHER)
{
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

AIGroupPtr currentlySelectedGroup = nullptr;

if (isInGame())
Expand Down
13 changes: 13 additions & 0 deletions Core/GameEngine/Source/GameNetwork/Network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
16 changes: 10 additions & 6 deletions Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DSnow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,15 @@ void W3DSnowManager::reset()
SnowManager::reset();
}

void W3DSnowManager::reloadWeather()
{
SnowManager::updateIniSettings();
ReleaseResources(); // Recreated by render() on the next visible frame.
}

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();

Expand Down Expand Up @@ -322,7 +329,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;
Expand Down Expand Up @@ -401,11 +408,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);

Expand Down
1 change: 1 addition & 0 deletions GeneralsMD/Code/GameEngine/Include/Common/MessageStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
10 changes: 10 additions & 0 deletions GeneralsMD/Code/GameEngine/Include/GameLogic/GameLogic.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class AudioEventRTS;
class Object;
class Drawable;
class Player;
class WeatherSetting;
class ThingTemplate;
class Team;
class CommandList;
Expand Down Expand Up @@ -171,6 +172,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, Int debugProfile = -1);
#endif

void updateLoadProgress( Int progress );
void deleteLoadScreen();
Expand Down Expand Up @@ -431,6 +435,12 @@ class GameLogic : public SubsystemInterface, public Snapshot
Bool m_startNewGame;
WindowLayout* m_background;

#if defined(GENERALS_ONLINE)
UnsignedInt m_weatherRoll = 0;
WeatherSetting *m_weatherOverride = nullptr;
NameKeyType m_weatherHost = NAMEKEY_INVALID;
#endif

Object* m_objList; ///< All of the objects in the world.
// ObjectPtrHash m_objHash; ///< Used for ObjectID lookups
ObjectPtrVector m_objVector;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class NGMPGame : public GameInfo
UnsignedInt m_exeCRC;
UnsignedInt m_iniCRC;
Bool m_isQM;
Bool m_dynamicWeather = TRUE;

AsciiString m_ladderIP;
AsciiString m_pingStr;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 0
#endif

#define GENERALS_ONLINE_USE_PLUGINS_INTERFACE

//#define USE_MAULLER_ONEDRIVE_FIX 1
Expand Down
1 change: 1 addition & 0 deletions GeneralsMD/Code/GameEngine/Source/Common/MessageStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading
Loading