Skip to content

Commit 7ce6184

Browse files
authored
[GEN] Backport some debug features from Zero Hour (#775)
1 parent 7735f6f commit 7ce6184

File tree

10 files changed

+259
-83
lines changed

10 files changed

+259
-83
lines changed

Generals/Code/GameEngine/Include/Common/GlobalData.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ class GlobalData : public SubsystemInterface
243243

244244
UnsignedInt m_noDraw; ///< Used to disable drawing, to profile game logic code.
245245
AIDebugOptions m_debugAI; ///< Used to display AI debug information
246+
Bool m_debugSupplyCenterPlacement; ///< Dumps to log everywhere it thinks about placing a supply center
246247
Bool m_debugAIObstacles; ///< Used to display AI obstacle debug information
247248
Bool m_showObjectHealth; ///< debug display object health
248249
Bool m_scriptDebug; ///< Should we attempt to load the script debugger window (.DLL)
@@ -471,6 +472,7 @@ class GlobalData : public SubsystemInterface
471472
Int m_debugProjectileTileDuration; ///< How long should these tiles stay around, in frames?
472473
RGBColor m_debugProjectileTileColor; ///< What color should these tiles be?
473474
Bool m_showCollisionExtents; ///< Used to display collision extents
475+
Bool m_showAudioLocations; ///< Used to display audio markers and ambient sound radii
474476
Bool m_saveStats;
475477
Bool m_saveAllStats;
476478
Bool m_useLocalMOTD;

Generals/Code/GameEngine/Include/GameClient/Drawable.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,7 @@ class Drawable : public Thing,
545545
void killIcon(DrawableIconType t) { if (m_iconInfo) m_iconInfo->killIcon(t); }
546546
Bool hasIconInfo() const { return m_iconInfo != NULL; }
547547

548+
const AudioEventRTS * getAmbientSound() const { return m_ambientSound == NULL ? NULL : &m_ambientSound->m_event; }
548549
protected:
549550

550551
// snapshot methods

Generals/Code/GameEngine/Include/GameClient/View.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,16 @@ class View : public Snapshot
8383
SHAKE_COUNT
8484
};
8585

86+
// Return values for worldToScreenTriReturn
87+
enum WorldToScreenReturn CPP_11(: Int)
88+
{
89+
WTS_INSIDE_FRUSTUM = 0, // On the screen (inside frustum of camera)
90+
WTS_OUTSIDE_FRUSTUM, // Return is valid but off the screen (outside frustum of camera)
91+
WTS_INVALID, // No transform possible
92+
93+
WTS_COUNT
94+
};
95+
8696
public:
8797

8898
View( void );
@@ -183,7 +193,8 @@ class View : public Snapshot
183193
virtual void setFieldOfView( Real angle ) { m_FOV = angle; } ///< Set the horizontal field of view angle
184194
virtual Real getFieldOfView( void ) { return m_FOV; } ///< Get the horizontal field of view angle
185195

186-
virtual Bool worldToScreen( const Coord3D *w, ICoord2D *s ) = 0; ///< Transform world coordinate "w" into screen coordinate "s"
196+
Bool worldToScreen( const Coord3D *w, ICoord2D *s ) { return worldToScreenTriReturn( w, s ) == WTS_INSIDE_FRUSTUM; } ///< Transform world coordinate "w" into screen coordinate "s"
197+
virtual WorldToScreenReturn worldToScreenTriReturn(const Coord3D *w, ICoord2D *s ) = 0; ///< Like worldToScreen(), but with a more informative return value
187198
virtual void screenToWorld( const ICoord2D *s, Coord3D *w ) = 0; ///< Transform screen coordinate "s" into world coordinate "w"
188199
virtual void screenToTerrain( const ICoord2D *screen, Coord3D *world ) = 0; ///< transform screen coord to a point on the 3D terrain
189200
virtual void screenToWorldAtZ( const ICoord2D *s, Coord3D *w, Real z ) = 0; ///< transform screen point to world point at the specified world Z value

