1 /** @file p_tick.cpp  Common top-level tick stuff.
2  *
3  * @authors Copyright © 2003-2017 Jaakko Keränen <jaakko.keranen@iki.fi>
4  * @authors Copyright © 2005-2014 Daniel Swanson <danij@dengine.net>
5  *
6  * @par License
7  * GPL: http://www.gnu.org/licenses/gpl.html
8  *
9  * <small>This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by the
11  * Free Software Foundation; either version 2 of the License, or (at your
12  * option) any later version. This program is distributed in the hope that it
13  * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
15  * Public License for more details. You should have received a copy of the GNU
16  * General Public License along with this program; if not, write to the Free
17  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18  * 02110-1301 USA</small>
19  */
20 
21 #include "common.h"
22 #include "p_tick.h"
23 
24 #include "gamesession.h"
25 #include "d_netsv.h"
26 #include "g_common.h"
27 #include "g_controls.h"
28 #include "hu_menu.h"
29 #include "hu_msg.h"
30 #include "p_actor.h"
31 #include "p_user.h"
32 #include "player.h"
33 #include "r_common.h"
34 #include "r_special.h"
35 
36 using namespace common;
37 
38 int mapTime;
39 int actualMapTime;
40 int timerGame;
41 
P_RunPlayers(timespan_t ticLength)42 void P_RunPlayers(timespan_t ticLength)
43 {
44     for(int i = 0; i < MAXPLAYERS; ++i)
45     {
46         if(players[i].plr->inGame)
47         {
48             // The player thinks.
49             P_PlayerThink(&players[i], ticLength);
50         }
51     }
52 }
53 
P_DoTick()54 void P_DoTick()
55 {
56     Pause_Ticker();
57 
58     // If the game is paused, nothing will happen.
59     if(paused) return;
60 
61     actualMapTime++;
62 
63     if(!IS_CLIENT && timerGame && !paused)
64     {
65         if(!--timerGame)
66         {
67             G_SetGameActionMapCompleted(gfw_Session()->mapUriForNamedExit("next"));
68         }
69     }
70 
71     // Pause if in menu and at least one tic has been run.
72     if(!IS_NETGAME && (Hu_MenuIsActive() || Hu_IsMessageActive()) &&
73        !Get(DD_PLAYBACK) && mapTime > 1)
74         return;
75 
76     Thinker_Run();
77 
78 #if __JDOOM__ || __JDOOM64__ || __JHERETIC__
79     // Extended lines and sectors.
80     XG_Ticker();
81 #endif
82 
83 #if __JHEXEN__
84     P_AnimateLightning();
85 #endif
86 
87 #if __JDOOM64__
88     P_ThunderSector();
89 #endif
90 
91     P_ProcessDeferredSpawns();
92 
93 #if __JHERETIC__
94     P_AmbientSound();
95 #endif
96 
97     // Let the engine know where the local players are now.
98     for(int i = 0; i < MAXPLAYERS; ++i)
99     {
100         R_UpdateConsoleView(i);
101     }
102 
103     R_UpdateSpecialFilter(DISPLAYPLAYER);
104 
105     // For par times, among other things.
106     mapTime++;
107 }
108