Add weapon cycling bindings for mouse and joystick buttons. Add weapon cycling bindi...
[chocolate-doom.git] / src / p_tick.c
blob9429cf20f42ec081455b2ac094fee5abc4fd1a0d
1 // Emacs style mode select -*- C++ -*-
2 //-----------------------------------------------------------------------------
3 //
4 // Copyright(C) 1993-1996 Id Software, Inc.
5 // Copyright(C) 2005 Simon Howard
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20 // 02111-1307, USA.
22 // DESCRIPTION:
23 // Archiving: SaveGame I/O.
24 // Thinker, Ticker.
26 //-----------------------------------------------------------------------------
29 #include "z_zone.h"
30 #include "p_local.h"
32 #include "doomstat.h"
35 int leveltime;
38 // THINKERS
39 // All thinkers should be allocated by Z_Malloc
40 // so they can be operated on uniformly.
41 // The actual structures will vary in size,
42 // but the first element must be thinker_t.
47 // Both the head and tail of the thinker list.
48 thinker_t thinkercap;
52 // P_InitThinkers
54 void P_InitThinkers (void)
56 thinkercap.prev = thinkercap.next = &thinkercap;
63 // P_AddThinker
64 // Adds a new thinker at the end of the list.
66 void P_AddThinker (thinker_t* thinker)
68 thinkercap.prev->next = thinker;
69 thinker->next = &thinkercap;
70 thinker->prev = thinkercap.prev;
71 thinkercap.prev = thinker;
77 // P_RemoveThinker
78 // Deallocation is lazy -- it will not actually be freed
79 // until its thinking turn comes up.
81 void P_RemoveThinker (thinker_t* thinker)
83 // FIXME: NOP.
84 thinker->function.acv = (actionf_v)(-1);
90 // P_AllocateThinker
91 // Allocates memory and adds a new thinker at the end of the list.
93 void P_AllocateThinker (thinker_t* thinker)
100 // P_RunThinkers
102 void P_RunThinkers (void)
104 thinker_t* currentthinker;
106 currentthinker = thinkercap.next;
107 while (currentthinker != &thinkercap)
109 if ( currentthinker->function.acv == (actionf_v)(-1) )
111 // time to remove it
112 currentthinker->next->prev = currentthinker->prev;
113 currentthinker->prev->next = currentthinker->next;
114 Z_Free (currentthinker);
116 else
118 if (currentthinker->function.acp1)
119 currentthinker->function.acp1 (currentthinker);
121 currentthinker = currentthinker->next;
128 // P_Ticker
131 void P_Ticker (void)
133 int i;
135 // run the tic
136 if (paused)
137 return;
139 // pause if in menu and at least one tic has been run
140 if ( !netgame
141 && menuactive
142 && !demoplayback
143 && players[consoleplayer].viewz != 1)
145 return;
149 for (i=0 ; i<MAXPLAYERS ; i++)
150 if (playeringame[i])
151 P_PlayerThink (&players[i]);
153 P_RunThinkers ();
154 P_UpdateSpecials ();
155 P_RespawnSpecials ();
157 // for par times
158 leveltime++;