]> git.lizzy.rs Git - plan9front.git/blob - sys/src/games/doom/p_tick.c
games/doom: fix switch textures swapping in ultimate doom (thansk qu7uux)
[plan9front.git] / sys / src / games / doom / p_tick.c
1 // Emacs style mode select   -*- C++ -*- 
2 //-----------------------------------------------------------------------------
3 //
4 // $Id:$
5 //
6 // Copyright (C) 1993-1996 by id Software, Inc.
7 //
8 // This source is available for distribution and/or modification
9 // only under the terms of the DOOM Source Code License as
10 // published by id Software. All rights reserved.
11 //
12 // The source is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License
15 // for more details.
16 //
17 // $Log:$
18 //
19 // DESCRIPTION:
20 //      Archiving: SaveGame I/O.
21 //      Thinker, Ticker.
22 //
23 //-----------------------------------------------------------------------------
24
25 static const char
26 rcsid[] = "$Id: p_tick.c,v 1.4 1997/02/03 16:47:55 b1 Exp $";
27
28 #include "z_zone.h"
29 #include "p_local.h"
30
31 #include "doomstat.h"
32
33
34 int     leveltime;
35
36 //
37 // THINKERS
38 // All thinkers should be allocated by Z_Malloc
39 // so they can be operated on uniformly.
40 // The actual structures will vary in size,
41 // but the first element must be thinker_t.
42 //
43
44
45
46 // Both the head and tail of the thinker list.
47 thinker_t       thinkercap;
48
49
50 //
51 // P_InitThinkers
52 //
53 void P_InitThinkers (void)
54 {
55     thinkercap.prev = thinkercap.next  = &thinkercap;
56 }
57
58
59
60
61 //
62 // P_AddThinker
63 // Adds a new thinker at the end of the list.
64 //
65 void P_AddThinker (thinker_t* thinker)
66 {
67     thinkercap.prev->next = thinker;
68     thinker->next = &thinkercap;
69     thinker->prev = thinkercap.prev;
70     thinkercap.prev = thinker;
71 }
72
73
74
75 //
76 // P_RemoveThinker
77 // Deallocation is lazy -- it will not actually be freed
78 // until its thinking turn comes up.
79 //
80 void P_RemoveThinker (thinker_t* thinker)
81 {
82   // FIXME: NOP.
83   thinker->function = (actionf_t)(-1);
84 }
85
86
87 //
88 // P_RunThinkers
89 //
90 void P_RunThinkers (void)
91 {
92     thinker_t*  currentthinker;
93
94     currentthinker = thinkercap.next;
95     while (currentthinker != &thinkercap)
96     {
97         if ( currentthinker->function == (actionf_t)(-1) )
98         {
99             // time to remove it
100             currentthinker->next->prev = currentthinker->prev;
101             currentthinker->prev->next = currentthinker->next;
102             Z_Free (currentthinker);
103         }
104         else
105         {
106             if (currentthinker->function)
107                 currentthinker->function(currentthinker, NULL);
108         }
109         currentthinker = currentthinker->next;
110     }
111 }
112
113
114
115 //
116 // P_Ticker
117 //
118
119 void P_Ticker (void)
120 {
121     int         i;
122     
123     // run the tic
124     if (paused)
125         return;
126                 
127     // pause if in menu and at least one tic has been run
128     if ( !netgame
129          && menuactive
130          && !demoplayback
131          && players[consoleplayer].viewz != 1)
132     {
133         return;
134     }
135     
136                 
137     for (i=0 ; i<MAXPLAYERS ; i++)
138         if (playeringame[i])
139             P_PlayerThink (&players[i]);
140                         
141     P_RunThinkers ();
142     P_UpdateSpecials ();
143     P_RespawnSpecials ();
144
145     // for par times
146     leveltime++;        
147 }