Generals/Code/GameEngine/Source/Common/GlobalData.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,7 @@ GlobalData* GlobalData::m_theOriginal = NULL;
500500
{ "ShroudOn", INI::parseBool, NULL, offsetof( GlobalData, m_shroudOn ) },
501501
{ "FogOfWarOn", INI::parseBool, NULL, offsetof( GlobalData, m_fogOfWarOn ) },
502502
{ "ShowCollisionExtents", INI::parseBool, NULL, offsetof( GlobalData, m_showCollisionExtents ) },
503+
{ "ShowAudioLocations", INI::parseBool, NULL, offsetof( GlobalData, m_showAudioLocations ) },
503504
{ "DebugProjectileTileWidth", INI::parseReal, NULL, offsetof( GlobalData, m_debugProjectileTileWidth) },
504505
{ "DebugProjectileTileDuration",INI::parseInt, NULL, offsetof( GlobalData, m_debugProjectileTileDuration) },
505506
{ "DebugProjectileTileColor", INI::parseRGBColor, NULL, offsetof( GlobalData, m_debugProjectileTileColor) },
@@ -518,7 +519,7 @@ GlobalData* GlobalData::m_theOriginal = NULL;
518519
{ "UseLocalMOTD", INI::parseBool, NULL, offsetof( GlobalData, m_useLocalMOTD ) },
519520
{ "BaseStatsDir", INI::parseAsciiString,NULL, offsetof( GlobalData, m_baseStatsDir ) },
520521
{ "LocalMOTDPath", INI::parseAsciiString,NULL, offsetof( GlobalData, m_MOTDPath ) },
521-
{ "ExtraLogging", INI::parseBool, NULL, offsetof(GlobalData, m_extraLogging) },
522+
{ "ExtraLogging", INI::parseBool, NULL, offsetof( GlobalData, m_extraLogging ) },
522523
#endif
523524

524525
{ NULL, NULL, NULL, 0 } // keep this last
@@ -551,6 +552,7 @@ GlobalData::GlobalData()
551552
m_jabberOn = FALSE;
552553
m_munkeeOn = FALSE;
553554
m_showCollisionExtents = FALSE;
555+
m_showAudioLocations = FALSE;
554556
m_debugCamera = FALSE;
555557
m_specialPowerUsesDelay = TRUE;
556558
m_debugVisibility = FALSE;
@@ -808,6 +810,7 @@ GlobalData::GlobalData()
808810
// End Add
809811

810812
m_debugAI = AI_DEBUG_NONE;
813+
m_debugSupplyCenterPlacement = FALSE;
811814
m_debugAIObstacles = FALSE;
812815
m_showClientPhysics = TRUE;
813816
m_showTerrainNormals = FALSE;

