1 
2 //**************************************************************************
3 //**
4 //** p_tick.c : Heretic 2 : Raven Software, Corp.
5 //**
6 //** $RCSfile: p_tick.c,v $
7 //** $Revision: 1.5 $
8 //** $Date: 95/10/08 21:53:00 $
9 //** $Author: bgokey $
10 //**
11 //**************************************************************************
12 
13 // HEADER FILES ------------------------------------------------------------
14 
15 #include "h2def.h"
16 #include "p_local.h"
17 
18 // MACROS ------------------------------------------------------------------
19 
20 // TYPES -------------------------------------------------------------------
21 
22 // EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
23 
24 // PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
25 
26 // PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
27 
28 static void RunThinkers(void);
29 
30 // EXTERNAL DATA DECLARATIONS ----------------------------------------------
31 
32 // PUBLIC DATA DEFINITIONS -------------------------------------------------
33 
34 int leveltime;
35 int TimerGame;
36 thinker_t thinkercap; // The head and tail of the thinker list
37 
38 // PRIVATE DATA DEFINITIONS ------------------------------------------------
39 
40 // CODE --------------------------------------------------------------------
41 
42 //==========================================================================
43 //
44 // P_Ticker
45 //
46 //==========================================================================
47 
P_Ticker(void)48 void P_Ticker(void)
49 {
50 	int i;
51 
52 	if(paused)
53 	{
54 		return;
55 	}
56 	for(i = 0; i < MAXPLAYERS; i++)
57 	{
58 		if(playeringame[i])
59 		{
60 			P_PlayerThink(&players[i]);
61 		}
62 	}
63 	if(TimerGame)
64 	{
65 		if(!--TimerGame)
66 		{
67 			G_Completed(P_TranslateMap(P_GetMapNextMap(gamemap)), 0);
68 		}
69 	}
70 	RunThinkers();
71 	P_UpdateSpecials();
72 	P_AnimateSurfaces();
73 	leveltime++;
74 }
75 
76 //==========================================================================
77 //
78 // RunThinkers
79 //
80 //==========================================================================
81 
RunThinkers(void)82 static void RunThinkers(void)
83 {
84 	thinker_t *currentthinker;
85 
86 	currentthinker = thinkercap.next;
87 	while(currentthinker != &thinkercap)
88 	{
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);
94 		}
95 		else if(currentthinker->function)
96 		{
97 			currentthinker->function(currentthinker);
98 		}
99 		currentthinker = currentthinker->next;
100 	}
101 }
102 
103 //==========================================================================
104 //
105 // P_InitThinkers
106 //
107 //==========================================================================
108 
P_InitThinkers(void)109 void P_InitThinkers(void)
110 {
111 	thinkercap.prev = thinkercap.next  = &thinkercap;
112 }
113 
114 //==========================================================================
115 //
116 // P_AddThinker
117 //
118 // Adds a new thinker at the end of the list.
119 //
120 //==========================================================================
121 
P_AddThinker(thinker_t * thinker)122 void P_AddThinker(thinker_t *thinker)
123 {
124 	thinkercap.prev->next = thinker;
125 	thinker->next = &thinkercap;
126 	thinker->prev = thinkercap.prev;
127 	thinkercap.prev = thinker;
128 }
129 
130 //==========================================================================
131 //
132 // P_RemoveThinker
133 //
134 // Deallocation is lazy -- it will not actually be freed until its
135 // thinking turn comes up.
136 //
137 //==========================================================================
138 
P_RemoveThinker(thinker_t * thinker)139 void P_RemoveThinker(thinker_t *thinker)
140 {
141 	thinker->function = (think_t)-1;
142 }
143