From 76472eed0a0beb430ccbf212228bf476e66bd2b1 Mon Sep 17 00:00:00 2001 From: Sevenfm Date: Wed, 12 Jan 2022 16:09:10 +0000 Subject: [PATCH] Separated cover view area update from RemoveCoverObjectsFromViewArea() into its own function to make it more explicit when and where we do it (by Asdow). git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@9253 3b4a5df2-a311-0410-b5c6-a8a6f20db521 --- Tactical/DisplayCover.cpp | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/Tactical/DisplayCover.cpp b/Tactical/DisplayCover.cpp index 388fceca..82a42c0d 100644 --- a/Tactical/DisplayCover.cpp +++ b/Tactical/DisplayCover.cpp @@ -381,9 +381,6 @@ BOOLEAN HasAdjTile( const INT32& ubX, const INT32& ubY, const INT32& ubZ ) void AddCoverObjectsToViewArea() { - if ( gsMaxCellY < 0 ) - return; - register INT32 ubX, ubY, ubZ; BOOLEAN fChanged = FALSE; @@ -416,21 +413,6 @@ void RemoveCoverObjectsFromViewArea() if ( gubDrawMode == DRAW_MODE_OFF && gNoRedraw ) return; - // Not needed for removing cover objects anymore, but this is the only place where we update the global gsMin & gsMaxCell variables and they're needed for adding cover objects. - INT16 usTmp; - GetScreenXYWorldCell( gsVIEWPORT_START_X, gsVIEWPORT_START_Y, &gsMinCellX, &usTmp ); - GetScreenXYWorldCell( gsVIEWPORT_END_X, gsVIEWPORT_END_Y, &gsMaxCellX, &usTmp ); - - GetScreenXYWorldCell( gsVIEWPORT_END_X, gsVIEWPORT_START_Y, &usTmp, &gsMinCellY ); - GetScreenXYWorldCell( gsVIEWPORT_START_X, gsVIEWPORT_END_Y, &usTmp, &gsMaxCellY ); - - // Flugente: hey, wouldn't it be cool if we DIDN'T access an array with implausible values? - gsMinCellX = max( 0, gsMinCellX ); - gsMaxCellX = min( COVER_X_CELLS, gsMaxCellX ); - gsMinCellY = max( 0, gsMinCellY ); - gsMaxCellY = min( COVER_Y_CELLS, gsMaxCellY ); - - // Go through the whole gCoverViewArea when removing cover objects. Otherwise we don't clean up tiles that are not in the viewport which results in an annoying visual bug. register INT32 ubX, ubY, ubZ; BOOLEAN fChanged = FALSE; @@ -467,6 +449,22 @@ void RemoveCoverObjectsFromViewArea() gNoRedraw = (gubDrawMode == DRAW_MODE_OFF); } +void updateCoverViewArea() +{ + INT16 usTmp; + GetScreenXYWorldCell(gsVIEWPORT_START_X, gsVIEWPORT_START_Y, &gsMinCellX, &usTmp); + GetScreenXYWorldCell(gsVIEWPORT_END_X, gsVIEWPORT_END_Y, &gsMaxCellX, &usTmp); + + GetScreenXYWorldCell(gsVIEWPORT_END_X, gsVIEWPORT_START_Y, &usTmp, &gsMinCellY); + GetScreenXYWorldCell(gsVIEWPORT_START_X, gsVIEWPORT_END_Y, &usTmp, &gsMaxCellY); + + // Sanity check because of array access + gsMinCellX = max(0, gsMinCellX); + gsMaxCellX = min(COVER_X_CELLS, gsMaxCellX); + gsMinCellY = max(0, gsMinCellY); + gsMaxCellY = min(COVER_Y_CELLS, gsMaxCellY); +} + // ubRadius in times of y or x cell sizes BOOLEAN GridNoOnScreenAndAround( const INT32& sGridNo, const UINT8& ubRadius ) { @@ -501,6 +499,7 @@ void DisplayCover( BOOLEAN forceUpdate ) { // remove old cover objects RemoveCoverObjectsFromViewArea(); + updateCoverViewArea(); switch ( gubDrawMode ) {