Skip to content

Commit 71df8d6

Browse files
committed
[GEN] Backports some debug features from ZH
1 parent 3feb3fc commit 71df8d6

File tree

11 files changed

+362
-52
lines changed

11 files changed

+362
-52
lines changed

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

+3
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)
@@ -470,6 +471,7 @@ class GlobalData : public SubsystemInterface
470471
Int m_debugProjectileTileDuration; ///< How long should these tiles stay around, in frames?
471472
RGBColor m_debugProjectileTileColor; ///< What color should these tiles be?
472473
Bool m_showCollisionExtents; ///< Used to display collision extents
474+
Bool m_showAudioLocations; ///< Used to display audio markers and ambient sound radii
473475
Bool m_saveStats;
474476
Bool m_saveAllStats;
475477
Bool m_useLocalMOTD;
@@ -480,6 +482,7 @@ class GlobalData : public SubsystemInterface
480482
Int m_latencyPeriod; ///< Period of sinusoidal modulation of latency
481483
Int m_latencyNoise; ///< Max amplitude of jitter to throw in
482484
Int m_packetLoss; ///< Percent of packets to drop
485+
Bool m_extraLogging; ///< More expensive debug logging to catch crashes.
483486
#endif
484487

485488
#ifdef DEBUG_CRASHING

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

+1
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

+12-1
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/CommandLine.cpp

+21
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@
3434
#include "GameClient/GameText.h"
3535
#include "GameNetwork/NetworkDefs.h"
3636

37+
#ifdef _INTERNAL
38+
// for occasional debugging...
39+
//#pragma optimize("", off)
40+
//#pragma MESSAGE("************************************** WARNING, optimization disabled for debugging purposes")
41+
#endif
42+
43+
44+
3745
Bool TheDebugIgnoreSyncErrors = FALSE;
3846
extern Int DX8Wrapper_PreserveFPU;
3947

@@ -835,6 +843,17 @@ Int parseConstantDebug( char *args[], int num )
835843
return 1;
836844
}
837845

846+
#if (defined(_DEBUG) || defined(_INTERNAL))
847+
Int parseExtraLogging( char *args[], int num )
848+
{
849+
if (TheWritableGlobalData)
850+
{
851+
TheWritableGlobalData->m_extraLogging = TRUE;
852+
}
853+
return 1;
854+
}
855+
#endif
856+
838857
Int parseShowTeamDot( char *args[], int num )
839858
{
840859
if( TheWritableGlobalData )
@@ -1247,6 +1266,8 @@ static CommandLineParam params[] =
12471266
{ "-jumpToFrame", parseJumpToFrame },
12481267
{ "-updateImages", parseUpdateImages },
12491268
{ "-showTeamDot", parseShowTeamDot },
1269+
{ "-extraLogging", parseExtraLogging },
1270+
12501271
#endif
12511272

12521273
#ifdef DEBUG_LOGGING

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

+5
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,6 +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 ) },
522+
{ "ExtraLogging", INI::parseBool, NULL, offsetof( GlobalData, m_extraLogging ) },
521523
#endif
522524

523525
{ NULL, NULL, NULL, 0 } // keep this last
@@ -550,6 +552,7 @@ GlobalData::GlobalData()
550552
m_jabberOn = FALSE;
551553
m_munkeeOn = FALSE;
552554
m_showCollisionExtents = FALSE;
555+
m_showAudioLocations = FALSE;
553556
m_debugCamera = FALSE;
554557
m_specialPowerUsesDelay = TRUE;
555558
m_debugVisibility = FALSE;
@@ -581,6 +584,7 @@ GlobalData::GlobalData()
581584
m_useLocalMOTD = FALSE;
582585
m_baseStatsDir = ".\\";
583586
m_MOTDPath = "MOTD.txt";
587+
m_extraLogging = FALSE;
584588
#endif
585589

586590
#ifdef DEBUG_CRASHING
@@ -806,6 +810,7 @@ GlobalData::GlobalData()
806810
// End Add
807811

808812
m_debugAI = AI_DEBUG_NONE;
813+
m_debugSupplyCenterPlacement = FALSE;
809814
m_debugAIObstacles = FALSE;
810815
m_showClientPhysics = TRUE;
811816
m_showTerrainNormals = FALSE;

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

+24-4
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

+46-2
Original file line numberDiff line numberDiff line change
@@ -852,6 +852,14 @@ AsciiString AIStateMachine::getCurrentStateName(void) const
852852
*/
853853
StateReturnType AIStateMachine::updateStateMachine()
854854
{
855+
//-extraLogging
856+
#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() ) );
860+
#endif
861+
//end -extraLogging
862+
855863
if (m_temporaryState)
856864
{
857865
// execute this state
@@ -862,13 +870,49 @@ StateReturnType AIStateMachine::updateStateMachine()
862870
status = STATE_SUCCESS;
863871
}
864872
}
865-
if (status==STATE_CONTINUE) {
873+
if (status==STATE_CONTINUE)
874+
{
875+
//-extraLogging
876+
#if (defined(_DEBUG) || defined(_INTERNAL))
877+
if( !idle && TheGlobalData->m_extraLogging )
878+
DEBUG_LOG( (" - RETURN EARLY STATE_CONTINUE\n") );
879+
#endif
880+
//end -extraLogging
881+
866882
return status;
867883
}
868884
m_temporaryState->onExit(EXIT_NORMAL);
869885
m_temporaryState = NULL;
870886
}
871-
return StateMachine::updateStateMachine();
887+
StateReturnType retType = StateMachine::updateStateMachine();
888+
889+
//-extraLogging
890+
#if (defined(_DEBUG) || defined(_INTERNAL))
891+
AsciiString result;
892+
if( TheGlobalData->m_extraLogging )
893+
{
894+
switch( retType )
895+
{
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() ) );
911+
}
912+
#endif
913+
//end -extraLogging
914+
915+
return retType;
872916
}
873917

