2 //**************************************************************************
4 //** p_tick.c : Heretic 2 : Raven Software, Corp.
11 //**************************************************************************
13 // HEADER FILES ------------------------------------------------------------
18 // MACROS ------------------------------------------------------------------
20 // TYPES -------------------------------------------------------------------
22 // EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
24 // PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
26 // PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
28 static void RunThinkers(void);
30 // EXTERNAL DATA DECLARATIONS ----------------------------------------------
32 // PUBLIC DATA DEFINITIONS -------------------------------------------------
36 thinker_t thinkercap; // The head and tail of the thinker list
38 // PRIVATE DATA DEFINITIONS ------------------------------------------------
40 // CODE --------------------------------------------------------------------
42 //==========================================================================
46 //==========================================================================
56 for(i = 0; i < MAXPLAYERS; i++)
60 P_PlayerThink(&players[i]);
67 G_Completed(P_TranslateMap(P_GetMapNextMap(gamemap)), 0);
76 //==========================================================================
80 //==========================================================================
82 static void RunThinkers(void)
84 thinker_t *currentthinker;
86 currentthinker = thinkercap.next;
87 while(currentthinker != &thinkercap)
89 if(currentthinker->function == (think_t)-1)
90 { // Time to remove it
91 currentthinker->next->prev = currentthinker->prev;
92 currentthinker->prev->next = currentthinker->next;
93 Z_Free(currentthinker);
95 else if(currentthinker->function)
97 currentthinker->function(currentthinker);
99 currentthinker = currentthinker->next;
103 //==========================================================================
107 //==========================================================================
109 void P_InitThinkers(void)
111 thinkercap.prev = thinkercap.next = &thinkercap;
114 //==========================================================================
118 // Adds a new thinker at the end of the list.
120 //==========================================================================
122 void P_AddThinker(thinker_t *thinker)
124 thinkercap.prev->next = thinker;
125 thinker->next = &thinkercap;
126 thinker->prev = thinkercap.prev;
127 thinkercap.prev = thinker;
130 //==========================================================================
134 // Deallocation is lazy -- it will not actually be freed until its
135 // thinking turn comes up.
137 //==========================================================================
139 void P_RemoveThinker(thinker_t *thinker)
141 thinker->function = (think_t)-1;