Skip to content

Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.

feat(w3ddevice): -nodevice plays a whole match with no Direct3D device

Olcay Seyganb7392a6c46ee
diff --git a/GeneralsMD/Code/GameEngineDevice/Include/Win32Device/Common/HeadlessRadar.h b/GeneralsMD/Code/GameEngineDevice/Include/Win32Device/Common/HeadlessRadar.h
new file mode 100644
index 000000000..7c480bbe8
--- /dev/null
+++ b/GeneralsMD/Code/GameEngineDevice/Include/Win32Device/Common/HeadlessRadar.h
@@ -0,0 +1,57 @@
+/*
+** Command & Conquer Generals Zero Hour(tm)
+** Copyright 2025 Electronic Arts Inc.
+**
+** This program is free software: you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation, either version 3 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+// FILE: HeadlessRadar.h /////////////////////////////////////////////////////////////////////////
+//
+// The radar for a run with no render device.
+//
+// W3DRadar is three textures it paints the terrain, the blips and the shroud into, and every one of
+// its methods reaches for one of them. Under -nodevice there is no device to hold them, and
+// guarding thirty methods one at a time would be thirty chances to miss one. The engine already
+// has the seam for this: Win32GameEngine picks the concrete class behind every abstract interface,
+// so a run with no picture gets a radar that keeps the half logic cares about - the events, the
+// under-attack pulse, the object lists - and draws nothing.
+//
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+#pragma once
+
+#ifndef __HEADLESSRADAR_H_
+#define __HEADLESSRADAR_H_
+
+#include "Common/Radar.h"
+
+//-------------------------------------------------------------------------------------------------
+class HeadlessRadar : public Radar
+{
+
+public:
+
+ HeadlessRadar( void ) { }
+ virtual ~HeadlessRadar( void ) { }
+
+ /// nothing is drawn, so there is nothing to draw with
+ virtual void draw( Int pixelX, Int pixelY, Int width, Int height ) { }
+
+ /// the shroud lives in a texture that was never made; logic keeps its own in PartitionManager
+ virtual void clearShroud( void ) { }
+ virtual void setShroudLevel( Int x, Int y, CellShroudStatus setting ) { }
+
+};
+
+#endif // __HEADLESSRADAR_H_
diff --git a/GeneralsMD/Code/GameEngineDevice/Include/Win32Device/Common/Win32GameEngine.h b/GeneralsMD/Code/GameEngineDevice/Include/Win32Device/Common/Win32GameEngine.h
index 6dffe897c..7274fa3d5 100644
--- a/GeneralsMD/Code/GameEngineDevice/Include/Win32Device/Common/Win32GameEngine.h
+++ b/GeneralsMD/Code/GameEngineDevice/Include/Win32Device/Common/Win32GameEngine.h
@@ -36,11 +36,13 @@
#define __WIN32GAMEENGINE_H_
#include "Common/GameEngine.h"
+#include "Common/GlobalData.h" // -nodevice picks different concrete classes below
#include "GameLogic/GameLogic.h"
#include "GameNetwork/NetworkInterface.h"
// The Miles SDK is binary-only and absent from the source release, so the audio
// device is the silent one in Stubs/ instead of MilesAudioManager.
#include "MilesAudioDevice/MilesAudioManager.h"
+#include "Win32Device/Common/HeadlessRadar.h"
#include "Win32Device/Common/Win32BIGFileSystem.h"
#include "Win32Device/Common/Win32LocalFileSystem.h"
#include "W3DDevice/Common/W3DModuleFactory.h"
@@ -102,7 +104,14 @@ inline ArchiveFileSystem *Win32GameEngine::createArchiveFileSystem( void ) { ret
inline ParticleSystemManager* Win32GameEngine::createParticleSystemManager( void ) { return NEW W3DParticleSystemManager; }
inline NetworkInterface *Win32GameEngine::createNetwork( void ) { return NetworkInterface::createNetwork(); }
-inline Radar *Win32GameEngine::createRadar( void ) { return NEW W3DRadar; }
+// -nodevice: W3DRadar is three textures and every method reaches for one, so a run with no device
+// takes the radar that keeps the events and draws nothing.
+inline Radar *Win32GameEngine::createRadar( void )
+{
+ if( TheGlobalData && TheGlobalData->m_noRenderDevice )
+ return NEW HeadlessRadar;
+ return NEW W3DRadar;
+}
inline WebBrowser *Win32GameEngine::createWebBrowser( void ) { return NEW CComObject<W3DWebBrowser>; }
inline AudioManager *Win32GameEngine::createAudioManager( void ) { return NEW MilesAudioManager; }
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/Common/System/W3DRadar.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/Common/System/W3DRadar.cpp
index 129501a4b..f97d7cb1d 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/Common/System/W3DRadar.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/Common/System/W3DRadar.cpp
@@ -870,12 +870,6 @@ void W3DRadar::init( void )
// extending functionality
Radar::init();
- // The radar's picture is three textures it paints the terrain and the blips into. Under
- // -nodevice there is nothing to hold them, and nothing looks at the result; the base class
- // above is the half that logic cares about, and that half has already run.
- if (TheGlobalData && TheGlobalData->m_noRenderDevice)
- return;
-
// gather specific texture format information
initializeTextureFormats();
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DShadow.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DShadow.cpp
index bb369cbce..f3dc9375d 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DShadow.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DShadow.cpp
@@ -127,19 +127,20 @@ Bool W3DShadowManager::init( void )
{
Bool result=TRUE;
- // A shadow is nothing but a thing drawn, and ReAcquireResources below asks the device for the
- // buffers to draw it with. Under -nodevice there is nothing here to acquire.
- if (TheGlobalData && TheGlobalData->m_noRenderDevice)
- return result;
+ /* Both managers are still brought up under -nodevice - the rest of the client assumes they
+ exist, and W3DTerrainVisual::reset walks the projected one's texture manager on the way out.
+ What is skipped is ReAcquireResources, which is the half that asks the device for the buffers
+ and the back buffer to draw a shadow with. */
+ const Bool haveDevice = !(TheGlobalData && TheGlobalData->m_noRenderDevice);
if (TheW3DVolumetricShadowManager && TheW3DVolumetricShadowManager->init())
{
- if (TheW3DVolumetricShadowManager->ReAcquireResources())
+ if (haveDevice && TheW3DVolumetricShadowManager->ReAcquireResources())
result = TRUE;
}
if ( TheW3DProjectedShadowManager && TheW3DProjectedShadowManager->init())
{
- if (TheW3DProjectedShadowManager->ReAcquireResources())
+ if (haveDevice && TheW3DProjectedShadowManager->ReAcquireResources())
result = TRUE;
}
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/TerrainTex.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/TerrainTex.cpp
index 7b4fe26f3..17fada773 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/TerrainTex.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/TerrainTex.cpp
@@ -97,6 +97,12 @@ int TerrainTextureClass::update(WorldHeightMap *htMap)
{
// D3DTexture is our texture;
+ // Except under -nodevice, where there is none: nothing built one and nothing will read the
+ // atlas this fills. Every line below reaches through it.
+ if (Peek_D3D_Texture() == NULL) {
+ return 0;
+ }
+
IDirect3DSurface8 *surface_level;
D3DSURFACE_DESC surface_desc;
D3DLOCKED_RECT locked_rect;
@@ -213,6 +219,12 @@ int TerrainTextureClass::update(WorldHeightMap *htMap)
{
// D3DTexture is our texture;
+ // Except under -nodevice, where there is none: nothing built one and nothing will read the
+ // atlas this fills. Every line below reaches through it.
+ if (Peek_D3D_Texture() == NULL) {
+ return 0;
+ }
+
IDirect3DSurface8 *surface_level;
D3DSURFACE_DESC surface_desc;
D3DLOCKED_RECT locked_rect;
@@ -376,6 +388,12 @@ Bool TerrainTextureClass::updateFlat(WorldHeightMap *htMap, Int xCell, Int yCell
{
// D3DTexture is our texture;
+ // Except under -nodevice, where there is none: nothing built one and nothing will read the
+ // atlas this fills. Every line below reaches through it.
+ if (Peek_D3D_Texture() == NULL) {
+ return 0;
+ }
+
IDirect3DSurface8 *surface_level;
D3DSURFACE_DESC surface_desc;
D3DLOCKED_RECT locked_rect;
@@ -770,6 +788,12 @@ int AlphaEdgeTextureClass::update(WorldHeightMap *htMap)
{
// D3DTexture is our texture;
+ // Except under -nodevice, where there is none: nothing built one and nothing will read the
+ // atlas this fills. Every line below reaches through it.
+ if (Peek_D3D_Texture() == NULL) {
+ return 0;
+ }
+
IDirect3DSurface8 *surface_level;
D3DSURFACE_DESC surface_desc;
D3DLOCKED_RECT locked_rect;
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DAssetManager.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DAssetManager.cpp
index 0e7942a6b..81ab8d0d4 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DAssetManager.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DAssetManager.cpp
@@ -668,8 +668,12 @@ TextureClass * W3DAssetManager::Recolor_Texture_One_Time(TextureClass *texture,
// if texture is procedural return NULL
if (name && name[0]=='!') return NULL;
+ // and under -nodevice there is no surface to copy and recolour, so there is no house-coloured
+ // texture either. Callers already cope with nothing coming back - see the line above.
+ if (TheGlobalData && TheGlobalData->m_noRenderDevice) return NULL;
+
// make sure texture is loaded
- if (!texture->Is_Initialized())
+ if (!texture->Is_Initialized())
TextureLoader::Request_Foreground_Loading(texture);
SurfaceClass::SurfaceDescription desc;
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp
index 999a175a3..cb4481e6b 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp
@@ -463,12 +463,17 @@ W3DDisplay::~W3DDisplay()
// shutdown
Debug_Statistics::Shutdown_Statistics();
- W3DShaderManager::shutdown();
+ // the shader manager and the browser control are the two things init skipped under -nodevice,
+ // so they are the two things there is nothing here to take down
+ const Bool hadDevice = !(TheGlobalData && TheGlobalData->m_noRenderDevice);
+ if( hadDevice )
+ W3DShaderManager::shutdown();
m_assetManager->Free_Assets();
delete m_assetManager;
WW3D::Shutdown();
WWMath::Shutdown();
- DX8WebBrowser::Shutdown();
+ if( hadDevice )
+ DX8WebBrowser::Shutdown();
delete TheW3DFileSystem;
TheW3DFileSystem = NULL;
@@ -1902,6 +1907,11 @@ void W3DDisplay::draw( void )
return;
}
+ // -nodevice: there is no device to begin a scene on. The load screen asks for a draw of its
+ // own while a map loads, so this is reached before the first frame and not only from the loop.
+ if (TheGlobalData && TheGlobalData->m_noRenderDevice) {
+ return;
+ }
updateAverageFPS();
if (TheGlobalData->m_enableDynamicLOD && TheGameLogic->getShowDynamicLOD())
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DShroud.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DShroud.cpp
index f45a60619..f88102079 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DShroud.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DShroud.cpp
@@ -107,6 +107,16 @@ W3DShroud::~W3DShroud(void)
m_drawFogOfWar=FALSE;
}
+//-----------------------------------------------------------------------------
+/**The shroud a player sees is two textures and a surface painted cell by cell. Under -nodevice
+ there are none, and none is wanted: what logic knows about who can see what lives in
+ PartitionManager, and this class only ever turned that into a picture.
+*/
+static Bool shroudHasNoDevice( void )
+{
+ return TheGlobalData && TheGlobalData->m_noRenderDevice;
+}
+
//-----------------------------------------------------------------------------
/**Called to initialize a new shroud for a new map. Should be done after the map is loaded
into the terrain object. worldCellSize is the world-space dimensions of each shroud cell.
@@ -114,6 +124,9 @@ W3DShroud::~W3DShroud(void)
*/
void W3DShroud::init(WorldHeightMap *pMap, Real worldCellSizeX, Real worldCellSizeY)
{
+ if (shroudHasNoDevice())
+ return;
+
DEBUG_ASSERTCRASH( m_pSrcTexture == NULL, ("ReAcquire of existing shroud textures"));
DEBUG_ASSERTCRASH( pMap != NULL, ("Shroud init with NULL WorldHeightMap"));
@@ -207,6 +220,9 @@ void W3DShroud::init(WorldHeightMap *pMap, Real worldCellSizeX, Real worldCellSi
///Called on map reset.
void W3DShroud::reset()
{
+ if (shroudHasNoDevice())
+ return;
+
//Free old shroud data since it may no longer fit new map.
if (m_pSrcTexture)
m_pSrcTexture->Release();
@@ -287,6 +303,9 @@ W3DShroudLevel W3DShroud::getShroudLevel(Int x, Int y)
//-----------------------------------------------------------------------------
void W3DShroud::setShroudLevel(Int x, Int y, W3DShroudLevel level, Bool textureOnly)
{
+ if (shroudHasNoDevice())
+ return;
+
DEBUG_ASSERTCRASH( m_pSrcTexture != NULL, ("Writing empty shroud. Usually means that map failed to load."));
if (!m_pSrcTexture)
@@ -355,6 +374,8 @@ void W3DShroud::setShroudLevel(Int x, Int y, W3DShroudLevel level, Bool textureO
///Quickly sets the shroud level of entire map to a single value
void W3DShroud::fillShroudData(W3DShroudLevel level)
{
+ if (shroudHasNoDevice())
+ return;
Int x,y;
UnsignedShort pixel;
@@ -510,6 +531,9 @@ void W3DShroud::fillBorderShroudData(W3DShroudLevel level, SurfaceClass* pDestSu
/**Set the shroud color within the border area of the map*/
void W3DShroud::setBorderShroudLevel(W3DShroudLevel level)
{
+ if (shroudHasNoDevice())
+ return;
+
m_boderShroudLevel = level;
m_clearDstTexture = TRUE;
}
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp
index 423592182..3aa184aa3 100644
--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp
@@ -2969,6 +2969,12 @@ IDirect3DSurface8 * DX8Wrapper::_Create_DX8_Surface(unsigned int width, unsigned
// Paletted surfaces not supported!
WWASSERT(format!=D3DFMT_P8);
+ // No device, no surface. SurfaceClass carries the null and the callers that matter in such a
+ // run check it; the alternative is CreateImageSurface on a null device.
+ if (_Get_D3D_Device8() == NULL) {
+ return NULL;
+ }
+
DX8CALL(CreateImageSurface(width, height, WW3DFormat_To_D3DFormat(format), &surface));
return surface;
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/textureloader.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/textureloader.cpp
index 303207f51..822e4d0ae 100644
--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/textureloader.cpp
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/textureloader.cpp
@@ -375,6 +375,13 @@ void TextureLoader::Validate_Texture_Size
unsigned& depth
)
{
+ // The whole of this is a clamp against what the device can hold, and with no device there is
+ // nothing to clamp against - Get_Current_Caps has nothing to return. Leave the sizes as asked:
+ // nothing in such a run allocates the surface they describe anyway.
+ if (DX8Wrapper::_Get_D3D_Device8() == NULL) {
+ return;
+ }
+
const D3DCAPS8& dx8caps=DX8Wrapper::Get_Current_Caps()->Get_DX8_Caps();
unsigned poweroftwowidth = 1;