commit 4acee0e428b421f19814c39acb97bfee0d2db68a Author: /dev/humancontroller Date: Thu Jun 16 22:01:48 2011 +0200 AMP DEBUG diff --git a/src/game/g_active.c b/src/game/g_active.c index 11d749f..f91fe61 100644 --- a/src/game/g_active.c +++ b/src/game/g_active.c @@ -299,7 +299,15 @@ void ClientImpacts( gentity_t *ent, pmove_t *pm ) // touch triggers if( other->touch ) - other->touch( other, ent, &trace ); + { + if( g_debugAMP.integer ) + { + char *s = va( "touched by #%i (%s^7)", (int)( ent-g_entities ), ent->client->pers.netname ); + G_LoggedActivation( other, ent, NULL, &trace, s ); + } + else + other->touch( other, ent, &trace ); + } } } @@ -373,7 +381,15 @@ void G_TouchTriggers( gentity_t *ent ) memset( &trace, 0, sizeof( trace ) ); if( hit->touch ) - hit->touch( hit, ent, &trace ); + { + if( g_debugAMP.integer ) + { + char *s = va( "triggered by #%i (%s^7)", (int)( ent-g_entities ), ent->client->pers.netname ); + G_LoggedActivation( hit, ent, NULL, &trace, s ); + } + else + hit->touch( hit, ent, &trace ); + } } } @@ -1688,7 +1704,15 @@ void ClientThink_real( gentity_t *ent ) traceEnt = &g_entities[ trace.entityNum ]; if( traceEnt && traceEnt->buildableTeam == client->ps.stats[ STAT_TEAM ] && traceEnt->use ) - traceEnt->use( traceEnt, ent, ent ); //other and activator are the same in this context + { + if( g_debugAMP.integer ) + { + char *s = va( "used by #%i (%s^7)", (int)( ent-g_entities ), client->pers.netname ); + G_LoggedActivation( traceEnt, ent, ent, NULL, s ); + } + else + traceEnt->use( traceEnt, ent, ent ); //other and activator are the same in this context + } else { //no entity in front of player - do a small area search @@ -1703,7 +1727,13 @@ void ClientThink_real( gentity_t *ent ) if( traceEnt && traceEnt->buildableTeam == client->ps.stats[ STAT_TEAM ] && traceEnt->use ) { - traceEnt->use( traceEnt, ent, ent ); //other and activator are the same in this context + if( g_debugAMP.integer ) + { + char *s = va( "used by #%i (%s^7)", (int)( ent-g_entities ), client->pers.netname ); + G_LoggedActivation( traceEnt, ent, ent, NULL, s ); + } + else + traceEnt->use( traceEnt, ent, ent ); //other and activator are the same in this context break; } } diff --git a/src/game/g_buildable.c b/src/game/g_buildable.c index 3579731..1d5ec5e 100644 --- a/src/game/g_buildable.c +++ b/src/game/g_buildable.c @@ -2711,7 +2711,16 @@ void G_BuildableTouchTriggers( gentity_t *ent ) memset( &trace, 0, sizeof( trace ) ); if( hit->touch ) - hit->touch( hit, ent, &trace ); + { + if( g_debugAMP.integer ) + { + char *s = va( "touched by #%i (a %s)", (int)( ent-g_entities ), + BG_Buildable( ent->s.modelindex )->humanName ); + G_LoggedActivation( hit, ent, NULL, &trace, s ); + } + else + hit->touch( hit, ent, &trace ); + } } } diff --git a/src/game/g_combat.c b/src/game/g_combat.c index 53082d3..68e6f2f 100644 --- a/src/game/g_combat.c +++ b/src/game/g_combat.c @@ -1021,7 +1021,20 @@ void G_Damage( gentity_t *targ, gentity_t *inflictor, gentity_t *attacker, if( targ->health > 0 ) return; - targ->use( targ, inflictor, attacker ); + if( g_debugAMP.integer ) + { + char *s; + if( attacker ) + { + s = va( "damaged by #%i (%s^7)", (int)( attacker-g_entities ), + attacker < g_entities + level.maxclients ? attacker->client->pers.netname : attacker->classname ); + } + else + s = "damaged"; + G_LoggedActivation( targ, inflictor, attacker, NULL, s ); + } + else + targ->use( targ, inflictor, attacker ); targ->health = targ->resetValue; return; diff --git a/src/game/g_local.h b/src/game/g_local.h index 5f3c0b4..5b0dc93 100644 --- a/src/game/g_local.h +++ b/src/game/g_local.h @@ -891,6 +891,8 @@ void G_CloseMenus( int clientNum ); qboolean G_Visible( gentity_t *ent1, gentity_t *ent2, int contents ); gentity_t *G_ClosestEnt( vec3_t origin, gentity_t **entities, int numEntities ); +void G_LoggedActivation( gentity_t *self, gentity_t *other, gentity_t *activator, trace_t *trace, const char *source ); + // // g_combat.c // @@ -1140,6 +1142,8 @@ extern vmCvar_t g_smoothClients; extern vmCvar_t pmove_fixed; extern vmCvar_t pmove_msec; +extern vmCvar_t g_debugAMP; + extern vmCvar_t g_alienBuildPoints; extern vmCvar_t g_alienBuildQueueTime; extern vmCvar_t g_humanBuildPoints; diff --git a/src/game/g_main.c b/src/game/g_main.c index 28d5225..c1661a0 100644 --- a/src/game/g_main.c +++ b/src/game/g_main.c @@ -79,6 +79,8 @@ vmCvar_t pmove_msec; vmCvar_t g_minNameChangePeriod; vmCvar_t g_maxNameChanges; +vmCvar_t g_debugAMP; + vmCvar_t g_alienBuildPoints; vmCvar_t g_alienBuildQueueTime; vmCvar_t g_humanBuildPoints; @@ -213,6 +215,8 @@ static cvarTable_t gameCvarTable[ ] = { &pmove_fixed, "pmove_fixed", "0", CVAR_SYSTEMINFO, 0, qfalse}, { &pmove_msec, "pmove_msec", "8", CVAR_SYSTEMINFO, 0, qfalse}, + { &g_debugAMP, "g_debugAMP", "0", 0, 0, qfalse }, + { &g_alienBuildPoints, "g_alienBuildPoints", DEFAULT_ALIEN_BUILDPOINTS, 0, 0, qfalse, cv_alienBuildPoints }, { &g_alienBuildQueueTime, "g_alienBuildQueueTime", DEFAULT_ALIEN_QUEUE_TIME, CVAR_ARCHIVE, 0, qfalse }, { &g_humanBuildPoints, "g_humanBuildPoints", DEFAULT_HUMAN_BUILDPOINTS, 0, 0, qfalse, cv_humanBuildPoints }, @@ -1892,7 +1896,16 @@ void LogExit( const char *string ) if( !Q_stricmp( ent->classname, "trigger_win" ) ) { if( level.lastWin == ent->stageTeam ) - ent->use( ent, ent, ent ); + { + if( g_debugAMP.integer ) + { + char *s = va( "%ss win", BG_TeamName( level.lastWin ) ); + s[ 0 ] = tolower( s[ 0 ] ); + G_LoggedActivation( ent, ent, ent, NULL, s ); + } + else + ent->use( ent, ent, ent ); + } } } diff --git a/src/game/g_target.c b/src/game/g_target.c index 675e57c..febbc9a 100644 --- a/src/game/g_target.c +++ b/src/game/g_target.c @@ -251,7 +251,12 @@ void target_relay_use( gentity_t *self, gentity_t *other, gentity_t *activator ) ent = G_PickTarget( self ); if( ent && ent->use ) - ent->use( ent, self, activator ); + { + if( g_debugAMP.integer ) + G_LoggedActivation( ent, self, activator, NULL, "randomly relayed" ); + else + ent->use( ent, self, activator ); + } return; } diff --git a/src/game/g_trigger.c b/src/game/g_trigger.c index 6182c55..74d2442 100644 --- a/src/game/g_trigger.c +++ b/src/game/g_trigger.c @@ -523,7 +523,16 @@ void G_Checktrigger_stages( team_t team, stage_t stage ) if( !Q_stricmp( ent->classname, "trigger_stage" ) ) { if( team == ent->stageTeam && stage == ent->stageStage ) - ent->use( ent, ent, ent ); + { + if( g_debugAMP.integer ) + { + char *s = va( "%ss staged up", BG_TeamName( level.lastWin ) ); + s[ 0 ] = tolower( s[ 0 ] ); + G_LoggedActivation( ent, ent, ent, NULL, s ); + } + else + ent->use( ent, ent, ent ); + } } } } diff --git a/src/game/g_utils.c b/src/game/g_utils.c index 968d7ee..17ce34c 100644 --- a/src/game/g_utils.c +++ b/src/game/g_utils.c @@ -236,6 +236,162 @@ gentity_t *G_PickTarget( gentity_t *self ) return choice[ rand( ) % num_choices ]; } +typedef struct loggedActivation_s { + int entityNum; + const char *classname; + const char *targetname; + int targetGate; + int gateStateBefore; + int gateStateAfter; + char *source; + struct loggedActivation_s *parent; + struct loggedActivation_s *children; + struct loggedActivation_s *next; +} loggedActivation_t; + +static loggedActivation_t *G_MakeLA( gentity_t *self ) +{ + loggedActivation_t *la = BG_Alloc( sizeof( loggedActivation_t ) ); + la->entityNum = (int)( self-g_entities ); + la->classname = self->classname; + la->targetname = NULL; + la->targetGate = self->targetGate; + la->gateStateBefore = self->gateState; + la->source = NULL; + la->parent = NULL; + la->children = NULL; + la->next = NULL; + return la; +} + +static loggedActivation_t *leafLA; + +static char laTimeStamp[ 32 ]; +static char laTimeSpace[ 32 ]; +static char *laTimePfx; + +static void G_PrepareTimePrefix( void ) +{ + int time = level.time - level.startTime; + Com_sprintf( laTimeStamp, sizeof( laTimeStamp ), "%i:%02i.%03i", + time / 1000 / 60, ( time / 1000 ) % 60, time % 1000 ); + memset( laTimeSpace, ' ', strlen( laTimeStamp ) ); + laTimeSpace[ strlen( laTimeStamp ) ] = '\0'; + laTimePfx = laTimeStamp; +} + +#define LA_DOWN '|' +#define LA_BEND '\'' +#define LA_RIGHT '-' + +static void G_PrintLA( loggedActivation_t *la ) +{ + static char laPfx[ 2048 ] = ""; + static size_t laPfxLen = 0; + + while( la != NULL ) + { + loggedActivation_t *del; + + if( la->parent != NULL && la->next == NULL ) + laPfx[ laPfxLen - 2 ] = LA_BEND; + + G_Printf( "%s %s#%i (%s) %s |%i| %i->%i%s\n", laTimePfx, laPfx, + la->entityNum, la->classname, la->targetname ? va( "[%s]", la->targetname ) : "][", + la->targetGate, la->gateStateBefore, la->gateStateAfter, + la->source ? va( " {%s}", la->source ) : "" ); + laTimePfx = laTimeSpace; + + if( la->parent != NULL ) + { + if( la->next == NULL ) + laPfx[ laPfxLen - 2 ] = ' '; + laPfx[ laPfxLen - 1 ] = ' '; + } + laPfx[ laPfxLen++ ] = LA_DOWN; + laPfx[ laPfxLen++ ] = LA_RIGHT; + laPfx[ laPfxLen ] = '\0'; + + G_PrintLA( la->children ); + + laPfxLen -= 2; + laPfx[ laPfxLen ] = '\0'; + if( la->parent != NULL ) + laPfx[ laPfxLen - 1 ] = la->next == NULL ? ' ' : LA_RIGHT; + + del = la; + la = la->next; + if( del->source != NULL ) + BG_Free( del->source ); + BG_Free( del ); + } +} + +void G_LoggedActivation( gentity_t *self, gentity_t *other, gentity_t *activator, trace_t *trace, const char *source ) +{ + loggedActivation_t *la; + qboolean top; + + la = G_MakeLA( self ); + la->source = G_CopyString( source ); + + top = leafLA == NULL; + if( !top ) + { + la->parent = leafLA; + leafLA->children = la; + } + + leafLA = la; + + if( trace ) + self->touch( self, other, trace ); + else + self->use( self, other, activator ); + + leafLA->gateStateAfter = self->gateState; + + if( top ) + { + G_PrepareTimePrefix(); + G_PrintLA( leafLA ); + + leafLA = NULL; + } + else + leafLA = leafLA->parent; +} + +static void G_LoggedMultiUse( const char *targetname, gentity_t *self, gentity_t *other, gentity_t *activator, qboolean subsequent ) +{ + loggedActivation_t *la; + + la = G_MakeLA( self ); + la->targetname = targetname; + + if( subsequent ) + { + leafLA->next = la; + la->parent = leafLA->parent; + } + else + { + leafLA->children = la; + la->parent = leafLA; + } + + leafLA = la; + + self->use( self, other, activator ); + + leafLA->gateStateAfter = self->gateState; +} + +static void G_LoggedMultiUsesEnd( qboolean subsequent ) +{ + if( subsequent ) + leafLA = leafLA->parent; +} /* ============================== @@ -251,6 +407,8 @@ void G_UseTargets( gentity_t *ent, gentity_t *activator ) { gentity_t *t = NULL; int i, j; + qboolean top = qfalse; + qboolean subsequent = qfalse; if( !ent ) return; @@ -262,19 +420,50 @@ void G_UseTargets( gentity_t *ent, gentity_t *activator ) trap_SetConfigstring( CS_SHADERSTATE, BuildShaderStateConfig( ) ); } + if( g_debugAMP.integer ) + { + top = leafLA == NULL; + if( top ) + { + leafLA = G_MakeLA( ent ); + leafLA->source = G_CopyString( "generic" ); + } + } + while( ( t = G_TargetFind( t, &i, &j, ent ) ) != NULL ) { if( t->use ) { - t->use( t, ent, activator ); + if( g_debugAMP.integer ) + { + G_LoggedMultiUse( ent->targetnames[ i ], t, ent, activator, subsequent ); + subsequent = qtrue; + } + else + t->use( t, ent, activator ); if( !ent->inuse ) { G_Printf( "entity was removed while using targets\n" ); - return; + break; } } } + + if( g_debugAMP.integer ) + { + G_LoggedMultiUsesEnd( subsequent ); + + if( top ) + { + leafLA->gateStateAfter = ent->gateState; + + G_PrepareTimePrefix(); + G_PrintLA( leafLA ); + + leafLA = NULL; + } + } }