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
fix(w3d): a narrowing pass that missed the box kept the last pass's cells
Olcay Seygan769755279a16
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/BaseHeightMap.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/BaseHeightMap.cppindex 4270d1d98..bed57084d 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/BaseHeightMap.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/BaseHeightMap.cpp@@ -721,6 +721,8 @@ bool BaseHeightMapRenderObjClass::Cast_Ray(RayCollisionTestClass & raytest)Bool hit = false;Int X,Y;Vector3 normal,P0,P1,P2,P3;+ Bool hasP0 = false;+ Bool hasP1 = false;if (!m_map)return false; //need valid pointer to heightmap samples@@ -752,10 +754,17 @@ bool BaseHeightMapRenderObjClass::Cast_Ray(RayCollisionTestClass & raytest)//find intersection point of ray and terrain bounding boxresult.Reset();result.ComputeContactPoint=true;+ Bool newP0 = false;+ Bool newP1 = false;+if (CollisionMath::Collide(lineseg,hbox,&result)){ //ray intersects terrain or starts inside the terrain.if (!result.StartBad) //check if start point inside terrain+ {+ newP0 = P0 != result.ContactPoint;+ hasP0 = true;P0 = result.ContactPoint; //make intersection point the new start of the ray.+ }//reverse direction of original ray and clip again to extent of//heightmap@@ -764,13 +773,20 @@ bool BaseHeightMapRenderObjClass::Cast_Ray(RayCollisionTestClass & raytest)lineseg2.Set(lineseg.Get_P1(),lineseg.Get_P0()); //reverse line segmentif (CollisionMath::Collide(lineseg2,hbox,&result)){ if (!result.StartBad) //check if end point inside terrain+ {+ newP1 = P1 != result.ContactPoint;+ hasP1 = true;P1 = result.ContactPoint; //make intersection point the new end pont of ray+ }}- } else {- if (p==0) return(false);- break;}+ // Narrowing has stopped moving the ends, so another pass would search the same box. The+ // old test broke on the box missing instead, which let a first pass that hit nothing on+ // p>0 carry the previous pass's cell range into the triangle search below.+ if (!newP0 || !newP1)+ break;+// Take the 2D bounding box of ray and check heights// inside this box for intersection.if (P0.X > P1.X) { //flip start/end points@@ -806,6 +822,10 @@ bool BaseHeightMapRenderObjClass::Cast_Ray(RayCollisionTestClass & raytest)hbox.Init(mmbox);}+ // Neither end was ever placed on the terrain box, so there is nothing to search.+ if (!hasP0 || !hasP1)+ return false;+raytest.Result->ComputeContactPoint=true; //tell CollisionMath that we need point.// Adjust indexes into the bordered height map.diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ddsfile.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ddsfile.cppindex c21d555fd..a711966e2 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ddsfile.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ddsfile.cpp@@ -18,6 +18,7 @@// 08/06/02 KM Added cube map and volume texture support#include "ddsfile.h"+#include "stringex.h"#include "ffactory.h"#include "bufffile.h"#include "formconv.h"@@ -47,7 +48,9 @@ DDSFileClass::DDSFileClass(const char* name,unsigned reduction_factor)DateTime(0),CubeFaceSize(0){- strncpy(Name,name,sizeof(Name));+ // strncpy leaves no terminator when the name fills the buffer, and strlen runs on the very+ // next line. A 256 character asset path walked off the end of this.+ strlcpy(Name,name,ARRAY_SIZE(Name));// The name could be given in .tga or .dds format, so ensure we're opening .dds...int len=strlen(Name);Name[len-3]='d';@@ -100,8 +103,11 @@ DDSFileClass::DDSFileClass(const char* name,unsigned reduction_factor)if (MipLevels>ReductionFactor) MipLevels-=ReductionFactor;else {- MipLevels=1;+ // The leftover reduction is what the file could not supply as mip levels. This used to+ // assign MipLevels=1 first and then subtract that 1, so it always came out one short of+ // the reduction asked for.ReductionFactor=ReductionFactor-MipLevels;+ MipLevels=1;}// Drop the two lowest miplevels!@@ -122,6 +128,8 @@ DDSFileClass::DDSFileClass(const char* name,unsigned reduction_factor)FullWidth=SurfaceDesc.Width;FullHeight=SurfaceDesc.Height;FullDepth=SurfaceDesc.Depth;+ // These two are private and only ever read through Get_Width and Get_Height, which already+ // hold the answer at four, so the reduction is allowed to take them below a DXT block here.Width=SurfaceDesc.Width>>ReductionFactor;Height=SurfaceDesc.Height>>ReductionFactor;Depth=SurfaceDesc.Depth;