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.
C++ cmakecnccommand-and-conquercppdirectx11game-enginegame-preservationgeneralsrtssage-enginex64zero-hour
build(ww3d2): port renderer core to CMake with vendored DX8 SDK
Olcay Seygandb616feb35f1
diff --git a/GeneralsMD/Code/CMakeLists.txt b/GeneralsMD/Code/CMakeLists.txtindex de776d187..9c024fa24 100644--- a/GeneralsMD/Code/CMakeLists.txt+++ b/GeneralsMD/Code/CMakeLists.txt@@ -129,3 +129,64 @@ add_library(wwsaveload STATIC${WW}/WWSaveLoad/twiddler.cpp ${WW}/WWSaveLoad/wwsaveload.cpp)target_include_directories(wwsaveload PUBLIC ${WW}/WWSaveLoad PRIVATE ${WW}/WWLib ${WW}/WWMath ${WW}/Wwutil)target_link_libraries(wwsaveload PRIVATE wwdebug wwlib wwmath)++# ---- ww3d2 (renderer core) ------------------------------------------------+# wwshade is header-only here on purpose: no .dsp links wwshade.lib and its+# shd*bump* sources need shdpp/NVASM-generated headers. Revisit at exe link.+# dx8webbrowser.cpp stays inert (ENABLE_EMBEDDED_BROWSER unset).+add_library(ww3d2 STATIC++ ${WW}/WW3D2/FramGrab.cpp ${WW}/WW3D2/aabtree.cpp ${WW}/WW3D2/aabtreebuilder.cpp+ ${WW}/WW3D2/agg_def.cpp ${WW}/WW3D2/animatedsoundmgr.cpp ${WW}/WW3D2/animobj.cpp+ ${WW}/WW3D2/assetmgr.cpp ${WW}/WW3D2/assetstatus.cpp ${WW}/WW3D2/bitmaphandler.cpp+ ${WW}/WW3D2/bmp2d.cpp ${WW}/WW3D2/boxrobj.cpp ${WW}/WW3D2/bwrender.cpp+ ${WW}/WW3D2/camera.cpp ${WW}/WW3D2/collect.cpp ${WW}/WW3D2/coltest.cpp+ ${WW}/WW3D2/composite.cpp ${WW}/WW3D2/dazzle.cpp ${WW}/WW3D2/ddsfile.cpp+ ${WW}/WW3D2/decalmsh.cpp ${WW}/WW3D2/decalsys.cpp ${WW}/WW3D2/distlod.cpp+ ${WW}/WW3D2/dx8caps.cpp ${WW}/WW3D2/dx8fvf.cpp ${WW}/WW3D2/dx8indexbuffer.cpp+ ${WW}/WW3D2/dx8polygonrenderer.cpp ${WW}/WW3D2/dx8renderer.cpp ${WW}/WW3D2/dx8rendererdebugger.cpp+ ${WW}/WW3D2/dx8texman.cpp ${WW}/WW3D2/dx8vertexbuffer.cpp ${WW}/WW3D2/dx8webbrowser.cpp+ ${WW}/WW3D2/dx8wrapper.cpp ${WW}/WW3D2/dynamesh.cpp ${WW}/WW3D2/font3d.cpp+ ${WW}/WW3D2/formconv.cpp ${WW}/WW3D2/hanim.cpp ${WW}/WW3D2/hanimmgr.cpp+ ${WW}/WW3D2/hcanim.cpp ${WW}/WW3D2/hlod.cpp ${WW}/WW3D2/hmdldef.cpp+ ${WW}/WW3D2/hmorphanim.cpp ${WW}/WW3D2/hrawanim.cpp ${WW}/WW3D2/htree.cpp+ ${WW}/WW3D2/htreemgr.cpp ${WW}/WW3D2/intersec.cpp ${WW}/WW3D2/layer.cpp+ ${WW}/WW3D2/light.cpp ${WW}/WW3D2/lightenvironment.cpp ${WW}/WW3D2/line3d.cpp+ ${WW}/WW3D2/linegrp.cpp ${WW}/WW3D2/mapper.cpp ${WW}/WW3D2/matinfo.cpp+ ${WW}/WW3D2/matpass.cpp ${WW}/WW3D2/matrixmapper.cpp ${WW}/WW3D2/mesh.cpp+ ${WW}/WW3D2/meshbuild.cpp ${WW}/WW3D2/meshdam.cpp ${WW}/WW3D2/meshgeometry.cpp+ ${WW}/WW3D2/meshmatdesc.cpp ${WW}/WW3D2/meshmdl.cpp ${WW}/WW3D2/meshmdlio.cpp+ ${WW}/WW3D2/metalmap.cpp ${WW}/WW3D2/missingtexture.cpp ${WW}/WW3D2/motchan.cpp+ ${WW}/WW3D2/nullrobj.cpp ${WW}/WW3D2/part_buf.cpp ${WW}/WW3D2/part_emt.cpp+ ${WW}/WW3D2/part_ldr.cpp ${WW}/WW3D2/pivot.cpp ${WW}/WW3D2/pointgr.cpp+ ${WW}/WW3D2/polyinfo.cpp ${WW}/WW3D2/predlod.cpp ${WW}/WW3D2/prim_anim.cpp+ ${WW}/WW3D2/projector.cpp ${WW}/WW3D2/proto.cpp ${WW}/WW3D2/render2d.cpp+ ${WW}/WW3D2/render2dsentence.cpp ${WW}/WW3D2/renderobjectrecycler.cpp ${WW}/WW3D2/rendobj.cpp+ ${WW}/WW3D2/rinfo.cpp ${WW}/WW3D2/ringobj.cpp ${WW}/WW3D2/scene.cpp+ ${WW}/WW3D2/segline.cpp ${WW}/WW3D2/seglinerenderer.cpp ${WW}/WW3D2/shader.cpp+ ${WW}/WW3D2/shattersystem.cpp ${WW}/WW3D2/snappts.cpp ${WW}/WW3D2/sortingrenderer.cpp+ ${WW}/WW3D2/soundrobj.cpp ${WW}/WW3D2/sphereobj.cpp ${WW}/WW3D2/static_sort_list.cpp+ ${WW}/WW3D2/statistics.cpp ${WW}/WW3D2/streak.cpp ${WW}/WW3D2/streakRender.cpp+ ${WW}/WW3D2/stripoptimizer.cpp ${WW}/WW3D2/surfaceclass.cpp ${WW}/WW3D2/texfcach.cpp+ ${WW}/WW3D2/texproject.cpp ${WW}/WW3D2/texture.cpp ${WW}/WW3D2/texturefilter.cpp+ ${WW}/WW3D2/textureloader.cpp ${WW}/WW3D2/texturethumbnail.cpp ${WW}/WW3D2/txt.cpp+ ${WW}/WW3D2/vertmaterial.cpp ${WW}/WW3D2/visrasterizer.cpp ${WW}/WW3D2/w3d_dep.cpp+ ${WW}/WW3D2/w3d_util.cpp ${WW}/WW3D2/w3dexclusionlist.cpp ${WW}/WW3D2/ww3d.cpp+ ${WW}/WW3D2/ww3dformat.cpp+)+target_include_directories(ww3d2+ PUBLIC ${WW}/WW3D2+ PRIVATE ${WW}/WWLib ${WW}/WWMath ${WW}/WWDebug ${WW}/WWSaveLoad ${WW}/Wwutil+ ${WW}/wwshade ${WW}/WWAudio ${WW}/Miles6/include+ ${CMAKE_CURRENT_SOURCE_DIR}/Libraries/DirectX/Include)+target_link_directories(ww3d2 PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/Libraries/DirectX/Lib)+target_link_libraries(ww3d2 PUBLIC d3d8 d3dx8 dxguid PRIVATE wwlib wwmath wwdebug wwsaveload)+# ponytail: VC6 for-scope leaks at ~40 sites across ww3d2; scoped flag beats mass+# edits in render code. Burn the sites down later, then drop the flag.+target_compile_options(ww3d2 PRIVATE /Zc:forScope-)++# Phase 1 checkpoint: vendored DX8 SDK + OS d3d8.dll create a real device.+add_executable(dx8_smoke ${WW}/WW3D2/test_dx8_smoke.cpp)+target_include_directories(dx8_smoke PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/Libraries/DirectX/Include)+target_link_directories(dx8_smoke PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/Libraries/DirectX/Lib)+target_link_libraries(dx8_smoke PRIVATE d3d8 user32)diff --git a/GeneralsMD/Code/Libraries/DirectX/.gitignore b/GeneralsMD/Code/Libraries/DirectX/.gitignorenew file mode 100644index 000000000..50ea60fe2--- /dev/null+++ b/GeneralsMD/Code/Libraries/DirectX/.gitignore@@ -0,0 +1,3 @@+# Vendored min-dx8-sdk (TheSuperHackers/min-dx8-sdk @ 7bddff8) - never committed+*+!.gitignorediff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/animatedsoundmgr.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/animatedsoundmgr.cppindex bb6bb104b..d5f9bcff8 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/animatedsoundmgr.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/animatedsoundmgr.cpp@@ -157,7 +157,7 @@ Build_List_From_String// Copy this entry into its own string//StringClass entry_string = entry;- char *delim_start = ::strstr (entry_string, delimiter);+ char *delim_start = const_cast<char*>(::strstr (entry_string, delimiter));if (delim_start != NULL) {delim_start[0] = 0;}diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/assetmgr.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/assetmgr.cppindex 513e54401..7f6023a55 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/assetmgr.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/assetmgr.cpp@@ -808,7 +808,7 @@ RenderObjClass * WW3DAssetManager::Create_Render_Obj(const char * name)AssetStatusClass::Peek_Instance()->Report_Load_On_Demand_RObj(name);char filename [MAX_PATH];- char *mesh_name = ::strchr (name, '.');+ const char *mesh_name = ::strchr (name, '.');if (mesh_name != NULL) {::lstrcpyn (filename, name, ((int)mesh_name) - ((int)name) + 1);::lstrcat (filename, ".w3d");@@ -989,7 +989,7 @@ HAnimClass * WW3DAssetManager::Get_HAnim(const char * name)AssetStatusClass::Peek_Instance()->Report_Load_On_Demand_HAnim(name);char filename[ MAX_PATH ];- char *animname = strchr( name, '.');+ const char *animname = strchr( name, '.');if (animname != NULL) {sprintf( filename, "%s.w3d", animname+1);} else {diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/hanimmgr.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/hanimmgr.cppindex ef2d95ff9..1bbcf3826 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/hanimmgr.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/hanimmgr.cpp@@ -385,7 +385,7 @@ void HAnimManagerClass::Create_Asset_List(DynamicVectorClass<StringClass> & excl// File that this anim came from should be the name after the '.'// Anims are named in the format: <skeleton>.<animname>const char * anim_name = anim->Get_Name();- char * filename = strchr(anim_name,'.');+ const char * filename = strchr(anim_name,'.');if (filename != NULL) {exclusion_list.Add(StringClass(filename+1));}diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/hmorphanim.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/hmorphanim.cppindex a39747cf4..291ecc6a5 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/hmorphanim.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/hmorphanim.cpp@@ -295,7 +295,7 @@ static int Build_List_From_String// Copy this entry into its own string//StringClass entry_string = entry;- char *delim_start = ::strstr (entry_string, delimiter);+ char *delim_start = const_cast<char*>(::strstr (entry_string, delimiter));if (delim_start != NULL) {delim_start[0] = 0;}@@ -489,7 +489,7 @@ void HMorphAnimClass::Set_Name(const char * name)// Try to find the separator (a period)//StringClass full_name = name;- char *separator = ::strchr (full_name, '.');+ char *separator = const_cast<char*>(::strchr (full_name, '.'));if (separator != NULL) {//diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/lightenvironment.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/lightenvironment.cppindex 5c473c5ed..4521679e8 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/lightenvironment.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/lightenvironment.cpp@@ -52,8 +52,8 @@ const float DIFFUSE_TO_AMBIENT_FRACTION = 1.0f;/*** Static variables*/-static _LightingLODCutoff = 0.5f;-static _LightingLODCutoff2 = 0.5f * 0.5f;+static float _LightingLODCutoff = 0.5f;+static float _LightingLODCutoff2 = 0.5f * 0.5f;/************************************************************************************************diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/prim_anim.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/prim_anim.hindex 6d0d7ab94..4473df374 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/prim_anim.h+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/prim_anim.h@@ -182,7 +182,7 @@ int PrimitiveAnimationChannelClass<T>::Get_Key_Count (void) const// Set_Key_Value/////////////////////////////////////////////////////////template<class T>-const PrimitiveAnimationChannelClass<T>::KeyClass &PrimitiveAnimationChannelClass<T>::Get_Key (int index) const+const typename PrimitiveAnimationChannelClass<T>::KeyClass &PrimitiveAnimationChannelClass<T>::Get_Key (int index) const{return m_Data[index];}diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/render2dsentence.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/render2dsentence.cppindex b255848dc..1c04cfb11 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/render2dsentence.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/render2dsentence.cpp@@ -1720,8 +1720,8 @@ FontCharsClass::Grow_Unicode_Array (WCHAR ch)return ;}- uint16 first_index = min( FirstUnicodeChar, ch );- uint16 last_index = max( LastUnicodeChar, ch );+ uint16 first_index = min( FirstUnicodeChar, (uint16)ch );+ uint16 last_index = max( LastUnicodeChar, (uint16)ch );uint16 count = (last_index - first_index) + 1;//diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/rendobj.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/rendobj.cppindex 039d0f0ce..c448670f0 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/rendobj.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/rendobj.cpp@@ -119,7 +119,7 @@ Filename_From_Asset_Name (const char *asset_name)//// Do we need to strip off the model's suffix?//- char *suffix = ::strchr (filename, '.');+ char *suffix = const_cast<char*>(::strchr (filename, '.'));if (suffix != NULL) {suffix[0] = 0;}diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/test_dx8_smoke.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/test_dx8_smoke.cppnew file mode 100644index 000000000..815129def--- /dev/null+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/test_dx8_smoke.cpp@@ -0,0 +1,54 @@+// Phase 1 checkpoint: prove the vendored DX8 SDK headers/libs and the OS's+// d3d8.dll actually work - create a windowed device on a hidden window, clear,+// present. Prints adapter info; "DX8 smoke OK" means pass.++#include <windows.h>+#include <d3d8.h>+#include <stdio.h>++int main(void)+{+ IDirect3D8 * d3d = Direct3DCreate8(D3D_SDK_VERSION);+ if (!d3d) { printf("FAIL: Direct3DCreate8 returned NULL\n"); return 1; }++ D3DADAPTER_IDENTIFIER8 id;+ if (d3d->GetAdapterIdentifier(D3DADAPTER_DEFAULT, 0, &id) == D3D_OK) {+ printf("adapter: %s\n", id.Description);+ }++ WNDCLASSA wc = {0};+ wc.lpfnWndProc = DefWindowProcA;+ wc.hInstance = GetModuleHandleA(NULL);+ wc.lpszClassName = "dx8smoke";+ RegisterClassA(&wc);+ HWND hwnd = CreateWindowA("dx8smoke", "dx8smoke", WS_OVERLAPPEDWINDOW,+ 0, 0, 64, 64, NULL, NULL, wc.hInstance, NULL);+ if (!hwnd) { printf("FAIL: CreateWindow\n"); d3d->Release(); return 1; }++ D3DDISPLAYMODE mode;+ d3d->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &mode);++ D3DPRESENT_PARAMETERS pp = {0};+ pp.Windowed = TRUE;+ pp.SwapEffect = D3DSWAPEFFECT_DISCARD;+ pp.BackBufferFormat = mode.Format;+ pp.hDeviceWindow = hwnd;++ IDirect3DDevice8 * dev = NULL;+ HRESULT hr = d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,+ D3DCREATE_SOFTWARE_VERTEXPROCESSING, &pp, &dev);+ if (hr != D3D_OK || !dev) {+ printf("FAIL: CreateDevice hr=0x%08lx\n", (unsigned long)hr);+ d3d->Release();+ return 1;+ }++ dev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(64, 0, 128), 1.0f, 0);+ dev->Present(NULL, NULL, NULL, NULL);++ dev->Release();+ d3d->Release();+ DestroyWindow(hwnd);+ printf("DX8 smoke OK\n");+ return 0;+}diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WWAudio/WWAudio.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WWAudio/WWAudio.hindex c7bfb7912..e677a77ee 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WWAudio/WWAudio.h+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WWAudio/WWAudio.h@@ -510,8 +510,8 @@ private:: string_id (0), buffer (NULL) {}_CACHE_ENTRY_STRUCT &operator= (const _CACHE_ENTRY_STRUCT &src) { string_id = ::strdup (src.string_id); REF_PTR_SET (buffer, src.buffer); return *this; }- operator== (const _CACHE_ENTRY_STRUCT &src) { return false; }- operator!= (const _CACHE_ENTRY_STRUCT &src) { return true; }+ bool operator== (const _CACHE_ENTRY_STRUCT &src) { return false; }+ bool operator!= (const _CACHE_ENTRY_STRUCT &src) { return true; }} CACHE_ENTRY_STRUCT;@@ -526,8 +526,8 @@ private:_LOGICAL_TYPE_STRUCT (int _id, LPCTSTR name): display_name (name), id (_id) {}- operator== (const _LOGICAL_TYPE_STRUCT &src) { return false; }- operator!= (const _LOGICAL_TYPE_STRUCT &src) { return true; }+ bool operator== (const _LOGICAL_TYPE_STRUCT &src) { return false; }+ bool operator!= (const _LOGICAL_TYPE_STRUCT &src) { return true; }} LOGICAL_TYPE_STRUCT;//////////////////////////////////////////////////////////////////////