From de91c7a9fdbdd0e57f99e19d393c8f804d666908 Mon Sep 17 00:00:00 2001 From: Asdow <20314541+Asdow@users.noreply.github.com> Date: Sun, 18 Feb 2024 12:30:46 +0200 Subject: [PATCH] Render debug info in tactical Functionality for rendering pathfinding and cover values in tactical was behind defunct #ifdefs. It's now compiled always, but only enabled if cheat level is BEDUG_CHEAT_LEVEL. Unified rendering the debug info into one function, instead of several nearly identical ones. Ctrl + Shift + Z cycles through the different debug modes. Now it should be fairly easy to add more info modes like these two in the future. --- Tactical/Handle UI.cpp | 53 +++++- Tactical/Handle UI.h | 4 +- Tactical/PATHAI.cpp | 135 ++++----------- Tactical/Turn Based Input.cpp | 25 +++ TacticalAI/FindLocations.cpp | 63 ++----- TacticalAI/ai.h | 4 - TileEngine/renderworld.cpp | 313 +++++++++++++++++----------------- TileEngine/renderworld.h | 12 +- TileEngine/worlddef.cpp | 14 +- 9 files changed, 301 insertions(+), 322 deletions(-) diff --git a/Tactical/Handle UI.cpp b/Tactical/Handle UI.cpp index e4243381..9aa9fc8f 100644 --- a/Tactical/Handle UI.cpp +++ b/Tactical/Handle UI.cpp @@ -87,7 +87,7 @@ #include "SaveLoadScreen.h" #include "Map Screen Interface.h" // added by Flugente for SquadNames #include "Keys.h" // added by silversurfer for door handling from the side - +#include "Cheats.h" #include "AIInternals.h" extern BOOLEAN gubWorldTileInLight[MAX_ALLOWED_WORLD_MAX]; extern BOOLEAN gubIsCorpseThere[MAX_ALLOWED_WORLD_MAX]; @@ -386,7 +386,7 @@ BOOLEAN gfDisplayTimerCursor = FALSE; UINT32 guiTimerCursorID = 0; UINT32 guiTimerLastUpdate = 0; UINT32 guiTimerCursorDelay = 0; - +UINT8 gRenderDebugInfoMode = DEBUG_OFF; CHAR16 gzLocation[ 20 ]; BOOLEAN gfLocation = FALSE; @@ -518,6 +518,54 @@ void GetMercOknoDirection( UINT8 ubSoldierID, BOOLEAN *pfGoDown, BOOLEAN *pfGoUp } //---------------------------------------------------------------------------------- +void HandleRenderDebugInfoModes() +{ + if (DEBUG_CHEAT_LEVEL()) + { + switch (gRenderDebugInfoMode) + { + case DEBUG_PATHFINDING: + // Nothing to do here, pathfinding info is filled in the pathing functions. + break; + case DEBUG_THREATVALUE: + break; + case DEBUG_COVERVALUE: + // Calculate cover values for pSoldier under cursor, or for currently selected merc, if nobody is under the cursor. + if (gTacticalStatus.Team[OUR_TEAM].bTeamActive) + { + static SOLDIERTYPE* previousSoldier = nullptr; + static INT32 previousLocation = NOWHERE; + static UINT8 previousStance = 0; + + UINT16 usSoldierIndex = NOBODY; + UINT32 uiMercFlags; + FindSoldierFromMouse(&usSoldierIndex, &uiMercFlags); + if (usSoldierIndex == NOBODY) + { + usSoldierIndex = gusSelectedSoldier; + } + + if (usSoldierIndex != NOBODY) + { + // Get Soldier + INT32 iPercentBetter; + SOLDIERTYPE* pSoldier; + GetSoldier(&pSoldier, usSoldierIndex); + if (previousSoldier != pSoldier || previousLocation != pSoldier->sGridNo || previousStance != gAnimControl[pSoldier->usAnimState].ubEndHeight) + { + FindBestNearbyCover(pSoldier, pSoldier->aiData.bAIMorale, &iPercentBetter); + previousSoldier = pSoldier; + previousLocation = pSoldier->sGridNo; + previousStance = gAnimControl[pSoldier->usAnimState].ubEndHeight; + } + } + } + break; + default: // off + break; + } + } +} void PreventFromTheFreezingBug(SOLDIERTYPE* pSoldier) { @@ -691,6 +739,7 @@ UINT32 HandleTacticalUI( void ) } } + HandleRenderDebugInfoModes(); // Check if current event has changed and clear event if so, to prepare it for execution // Clearing it does things like set first time flag, param variables, etc if ( uiNewEvent != guiOldEvent ) diff --git a/Tactical/Handle UI.h b/Tactical/Handle UI.h index 5937d911..bdcc6a1f 100644 --- a/Tactical/Handle UI.h +++ b/Tactical/Handle UI.h @@ -296,6 +296,8 @@ extern BOOLEAN gfUIForceReExamineCursorData; extern INT16 guiCreateGuyIndex; extern INT16 guiCreateBadGuyIndex; +extern UINT8 gRenderDebugInfoMode; + // WANNE: Calculate the APs to turn around INT16 APsToTurnAround(SOLDIERTYPE *pSoldier, INT32 sAdjustedGridNo); @@ -382,4 +384,4 @@ void GetGridNoScreenXY( INT32 sGridNo, INT16 *pScreenX, INT16 *pScreenY ); //Legion by Jazz void GetMercOknoDirection( UINT8 ubSoldierID, BOOLEAN *pfGoDown, BOOLEAN *pfGoUp ); -#endif \ No newline at end of file +#endif diff --git a/Tactical/PATHAI.cpp b/Tactical/PATHAI.cpp index 02a8067d..882c6e47 100644 --- a/Tactical/PATHAI.cpp +++ b/Tactical/PATHAI.cpp @@ -25,7 +25,7 @@ #include "english.h" #include "worlddef.h" #include "worldman.h" -// #include "renderworld.h" + #include "renderworld.h" #include "pathai.h" #include "Points.h" #include "ai.h" @@ -41,7 +41,7 @@ #include "Rotting Corpses.h" #include "Meanwhile.h" #include "connect.h" - +#include #include "LOS.h" //ddd //forward declarations of common classes to eliminate includes @@ -66,19 +66,8 @@ extern BOOLEAN InGasSpot(SOLDIERTYPE *pSoldier, INT32 sGridNo, INT8 bLevel); // skiplist has extra level of pointers every 4 elements, so a level 5is optimized for // 4 to the power of 5 elements, or 2 to the power of 10, 1024 -//#define PATHAI_VISIBLE_DEBUG //#define PATHAI_SKIPLIST_DEBUG - -#ifdef PATHAI_VISIBLE_DEBUG - #include "video.h" - -//extern INT16 gsCoverValue[WORLD_MAX]; -extern INT16 * gsCoverValue; - BOOLEAN gfDisplayCoverValues = TRUE; - BOOLEAN gfDrawPathPoints = TRUE; -#endif - BOOLEAN gfPlotPathToExitGrid = FALSE; BOOLEAN gfRecalculatingExistingPathCost = FALSE; UINT8 gubGlobalPathFlags = 0; @@ -623,15 +612,12 @@ int AStarPathfinder::GetPath(SOLDIERTYPE *s , } - -#if defined( PATHAI_VISIBLE_DEBUG ) - if (gfDisplayCoverValues && gfDrawPathPoints) + if (gRenderDebugInfoMode == DEBUG_PATHFINDING && DEBUG_CHEAT_LEVEL()) { - memset( gsCoverValue, 0x7F, sizeof( INT16 ) * WORLD_MAX ); + ResetDebugInfoValues(); + gRenderDebugInfoValues[ StartNode ] = 0; + PATHAI_VISIBLE_DEBUG_Counter = 1; } - gsCoverValue[ StartNode ] = 0; - PATHAI_VISIBLE_DEBUG_Counter = 1; -#endif //init other private data, mostly flags endDir = lastDir = direction = startDir = 0; @@ -796,12 +782,10 @@ int AStarPathfinder::GetPath(SOLDIERTYPE *s , return 0; } -#if defined( PATHAI_VISIBLE_DEBUG ) - if (gfDisplayCoverValues && gfDrawPathPoints) + if (gRenderDebugInfoMode == DEBUG_PATHFINDING && DEBUG_CHEAT_LEVEL()) { SetRenderFlags( RENDER_FLAG_FULL ); } -#endif // Count the number of steps, but keep it less than the max path length. // Adjust the parent until it begins at the tail end of the max path length (or the dest if reachable) @@ -884,12 +868,10 @@ int AStarPathfinder::GetPath(SOLDIERTYPE *s , sizePath = giPathDataSize; } -#if defined( PATHAI_VISIBLE_DEBUG ) - if (gfDisplayCoverValues && gfDrawPathPoints) + if (gRenderDebugInfoMode == DEBUG_PATHFINDING && DEBUG_CHEAT_LEVEL()) { SetRenderFlags( RENDER_FLAG_FULL ); } -#endif #ifdef COUNT_PATHS guiSuccessfulPathChecks++; @@ -1001,15 +983,13 @@ void AStarPathfinder::ExecuteAStarLogic() SetAStarStatus(ParentNode, AStar_Closed); //ClosedList.push_back(ParentNode); -#if defined( PATHAI_VISIBLE_DEBUG ) - if (gfDisplayCoverValues && gfDrawPathPoints) + if (gRenderDebugInfoMode == DEBUG_PATHFINDING && DEBUG_CHEAT_LEVEL()) { - if (gsCoverValue[ ParentNode ] > 0) + if (gRenderDebugInfoValues[ParentNode] > 0) { - gsCoverValue[ ParentNode ] *= -1; + gRenderDebugInfoValues[ParentNode] *= -1; } } -#endif // Shouldn't G and AP be the same thing? INT16 baseGCost = GetAStarG(ParentNode); @@ -1092,7 +1072,7 @@ void AStarPathfinder::ExecuteAStarLogic() gpWorldLevelData[ CurrentNode ].ubExtFlags[0] |= MAPELEMENT_EXT_CLIMBPOINT; gpWorldLevelData[ ParentNode ].ubExtFlags[1] |= MAPELEMENT_EXT_CLIMBPOINT; #ifdef ROOF_DEBUG - gsCoverValue[CurrentNode] = 1; + gRenderDebugInfoValues[CurrentNode] = 1; #endif } @@ -1190,26 +1170,13 @@ void AStarPathfinder::ExecuteAStarLogic() int AStarH = CalcH(); int AStarF = (AStarG + extraGCoverCost) + AStarH; -#if defined( PATHAI_VISIBLE_DEBUG ) - if (gfDisplayCoverValues && gfDrawPathPoints) + if (gRenderDebugInfoMode == DEBUG_PATHFINDING && DEBUG_CHEAT_LEVEL()) { - if (gsCoverValue[CurrentNode] == 0x7F7F) + if (gRenderDebugInfoValues[CurrentNode] == 0x7FFFFFFF) { - //gsCoverValue[CurrentNode] = PATHAI_VISIBLE_DEBUG_Counter++; - gsCoverValue[CurrentNode] = (INT16) AStarF; + gRenderDebugInfoValues[CurrentNode] = (INT16) AStarF; } - /* - else if (gsCoverValue[CurrentNodeIndex] >= 0) - { - gsCoverValue[CurrentNodeIndex]++; - } - else - { - gsCoverValue[CurrentNodeIndex]--; - } - */ } -#endif //insert this node onto the heap if (GetAStarStatus(CurrentNode) == AStar_Init) @@ -2260,9 +2227,7 @@ INT32 FindBestPath(SOLDIERTYPE *s , INT32 sDestination, INT8 bLevel, INT16 usMov CHAR8 zTempString[1000], zTS[50]; #endif -#ifdef PATHAI_VISIBLE_DEBUG UINT16 usCounter = 0; -#endif fVehicle = FALSE; iOriginationX = iOriginationY = 0; @@ -2512,12 +2477,10 @@ if(!GridNoOnVisibleWorldTile(iDestination)) memset( pathQ, 0, iMaxPathQ * sizeof( path_t ) ); memset( trailTree, 0, iMaxTrailTree * sizeof( trail_t ) ); -#if defined( PATHAI_VISIBLE_DEBUG ) - if (gfDisplayCoverValues && gfDrawPathPoints) + if (gRenderDebugInfoMode == DEBUG_PATHFINDING && DEBUG_CHEAT_LEVEL()) { - memset( gsCoverValue, 0x7F, sizeof( INT16 ) * WORLD_MAX ); + ResetDebugInfoValues(); } -#endif bSkipListLevel = 1; iSkipListSize = 0; @@ -2629,15 +2592,13 @@ if(!GridNoOnVisibleWorldTile(iDestination)) // remember the cost used to get here... prevCost = gubWorldMovementCosts[ trailTree[ sCurPathNdx ].sGridNo ][ trailTree[ sCurPathNdx ].stepDir ][ bLevel ]; -#if defined( PATHAI_VISIBLE_DEBUG ) - if (gfDisplayCoverValues && gfDrawPathPoints) + if (gRenderDebugInfoMode == DEBUG_PATHFINDING && DEBUG_CHEAT_LEVEL()) { - if (gsCoverValue[ curLoc ] > 0) + if (gRenderDebugInfoValues[ curLoc ] > 0) { - gsCoverValue[ curLoc ] *= -1; + gRenderDebugInfoValues[ curLoc ] *= -1; } } -#endif /* if (fTurnSlow) @@ -3563,27 +3524,13 @@ if(!GridNoOnVisibleWorldTile(iDestination)) // costs less than the best so far to the same location? if (trailCostUsed[newLoc] != gubGlobalPathCount || newTotCost < trailCost[newLoc]) { - - #if defined( PATHAI_VISIBLE_DEBUG ) - - if (gfDisplayCoverValues && gfDrawPathPoints) - { - if (gsCoverValue[newLoc] == 0x7F7F) + if (gRenderDebugInfoMode == DEBUG_PATHFINDING && DEBUG_CHEAT_LEVEL()) + { + if (gRenderDebugInfoValues[newLoc] == 0x7FFFFFFF) { - gsCoverValue[newLoc] = usCounter++; + gRenderDebugInfoValues[newLoc] = usCounter++; } - /* - else if (gsCoverValue[newLoc] >= 0) - { - gsCoverValue[newLoc]++; - } - else - { - gsCoverValue[newLoc]--; - } - */ - } - #endif + } //NEWQUENODE; { @@ -3826,20 +3773,13 @@ ENDOFLOOP: while (pathQNotEmpty && pathNotYetFound); - #if defined( PATHAI_VISIBLE_DEBUG ) - if (gfDisplayCoverValues && gfDrawPathPoints) + if (gRenderDebugInfoMode == DEBUG_PATHFINDING && DEBUG_CHEAT_LEVEL()) + { + if ( guiCurrentScreen == GAME_SCREEN ) { - SetRenderFlags( RENDER_FLAG_FULL ); - if ( guiCurrentScreen == GAME_SCREEN ) - { - RenderWorld(); - RenderCoverDebug( ); - InvalidateScreen( ); - EndFrameBufferRender(); - RefreshScreen( NULL ); - } + InvalidateRegion(gsVIEWPORT_START_X, gsVIEWPORT_START_Y, gsVIEWPORT_END_X, gsVIEWPORT_WINDOW_END_Y); } - #endif + } // work finished. Did we find a path? @@ -3894,17 +3834,10 @@ ENDOFLOOP: } - #if defined( PATHAI_VISIBLE_DEBUG ) - if (gfDisplayCoverValues && gfDrawPathPoints) - { - SetRenderFlags( RENDER_FLAG_FULL ); - RenderWorld(); - RenderCoverDebug( ); - InvalidateScreen( ); - EndFrameBufferRender(); - RefreshScreen( NULL ); - } - #endif + if (gRenderDebugInfoMode == DEBUG_PATHFINDING && DEBUG_CHEAT_LEVEL()) + { + InvalidateRegion(gsVIEWPORT_START_X, gsVIEWPORT_START_Y, gsVIEWPORT_END_X, gsVIEWPORT_WINDOW_END_Y); + } // return path length : serves as a "successful" flag and a path length counter diff --git a/Tactical/Turn Based Input.cpp b/Tactical/Turn Based Input.cpp index abc77380..3e71b683 100644 --- a/Tactical/Turn Based Input.cpp +++ b/Tactical/Turn Based Input.cpp @@ -1700,6 +1700,24 @@ void ItemCreationCallBack( UINT8 ubResult ) memset(gszMsgBoxInputString,0,sizeof(gszMsgBoxInputString)); } +static void CycleThroughTileDebugInfo() +{ + const STR16 modeStrings[] = + { + L"Pathfinding", + L"Threat values", + L"Cover values", + L"Off", + }; + + gRenderDebugInfoMode += 1; + if (gRenderDebugInfoMode > DEBUG_OFF) + { + gRenderDebugInfoMode = 0; + } + ScreenMsg(FONT_MCOLOR_LTYELLOW, MSG_INTERFACE, modeStrings[gRenderDebugInfoMode]); +} + extern BOOLEAN gfDisableRegionActive; extern BOOLEAN gfUserTurnRegionActive; @@ -4763,6 +4781,13 @@ void GetKeyboardInput( UINT32 *puiNewEvent ) break; case 'Z': + if (fCtrl) + { + if (DEBUG_CHEAT_LEVEL()) + { + CycleThroughTileDebugInfo(); + } + } break; } diff --git a/TacticalAI/FindLocations.cpp b/TacticalAI/FindLocations.cpp index 33faab03..02f1f5ab 100644 --- a/TacticalAI/FindLocations.cpp +++ b/TacticalAI/FindLocations.cpp @@ -15,10 +15,7 @@ #include "Render Fun.h" #include "Boxing.h" #include "Text.h" - #ifdef _DEBUG - #include "renderworld.h" - #include "video.h" - #endif + #include "renderworld.h" #include "worldman.h" #include "strategicmap.h" #include "environment.h" @@ -27,6 +24,7 @@ #include "GameSettings.h" #include "Soldier Profile.h" #include "rotting corpses.h" // sevenfm +#include //////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -34,17 +32,7 @@ // were changed to GetAPsCrouch() and GetAPsProne() // - also all "APBPConstants[AP_PICKUP_ITEM]" were replaced by GetBasicAPsToPickupItem() //////////////////////////////////////////////////////////////////////////////////////////////////////// - - INT16 * gsCoverValue = NULL; -#ifdef _DEBUG - - INT16 gsBestCover; - #ifndef PATHAI_VISIBLE_DEBUG - // NB Change this to true to get visible cover debug -- CJC - BOOLEAN gfDisplayCoverValues = FALSE; - #endif - extern void RenderCoverDebug( void ); -#endif +INT16 gsBestCover; INT16 gubAIPathCosts[19][19]; @@ -693,6 +681,11 @@ static void CalculateCoverValue(SOLDIERTYPE* pSoldier, const INT32 sGridNo, cons INT32 FindBestNearbyCover(SOLDIERTYPE *pSoldier, INT32 morale, INT32 *piPercentBetter, INT32 targetGridNo) { + if (gRenderDebugInfoMode == DEBUG_COVERVALUE && DEBUG_CHEAT_LEVEL()) + { + ResetDebugInfoValues(); + } + DebugMsg(TOPIC_JA2AI,DBG_LEVEL_3,String("FindBestNearbyCover")); // all 32-bit integers for max. speed @@ -761,12 +754,6 @@ INT32 FindBestNearbyCover(SOLDIERTYPE *pSoldier, INT32 morale, INT32 *piPercentB iBestCoverValue = -1; -#if defined( _DEBUG ) && defined( COVER_DEBUG ) - if (gfDisplayCoverValues) - { - memset( gsCoverValue, 0x7F, sizeof( INT16 ) * WORLD_MAX ); - } -#endif //NameMessage(pSoldier,"looking for some cover..."); @@ -850,6 +837,11 @@ INT32 FindBestNearbyCover(SOLDIERTYPE *pSoldier, INT32 morale, INT32 *piPercentB // cover we are searching for must be better than what we have now! CalculateCoverValue(pSoldier, targetGridNo, 0, iMyThreatValue, uiThreatCnt, ubDiff, fNight, ubBackgroundLightPercent, morale, iCurrentCoverValue, iCurrentScale); + if (gRenderDebugInfoMode == DEBUG_COVERVALUE && DEBUG_CHEAT_LEVEL()) + { + gRenderDebugInfoValues[targetGridNo] = (INT32)(iCurrentCoverValue / 100); + } + #ifdef DEBUGCOVER // AINumMessage("Search Range = ",iSearchRange); #endif @@ -1057,12 +1049,10 @@ INT32 FindBestNearbyCover(SOLDIERTYPE *pSoldier, INT32 morale, INT32 *piPercentB } #endif -#if defined( _DEBUG ) && defined( COVER_DEBUG ) - if (gfDisplayCoverValues) + if (gRenderDebugInfoMode == DEBUG_COVERVALUE && DEBUG_CHEAT_LEVEL()) { - gsCoverValue[sGridNo] = (INT16) (iCoverValue / 100); + gRenderDebugInfoValues[sGridNo] = (INT32) (iCoverValue / 100); } -#endif // if this is better than the best place found so far @@ -1099,34 +1089,15 @@ INT32 FindBestNearbyCover(SOLDIERTYPE *pSoldier, INT32 morale, INT32 *piPercentB gubNPCAPBudget = 0; gubNPCDistLimit = 0; - #if defined( _DEBUG ) && !defined( PATHAI_VISIBLE_DEBUG ) - if (gfDisplayCoverValues) + if (gRenderDebugInfoMode == DEBUG_COVERVALUE && DEBUG_CHEAT_LEVEL()) { - // do a locate? - LocateSoldier( pSoldier->ubID, SETLOCATORFAST ); gsBestCover = sBestCover; - SetRenderFlags( RENDER_FLAG_FULL ); - RenderWorld(); - RenderCoverDebug( ); - InvalidateScreen( ); - EndFrameBufferRender(); - RefreshScreen( NULL ); - /* - iLoop = GetJA2Clock(); - do - { - - } while( ( GetJA2Clock( ) - iLoop ) < 2000 ); - */ + InvalidateRegion(gsVIEWPORT_START_X, gsVIEWPORT_START_Y, gsVIEWPORT_END_X, gsVIEWPORT_WINDOW_END_Y); } - #endif // if a better cover location was found if (!TileIsOutOfBounds(sBestCover)) { - #if defined( _DEBUG ) && !defined( PATHAI_VISIBLE_DEBUG ) - gsBestCover = sBestCover; - #endif // cover values already take the AP cost of getting there into account in // a BIG way, so no need to worry about that here, even small improvements // are actually very significant once we get our APs back (if we live!) diff --git a/TacticalAI/ai.h b/TacticalAI/ai.h index 60f0f45c..d2a32b5b 100644 --- a/TacticalAI/ai.h +++ b/TacticalAI/ai.h @@ -12,10 +12,6 @@ extern INT16 gubAIPathCosts[19][19]; #define AI_PATHCOST_RADIUS 9 -extern BOOLEAN gfDisplayCoverValues; -//extern INT16 gsCoverValue[WORLD_MAX]; -extern INT16 * gsCoverValue; - // AI actions enum CreatureCalls diff --git a/TileEngine/renderworld.cpp b/TileEngine/renderworld.cpp index 85eb7bd9..5e03e74b 100644 --- a/TileEngine/renderworld.cpp +++ b/TileEngine/renderworld.cpp @@ -23,6 +23,7 @@ #include "LogicalBodyTypes/BodyTypeDB.h" #include "Utilities.h" +#include UINT32 guiShieldGraphic = 0; BOOLEAN fShieldGraphicInit = FALSE; @@ -552,22 +553,25 @@ void ResetRenderParameters( ); void RenderRoomInfo( INT16 sStartPointX_M, INT16 sStartPointY_M, INT16 sStartPointX_S, INT16 sStartPointY_S, INT16 sEndXS, INT16 sEndYS ); - -#ifdef _DEBUG -//extern UINT8 gubFOVDebugInfoInfo[ WORLD_MAX ]; -//extern UINT8 gubGridNoMarkers[ WORLD_MAX ]; -extern UINT8 * gubFOVDebugInfoInfo; -extern UINT8 * gubGridNoMarkers; -extern UINT8 gubGridNoValue; -extern BOOLEAN gfDisplayCoverValues; -extern BOOLEAN gfDisplayGridNoVisibleValues = 0; -//extern INT16 gsCoverValue[ WORLD_MAX ]; -extern INT16 * gsCoverValue; -extern INT16 gsBestCover; -void RenderFOVDebugInfo( INT16 sStartPointX_M, INT16 sStartPointY_M, INT16 sStartPointX_S, INT16 sStartPointY_S, INT16 sEndXS, INT16 sEndYS ); -void RenderCoverDebugInfo( INT16 sStartPointX_M, INT16 sStartPointY_M, INT16 sStartPointX_S, INT16 sStartPointY_S, INT16 sEndXS, INT16 sEndYS ); -void RenderGridNoVisibleDebugInfo( INT16 sStartPointX_M, INT16 sStartPointY_M, INT16 sStartPointX_S, INT16 sStartPointY_S, INT16 sEndXS, INT16 sEndYS ); -#endif +//extern UINT8 * gubFOVDebugInfoInfo; +//extern UINT8 * gubGridNoMarkers; +//extern UINT8 gubGridNoValue; +//extern BOOLEAN gfDisplayGridNoVisibleValues = 0; +//void RenderFOVDebugInfo( INT16 sStartPointX_M, INT16 sStartPointY_M, INT16 sStartPointX_S, INT16 sStartPointY_S, INT16 sEndXS, INT16 sEndYS ); +//void RenderGridNoVisibleDebugInfo( INT16 sStartPointX_M, INT16 sStartPointY_M, INT16 sStartPointX_S, INT16 sStartPointY_S, INT16 sEndXS, INT16 sEndYS ); +extern INT16 gsBestCover; +INT32* gRenderDebugInfoValues = nullptr; +void RenderDebugInfo(INT16 sStartPointX_M, INT16 sStartPointY_M, INT16 sStartPointX_S, INT16 sStartPointY_S, INT16 sEndXS, INT16 sEndYS); +void ResetDebugInfoValues() +{ + if (gRenderDebugInfoValues) + { + for (size_t i = 0; i < WORLD_MAX; i++) + { + gRenderDebugInfoValues[i] = 0x7FFFFFFF; + } + } +} void DeleteFromWorld( UINT16 usTileIndex, UINT32 uiRenderTiles, UINT16 usIndex ); @@ -3363,23 +3367,10 @@ UINT32 cnt = 0; RenderRoomInfo( gsStartPointX_M, gsStartPointY_M, gsStartPointX_S, gsStartPointY_S, gsEndXS, gsEndYS ); } -#ifdef _DEBUG - if( gRenderFlags&RENDER_FLAG_FOVDEBUG ) + if (DEBUG_CHEAT_LEVEL() && gTacticalStatus.Team[OUR_TEAM].bTeamActive) { - RenderFOVDebugInfo( gsStartPointX_M, gsStartPointY_M, gsStartPointX_S, gsStartPointY_S, gsEndXS, gsEndYS ); + RenderDebugInfo(gsStartPointX_M, gsStartPointY_M, gsStartPointX_S, gsStartPointY_S, gsEndXS, gsEndYS); } - else if (gfDisplayCoverValues) - { - RenderCoverDebugInfo( gsStartPointX_M, gsStartPointY_M, gsStartPointX_S, gsStartPointY_S, gsEndXS, gsEndYS ); - } - else if (gfDisplayGridNoVisibleValues) - { - RenderGridNoVisibleDebugInfo( gsStartPointX_M, gsStartPointY_M, gsStartPointX_S, gsStartPointY_S, gsEndXS, gsEndYS ); - } - -#endif - -//#endif //RenderStaticWorldRect( gsVIEWPORT_START_X, gsVIEWPORT_START_Y, gsVIEWPORT_END_X, gsVIEWPORT_END_Y ); //AddBaseDirtyRect(gsVIEWPORT_START_X, gsVIEWPORT_START_Y, gsVIEWPORT_END_X, gsVIEWPORT_END_Y ); @@ -8105,7 +8096,6 @@ void RenderRoomInfo( INT16 sStartPointX_M, INT16 sStartPointY_M, INT16 sStartPoi #ifdef _DEBUG - void RenderFOVDebugInfo( INT16 sStartPointX_M, INT16 sStartPointY_M, INT16 sStartPointX_S, INT16 sStartPointY_S, INT16 sEndXS, INT16 sEndYS ) { INT8 bXOddFlag = 0; @@ -8215,114 +8205,7 @@ void RenderFOVDebugInfo( INT16 sStartPointX_M, INT16 sStartPointY_M, INT16 sStar } -void RenderCoverDebugInfo( INT16 sStartPointX_M, INT16 sStartPointY_M, INT16 sStartPointX_S, INT16 sStartPointY_S, INT16 sEndXS, INT16 sEndYS ) -{ - INT8 bXOddFlag = 0; - INT16 sAnchorPosX_M, sAnchorPosY_M; - INT16 sAnchorPosX_S, sAnchorPosY_S; - INT16 sTempPosX_M, sTempPosY_M; - INT16 sTempPosX_S, sTempPosY_S; - BOOLEAN fEndRenderRow = FALSE, fEndRenderCol = FALSE; - UINT16 usTileIndex; - INT16 sX, sY; - UINT32 uiDestPitchBYTES; - UINT8 *pDestBuf; - - - // Begin Render Loop - sAnchorPosX_M = sStartPointX_M; - sAnchorPosY_M = sStartPointY_M; - sAnchorPosX_S = sStartPointX_S; - sAnchorPosY_S = sStartPointY_S; - - pDestBuf = LockVideoSurface( FRAME_BUFFER, &uiDestPitchBYTES ); - - do - { - - fEndRenderRow = FALSE; - sTempPosX_M = sAnchorPosX_M; - sTempPosY_M = sAnchorPosY_M; - sTempPosX_S = sAnchorPosX_S; - sTempPosY_S = sAnchorPosY_S; - - if(bXOddFlag > 0) - sTempPosX_S += 20; - - - do - { - - usTileIndex=FASTMAPROWCOLTOPOS( sTempPosY_M, sTempPosX_M ); - - if ( usTileIndex < GRIDSIZE ) - { - sX = sTempPosX_S + ( WORLD_TILE_X / 2 ) - 5; - sY = sTempPosY_S + ( WORLD_TILE_Y / 2 ) - 5; - - // Adjust for interface level - sY -= gpWorldLevelData[ usTileIndex ].sHeight; - sY += gsRenderHeight; - - if (gsCoverValue[ usTileIndex] != 0x7F7F) - { - SetFont( SMALLCOMPFONT ); - SetFontDestBuffer( FRAME_BUFFER , 0, 0, SCREEN_WIDTH, gsVIEWPORT_END_Y, FALSE ); - if (usTileIndex == gsBestCover) - { - SetFontForeground( FONT_MCOLOR_RED ); - } - else if (gsCoverValue[ usTileIndex ] < 0) - { - SetFontForeground( FONT_MCOLOR_WHITE ); - } - else - { - SetFontForeground( FONT_GRAY3 ); - } - mprintf_buffer( pDestBuf, uiDestPitchBYTES, TINYFONT1, sX, sY , L"%d", gsCoverValue[ usTileIndex ] ); - SetFontDestBuffer( FRAME_BUFFER , 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, FALSE ); - } - - } - - sTempPosX_S += 40; - sTempPosX_M ++; - sTempPosY_M --; - - if ( sTempPosX_S >= sEndXS ) - { - fEndRenderRow = TRUE; - } - - } while( !fEndRenderRow ); - - if ( bXOddFlag > 0 ) - { - sAnchorPosY_M ++; - } - else - { - sAnchorPosX_M ++; - } - - - bXOddFlag = !bXOddFlag; - sAnchorPosY_S += 10; - - if ( sAnchorPosY_S >= sEndYS ) - { - fEndRenderCol = TRUE; - } - - } - while( !fEndRenderCol ); - - UnLockVideoSurface( FRAME_BUFFER ); - -} - - +// This one just renders tile gridnos. Not much use nowadays void RenderGridNoVisibleDebugInfo( INT16 sStartPointX_M, INT16 sStartPointY_M, INT16 sStartPointX_S, INT16 sStartPointY_S, INT16 sEndXS, INT16 sEndYS ) { INT8 bXOddFlag = 0; @@ -8423,11 +8306,139 @@ void RenderGridNoVisibleDebugInfo( INT16 sStartPointX_M, INT16 sStartPointY_M, I UnLockVideoSurface( FRAME_BUFFER ); } - - #endif +void RenderDebugInfo(INT16 sStartPointX_M, INT16 sStartPointY_M, INT16 sStartPointX_S, INT16 sStartPointY_S, INT16 sEndXS, INT16 sEndYS) +{ + INT8 bXOddFlag = 0; + INT16 sTempPosX_M, sTempPosY_M; + INT16 sTempPosX_S, sTempPosY_S; + BOOLEAN fEndRenderRow = FALSE, fEndRenderCol = FALSE; + + // Begin Render Loop + INT16 sAnchorPosX_M = sStartPointX_M; + INT16 sAnchorPosY_M = sStartPointY_M; + INT16 sAnchorPosX_S = sStartPointX_S; + INT16 sAnchorPosY_S = sStartPointY_S; + + UINT32 uiDestPitchBYTES; + UINT8* pDestBuf = LockVideoSurface(FRAME_BUFFER, &uiDestPitchBYTES); + + const auto mode = gRenderDebugInfoMode; + + do + { + fEndRenderRow = FALSE; + sTempPosX_M = sAnchorPosX_M; + sTempPosY_M = sAnchorPosY_M; + sTempPosX_S = sAnchorPosX_S; + sTempPosY_S = sAnchorPosY_S; + + if (bXOddFlag > 0) + sTempPosX_S += 20; + + do + { + UINT16 usTileIndex = FASTMAPROWCOLTOPOS(sTempPosY_M, sTempPosX_M); + if (usTileIndex < GRIDSIZE) + { + INT16 sX = sTempPosX_S + (WORLD_TILE_X / 2) - 5; + INT16 sY = sTempPosY_S + (WORLD_TILE_Y / 2) - 5; + + // Adjust for interface level + sY -= gpWorldLevelData[usTileIndex].sHeight; + sY += gsRenderHeight; + + + if (gRenderDebugInfoValues[usTileIndex] != 0x7FFFFFFF) + { + SetFont(SMALLCOMPFONT); + SetFontDestBuffer(FRAME_BUFFER, 0, 0, SCREEN_WIDTH, gsVIEWPORT_END_Y, FALSE); + + + //////////////////////////// + // Debug mode specific setup + switch (mode) + { + case DEBUG_PATHFINDING: + if (gRenderDebugInfoValues[usTileIndex] < 0) + { + SetFontForeground(FONT_LTRED); + } + else + { + SetFontForeground(FONT_LTGREEN); + } + break; + case DEBUG_THREATVALUE: + //TODO implement + goto exit_loop; + break; + case DEBUG_COVERVALUE: + if (usTileIndex == gsBestCover) + { + SetFontForeground(FONT_YELLOW); + } + else if (gRenderDebugInfoValues[usTileIndex] < 0) + { + SetFontForeground(FONT_LTRED); + } + else + { + SetFontForeground(FONT_LTGREEN); + } + break; + + default: + goto exit_loop; + break; + } + //////////////////////////// + + + mprintf_buffer(pDestBuf, uiDestPitchBYTES, TINYFONT1, sX, sY, L"%d", gRenderDebugInfoValues[usTileIndex]); + SetFontDestBuffer(FRAME_BUFFER, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, FALSE); + } + + } + + sTempPosX_S += 40; + sTempPosX_M++; + sTempPosY_M--; + + if (sTempPosX_S >= sEndXS) + { + fEndRenderRow = TRUE; + } + + } while (!fEndRenderRow); + + if (bXOddFlag > 0) + { + sAnchorPosY_M++; + } + else + { + sAnchorPosX_M++; + } + + + bXOddFlag = !bXOddFlag; + sAnchorPosY_S += 10; + + if (sAnchorPosY_S >= sEndYS) + { + fEndRenderCol = TRUE; + } + } while (!fEndRenderCol); + + exit_loop: + UnLockVideoSurface(FRAME_BUFFER); +} + + + void ExamineZBufferRect( INT16 sLeft, INT16 sTop, INT16 sRight, INT16 sBottom) { CalcRenderParameters( sLeft, sTop, sRight, sBottom ); @@ -9088,21 +9099,3 @@ void SetRenderCenter( INT16 sNewX, INT16 sNewY ) gfScrollInertia = FALSE; } - -#ifdef _DEBUG -void RenderFOVDebug( ) -{ - RenderFOVDebugInfo( gsStartPointX_M, gsStartPointY_M, gsStartPointX_S, gsStartPointY_S, gsEndXS, gsEndYS ); -} - -void RenderCoverDebug( ) -{ - RenderCoverDebugInfo( gsStartPointX_M, gsStartPointY_M, gsStartPointX_S, gsStartPointY_S, gsEndXS, gsEndYS ); -} - -void RenderGridNoVisibleDebug( ) -{ - RenderGridNoVisibleDebugInfo( gsStartPointX_M, gsStartPointY_M, gsStartPointX_S, gsStartPointY_S, gsEndXS, gsEndYS ); -} - -#endif diff --git a/TileEngine/renderworld.h b/TileEngine/renderworld.h index 140e5d5f..4ba08f78 100644 --- a/TileEngine/renderworld.h +++ b/TileEngine/renderworld.h @@ -216,6 +216,16 @@ void SetRenderCenter( INT16 sNewX, INT16 sNewY ); #ifdef _DEBUG void RenderFOVDebug( ); #endif +enum RenderDebugInfoModes +{ + DEBUG_PATHFINDING, + DEBUG_THREATVALUE, + DEBUG_COVERVALUE, + DEBUG_OFF +}; +void ResetDebugInfoValues(); +extern INT32* gRenderDebugInfoValues; + BOOLEAN Zero8BPPDataTo16BPPBufferTransparent( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex ); BOOLEAN Blt8BPPDataTo16BPPBufferTransZIncClipZSameZBurnsThrough( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, UINT16 *pZBuffer, UINT16 usZValue, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex, SGPRect *clipregion, INT16 sZStripIndex ); @@ -227,4 +237,4 @@ BOOLEAN Blt8BPPDataTo16BPPBufferTransZIncObscureClip(UINT16 *pBuffer, UINT32 uiD BOOLEAN Blt8BPPDataTo16BPPBufferTransZTransShadowIncObscureClip(UINT16 *pBuffer, UINT32 uiDestPitchBYTES, UINT16 *pZBuffer, UINT16 usZValue, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex, SGPRect *clipregion, INT16 sZIndex, UINT16 *p16BPPPalette, BOOLEAN fIgnoreShadows = FALSE); BOOLEAN Blt8BPPDataTo16BPPBufferTransZTransShadowIncObscureClipAlpha(UINT16 *pBuffer, UINT32 uiDestPitchBYTES, UINT16 *pZBuffer, UINT16 usZValue, HVOBJECT hSrcVObject, HVOBJECT hAlphaVObject, INT32 iX, INT32 iY, UINT16 usIndex, SGPRect *clipregion, INT16 sZIndex, UINT16 *p16BPPPalette, BOOLEAN fIgnoreShadows = FALSE); -#endif \ No newline at end of file +#endif diff --git a/TileEngine/worlddef.cpp b/TileEngine/worlddef.cpp index 628a35e3..012568a3 100644 --- a/TileEngine/worlddef.cpp +++ b/TileEngine/worlddef.cpp @@ -49,6 +49,7 @@ #include "Button Defines.h" #include "Animation Data.h" #endif +#include #define SET_MOVEMENTCOST( a, b, c, d ) ( ( gubWorldMovementCosts[ a ][ b ][ c ] < d ) ? ( gubWorldMovementCosts[ a ][ b ][ c ] = d ) : 0 ); @@ -84,7 +85,6 @@ extern UINT8 *gubFOVDebugInfoInfo; extern INT16 gsFullTileDirections[MAX_FULLTILE_DIRECTIONS]; extern INT32 dirDelta[8]; extern INT16 DirIncrementer[8]; -extern INT16 *gsCoverValue; extern INT32 gsTempActionGridNo; extern INT32 gsOverItemsGridNo; extern INT32 gsOutOfRangeGridNo; @@ -320,8 +320,6 @@ void DeinitializeWorld() TrashWorld(); if(gubGridNoMarkers) MemFree(gubGridNoMarkers); - if(gsCoverValue) - MemFree(gsCoverValue); if(gubBuildingInfo) MemFree(gubBuildingInfo); if(gusWorldRoomInfo) @@ -4313,10 +4311,12 @@ void SetWorldSize(INT32 nWorldRows, INT32 nWorldCols) gubGridNoMarkers = (UINT8*)MemAlloc(WORLD_MAX); memset(gubGridNoMarkers, 0, sizeof(UINT8)*WORLD_MAX); - if(gsCoverValue) - MemFree(gsCoverValue); - gsCoverValue = (INT16*)MemAlloc(sizeof(INT16)*WORLD_MAX); - memset(gsCoverValue, 0x7F, sizeof(INT16)*WORLD_MAX); + if (DEBUG_CHEAT_LEVEL()) + { + MemFree(gRenderDebugInfoValues); + gRenderDebugInfoValues = (INT32*)MemAlloc(sizeof(INT32) * WORLD_MAX); + ResetDebugInfoValues(); + } // Init building structures and variables if(gubBuildingInfo)