codemp/game/g_timer.c File Reference

#include "g_local.h"

Go to the source code of this file.

Data Structures

struct  gtimer_s

Defines

#define MAX_GTIMERS   16384

Typedefs

typedef gtimer_s gtimer_t

Functions

void TIMER_Clear (void)
void TIMER_Clear2 (gentity_t *ent)
gtimer_tTIMER_GetNew (int num, const char *identifier)
gtimer_tTIMER_GetExisting (int num, const char *identifier)
void TIMER_Set (gentity_t *ent, const char *identifier, int duration)
int TIMER_Get (gentity_t *ent, const char *identifier)
qboolean TIMER_Done (gentity_t *ent, const char *identifier)
void TIMER_RemoveHelper (int num, gtimer_t *timer)
qboolean TIMER_Done2 (gentity_t *ent, const char *identifier, qboolean remove)
qboolean TIMER_Exists (gentity_t *ent, const char *identifier)
void TIMER_Remove (gentity_t *ent, const char *identifier)
qboolean TIMER_Start (gentity_t *self, const char *identifier, int duration)

Variables

gtimer_t g_timerPool [MAX_GTIMERS]
gtimer_tg_timers [MAX_GENTITIES]
gtimer_tg_timerFreeList


Define Documentation

#define MAX_GTIMERS   16384
 

Definition at line 8 of file g_timer.c.

Referenced by TIMER_Clear().


Typedef Documentation

typedef struct gtimer_s gtimer_t
 

Referenced by TIMER_Clear2(), TIMER_Done(), TIMER_Done2(), TIMER_Exists(), TIMER_Get(), TIMER_GetExisting(), TIMER_GetNew(), TIMER_Remove(), TIMER_RemoveHelper(), and TIMER_Set().


Function Documentation

void TIMER_Clear void   ) 
 

Definition at line 27 of file g_timer.c.

References g_timerFreeList, g_timerPool, g_timers, MAX_GENTITIES, MAX_GTIMERS, gtimer_s::next, and NULL.

Referenced by G_InitGame().

00028 {
00029         int i;
00030         for (i = 0; i < MAX_GENTITIES; i++)
00031         {
00032                 g_timers[i] = NULL;
00033         }
00034 
00035         for (i = 0; i < MAX_GTIMERS - 1; i++)
00036         {
00037                 g_timerPool[i].next = &g_timerPool[i+1];
00038         }
00039         g_timerPool[MAX_GTIMERS-1].next = NULL;
00040         g_timerFreeList = &g_timerPool[0];
00041 }

void TIMER_Clear2 gentity_t ent  ) 
 

Definition at line 49 of file g_timer.c.

References g_timerFreeList, g_timers, gentity_t, gtimer_t, MAX_GENTITIES, gtimer_s::next, NULL, entityState_s::number, and gentity_s::s.

Referenced by player_die().

00050 {
00051         // rudimentary safety checks, might be other things to check?
00052         if ( ent && ent->s.number > 0 && ent->s.number < MAX_GENTITIES )
00053         {
00054                 gtimer_t *p = g_timers[ent->s.number];
00055 
00056                 // No timers at all -> do nothing
00057                 if (!p)
00058                 {
00059                         return;
00060                 }
00061 
00062                 // Find the end of this ents timer list
00063                 while (p->next)
00064                 {
00065                         p = p->next;
00066                 }
00067 
00068                 // Splice the lists
00069                 p->next = g_timerFreeList;
00070                 g_timerFreeList = g_timers[ent->s.number];
00071                 g_timers[ent->s.number] = NULL;
00072                 return;
00073         }
00074 }

qboolean TIMER_Done gentity_t ent,
const char *  identifier
 

Definition at line 165 of file g_timer.c.

References gentity_t, gtimer_t, level, entityState_s::number, qboolean, qtrue, gentity_s::s, level_locals_t::time, gtimer_s::time, and TIMER_GetExisting().