Generals/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1776,9 +1776,16 @@ void AIPlayer::buildBySupplies(Int minimumCash, const AsciiString& thingName)
17761776
BuildAssistant::NO_OBJECT_OVERLAP,
17771777
NULL, m_player ) != LBC_OK ) {
17781778
// Warn.
1779-
AsciiString bldgName = tTemplate->getName();
1780-
bldgName.concat(" - buildAISupplyCenter unable to place. Attempting to adjust position.");
1781-
TheScriptEngine->AppendDebugMessage(bldgName, false);
1779+
const Coord3D *warehouseLocation = bestSupplyWarehouse->getPosition();
1780+
AsciiString debugMessage;
1781+
debugMessage.format(" %s - buildBySupplies unable to place near dock at (%.2f,%.2f). Attempting to adjust position.",
1782+
tTemplate->getName().str(),
1783+
warehouseLocation->x,
1784+
warehouseLocation->y
1785+
);
1786+
TheScriptEngine->AppendDebugMessage(debugMessage, false);
1787+
if( TheGlobalData->m_debugSupplyCenterPlacement )
1788+
DEBUG_LOG(("%s", debugMessage.str()));
17821789
// try to fix.
17831790
Real posOffset;
17841791
// Wiggle it a little :)
@@ -1795,12 +1802,16 @@ void AIPlayer::buildBySupplies(Int minimumCash, const AsciiString& thingName)
17951802
BuildAssistant::NO_OBJECT_OVERLAP,
17961803
NULL, m_player ) == LBC_OK;
17971804
if (valid) break;
1805+
if( TheGlobalData->m_debugSupplyCenterPlacement )
1806+
DEBUG_LOG(("buildBySupplies -- Fail at (%.2f,%.2f)\n", newPos.x, newPos.y));
17981807
newPos.y = yPos+posOffset;
17991808
valid = TheBuildAssistant->isLocationLegalToBuild( &newPos, tTemplate, angle,
18001809
BuildAssistant::CLEAR_PATH |
18011810
BuildAssistant::TERRAIN_RESTRICTIONS |
18021811
BuildAssistant::NO_OBJECT_OVERLAP,
18031812
NULL, m_player ) == LBC_OK;
1813+
if( !valid && TheGlobalData->m_debugSupplyCenterPlacement )
1814+
DEBUG_LOG(("buildBySupplies -- Fail at (%.2f,%.2f)\n", newPos.x, newPos.y));
18041815
}
18051816
if (valid) break;
18061817
xPos = location.x-offset;
@@ -1813,17 +1824,26 @@ void AIPlayer::buildBySupplies(Int minimumCash, const AsciiString& thingName)
18131824
BuildAssistant::NO_OBJECT_OVERLAP,
18141825
NULL, m_player ) == LBC_OK;
18151826
if (valid) break;
1827+
if( TheGlobalData->m_debugSupplyCenterPlacement )
1828+
DEBUG_LOG(("buildBySupplies -- Fail at (%.2f,%.2f)\n", newPos.x, newPos.y));
18161829
newPos.x = xPos+posOffset;
18171830
valid = TheBuildAssistant->isLocationLegalToBuild( &newPos, tTemplate, angle,
18181831
BuildAssistant::CLEAR_PATH |
18191832
BuildAssistant::TERRAIN_RESTRICTIONS |
18201833
BuildAssistant::NO_OBJECT_OVERLAP,
18211834
NULL, m_player ) == LBC_OK;
1835+
if( !valid && TheGlobalData->m_debugSupplyCenterPlacement )
1836+
DEBUG_LOG(("buildBySupplies -- Fail at (%.2f,%.2f)\n", newPos.x, newPos.y));
18221837
}
18231838
if (valid) break;
18241839
}
18251840
}
1826-
if (valid) location = newPos;
1841+
if (valid)
1842+
{
1843+
if( TheGlobalData->m_debugSupplyCenterPlacement )
1844+
DEBUG_LOG(("buildAISupplyCenter -- SUCCESS at (%.2f,%.2f)\n", newPos.x, newPos.y));
1845+
location = newPos;
1846+
}
18271847
TheTerrainVisual->removeAllBibs(); // isLocationLegalToBuild adds bib feedback, turn it off. jba.
18281848
location.z = 0; // All build list locations are ground relative.
18291849
m_player->addToPriorityBuildList(thingName, &location, angle);

Generals/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -854,9 +854,9 @@ StateReturnType AIStateMachine::updateStateMachine()
854854
{
855855
//-extraLogging
856856
#if (defined(_DEBUG) || defined(_INTERNAL))
857-
Bool idle = getOwner()->getAI()->isIdle();
858-
if (!idle && TheGlobalData->m_extraLogging)
859-
DEBUG_LOG(("%d - %s::update() start - %s", TheGameLogic->getFrame(), getCurrentStateName().str(), getOwner()->getTemplate()->getName().str()));
857+
Bool idle = getOwner()->getAI()->isIdle();
858+
if( !idle && TheGlobalData->m_extraLogging )
859+
DEBUG_LOG( ("%d - %s::update() start - %s", TheGameLogic->getFrame(), getCurrentStateName().str(), getOwner()->getTemplate()->getName().str() ) );
860860
#endif
861861
//end -extraLogging
862862

@@ -874,10 +874,11 @@ StateReturnType AIStateMachine::updateStateMachine()
874874
{
875875
//-extraLogging
876876
#if (defined(_DEBUG) || defined(_INTERNAL))
877-
if (!idle && TheGlobalData->m_extraLogging)
878-
DEBUG_LOG((" - RETURN EARLY STATE_CONTINUE\n"));
877+
if( !idle && TheGlobalData->m_extraLogging )
878+
DEBUG_LOG( (" - RETURN EARLY STATE_CONTINUE\n") );
879879
#endif
880880
//end -extraLogging
881+
881882
return status;
882883
}
883884
m_temporaryState->onExit(EXIT_NORMAL);
@@ -888,25 +889,25 @@ StateReturnType AIStateMachine::updateStateMachine()
888889
//-extraLogging
889890
#if (defined(_DEBUG) || defined(_INTERNAL))
890891
AsciiString result;
891-
if (TheGlobalData->m_extraLogging)
892+
if( TheGlobalData->m_extraLogging )
892893
{
893-
switch (retType)
894+
switch( retType )
894895
{
895-
case STATE_CONTINUE:
896-
result.format("CONTINUE");
897-
break;
898-
case STATE_SUCCESS:
899-
result.format("SUCCESS");
900-
break;
901-
case STATE_FAILURE:
902-
result.format("FAILURE");
903-
break;
904-
default:
905-
result.format("UNKNOWN %d", retType);
906-
break;
907-
}
908-
if (!idle)
909-
DEBUG_LOG((" - RETURNING %s\n", result.str()));
896+
case STATE_CONTINUE:
897+
result.format( "CONTINUE" );
898+
break;
899+
case STATE_SUCCESS:
900+
result.format( "SUCCESS" );
901+
break;
902+
case STATE_FAILURE:
903+
result.format( "FAILURE" );
904+
break;
905+
default:
906+
result.format( "UNKNOWN %d", retType );
907+
break;
908+
}
909+
if( !idle )
910+
DEBUG_LOG( (" - RETURNING %s\n", result.str() ) );
910911
}
911912
#endif
912913
//end -extraLogging

