Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions Generals/Code/Tools/WorldBuilder/include/WHeightMapEdit.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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();
Expand Down
20 changes: 17 additions & 3 deletions Generals/Code/Tools/WorldBuilder/src/BorderTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}
}
Expand Down
75 changes: 31 additions & 44 deletions Generals/Code/Tools/WorldBuilder/src/WHeightMapEdit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@

#include "Common/DataChunk.h"


int WorldHeightMapEdit::m_numGlobalTextureClasses=0;
TGlobalTextureClass WorldHeightMapEdit::m_globalTextureClasses[NUM_TEXTURE_CLASSES];
/** Destructor -.
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<width; j++) {
UnsignedByte *pDestData = buffer;
pDestData += j*(width)*TILE_BYTES_PER_PIXEL;
UnsignedByte *pSrc = pSrcData;
pSrc += (j+yOffset)*width*TILE_BYTES_PER_PIXEL*2;
pSrc += xOffset*TILE_BYTES_PER_PIXEL;
memcpy(pDestData, pSrc, width*TILE_BYTES_PER_PIXEL);
}
return(true);
}
return(false);
}



UnsignedByte * WorldHeightMapEdit::getPointerToClassTileData(Int texClass)
{
TileData *pSrc = nullptr;
Expand Down Expand Up @@ -633,13 +600,28 @@ void WorldHeightMapEdit::saveToFile(DataChunkOutput &chunkWriter)
chunkWriter.closeDataChunk();

/***************BLEND TILE DATA ***************/
chunkWriter.openDataChunk("BlendTileData", K_BLEND_TILE_VERSION_7);
#if RTS_GENERALS && RETAIL_COMPATIBLE_DATA
const DataChunkVersionType blendTileVersion = K_BLEND_TILE_VERSION_7;
#else
const DataChunkVersionType blendTileVersion = K_BLEND_TILE_VERSION_8;
#endif
chunkWriter.openDataChunk("BlendTileData", blendTileVersion);
chunkWriter.writeInt(m_dataSize);
chunkWriter.writeArrayOfBytes((char*)m_tileNdxes, m_dataSize*sizeof(Short));
chunkWriter.writeArrayOfBytes((char*)m_blendTileNdxes, m_dataSize*sizeof(Short));
chunkWriter.writeArrayOfBytes((char*)m_extraBlendTileNdxes, m_dataSize*sizeof(Short));
chunkWriter.writeArrayOfBytes((char*)m_cliffInfoNdxes, m_dataSize*sizeof(Short));
chunkWriter.writeArrayOfBytes((char*)m_cellCliffState, m_height*m_flipStateWidth);
if (blendTileVersion >= K_BLEND_TILE_VERSION_7) {
if (blendTileVersion == K_BLEND_TILE_VERSION_7) {
// Version 7 uses the legacy row width, even when the in-memory rows are wider.
Int byteWidth = (m_width+1)/8;
for (Int j=0; j<m_height; j++) {
chunkWriter.writeArrayOfBytes((char*)m_cellCliffState + j*m_flipStateWidth, byteWidth);
}
} else {
chunkWriter.writeArrayOfBytes((char*)m_cellCliffState, m_height*m_flipStateWidth);
}
}
chunkWriter.writeInt(m_numBitmapTiles);
chunkWriter.writeInt(m_numBlendedTiles);
chunkWriter.writeInt(m_numCliffInfo);
Expand Down Expand Up @@ -1133,7 +1115,7 @@ void WorldHeightMapEdit::blendSpecificTiles(Int xIndex, Int yIndex, Int srcXInde
blendInfo.customBlendEdgeClass = edgeClass;

//Check if there is already a blend tile at the destination and record its flip state.
//We need to know this so that we don't accidentally apply a third blend layer with with
//We need to know this so that we don't accidentally apply a third blend layer with
//a different flip and introduce z-fighting over this tile.
Bool baseNeedsFlip = false;
UnsignedByte baseIsDiagonal = 0;
Expand Down Expand Up @@ -1207,7 +1189,13 @@ void WorldHeightMapEdit::blendSpecificTiles(Int xIndex, Int yIndex, Int srcXInde
//force the primary layer to flip if the extra blend layer needs flip.
//we only do this on vertical/horizontal base blends because they work in either flip cases.
if (flipped && !baseIsDiagonal)
m_blendedTiles[m_blendTileNdxes[ndx]].inverted |= FLIPPED_MASK;
{
//Find a new tile so as not to affect other cells using the base one.
TBlendTileInfo tempBlendTileInfo=m_blendedTiles[m_blendTileNdxes[ndx]];
tempBlendTileInfo.inverted |= FLIPPED_MASK;
Short newNdx = findOrCreateBlendTile(&tempBlendTileInfo);
m_blendTileNdxes[ndx] = newNdx; //remap this tile to use a new one.
}
}
else
m_blendTileNdxes[ndx] = newNdx;
Expand Down Expand Up @@ -1895,7 +1883,7 @@ Bool WorldHeightMapEdit::resize(Int newXSize, Int newYSize, Int newHeight, Int n
m_dataSize = newDataSize;
delete(m_cellCliffState);
delete(m_cellFlipState);
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
m_flipStateWidth=numBytesX;

m_cellFlipState = MSGNEW("WorldHeightMapEdit::resize") UnsignedByte[numBytesX*m_height];
Expand Down Expand Up @@ -3454,6 +3442,5 @@ void WorldHeightMapEdit::findBoundaryNear(Coord3D *pt, float okDistance, Int *ou
}

(*outNdx) = -1;
(*outHandle) = -1;
Comment thread
xezon marked this conversation as resolved.
}


19 changes: 17 additions & 2 deletions GeneralsMD/Code/Tools/WorldBuilder/src/WHeightMapEdit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -600,13 +600,28 @@ void WorldHeightMapEdit::saveToFile(DataChunkOutput &chunkWriter)
chunkWriter.closeDataChunk();

/***************BLEND TILE DATA ***************/
chunkWriter.openDataChunk("BlendTileData", K_BLEND_TILE_VERSION_8);
#if RTS_GENERALS && RETAIL_COMPATIBLE_DATA
const DataChunkVersionType blendTileVersion = K_BLEND_TILE_VERSION_7;
#else
const DataChunkVersionType blendTileVersion = K_BLEND_TILE_VERSION_8;
#endif
chunkWriter.openDataChunk("BlendTileData", blendTileVersion);
chunkWriter.writeInt(m_dataSize);
chunkWriter.writeArrayOfBytes((char*)m_tileNdxes, m_dataSize*sizeof(Short));
chunkWriter.writeArrayOfBytes((char*)m_blendTileNdxes, m_dataSize*sizeof(Short));
chunkWriter.writeArrayOfBytes((char*)m_extraBlendTileNdxes, m_dataSize*sizeof(Short));
chunkWriter.writeArrayOfBytes((char*)m_cliffInfoNdxes, m_dataSize*sizeof(Short));
chunkWriter.writeArrayOfBytes((char*)m_cellCliffState, m_height*m_flipStateWidth);
if (blendTileVersion >= K_BLEND_TILE_VERSION_7) {
if (blendTileVersion == K_BLEND_TILE_VERSION_7) {
// Version 7 uses the legacy row width, even when the in-memory rows are wider.
Int byteWidth = (m_width+1)/8;
for (Int j=0; j<m_height; j++) {
chunkWriter.writeArrayOfBytes((char*)m_cellCliffState + j*m_flipStateWidth, byteWidth);
}
} else {
chunkWriter.writeArrayOfBytes((char*)m_cellCliffState, m_height*m_flipStateWidth);
}
}
chunkWriter.writeInt(m_numBitmapTiles);
chunkWriter.writeInt(m_numBlendedTiles);
chunkWriter.writeInt(m_numCliffInfo);
Expand Down
Loading