Referenced by AI_ValidateGroupMember(), ATST_Ranged(), Boba_DoFlameThrower(), Boba_FireDecide(), Boba_FlyStart(), Droid_Pain(), Droid_Patrol(), Droid_Spin(), G_AngerAlert(), G_DroidSounds(), GM_Dying(), Howler_Combat(), Howler_Patrol(), ImperialProbe_AttackDecision(), ImperialProbe_Patrol(), ImperialProbe_Ranged(), Interrogator_Attack(), Interrogator_Melee(), Interrogator_PartsMove(), Jedi_CanPullBackSaber(), Jedi_SaberBlockGo(), Mark1_AttackDecision(), Mark1_BlasterAttack(), Mark1_dying(), Mark1_RocketAttack(), Mark2_AttackDecision(), Mark2_BlasterAttack(), Mark2_Patrol(), MineMonster_Combat(), MineMonster_Patrol(), NPC_AimAdjust(), NPC_BSFlee(), NPC_BSGM_Attack(), NPC_BSGrenadier_Attack(), NPC_BSRancor_Default(), NPC_BSSniper_Attack(), NPC_BSST_Attack(), NPC_BSST_Patrol(), NPC_BSWampa_Default(), NPC_CheckEnemyStealth(), NPC_CheckGetNewWeapon(), NPC_GM_Pain(), NPC_PlayConfusionSound(), NPC_Rancor_Pain(), NPC_Sentry_Patrol(), NPC_Wampa_Pain(), R2D2_PartsMove(), Rancor_Combat(), Rancor_Patrol(), Remote_Attack(), Remote_MaintainHeight(), Remote_Ranged(), Seeker_FollowOwner(), Seeker_MaintainHeight(), Seeker_Ranged(), Sentry_AttackDecision(), Sentry_Fire(), Sentry_RangedAttack(), Sniper_FaceEnemy(), ST_Commander(), ST_ResolveBlockedShot(), TIMER_Start(), Wampa_Combat(), Wampa_Move(), and Wampa_Patrol().

00166 {
00167         gtimer_t *timer = TIMER_GetExisting(ent->s.number, identifier);
00168 
00169         if (!timer)
00170         {
00171                 return qtrue;
00172         }
00173 
00174         return (timer->time < level.time);
00175 }

qboolean TIMER_Done2 gentity_t ent,
const char *  identifier,
qboolean  remove
 

Definition at line 223 of file g_timer.c.

References gentity_t, gtimer_t, level, entityState_s::number, qboolean, qfalse, gentity_s::s, level_locals_t::time, gtimer_s::time, TIMER_GetExisting(), and TIMER_RemoveHelper().

Referenced by Howler_Attack(), Howler_Combat(), MineMonster_Attack(), MineMonster_Combat(), NPC_BSRancor_Default(), Rancor_Attack(), Rancor_Combat(), Wampa_Attack(), and Wampa_Combat().

00224 {
00225         gtimer_t *timer = TIMER_GetExisting(ent->s.number, identifier);
00226         qboolean res;
00227 
00228         if (!timer)
00229         {
00230                 return qfalse;
00231         }
00232 
00233         res = (timer->time < level.time);
00234 
00235         if (res && remove)
00236         {
00237                 // Put it back on the free list
00238                 TIMER_RemoveHelper(ent->s.number, timer);
00239         }
00240 
00241         return res;
00242 }

qboolean TIMER_Exists gentity_t ent,
const char *  identifier
 

Definition at line 249 of file g_timer.c.

References gentity_t, gtimer_t, entityState_s::number, qboolean, qfalse, qtrue, gentity_s::s, and TIMER_GetExisting().

Referenced by Howler_Attack(), MineMonster_Attack(), NPC_AimAdjust(), Rancor_Attack(), and Wampa_Attack().

00250 {
00251         gtimer_t *timer = TIMER_GetExisting(ent->s.number, identifier);
00252 
00253         if (!timer)
00254         {
00255                 return qfalse;
00256         }
00257 
00258         return qtrue;
00259 }

int TIMER_Get gentity_t ent,
const char *  identifier
 

Definition at line 147 of file g_timer.c.

References gentity_t, gtimer_t, entityState_s::number, gentity_s::s, gtimer_s::time, and TIMER_GetExisting().

Referenced by NPC_BSSniper_Attack(), NPC_CheckEnemyStealth(), ST_ApproachEnemy(), ST_HuntEnemy(), ST_ResolveBlockedShot(), ST_TrackEnemy(), and ST_TransferTimers().