Generals/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -747,17 +747,17 @@ UnsignedInt WeaponTemplate::fireWeaponTemplate
747747
//-extraLogging
748748
#if (defined(_DEBUG) || defined(_INTERNAL))
749749
AsciiString targetStr;
750-
if (TheGlobalData->m_extraLogging)
750+
if( TheGlobalData->m_extraLogging )
751751
{
752-
if (victimObj)
753-
targetStr.format("%s", victimObj->getTemplate()->getName().str());
754-
else if (victimPos)
755-
targetStr.format("%d,%d,%d", victimPos->x, victimPos->y, victimPos->z);
752+
if( victimObj )
753+
targetStr.format( "%s", victimObj->getTemplate()->getName().str() );
754+
else if( victimPos )
755+
targetStr.format( "%d,%d,%d", victimPos->x, victimPos->y, victimPos->z );
756756
else
757-
targetStr.format("SELF.");
757+
targetStr.format( "SELF." );
758758

759-
DEBUG_LOG(("%d - WeaponTemplate::fireWeaponTemplate() begin - %s attacking %s - ",
760-
TheGameLogic->getFrame(), sourceObj->getTemplate()->getName().str(), targetStr.str()));
759+
DEBUG_LOG( ("%d - WeaponTemplate::fireWeaponTemplate() begin - %s attacking %s - ",
760+
TheGameLogic->getFrame(), sourceObj->getTemplate()->getName().str(), targetStr.str() ) );
761761
}
762762
#endif
763763
//end -extraLogging
@@ -769,8 +769,8 @@ UnsignedInt WeaponTemplate::fireWeaponTemplate
769769
{
770770
//-extraLogging
771771
#if (defined(_DEBUG) || defined(_INTERNAL))
772-
if (TheGlobalData->m_extraLogging)
773-
DEBUG_LOG(("FAIL 1 (sourceObj %d == NULL || (victimObj %d == NULL && victimPos %d == NULL)\n", sourceObj != 0, victimObj != 0, victimPos != 0));
772+
if( TheGlobalData->m_extraLogging )
773+
DEBUG_LOG( ("FAIL 1 (sourceObj %d == NULL || (victimObj %d == NULL && victimPos %d == NULL)\n", sourceObj != 0, victimObj != 0, victimPos != 0) );
774774
#endif
775775
//end -extraLogging
776776

Generals/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DView.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ class W3DView : public View, public SubsystemInterface
186186

187187
virtual void setFieldOfView( Real angle ); ///< Set the horizontal field of view angle
188188

189-
virtual Bool worldToScreen( const Coord3D *w, ICoord2D *s ); ///< Transform world coordinate "w" into screen coordinate "s"
189+
virtual WorldToScreenReturn worldToScreenTriReturn( const Coord3D *w, ICoord2D *s ); ///< Transform world coordinate "w" into screen coordinate "s"
190190
virtual void screenToWorld( const ICoord2D *s, Coord3D *w ); ///< Transform screen coordinate "s" into world coordinate "w"
191191
virtual void screenToTerrain( const ICoord2D *screen, Coord3D *world ); ///< transform screen coord to a point on the 3D terrain
192192
virtual void screenToWorldAtZ( const ICoord2D *s, Coord3D *w, Real z ); ///< transform screen point to world point at the specified world Z value

0 commit comments

Comments
 (0)