874918
//----------------------------------------------------------------------------------------------------------

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

+67
Original file line numberDiff line numberDiff line change
@@ -743,11 +743,37 @@ UnsignedInt WeaponTemplate::fireWeaponTemplate
743743
ObjectID* projectileID
744744
) const
745745
{
746+
747+
//-extraLogging
748+
#if (defined(_DEBUG) || defined(_INTERNAL))
749+
AsciiString targetStr;
750+
if( TheGlobalData->m_extraLogging )
751+
{
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 );
756+
else
757+
targetStr.format( "SELF." );
758+
759+
DEBUG_LOG( ("%d - WeaponTemplate::fireWeaponTemplate() begin - %s attacking %s - ",
760+
TheGameLogic->getFrame(), sourceObj->getTemplate()->getName().str(), targetStr.str() ) );
761+
}
762+
#endif
763+
//end -extraLogging
764+
746765
//CRCDEBUG_LOG(("WeaponTemplate::fireWeaponTemplate() from %s\n", DescribeObject(sourceObj).str()));
747766
DEBUG_ASSERTCRASH(specificBarrelToUse >= 0, ("specificBarrelToUse should no longer be -1\n"));
748767

749768
if (sourceObj == NULL || (victimObj == NULL && victimPos == NULL))
750769
{
770+
//-extraLogging
771+
#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) );
774+
#endif
775+
//end -extraLogging
776+
751777
return 0;
752778
}
753779

@@ -819,6 +845,14 @@ UnsignedInt WeaponTemplate::fireWeaponTemplate
819845
if (distSqr > attackRangeSqr)
820846
{
821847
//DEBUG_ASSERTCRASH(distSqr < 5*5 || distSqr < attackRangeSqr*1.2f, ("*** victim is out of range (%f vs %f) of this weapon -- why did we attempt to fire?\n",sqrtf(distSqr),sqrtf(attackRangeSqr)));
848+
849+
//-extraLogging
850+
#if (defined(_DEBUG) || defined(_INTERNAL))
851+
if( TheGlobalData->m_extraLogging )
852+
DEBUG_LOG( ("FAIL 2 (distSqr %.2f > attackRangeSqr %.2f)\n", distSqr, attackRangeSqr ) );
853+
#endif
854+
//end -extraLogging
855+
822856
return 0;
823857
}
824858
}
@@ -833,6 +867,14 @@ UnsignedInt WeaponTemplate::fireWeaponTemplate
833867
#endif
834868
{
835869
DEBUG_ASSERTCRASH(distSqr > minAttackRangeSqr*0.8f, ("*** victim is closer than min attack range (%f vs %f) of this weapon -- why did we attempt to fire?\n",sqrtf(distSqr),sqrtf(minAttackRangeSqr)));
870+
871+
//-extraLogging
872+
#if (defined(_DEBUG) || defined(_INTERNAL))
873+
if( TheGlobalData->m_extraLogging )
874+
DEBUG_LOG( ("FAIL 3 (distSqr %.2f< minAttackRangeSqr %.2f - 0.5f && !isProjectileDetonation %d)\n", distSqr, minAttackRangeSqr, isProjectileDetonation ) );
875+
#endif
876+
//end -extraLogging
877+
836878
return 0;
837879
}
838880
}
@@ -921,6 +963,15 @@ UnsignedInt WeaponTemplate::fireWeaponTemplate
921963
// go ahead and do it now
922964
//DEBUG_LOG(("WeaponTemplate::fireWeaponTemplate: firing weapon immediately!\n"));
923965
dealDamageInternal(sourceID, damageID, damagePos, bonus, isProjectileDetonation);
966+
967+
//-extraLogging
968+
#if (defined(_DEBUG) || defined(_INTERNAL))
969+
if( TheGlobalData->m_extraLogging )
970+
DEBUG_LOG( ("EARLY 4 (delayed damage applied now)\n") );
971+
#endif
972+
//end -extraLogging
973+
974+
924975
return TheGameLogic->getFrame();
925976
}
926977
else
@@ -933,6 +984,15 @@ UnsignedInt WeaponTemplate::fireWeaponTemplate
933984
//DEBUG_LOG(("WeaponTemplate::fireWeaponTemplate: firing weapon in %d frames (= %d)!\n", delayInWholeFrames,when));
934985
TheWeaponStore->setDelayedDamage(this, damagePos, when, sourceID, damageID, bonus);
935986
}
987+
988+
//-extraLogging
989+
#if (defined(_DEBUG) || defined(_INTERNAL))
990+
if( TheGlobalData->m_extraLogging )
991+
DEBUG_LOG( ("EARLY 5 (delaying damage applied until frame %d)\n", when ) );
992+
#endif
993+
//end -extraLogging
994+
995+
936996
return when;
937997
}
938998
}
@@ -1040,6 +1100,13 @@ UnsignedInt WeaponTemplate::fireWeaponTemplate
10401100
// actually, this is ok, for things like Firestorm.... (srj)
10411101
projectile->setPosition(&projectileDestination);
10421102
}
1103+
//-extraLogging
1104+
#if (defined(_DEBUG) || defined(_INTERNAL))
1105+
if( TheGlobalData->m_extraLogging )
1106+
DEBUG_LOG( ("DONE\n") );
1107+
#endif
1108+
//end -extraLogging
1109+
10431110
return 0;
10441111
}
10451112
}

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

+1-1
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)