00148 {
00149         gtimer_t *timer = TIMER_GetExisting(ent->s.number, identifier);
00150 
00151         if (!timer)
00152         {
00153                 return -1;
00154         }
00155 
00156         return timer->time;
00157 }

gtimer_t* TIMER_GetExisting int  num,
const char *  identifier
 

Definition at line 106 of file g_timer.c.

References g_timers, gtimer_t, gtimer_s::name, gtimer_s::next, NULL, and Q_stricmp().

Referenced by TIMER_Done(), TIMER_Done2(), TIMER_Exists(), TIMER_Get(), and TIMER_Remove().

00107 {
00108         gtimer_t *p = g_timers[num];
00109 
00110         while (p)
00111         {
00112                 if (!Q_stricmp(p->name, identifier))
00113                 { // Found it
00114                         return p;
00115                 }
00116 
00117                 p = p->next;
00118         }
00119         
00120         return NULL;
00121 }       

gtimer_t* TIMER_GetNew int  num,
const char *  identifier
 

Definition at line 79 of file g_timer.c.

References g_timerFreeList, g_timers, gtimer_t, gtimer_s::name, gtimer_s::next, NULL, and Q_stricmp().

Referenced by TIMER_Set().

00080 {
00081         gtimer_t *p = g_timers[num];
00082 
00083         // Search for an existing timer with this name
00084         while (p)
00085         {
00086                 if (!Q_stricmp(p->name, identifier))
00087                 { // Found it
00088                         return p;
00089                 }
00090 
00091                 p = p->next;
00092         }
00093 
00094         // No existing timer with this name was found, so grab one from the free list
00095         if (!g_timerFreeList)
00096                 return NULL;
00097 
00098         p = g_timerFreeList;
00099         g_timerFreeList = g_timerFreeList->next;
00100         p->next = g_timers[num];
00101         g_timers[num] = p;
00102         return p;
00103 }

void TIMER_Remove gentity_t ent,
const char *  identifier
 

Definition at line 267 of file g_timer.c.

References gentity_t, gtimer_t, entityState_s::number, gentity_s::s, TIMER_GetExisting(), and TIMER_RemoveHelper().

Referenced by NPC_BSRancor_Default(), NPC_BSWampa_Default(), NPC_Howler_Pain(), NPC_MineMonster_Pain(), NPC_Rancor_Pain(), NPC_Wampa_Pain(), and Rancor_Swing().

00268 {
00269         gtimer_t *timer = TIMER_GetExisting(ent->s.number, identifier);
00270 
00271         if (!timer)
00272         {
00273                 return;
00274         }
00275 
00276         // Put it back on the free list
00277         TIMER_RemoveHelper(ent->s.number, timer);
00278 }

void TIMER_RemoveHelper int  num,
gtimer_t timer
 

Definition at line 187 of file g_timer.c.

References g_timerFreeList, g_timers, gtimer_t, and gtimer_s::next.

Referenced by TIMER_Done2(), and TIMER_Remove().

00188 {
00189         gtimer_t *p = g_timers[num];
00190 
00191         // Special case: first timer in list
00192         if (p == timer)
00193         {
00194                 g_timers[num] = g_timers[num]->next;
00195                 p->next = g_timerFreeList;
00196                 g_timerFreeList = p;
00197                 return;
00198         }
00199 
00200         // Find the predecessor
00201         while (p->next != timer)
00202         {
00203                 p = p->next;
00204         }
00205 
00206         // Rewire
00207         p->next = p->next->next;
00208         timer->next = g_timerFreeList;
00209         g_timerFreeList = timer;
00210         return;
00211 }

void TIMER_Set gentity_t ent,
const char *  identifier,
int  duration
 

Definition at line 129 of file g_timer.c.

References gentity_t, gtimer_t, level, gtimer_s::name, entityState_s::number, gentity_s::s, level_locals_t::time, gtimer_s::time, and TIMER_GetNew().

