From 4ffc71f984e00f807de3588f78012641cb6ac590 Mon Sep 17 00:00:00 2001 From: Omar Aglan Date: Sat, 26 Sep 2026 12:19:51 +0300 Subject: [PATCH 1/2] unify(worldbuilder): Merge heightmap editing (#3368) Align WorldHeightMapEdit and BorderTool with Zero Hour. Preserve Generals BlendTileData v7 row packing under RETAIL_COMPATIBLE_DATA, adopt the wider in-memory flag rows, and inherit the shared raw-tile accessor. --- .../WorldBuilder/include/WHeightMapEdit.h | 6 +- .../Tools/WorldBuilder/src/BorderTool.cpp | 20 ++++- .../Tools/WorldBuilder/src/WHeightMapEdit.cpp | 73 ++++++++----------- .../Tools/WorldBuilder/src/WHeightMapEdit.cpp | 17 ++++- 4 files changed, 63 insertions(+), 53 deletions(-) diff --git a/Generals/Code/Tools/WorldBuilder/include/WHeightMapEdit.h b/Generals/Code/Tools/WorldBuilder/include/WHeightMapEdit.h index e923b87c432..7f554481882 100644 --- a/Generals/Code/Tools/WorldBuilder/include/WHeightMapEdit.h +++ b/Generals/Code/Tools/WorldBuilder/include/WHeightMapEdit.h @@ -137,8 +137,8 @@ class WorldHeightMapEdit : public WorldHeightMap void showTileStatusInfo(); ///< pops up a dialog box with tile mem usage. - Bool selectDuplicates(); ///< Selects any dupicate map objects. - Bool selectSimilar(); ///< Selects any dupicate map objects. + Bool selectDuplicates(); ///< Selects any duplicate map objects. + Bool selectSimilar(); ///< Selects any duplicate map objects. Bool selectInvalidTeam(); ///< Selects any objects with invalid teams. Bool resize(Int newXSize, Int newYSize, Int newHeight, Int newBorder, Bool anchorTop, Bool anchorBottom, @@ -147,8 +147,6 @@ class WorldHeightMapEdit : public WorldHeightMap void reloadTextures(); ///< Reloads textures from disk. void resetResources(); ///< Releases textures in preparation for device reset. - Bool getRawTileData(Short tileNdx, Int width, UnsignedByte *buffer, Int bufLen); - void dbgVerifyAfterUndo(); ///< Verifies the structures are still consistent. Bool doCliffAdjustment(Int xIndex, Int yIndex); Bool removeCliffMapping(); diff --git a/Generals/Code/Tools/WorldBuilder/src/BorderTool.cpp b/Generals/Code/Tools/WorldBuilder/src/BorderTool.cpp index 73aa050139f..db1213e8e56 100644 --- a/Generals/Code/Tools/WorldBuilder/src/BorderTool.cpp +++ b/Generals/Code/Tools/WorldBuilder/src/BorderTool.cpp @@ -124,7 +124,7 @@ void BorderTool::mouseDown(TTrackingMode m, CPoint viewPt, WbView* pView, CWorld return; } - static Coord3D zero = {0.0f, 0.0f, 0.0f}; + //static Coord3D zero = {0.0f, 0.0f, 0.0f}; Coord3D groundPt; pView->viewToDocCoords(viewPt, &groundPt); @@ -138,10 +138,24 @@ void BorderTool::mouseDown(TTrackingMode m, CPoint viewPt, WbView* pView, CWorld Int motion; pDoc->findBoundaryNear(&groundPt, BOUNDARY_PICK_DISTANCE, &m_modifyBorderNdx, &motion); - if (motion == 0) { + + // if bottom left boundary grabbed + if (motion == 0) + { // modifying the bottom left is not allowed. m_modifyBorderNdx = -1; - } else { + } + // else if no boundary is near + else if (motion == -1) + { + // add a boundary + m_addingNewBorder = true; + + ICoord2D initialBoundary = { 1, 1 }; + pDoc->addBoundary(&initialBoundary); + } + else + { m_modificationType = (ModificationType) motion; } } diff --git a/Generals/Code/Tools/WorldBuilder/src/WHeightMapEdit.cpp b/Generals/Code/Tools/WorldBuilder/src/WHeightMapEdit.cpp index dad0e9a3217..0590c153156 100644 --- a/Generals/Code/Tools/WorldBuilder/src/WHeightMapEdit.cpp +++ b/Generals/Code/Tools/WorldBuilder/src/WHeightMapEdit.cpp @@ -43,6 +43,7 @@ #include "Common/DataChunk.h" + int WorldHeightMapEdit::m_numGlobalTextureClasses=0; TGlobalTextureClass WorldHeightMapEdit::m_globalTextureClasses[NUM_TEXTURE_CLASSES]; /** Destructor -. @@ -120,7 +121,7 @@ WorldHeightMapEdit::WorldHeightMapEdit(Int width, Int height, UnsignedByte initi // Note - we have one less cell than the width & height. But for paranoia, allocate // extra row. jba. // - Int numBytesX = (m_width+1)/8; //how many bytes to fit all bitflags + Int numBytesX = (m_width+7)/8; //how many bytes to fit all bitflags Int numBytesY = m_height; m_flipStateWidth=numBytesX; @@ -209,7 +210,7 @@ m_warnTooManyBlend(false) // Note - we have one less cell than the width & height. But for paranoia, allocate // extra row. jba. // - Int numBytesX = (m_width+1)/8; //how many bytes to fit all bitflags + Int numBytesX = (m_width+7)/8; //how many bytes to fit all bitflags Int numBytesY = m_height; m_flipStateWidth=numBytesX; @@ -433,8 +434,7 @@ void WorldHeightMapEdit::loadDirectoryOfImages(const char *pFilePath) FilenameList::iterator it = filenameList.begin(); do { AsciiString filename = *it; - - snprintf(fileBuf, ARRAY_SIZE(fileBuf), "%s%s", dirBuf, filename.str()); + strlcpy(fileBuf, filename.str(), ARRAY_SIZE(fileBuf)); loadBitmap(fileBuf, filename.str()); ++it; @@ -506,39 +506,6 @@ void WorldHeightMapEdit::loadImagesFromTerrainType( TerrainType *terrain ) } - -Bool WorldHeightMapEdit::getRawTileData(Short tileNdx, Int width, - UnsignedByte *buffer, Int bufLen) -{ - TileData *pSrc = nullptr; - if (tileNdx/4 < NUM_SOURCE_TILES) { - pSrc = m_sourceTiles[tileNdx/4]; - } - if (bufLen < (width*width*TILE_BYTES_PER_PIXEL)) { - return(false); - } - if (pSrc && pSrc->hasRGBDataForWidth(2*width)) { - Int j; - UnsignedByte *pSrcData = pSrc->getRGBDataForWidth(2*width); - Int xOffset=0; - Int yOffset=0; - if (tileNdx & 1) xOffset = width; - if (tileNdx & 2) yOffset = width; - for (j=0; j Date: Mon, 28 Sep 2026 17:42:23 +0300 Subject: [PATCH 2/2] bugfix(worldbuilder): Handle null boundary lookup output --- Generals/Code/Tools/WorldBuilder/src/WHeightMapEdit.cpp | 5 ++++- GeneralsMD/Code/Tools/WorldBuilder/src/WHeightMapEdit.cpp | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Generals/Code/Tools/WorldBuilder/src/WHeightMapEdit.cpp b/Generals/Code/Tools/WorldBuilder/src/WHeightMapEdit.cpp index 0590c153156..3951a78512a 100644 --- a/Generals/Code/Tools/WorldBuilder/src/WHeightMapEdit.cpp +++ b/Generals/Code/Tools/WorldBuilder/src/WHeightMapEdit.cpp @@ -3440,5 +3440,8 @@ void WorldHeightMapEdit::findBoundaryNear(Coord3D *pt, float okDistance, Int *ou } (*outNdx) = -1; - (*outHandle) = -1; + // TheSuperHackers @bugfix Handle an omitted boundary handle on the no-match path. + if (outHandle) { + (*outHandle) = -1; + } } diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/WHeightMapEdit.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/WHeightMapEdit.cpp index 65894c9fd2f..8bc79fe52f5 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/src/WHeightMapEdit.cpp +++ b/GeneralsMD/Code/Tools/WorldBuilder/src/WHeightMapEdit.cpp @@ -3440,5 +3440,8 @@ void WorldHeightMapEdit::findBoundaryNear(Coord3D *pt, float okDistance, Int *ou } (*outNdx) = -1; - (*outHandle) = -1; + // TheSuperHackers @bugfix Handle an omitted boundary handle on the no-match path. + if (outHandle) { + (*outHandle) = -1; + } }