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.

fix(gameenginedevice): put the water animation back on the logic clock

Olcay Seygan6a8ee7728631
diff --git a/GeneralsMD/Code/CMakeLists.txt b/GeneralsMD/Code/CMakeLists.txt
index ac38a55de..7fae2fa29 100644
--- a/GeneralsMD/Code/CMakeLists.txt
+++ b/GeneralsMD/Code/CMakeLists.txt
@@ -526,6 +526,9 @@ add_custom_command(TARGET dx8_smoke POST_BUILD
add_dependencies(dx8_smoke d3d8to9)
add_test(NAME dx8_smoke COMMAND dx8_smoke)
add_test(NAME dx8_smoke_d3d12 COMMAND dx8_smoke -d3d12)
+# "-msaa": a multisampled back buffer, and the plain render target + non-multisampled depth
+# buffer pairing that DX8Wrapper::_Get_Non_MultiSampled_Depth_Buffer hands the screen filters.
+add_test(NAME dx8_smoke_msaa COMMAND dx8_smoke -msaa 4)
if(RELEASE_DEBUG_LOGGING)
target_compile_definitions(gameengine PRIVATE RELEASE_DEBUG_LOGGING)
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h
index a00200d58..6e942d423 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h
@@ -332,7 +332,6 @@ public:
Bool m_showHudOverlay; ///< draw the fps / elapsed time / income line in the corner
Bool m_showPlacementRangeRing; ///< while placing a structure, ring its weapon range
Bool m_workersReturnToSupply; ///< a worker that finishes a build job goes back to the dock it left
- Bool m_alwaysShowWaypointLines; ///< draw a selected unit's queued waypoint path without holding the waypoint key
Bool m_detailedBuildTooltips; ///< put build time, weapon range and damage in the build tooltip
Bool m_buildMapCache;
AsciiString m_initialFile; ///< If this is specified, load a specific map/replay from the command-line
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/UserPreferences.h b/GeneralsMD/Code/GameEngine/Include/Common/UserPreferences.h
index 78f690557..4aa8cec17 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/UserPreferences.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/UserPreferences.h
@@ -117,7 +117,6 @@ public:
Bool getShowHudOverlay(void);
Bool getShowPlacementRangeRing(void);
Bool getWorkersReturnToSupply(void);
- Bool getAlwaysShowWaypointLines(void);
Bool getDetailedBuildTooltips(void);
Int getTextureReduction(void);
void getResolution(Int *xres, Int *yres);
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.h b/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.h
index 444f1ad29..08847fe5c 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.h
@@ -702,6 +702,8 @@ private:
ModelConditionFlags m_conditionState; ///< The Drawables current behavior state
Real m_lastConstructDisplayed; ///< last construct percent used to make the string
DisplayString* m_constructDisplayString; ///< string to display construction % complete
+ Int m_lastChargeDisplayed; ///< last countdown second drawn, so the string is not rebuilt every frame
+ DisplayString* m_chargeDisplayString; ///< seconds left on a special power or an OCL payout
DisplayString* m_captionDisplayString; ///< string to display caption
DisplayString* m_groupNumber; ///< string to display the group number of this drawable
@@ -742,6 +744,7 @@ public:
private:
// "icon" drawing methods **************
void drawConstructPercent( const IRegion2D *healthBarRegion ); ///< display % construction complete
+ void drawChargeCountdown( const IRegion2D *healthBarRegion ); ///< seconds left on a special power or an OCL payout
void drawCaption( const IRegion2D *healthBarRegion ); ///< draw caption
void drawAmmo( const IRegion2D *healthBarRegion ); ///< draw icons
void drawContained( const IRegion2D *healthBarRegion ); ///< draw icons
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h
index 35d5d16bb..23a65e553 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h
@@ -754,12 +754,15 @@ protected:
enum { HUD_OVERLAY_POINT_SIZE = 9 }; ///< small: this sits over the battlefield, not in a panel
void drawHudOverlay( void ); ///< the small elapsed-time / fps plate (ShowHudOverlay)
+ void drawIncomeRate( void ); ///< income per minute, drawn beside the money window
void updateIncomeEstimate( Player *player ); ///< income per minute, shown beside the money
Bool m_placementRangeRingUp; ///< we put a radius cursor up for a pending structure, so we owe a clear
Real m_placementRingRadius; ///< the radius that ring was built at, so it is not rebuilt every frame
DisplayString * m_hudDisplayString; ///< the ShowHudOverlay line (fps / clock / income)
+ DisplayString * m_incomeDisplayString; ///< the "(+N/min)" drawn beside the money
+ Int m_lastIncomeDisplayed; ///< so that string is only rebuilt when the rate changes
UnsignedInt m_hudLastSampleFrame; ///< client frame the fps sample was last refreshed on
UnsignedInt m_hudLastSampleMs; ///< wall clock of that sample
Real m_hudFps; ///< smoothed render rate
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GameLOD.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GameLOD.cpp
index 5b7b9538c..668dc9888 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/GameLOD.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/GameLOD.cpp
@@ -373,7 +373,6 @@ void GameLODManager::init(void)
TheWritableGlobalData->m_showHudOverlay = optionPref.getShowHudOverlay();
TheWritableGlobalData->m_showPlacementRangeRing = optionPref.getShowPlacementRangeRing();
TheWritableGlobalData->m_workersReturnToSupply = optionPref.getWorkersReturnToSupply();
- TheWritableGlobalData->m_alwaysShowWaypointLines = optionPref.getAlwaysShowWaypointLines();
TheWritableGlobalData->m_detailedBuildTooltips = optionPref.getDetailedBuildTooltips();
setStaticLODLevel(userSetDetail);
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp
index 190e60ee9..b088f5eac 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp
@@ -189,7 +189,6 @@ GlobalData* GlobalData::m_theOriginal = NULL;
{ "ShowHudOverlay", INI::parseBool, NULL, offsetof( GlobalData, m_showHudOverlay ) },
{ "ShowPlacementRangeRing", INI::parseBool, NULL, offsetof( GlobalData, m_showPlacementRangeRing ) },
{ "WorkersReturnToSupply", INI::parseBool, NULL, offsetof( GlobalData, m_workersReturnToSupply ) },
- { "AlwaysShowWaypointLines", INI::parseBool, NULL, offsetof( GlobalData, m_alwaysShowWaypointLines ) },
{ "DetailedBuildTooltips", INI::parseBool, NULL, offsetof( GlobalData, m_detailedBuildTooltips ) },
{ "MinCameraHeight", INI::parseReal, NULL, offsetof( GlobalData, m_minCameraHeight ) },
{ "TerrainHeightAtEdgeOfMap", INI::parseReal, NULL, offsetof( GlobalData, m_terrainHeightAtEdgeOfMap ) },
@@ -1008,7 +1007,6 @@ GlobalData::GlobalData()
m_showHudOverlay = TRUE;
m_showPlacementRangeRing = TRUE;
m_workersReturnToSupply = TRUE;
- m_alwaysShowWaypointLines = TRUE;
m_detailedBuildTooltips = TRUE;
m_animateWindows = TRUE;
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp
index 3de849e38..bc9d2a49b 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp
@@ -52,6 +52,9 @@
#include "GameLogic/ExperienceTracker.h"
#include "GameLogic/GameLogic.h" // for logic frame count
#include "GameLogic/Object.h"
+#include "GameLogic/Module/OCLUpdate.h"
+#include "GameLogic/Module/SpecialPowerModule.h"
+ // countdown text over a building
#include "GameLogic/Locomotor.h"
#include "GameLogic/Module/AIUpdate.h"
#include "GameLogic/Module/BodyModule.h"
@@ -380,6 +383,8 @@ Drawable::Drawable( const ThingTemplate *thingTemplate, DrawableStatus statusBit
m_expirationDate = 0; // 0 == never expires
m_lastConstructDisplayed = -1.0f;
+ m_lastChargeDisplayed = -1;
+ m_chargeDisplayString = NULL;
//Added By Sadullah Nader
//Fix for the building percent
@@ -540,6 +545,10 @@ Drawable::~Drawable()
TheDisplayStringManager->freeDisplayString( m_constructDisplayString );
m_constructDisplayString = NULL;
+ if( m_chargeDisplayString )
+ TheDisplayStringManager->freeDisplayString( m_chargeDisplayString );
+ m_chargeDisplayString = NULL;
+
if ( m_captionDisplayString )
TheDisplayStringManager->freeDisplayString( m_captionDisplayString );
m_captionDisplayString = NULL;
@@ -2780,6 +2789,7 @@ void Drawable::drawIconUI( void )
drawCaption( healthBarRegion );
drawConstructPercent( healthBarRegion );
+ drawChargeCountdown( healthBarRegion );
//All Icons Below only draw on ALIVE things, so bail here -------------------------
if( obj->isEffectivelyDead() || obj->isKindOf( KINDOF_IGNORED_IN_GUI )) // object explicitly wants nothing to do with these icons, so...
@@ -3763,6 +3773,92 @@ void Drawable::drawConstructPercent( const IRegion2D *healthBarRegion )
} // end drawConstructPercent
+//-------------------------------------------------------------------------------------------------
+/** Seconds left until this building's next payout, or until its special power comes up, written
+ * over the building itself. The control bar counts these down too, but only for whatever is
+ * selected, and the superweapon list in the corner never says which building on the map it
+ * belongs to. */
+//-------------------------------------------------------------------------------------------------
+void Drawable::drawChargeCountdown( const IRegion2D *healthBarRegion )
+{
+ Object *obj = getObject();
+
+ Int secondsLeft = -1;
+
+ if( obj != NULL &&
+ obj->isLocallyControlled() &&
+ !obj->getStatusBits().test( OBJECT_STATUS_UNDER_CONSTRUCTION ) &&
+ !obj->getStatusBits().test( OBJECT_STATUS_SOLD ) )
+ {
+ const UnsignedInt now = TheGameLogic->getFrame();
+
+ // a charging special power - the superweapons, and the powers a building holds
+ for( BehaviorModule** m = obj->getBehaviorModules(); *m; ++m )
+ {
+ SpecialPowerModuleInterface* sp = (*m)->getSpecialPower();
+ if( sp == NULL || sp->isReady() )
+ continue;
+
+ UnsignedInt ready = sp->getReadyFrame();
+ if( ready > now )
+ {
+ Int secs = (ready - now) / LOGICFRAMES_PER_SECOND;
+ if( secondsLeft < 0 || secs < secondsLeft )
+ secondsLeft = secs;
+ }
+ }
+
+ // ...and a timed payout, which is what the supply drop zone runs on
+ if( secondsLeft < 0 )
+ {
+ static const NameKeyType key_OCLUpdate = NAMEKEY( "OCLUpdate" );
+ OCLUpdate *ocl = (OCLUpdate*)obj->findUpdateModule( key_OCLUpdate );
+ if( ocl != NULL )
+ secondsLeft = ocl->getRemainingFrames() / LOGICFRAMES_PER_SECOND;
+ }
+ }
+
+ if( secondsLeft < 0 )
+ {
+ if( m_chargeDisplayString )
+ {
+ TheDisplayStringManager->freeDisplayString( m_chargeDisplayString );
+ m_chargeDisplayString = NULL;
+ m_lastChargeDisplayed = -1;
+ }
+ return;
+ }
+
+ if( m_chargeDisplayString == NULL )
+ {
+ m_chargeDisplayString = TheDisplayStringManager->newDisplayString();
+ m_chargeDisplayString->setFont(TheFontLibrary->getFont(TheInGameUI->getDrawableCaptionFontName(),
+ TheGlobalLanguageData->adjustFontSize(TheInGameUI->getDrawableCaptionPointSize()),
+ TheInGameUI->isDrawableCaptionBold() ));
+ }
+
+ if( m_lastChargeDisplayed != secondsLeft )
+ {
+ UnicodeString buffer;
+ buffer.format( L"%ds", secondsLeft );
+ m_chargeDisplayString->setText( buffer );
+ m_lastChargeDisplayed = secondsLeft;
+ }
+
+ ICoord2D screen;
+ Coord3D pos;
+ getDrawableGeometryInfo().getCenterPosition( *getPosition(), pos );
+ TheTacticalView->worldToScreen( &pos, &screen );
+ if( screen.x < 1 )
+ return;
+
+ Color color = GameMakeColor( 255, 220, 120, 255 );
+ Color dropColor = GameMakeColor( 0, 0, 0, 255 );
+ screen.x -= (m_chargeDisplayString->getWidth() / 2);
+ m_chargeDisplayString->draw( screen.x, screen.y, color, dropColor );
+
+} // end drawChargeCountdown
+
//-------------------------------------------------------------------------------------------------
/** Draw caption */
//-------------------------------------------------------------------------------------------------
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 b7ebb756a..69c0761fd 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp
@@ -814,15 +814,6 @@ Bool OptionPreferences::getWorkersReturnToSupply(void)
return stricmp(it->second.str(), "yes") == 0;
}
-Bool OptionPreferences::getAlwaysShowWaypointLines(void)
-{
- OptionPreferences::const_iterator it = find("AlwaysShowWaypointLines");
- if (it == end())
- return TheGlobalData->m_alwaysShowWaypointLines;
-
- return stricmp(it->second.str(), "yes") == 0;
-}
-
Bool OptionPreferences::getDetailedBuildTooltips(void)
{
OptionPreferences::const_iterator it = find("DetailedBuildTooltips");
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
index 542716f25..64f2f4e77 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
@@ -1023,6 +1023,8 @@ InGameUI::InGameUI()
m_placementRangeRingUp = FALSE;
m_placementRingRadius = 0.0f;
m_hudDisplayString = NULL;
+ m_incomeDisplayString = NULL;
+ m_lastIncomeDisplayed = -1;
m_hudLastSampleFrame = 0;
m_hudLastSampleMs = 0;
m_hudFps = 0.0f;
@@ -1934,24 +1936,17 @@ void InGameUI::update( void )
{
Int currentMoney = moneyPlayer->getMoney()->countMoney();
- // income per minute, shown in brackets beside the balance it should be compared against
+ // income per minute is drawn beside this window by drawIncomeRate(), not put inside it -
+ // the money gadget wraps at its own width and a second line looked broken
updateIncomeEstimate( moneyPlayer );
- static Int lastIncome = -1;
- if( lastMoney != currentMoney || lastIncome != m_hudIncomePerMin )
+ if( lastMoney != currentMoney )
{
UnicodeString buffer;
buffer.format( TheGameText->fetch( "GUI:ControlBarMoneyDisplay" ), currentMoney );
- if( m_hudIncomePerMin > 0 )
- {
- UnicodeString rate;
- rate.format( L" (%d/min)", m_hudIncomePerMin );
- buffer.concat( rate );
- }
GadgetStaticTextSetText( moneyWin, buffer );
lastMoney = currentMoney;
- lastIncome = m_hudIncomePerMin;
} // end if
moneyWin->winHide(FALSE);
@@ -2680,7 +2675,14 @@ void InGameUI::createCommandHint( const GameMessage *msg )
//#endif
- setRadiusCursorNone();
+ //
+ // While a structure is on the cursor, handleBuildPlacements owns the radius cursor - it is the
+ // range ring for the thing being placed. Wiping it here (this runs on every mouse hint) is what
+ // made that ring flicker or never appear at all.
+ //
+ if( m_pendingPlaceType == NULL )
+ setRadiusCursorNone();
+
if ( TheGlobalData->m_doubleClickAttackMove )
{
if ( --m_duringDoubleClickAttackMoveGuardHintTimer > 0 )
@@ -3593,6 +3595,7 @@ void InGameUI::disregardDrawable( Drawable *draw )
void InGameUI::postDraw( void )
{
drawHudOverlay();
+ drawIncomeRate();
// render our display strings for the messages if on
@@ -5291,6 +5294,49 @@ void InGameUI::updateIncomeEstimate( Player *player )
/** A small heads-up line in the top right: elapsed game time and the render rate, on a plate so it
* stays readable over terrain. Income is not here - it lives next to the money, where it is
* being compared to something. Off unless ShowHudOverlay is set in Options.ini. */
+//-------------------------------------------------------------------------------------------------
+void InGameUI::drawIncomeRate( void )
+{
+ if( !TheGlobalData->m_showHudOverlay || m_hudIncomePerMin <= 0 )
+ return;
+
+ if( TheGameLogic == NULL || !TheGameLogic->isInGame() || TheGameLogic->isInShellGame() )
+ return;
+
+ static NameKeyType moneyWindowKey = TheNameKeyGenerator->nameToKey( "ControlBar.wnd:MoneyDisplay" );
+ GameWindow *moneyWin = TheWindowManager->winGetWindowFromId( NULL, moneyWindowKey );
+ if( moneyWin == NULL || moneyWin->winIsHidden() )
+ return;
+
+ if( m_incomeDisplayString == NULL )
+ {
+ m_incomeDisplayString = TheDisplayStringManager->newDisplayString();
+ m_incomeDisplayString->setFont( TheFontLibrary->getFont( m_superweaponNormalFont,
+ TheGlobalLanguageData->adjustFontSize( HUD_OVERLAY_POINT_SIZE ),
+ FALSE ) );
+ }
+
+ if( m_lastIncomeDisplayed != m_hudIncomePerMin )
+ {
+ UnicodeString buffer;
+ buffer.format( L"(+%d/min)", m_hudIncomePerMin );
+ m_incomeDisplayString->setText( buffer );
+ m_lastIncomeDisplayed = m_hudIncomePerMin;
+ }
+
+ ICoord2D pos, size;
+ moneyWin->winGetScreenPosition( &pos.x, &pos.y );
+ moneyWin->winGetSize( &size.x, &size.y );
+
+ Int textHeight = 0;
+ m_incomeDisplayString->getSize( NULL, &textHeight );
+
+ // tucked under the balance rather than after it: the money window runs to the panel edge
+ m_incomeDisplayString->draw( pos.x + 4, pos.y + size.y - 2,
+ GameMakeColor( 180, 235, 180, 255 ),
+ GameMakeColor( 0, 0, 0, 255 ) );
+}
+
//-------------------------------------------------------------------------------------------------
void InGameUI::drawHudOverlay( void )
{
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp
index e3922d004..210167a9e 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp
@@ -793,6 +793,9 @@ void W3DDisplay::init( void )
: "Direct3D 12 (d3d8to9 -> Direct3D 9On12)")
: GetModuleHandleA("d3d9.dll") ? "Direct3D 9 (d3d8to9)"
: "Direct3D 8 (system d3d8.dll)"));
+ // multisampling is opt-in with "-msaa" / "-msaa N" and silently degrades to whatever the
+ // device supports, so log what was actually granted
+ DEBUG_LOG(("W3DDisplay::init - multisampling: %ux\n", DX8Wrapper::Get_MultiSample_Level()));
//Check if level was never set and default to setting most suitable for system.
if (TheGameLODManager->getStaticLODLevel() == STATIC_GAME_LOD_UNKNOWN)
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DShaderManager.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DShaderManager.cpp
index 5f0e68948..42722d215 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DShaderManager.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DShaderManager.cpp
@@ -2843,7 +2843,12 @@ void W3DShaderManager::startRenderToTexture(void)
DEBUG_ASSERTCRASH(!m_renderingToTexture, ("Already rendering to texture - cannot nest calls."));
if (m_renderingToTexture || m_newRenderSurface==NULL || m_oldDepthSurface==NULL) return;
- HRESULT hr = DX8Wrapper::_Get_D3D_Device8()->SetRenderTarget(m_newRenderSurface,m_oldDepthSurface);
+ //m_oldDepthSurface is the back buffer's depth surface, which is multisampled when the back
+ //buffer is; D3D wants the depth buffer to match the render target, and ours is a plain
+ //texture. Ask the wrapper for a matching one (NULL = not multisampling, nothing to do).
+ IDirect3DSurface8 *depthSurface = DX8Wrapper::_Get_Non_MultiSampled_Depth_Buffer();
+ if (depthSurface == NULL) depthSurface = m_oldDepthSurface;
+ HRESULT hr = DX8Wrapper::_Get_D3D_Device8()->SetRenderTarget(m_newRenderSurface,depthSurface);
DEBUG_ASSERTCRASH(hr==S_OK, ("Set target failed unexpectedly."));
if (hr != S_OK)
return;
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3dWaypointBuffer.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3dWaypointBuffer.cpp
index 3be5a6cef..88b5ce02d 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3dWaypointBuffer.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3dWaypointBuffer.cpp
@@ -189,17 +189,7 @@ void W3DWaypointBuffer::drawWaypoints(RenderInfoClass &rinfo)
- //
- // AlwaysShowWaypointLines: retail only draws a route while the waypoint key is held, so you
- // cannot look at an order you already gave. With this on, a selected unit shows the route it
- // is actually following - its queued waypoints if it has any, otherwise the path it computed
- // for a plain move order, which is what you get from a single click.
- //
- // Note this block and the rally-point one below are NOT alternatives: rally points used to be
- // drawn only when we were not in waypoint mode, so making this condition always true silently
- // took every rally line away.
- //
- if( TheInGameUI->isInWaypointMode() || TheGlobalData->m_alwaysShowWaypointLines )
+ if( TheInGameUI->isInWaypointMode() )
{
//Create a default light environment with no lights and only full ambient.
//@todo: Fix later by copying default scene light environement from W3DScene.cpp.
@@ -210,16 +200,10 @@ void W3DWaypointBuffer::drawWaypoints(RenderInfoClass &rinfo)
localRinfo.light_environment=&lightEnv;
Vector3 points[ MAX_DISPLAY_NODES + 1 ]; //Lines have nodes + 1 points.
- //
- // A whole army's worth of routes is a lot of line work for something nobody can read
- // anyway, so only the first few selected units draw one.
- //
- const Int MAX_ROUTE_LINES = 8;
- Int routeLines = 0;
const DrawableList *selected = TheInGameUI->getAllSelectedDrawables();
Drawable *draw;
- for( DrawableListCIt it = selected->begin(); it != selected->end() && routeLines < MAX_ROUTE_LINES; ++it )
+ for( DrawableListCIt it = selected->begin(); it != selected->end(); ++it )
{
draw = *it;
Object *obj = draw->getObject();
@@ -230,37 +214,8 @@ void W3DWaypointBuffer::drawWaypoints(RenderInfoClass &rinfo)
Int goalSize = ai ? ai->friend_getWaypointGoalPathSize() : 0;
Int gpIdx = ai ? ai->friend_getCurrentGoalPathIndex() : 0;
- if( ai && !(gpIdx >= 0 && gpIdx < goalSize) && TheGlobalData->m_alwaysShowWaypointLines )
- {
- //
- // No queued waypoints - this is a plain move order, which is what a single
- // click gives you. Draw the route it actually computed instead, or there is
- // nothing to see until you queue a second point.
- //
- const Path *path = ai->getPath();
- const PathNode *node = path ? path->getFirstNode() : NULL;
- if( node )
- {
- const Coord3D *pos = obj->getPosition();
- points[ 0 ].Set( Vector3( pos->x, pos->y, pos->z ) );
-
- for( ; node && numPoints < MAX_DISPLAY_NODES + 1; node = node->getNextOptimized() )
- {
- const Coord3D *np = node->getPosition();
- points[ numPoints ].Set( Vector3( np->x, np->y, np->z ) );
- numPoints++;
- }
-
- if( numPoints > 1 )
- {
- queueLine( numPoints, points );
- ++routeLines;
- }
- }
- }
- else if( ai && gpIdx >= 0 && gpIdx < goalSize )
+ if( ai && gpIdx >= 0 && gpIdx < goalSize )
{
- ++routeLines;
const Coord3D *pos = obj->getPosition();
points[ 0 ].Set( Vector3( pos->x, pos->y, pos->z ) );
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Water/W3DWater.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Water/W3DWater.cpp
index 9ef315b82..0779e466b 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Water/W3DWater.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Water/W3DWater.cpp
@@ -1222,23 +1222,27 @@ void WaterRenderObjClass::update( void )
if( TheGameLogic )
currLogicFrame = TheGameLogic->getFrame();
- m_riverVOrigin += 0.002f;
- m_riverXOffset += (Real)(0.0125*33/5000);
- m_riverYOffset += (Real)(2*0.0125*33/5000);
- if (m_riverXOffset > 1) m_riverXOffset -= 1;
- if (m_riverYOffset > 1) m_riverYOffset -= 1;
- if (m_riverXOffset < -1) m_riverXOffset += 1;
- if (m_riverYOffset < -1) m_riverYOffset += 1;
- m_iBumpFrame++;
- if (m_iBumpFrame >= NUM_BUMP_FRAMES) {
- m_iBumpFrame = 0;
- }
-
-
-
// we only process some things if the logic frame has changed
if( lastLogicFrame != currLogicFrame )
{
+ //
+ // The river scroll and the bump frame used to advance on every call, which is once per
+ // RENDER frame - fine when the loop was capped, wrong now that it is not: the water tore
+ // along at whatever the frame rate happened to be. They belong on the logic clock with
+ // the rest of this function.
+ //
+ m_riverVOrigin += 0.002f;
+ m_riverXOffset += (Real)(0.0125*33/5000);
+ m_riverYOffset += (Real)(2*0.0125*33/5000);
+ if (m_riverXOffset > 1) m_riverXOffset -= 1;
+ if (m_riverYOffset > 1) m_riverYOffset -= 1;
+ if (m_riverXOffset < -1) m_riverXOffset += 1;
+ if (m_riverYOffset < -1) m_riverYOffset += 1;
+ m_iBumpFrame++;
+ if (m_iBumpFrame >= NUM_BUMP_FRAMES) {
+ m_iBumpFrame = 0;
+ }
+
// for vertex animated water we need to update the vector field
if( m_doWaterGrid && m_meshInMotion == TRUE )
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp
index 61983ce7f..a97fc0be8 100644
--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp
@@ -193,6 +193,41 @@ static unsigned last_frame_draw_calls = 0;
static D3DDISPLAYMODE DesktopMode;
static D3DPRESENT_PARAMETERS _PresentParameters;
+
+// Multisampling (anti-aliasing) is opt-in and off by default, which is exactly what retail did.
+// "-msaa" on the command line asks for 4x, "-msaa N" for N (2..16); the highest level the device
+// actually reports for BOTH the back buffer and the depth/stencil format is the one used, so an
+// unsupported request quietly degrades instead of failing device creation. The command line is
+// read here rather than plumbed through GlobalData because WW3D2 has no view of it - and it must
+// be the WIDE one: WinMain tokenizes the ANSI command line in place, so GetCommandLineA() is
+// already truncated by the time the device is created.
+static unsigned Get_Requested_MultiSample_Level(void)
+{
+ static int requested = -1;
+ if (requested >= 0) return (unsigned)requested;
+ requested = 0;
+ for (const wchar_t * p = ::GetCommandLineW(); p != NULL && *p != L'\0'; ++p) {
+ if ((*p != L'-' && *p != L'/') || ::_wcsnicmp(p + 1, L"msaa", 4) != 0) continue;
+ p += 5;
+ while (*p == L' ' || *p == L'=' || *p == L':') ++p;
+ int n = 0;
+ while (*p >= L'0' && *p <= L'9') { n = n * 10 + (int)(*p - L'0'); ++p; }
+ requested = n ? n : 4; // a bare "-msaa" means 4x
+ break;
+ }
+ if (requested < 2) requested = 0; // 0 and 1 both mean "no multisampling"
+ if (requested > 16) requested = 16;
+ return (unsigned)requested;
+}
+
+// Non-multisampled depth/stencil for render-to-texture. A multisampled back buffer gets a
+// multisampled auto depth/stencil, and Direct3D requires the depth buffer to match the render
+// target - so the plain render target textures the screen filters and the water reflection draw
+// into need a non-multisampled one of their own. (The retail runtime does not reject the
+// mismatch at bind time; the debug runtime and the docs do. dx8_smoke_msaa records both.)
+// NULL means "not multisampling, keep the depth buffer you already have".
+static IDirect3DSurface8 * _RTTDepthBuffer = NULL;
+
static DynamicVectorClass<StringClass> _RenderDeviceNameTable;
static DynamicVectorClass<StringClass> _RenderDeviceShortNameTable;
static DynamicVectorClass<RenderDeviceDescClass> _RenderDeviceDescriptionTable;
@@ -638,6 +673,9 @@ bool DX8Wrapper::Reset_Device(bool reload_assets)
DX8TextureManagerClass::Release_Textures();
SHD_SHUTDOWN_SHADERS;
+ // D3DPOOL_DEFAULT: must be gone before Reset(), and the back buffer may change size
+ if (_RTTDepthBuffer) { _RTTDepthBuffer->Release(); _RTTDepthBuffer = NULL; }
+
// Reset frame count to reflect the flipping chain being reset by Reset()
FrameCount = 0;
@@ -674,6 +712,8 @@ void DX8Wrapper::Release_Device(void)
{
if (D3DDevice) {
+ if (_RTTDepthBuffer) { _RTTDepthBuffer->Release(); _RTTDepthBuffer = NULL; }
+
for (int a=0;a<MAX_TEXTURE_STAGES;++a)
{ //release references to any textures that were used in last rendering call
DX8CALL(SetTexture(a,NULL));
@@ -1055,6 +1095,28 @@ bool DX8Wrapper::Set_Render_Device(int dev, int width, int height, int bits, int
}
}
+ /*
+ ** Pick the multisampling level now that both formats are known. D3D only allows
+ ** multisampling with SWAPEFFECT_DISCARD, which is what we use unconditionally.
+ */
+ _PresentParameters.MultiSampleType = D3DMULTISAMPLE_NONE;
+ {
+ unsigned wanted = Get_Requested_MultiSample_Level();
+ for (unsigned samples = wanted; samples >= 2; --samples) {
+ D3DMULTISAMPLE_TYPE type = (D3DMULTISAMPLE_TYPE)samples;
+ if (FAILED(D3DInterface->CheckDeviceMultiSampleType(CurRenderDevice,D3DDEVTYPE_HAL,
+ _PresentParameters.BackBufferFormat,_PresentParameters.Windowed,type))) continue;
+ if (FAILED(D3DInterface->CheckDeviceMultiSampleType(CurRenderDevice,D3DDEVTYPE_HAL,
+ _PresentParameters.AutoDepthStencilFormat,_PresentParameters.Windowed,type))) continue;
+ _PresentParameters.MultiSampleType = type;
+ break;
+ }
+ if (wanted) {
+ WWDEBUG_SAY(("Multisampling: %ux requested, %ux in use\n",
+ wanted,(unsigned)_PresentParameters.MultiSampleType));
+ }
+ }
+
StringClass displayFormat;
StringClass backbufferFormat;
@@ -3347,6 +3409,32 @@ void DX8Wrapper::Set_Render_Target_With_Z
IsRenderToTexture = true;
}
+//**********************************************************************************************
+//! Depth/stencil surface to pair with a non-multisampled render target
+/*! Returns NULL when the back buffer is not multisampled - callers then keep whatever depth
+** buffer they already have, which is what every one of them did before multisampling existed.
+** Created lazily at back buffer size, which covers every render target this game binds.
+*/
+// Samples per pixel actually in use: 0 when not multisampling. The exe logs this, so a
+// player can tell whether "-msaa N" was honoured or quietly degraded.
+unsigned DX8Wrapper::Get_MultiSample_Level(void)
+{
+ return (unsigned)_PresentParameters.MultiSampleType;
+}
+
+IDirect3DSurface8 * DX8Wrapper::_Get_Non_MultiSampled_Depth_Buffer(void)
+{
+ if (_PresentParameters.MultiSampleType == D3DMULTISAMPLE_NONE) return NULL;
+ if (_RTTDepthBuffer == NULL && D3DDevice != NULL) {
+ if (FAILED(D3DDevice->CreateDepthStencilSurface(
+ _PresentParameters.BackBufferWidth,_PresentParameters.BackBufferHeight,
+ _PresentParameters.AutoDepthStencilFormat,D3DMULTISAMPLE_NONE,&_RTTDepthBuffer))) {
+ _RTTDepthBuffer = NULL;
+ }
+ }
+ return _RTTDepthBuffer;
+}
+
void
DX8Wrapper::Set_Render_Target(IDirect3DSwapChain8 *swap_chain)
{
@@ -3476,7 +3564,10 @@ DX8Wrapper::Set_Render_Target(IDirect3DSurface8 *render_target, bool use_default
//
if (use_default_depth_buffer)
{
- DX8CALL(SetRenderTarget (CurrentRenderTarget, DefaultDepthBuffer));
+ // The default depth buffer is multisampled when the back buffer is; this
+ // target is not, so it needs the plain one instead.
+ IDirect3DSurface8 * z = _Get_Non_MultiSampled_Depth_Buffer();
+ DX8CALL(SetRenderTarget (CurrentRenderTarget, z ? z : DefaultDepthBuffer));
}
else
{
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.h
index 23ad9da6c..942ea2ad7 100644
--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.h
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.h
@@ -490,6 +490,10 @@ public:
static void Set_Render_Target (IDirect3DSurface8* render_target, IDirect3DSurface8* dpeth_buffer);
static void Set_Render_Target (IDirect3DSwapChain8 *swap_chain);
+ // Samples per pixel in use, 0 if not multisampling ("-msaa N" on the command line).
+ static unsigned Get_MultiSample_Level (void);
+ // Depth/stencil to use with a non-multisampled render target; NULL if not multisampling.
+ static IDirect3DSurface8 * _Get_Non_MultiSampled_Depth_Buffer (void);
static bool Is_Render_To_Texture(void) { return IsRenderToTexture; }
// for depth map support KJM V
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/test_dx8_smoke.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/test_dx8_smoke.cpp
index 560b22c31..cbb236993 100644
--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/test_dx8_smoke.cpp
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/test_dx8_smoke.cpp
@@ -34,7 +34,9 @@ int main(int argc, char **argv)
if (strcmp(argv[i], "-bb2") == 0) bb2 = true; // BackBufferCount = 2
}
int bbW = big ? 1280 : 640, bbH = big ? 768 : 480, posX = 100, posY = 100;
+ int msaa = 0; // "-msaa N": multisampled back buffer, plus the render-to-texture pairing it forces
for (int i = 1; i + 1 < argc; i++) { // "-w N -h N": back buffer size, "-x N -y N": window position
+ if (strcmp(argv[i], "-msaa") == 0) msaa = atoi(argv[i + 1]);
if (strcmp(argv[i], "-w") == 0) bbW = atoi(argv[i + 1]);
if (strcmp(argv[i], "-h") == 0) bbH = atoi(argv[i + 1]);
if (strcmp(argv[i], "-x") == 0) posX = atoi(argv[i + 1]);
@@ -83,6 +85,31 @@ int main(int argc, char **argv)
if (flip) pp.SwapEffect = D3DSWAPEFFECT_FLIP;
if (bb2) pp.BackBufferCount = 2;
+ // "-msaa N": the highest level up to N that the device reports for BOTH the back buffer
+ // and the depth/stencil format, exactly as dx8wrapper.cpp picks it. A multisampled back
+ // buffer cannot be lockable, so the pixel readback below is skipped in that mode.
+ D3DMULTISAMPLE_TYPE msType = D3DMULTISAMPLE_NONE;
+ if (msaa >= 2) {
+ for (int s = msaa > 16 ? 16 : msaa; s >= 2; --s) {
+ D3DMULTISAMPLE_TYPE type = (D3DMULTISAMPLE_TYPE)s;
+ if (d3d->CheckDeviceMultiSampleType(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
+ pp.BackBufferFormat, TRUE, type) != D3D_OK) continue;
+ if (d3d->CheckDeviceMultiSampleType(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
+ pp.AutoDepthStencilFormat, TRUE, type) != D3D_OK) continue;
+ msType = type;
+ break;
+ }
+ printf("msaa: %dx requested, %dx supported\n", msaa, (int)msType);
+ if (msType == D3DMULTISAMPLE_NONE) {
+ printf("FAIL: no multisample level up to %dx is supported\n", msaa);
+ d3d->Release(); DestroyWindow(hwnd);
+ return 1;
+ }
+ pp.MultiSampleType = msType;
+ pp.SwapEffect = D3DSWAPEFFECT_DISCARD; // the only swap effect D3D allows with multisampling
+ pp.Flags = 0;
+ }
+
IDirect3DDevice8 * dev = NULL;
HRESULT hr = d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,
D3DCREATE_MIXED_VERTEXPROCESSING, &pp, &dev);
@@ -96,7 +123,7 @@ int main(int argc, char **argv)
// read the cleared back buffer back: proves the runtime really rendered, not just created
// (a D3D12 path that only returned a device but painted nothing would pass otherwise)
- {
+ if (msType == D3DMULTISAMPLE_NONE) {
IDirect3DSurface8 * bb = NULL;
if (dev->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &bb) == D3D_OK && bb) {
D3DLOCKED_RECT lr;
@@ -116,6 +143,59 @@ int main(int argc, char **argv)
bb->Release();
}
}
+ // With a multisampled back buffer the auto depth/stencil is multisampled too, and Direct3D
+ // requires the depth buffer to match the render target - so the plain render-target textures
+ // every screen filter and the water reflection bind need a non-multisampled depth buffer of
+ // their own. That is DX8Wrapper::_Get_Non_MultiSampled_Depth_Buffer; this is its pairing,
+ // cleared green and read back to prove the target really was drawn into.
+ if (msType != D3DMULTISAMPLE_NONE) {
+ IDirect3DTexture8 * rtt = NULL;
+ IDirect3DSurface8 * rttSurf = NULL, * rttZ = NULL, * bb = NULL, * autoZ = NULL, * copy = NULL;
+ if (FAILED(dev->CreateTexture(256, 256, 1, D3DUSAGE_RENDERTARGET, pp.BackBufferFormat,
+ D3DPOOL_DEFAULT, &rtt))
+ || FAILED(rtt->GetSurfaceLevel(0, &rttSurf))
+ || FAILED(dev->CreateDepthStencilSurface(256, 256, pp.AutoDepthStencilFormat,
+ D3DMULTISAMPLE_NONE, &rttZ))
+ || FAILED(dev->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &bb))
+ || FAILED(dev->GetDepthStencilSurface(&autoZ))
+ || FAILED(dev->CreateImageSurface(256, 256, pp.BackBufferFormat, &copy))) {
+ printf("FAIL: could not build the render-to-texture surfaces\n");
+ dev->Release(); d3d->Release(); DestroyWindow(hwnd);
+ return 1;
+ }
+ // For the record: the retail runtime does NOT reject the mismatch at bind time (the debug
+ // runtime and the D3D9 docs do), which is why this is reported rather than asserted.
+ printf("rtt: multisampled z with a plain target hr=0x%08lx (0 = the runtime allows it)\n",
+ (unsigned long)dev->SetRenderTarget(rttSurf, autoZ));
+ HRESULT good = dev->SetRenderTarget(rttSurf, rttZ);
+ HRESULT cleared = dev->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,
+ D3DCOLOR_XRGB(0, 255, 0), 1.0f, 0);
+ HRESULT copied = dev->CopyRects(rttSurf, NULL, 0, copy, NULL);
+ HRESULT back = dev->SetRenderTarget(bb, autoZ);
+ printf("rtt: matched z hr=0x%08lx, clear hr=0x%08lx, copy hr=0x%08lx, restore hr=0x%08lx\n",
+ (unsigned long)good, (unsigned long)cleared, (unsigned long)copied, (unsigned long)back);
+ if (FAILED(good) || FAILED(cleared) || FAILED(copied) || FAILED(back)) {
+ printf("FAIL: render-to-texture with a matching non-multisampled depth buffer failed\n");
+ dev->Release(); d3d->Release(); DestroyWindow(hwnd);
+ return 1;
+ }
+ D3DLOCKED_RECT lr;
+ bool green = false;
+ if (SUCCEEDED(copy->LockRect(&lr, NULL, D3DLOCK_READONLY))) {
+ const unsigned char * px = (const unsigned char *)lr.pBits + 10 * lr.Pitch + 10 * 4;
+ printf("render texture pixel (b,g,r) = (%u,%u,%u)\n", px[0], px[1], px[2]);
+ green = px[1] > 200 && px[0] < 32 && px[2] < 32;
+ copy->UnlockRect();
+ }
+ if (!green) {
+ printf("FAIL: the render texture does not hold the clear colour (0,255,0)\n");
+ dev->Release(); d3d->Release(); DestroyWindow(hwnd);
+ return 1;
+ }
+ copy->Release(); autoZ->Release(); bb->Release(); rttZ->Release();
+ rttSurf->Release(); rtt->Release();
+ }
+
HRESULT phr = dev->Present(NULL, NULL, NULL, NULL);
printf("Present hr=0x%08lx\n", (unsigned long)phr);
if (show) {