Referenced by ATST_Ranged(), Boba_FireDecide(), Boba_FlyStop(), Boba_StartFlameThrower(), Boba_StopKnockdown(), Droid_Patrol(), Droid_Spin(), G_AimSet(), G_AttackDelay(), G_CheckVictoryScript(), G_DroidSounds(), GM_Dying(), Grenadier_ClearTimers(), Howler_Attack(), Howler_Patrol(), ImperialProbe_AttackDecision(), ImperialProbe_Patrol(), ImperialProbe_Ranged(), Interrogator_Attack(), Interrogator_Melee(), Interrogator_PartsMove(), Jedi_CheckAmbushPlayer(), Jedi_CheckDanger(), Jedi_ClearTimers(), Jedi_RageStop(), Jedi_SaberBlockGo(), Mark1_AttackDecision(), Mark1_BlasterAttack(), Mark1_dying(), Mark1_RocketAttack(), Mark2_AttackDecision(), Mark2_BlasterAttack(), Mark2_Patrol(), MineMonster_Attack(), MineMonster_Patrol(), NPC_AimAdjust(), NPC_BSFollowLeader(), NPC_BSGM_Attack(), NPC_BSGrenadier_Attack(), NPC_BSGrenadier_Patrol(), NPC_BSJedi_FollowLeader(), NPC_BSRancor_Default(), NPC_BSSniper_Attack(), NPC_BSSniper_Patrol(), NPC_BSST_Attack(), NPC_BSWampa_Default(), NPC_CheckEnemyStealth(), NPC_Droid_Pain(), NPC_GalakMech_Init(), NPC_GM_Pain(), NPC_GM_StartLaser(), NPC_Grenadier_Pain(), NPC_Grenadier_PlayConfusionSound(), NPC_Howler_Pain(), NPC_Jedi_Pain(), NPC_Jedi_RateNewEnemy(), NPC_MineMonster_Pain(), NPC_PlayConfusionSound(), NPC_Rancor_Pain(), NPC_Sentry_Pain(), NPC_Sentry_Patrol(), NPC_Sniper_Pain(), NPC_Sniper_PlayConfusionSound(), NPC_ST_Pain(), NPC_StartFlee(), NPC_Wampa_Pain(), R2D2_PartsMove(), Rancor_Attack(), Rancor_CheckRoar(), Rancor_Combat(), Rancor_Patrol(), Rancor_Swing(), Remote_Attack(), Remote_MaintainHeight(), Remote_Ranged(), Seeker_FollowOwner(), Seeker_MaintainHeight(), Seeker_Ranged(), Sentry_AttackDecision(), Sentry_Fire(), Sentry_RangedAttack(), Sniper_ClearTimers(), Sniper_StartHide(), ST_ApproachEnemy(), ST_ClearTimers(), ST_Commander(), ST_HuntEnemy(), ST_MarkToCover(), ST_ResolveBlockedShot(), ST_TrackEnemy(), ST_TransferMoveGoal(), ST_TransferTimers(), TIMER_Start(), Wampa_Attack(), Wampa_CheckRoar(), Wampa_Move(), Wampa_Patrol(), and WP_SaberStartMissileBlockCheck().

00130 {
00131         gtimer_t *timer = TIMER_GetNew(ent->s.number, identifier);
00132 
00133         if (!timer)
00134         {
00135                 return;
00136         }
00137         timer->name = identifier;
00138         timer->time = level.time + duration;
00139 }

qboolean TIMER_Start gentity_t self,
const char *  identifier,
int  duration
 

Definition at line 286 of file g_timer.c.

References gentity_t, qboolean, qfalse, qtrue, TIMER_Done(), and TIMER_Set().

Referenced by Jedi_SaberBlockGo().

00287 {
00288         if ( TIMER_Done( self, identifier ) )
00289         {
00290                 TIMER_Set( self, identifier, duration );
00291                 return qtrue;
00292         }
00293         return qfalse;
00294 }


Variable Documentation

gtimer_t* g_timerFreeList
 

Definition at line 19 of file g_timer.c.

Referenced by TIMER_Clear(), TIMER_Clear2(), TIMER_GetNew(), and TIMER_RemoveHelper().

gtimer_t g_timerPool[ MAX_GTIMERS ]
 

Definition at line 17 of file g_timer.c.

Referenced by TIMER_Clear().

gtimer_t* g_timers[ MAX_GENTITIES ]
 

Definition at line 18 of file g_timer.c.

Referenced by TIMER_Clear(), TIMER_Clear2(), TIMER_GetExisting(), TIMER_GetNew(), and TIMER_RemoveHelper().