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(w3ddevice): keep the behind-building option across a stencil loss

Olcay Seygan26eb76ed2774
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1d22dde1b..f65d5baa4 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1272,6 +1272,10 @@ The whole HUD is on the hardware. Four colours carry it, and they mean the same
building so you can still make it out, and the flag that says "yes, something is in front of this
one" was set once and never cleared - so the first unit genuinely behind a wall made every unit
checked after it see-through too, wall or no wall. On a busy screen that was most of them.
+- The outlines of your units behind a building stay switched on. If the screen was lost for a
+ moment, an alt-tab or a resolution change, the game turned the setting itself off, so the
+ outlines were gone until you found the box and ticked it again.
+ A lost screen now hides them only while it lasts.
- Bloom and antialiasing work together. Turning bloom on with antialiasing on gave you a black battlefield under a live interface: the glow pass draws the world into its own picture first, and that picture came with a depth buffer nobody had cleared, so every triangle in the scene was rejected as being behind something that was not there.
- Lakes stop showing jagged bands of shore while you scroll. The glow and smoothing effects draw the world into a picture of their own, and that picture was never wiped between frames, so the water kept reading last frame's shoreline from wherever the camera had just been.
- A switch you write in `Options.ini` by hand takes `yes`, `true`, `on` or `1` for on. Only the
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DScene.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DScene.cpp
index c9855a0d3..690d138b5 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DScene.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DScene.cpp
@@ -94,6 +94,13 @@ extern void DoParticles(RenderInfoClass & rinfo);
ShaderClass::DETAILCOLOR_DISABLE, ShaderClass::DETAILALPHA_DISABLE) )
static ShaderClass PlayerColorShader(SC_PLAYER_COLOR);
+// The player's option, gated by the stencil buffer the markers need. Asked per frame and never
+// written back: a device reset that loses the stencil for a moment must not clear the option.
+static Bool behindBuildingMarkersEnabled()
+{
+ return TheGlobalData->m_enableBehindBuildingMarkers && DX8Wrapper::Has_Stencil();
+}
+
//=============================================================================
// RTS3DScene::RTS3DScene
//=============================================================================
@@ -507,7 +514,7 @@ void RTS3DScene::Visibility_Check(CameraClass * camera)
{ drawInfo->m_flags |= DrawableInfo::ERF_IS_TRANSLUCENT; //object is translucent
m_translucentObjectsBuffer[m_translucentObjectsCount++] = robj;
}
- if (TheGlobalData->m_enableBehindBuildingMarkers && TheGameLogic->getShowBehindBuildingMarkers())
+ if (behindBuildingMarkersEnabled() && TheGameLogic->getShowBehindBuildingMarkers())
{
//visible drawable. Check if it's either an occluder or occludee
if (draw->isKindOf(KINDOF_STRUCTURE) && m_numPotentialOccluders < TheGlobalData->m_maxVisibleOccluderObjects)
@@ -1005,7 +1012,7 @@ void RTS3DScene::updatePlayerColorPasses(void)
#ifdef USE_NON_STENCIL_OCCLUSION
Vector3 hsv,rgb;
- if (TheGlobalData->m_enableBehindBuildingMarkers && TheGameLogic->getShowBehindBuildingMarkers())
+ if (behindBuildingMarkersEnabled() && TheGameLogic->getShowBehindBuildingMarkers())
{
Int numPlayers=ThePlayerList->getPlayerCount();
@@ -1032,9 +1039,6 @@ void RTS3DScene::Render(RenderInfoClass & rinfo)
USE_PERF_TIMER(NonTerrainRender)
DX8Wrapper::Set_Fog(FogEnabled, FogColor, FogStart, FogEnd);
- //Override the behind building selection if it's not available on current hardware (needs stencil).
- TheWritableGlobalData->m_enableBehindBuildingMarkers = TheWritableGlobalData->m_enableBehindBuildingMarkers && DX8Wrapper::Has_Stencil();
-
if (Get_Extra_Pass_Polygon_Mode() == EXTRA_PASS_DISABLE)
{
if (m_customPassMode == SCENE_PASS_DEFAULT)
@@ -2044,7 +2048,7 @@ void RTS3DScene::Visibility_Check(CameraClass * camera)
{ drawInfo->m_flags |= DrawableInfo::ERF_IS_TRANSLUCENT; //object is translucent
m_translucentObjectsBuffer[m_translucentObjectsCount++] = robj;
}
- if (TheGlobalData->m_enableBehindBuildingMarkers && TheGameLogic->getShowBehindBuildingMarkers())
+ if (behindBuildingMarkersEnabled() && TheGameLogic->getShowBehindBuildingMarkers())
{
//visible drawable. Check if it's either an occluder or occludee
if (draw->isKindOf(KINDOF_STRUCTURE) && m_numPotentialOccluders < TheGlobalData->m_maxVisibleOccluderObjects)