Skip to content

Commit ed7e96f

Browse files
authored
unify(shroud): Merge W3DShroud code from Zero Hour and implicitly fix black terrain for one frame on far camera jumps (TheSuperHackers#2757)
1 parent d7f7203 commit ed7e96f

1 file changed

Lines changed: 19 additions & 5 deletions

File tree

  • Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient

Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DShroud.cpp

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,19 +120,24 @@ void W3DShroud::init(WorldHeightMap *pMap, Real worldCellSizeX, Real worldCellSi
120120
//Precompute a bounding box for entire shroud layer
121121
if (pMap)
122122
{
123-
m_numCellsX = REAL_TO_INT_CEIL((Real)(pMap->getXExtent() - 1 - pMap->getBorderSize()*2)*MAP_XY_FACTOR/m_cellWidth);
124-
m_numCellsY = REAL_TO_INT_CEIL((Real)(pMap->getYExtent() - 1 - pMap->getBorderSize()*2)*MAP_XY_FACTOR/m_cellHeight);
123+
m_numCellsX = REAL_TO_INT_CEIL((Real)(pMap->getXExtent() - 1 - pMap->getBorderSizeInline()*2)*MAP_XY_FACTOR/m_cellWidth);
124+
m_numCellsY = REAL_TO_INT_CEIL((Real)(pMap->getYExtent() - 1 - pMap->getBorderSizeInline()*2)*MAP_XY_FACTOR/m_cellHeight);
125125

126126
//Maximum visible cells will depend on maximum drawable terrain size plus 1 for partial cells (since
127127
//shroud cells are larger than terrain cells).
128128
dstTextureWidth=m_numMaxVisibleCellsX=REAL_TO_INT_FLOOR((Real)(pMap->getDrawWidth()-1)*MAP_XY_FACTOR/m_cellWidth)+1;
129129
dstTextureHeight=m_numMaxVisibleCellsY=REAL_TO_INT_FLOOR((Real)(pMap->getDrawHeight()-1)*MAP_XY_FACTOR/m_cellHeight)+1;
130+
131+
dstTextureWidth = m_numCellsX;
132+
dstTextureHeight = m_numCellsY;
133+
130134
dstTextureWidth += 2; //enlarge by 2 pixels so we can have a border color all the way around.
131135
unsigned int depth = 1;
132136
dstTextureHeight += 2; //enlarge by 2 pixels so we can have border color all the way around.
133137
TextureLoader::Validate_Texture_Size((unsigned int &)dstTextureWidth,(unsigned int &)dstTextureHeight, depth);
134138
}
135139

140+
136141
UnsignedInt srcWidth,srcHeight;
137142

138143
srcWidth=m_numCellsX;
@@ -225,7 +230,7 @@ void W3DShroud::ReleaseResources()
225230
Bool W3DShroud::ReAcquireResources()
226231
{
227232
if (!m_dstTextureWidth)
228-
return TRUE; //nothing to reaquire since shroud was never initialized with valid data
233+
return TRUE; //nothing to reacquire since shroud was never initialized with valid data
229234

230235
DEBUG_ASSERTCRASH( m_pDstTexture == nullptr, ("ReAcquire of existing shroud texture"));
231236

@@ -613,15 +618,24 @@ void W3DShroud::render(CameraClass *cam)
613618

614619

615620
WorldHeightMap *hm=TheTerrainRenderObject->getMap();
616-
Int visStartX=REAL_TO_INT_FLOOR((Real)(hm->getDrawOrgX()-hm->getBorderSize())*MAP_XY_FACTOR/m_cellWidth); //start of rendered heightmap rectangle
621+
Int visStartX=REAL_TO_INT_FLOOR((Real)(hm->getDrawOrgX()-hm->getBorderSizeInline())*MAP_XY_FACTOR/m_cellWidth); //start of rendered heightmap rectangle
617622
if (visStartX < 0)
618623
visStartX = 0; //no shroud is applied in border area so it always starts at > 0
619-
Int visStartY=REAL_TO_INT_FLOOR((Real)(hm->getDrawOrgY()-hm->getBorderSize())*MAP_XY_FACTOR/m_cellHeight);
624+
Int visStartY=REAL_TO_INT_FLOOR((Real)(hm->getDrawOrgY()-hm->getBorderSizeInline())*MAP_XY_FACTOR/m_cellHeight);
620625
if (visStartY < 0)
621626
visStartY = 0; //no shroud is applied in border area so it always starts at > 0
627+
628+
// Do it all [3/11/2003]
629+
visStartX = 0;
630+
visStartY = 0;
631+
622632
Int visEndX=visStartX+REAL_TO_INT_FLOOR((Real)(hm->getDrawWidth()-1)*MAP_XY_FACTOR/m_cellWidth)+1; //size of rendered heightmap rectangle
623633
Int visEndY=visStartY+REAL_TO_INT_FLOOR((Real)(hm->getDrawHeight()-1)*MAP_XY_FACTOR/m_cellHeight)+1;
624634

635+
// Do it all [3/11/2003]
636+
visEndX = m_numCellsX;
637+
visEndY = m_numCellsY;
638+
625639
if (visEndX > m_numCellsX)
626640
{
627641
visStartX -= visEndX - m_numCellsX; //shift visible rectangle to fall within terrain bounds

0 commit comments

Comments
 (0)