DOOM-3-BFG

DOOM 3 BFG Edition
Log | Files | Refs

p_tick.cpp (4004B)


      1 /*
      2 ===========================================================================
      3 
      4 Doom 3 BFG Edition GPL Source Code
      5 Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company. 
      6 
      7 This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").  
      8 
      9 Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
     10 it under the terms of the GNU General Public License as published by
     11 the Free Software Foundation, either version 3 of the License, or
     12 (at your option) any later version.
     13 
     14 Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
     15 but WITHOUT ANY WARRANTY; without even the implied warranty of
     16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     17 GNU General Public License for more details.
     18 
     19 You should have received a copy of the GNU General Public License
     20 along with Doom 3 BFG Edition Source Code.  If not, see <http://www.gnu.org/licenses/>.
     21 
     22 In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code.  If not, please request a copy in writing from id Software at the address below.
     23 
     24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
     25 
     26 ===========================================================================
     27 */
     28 
     29 #include "Precompiled.h"
     30 #include "globaldata.h"
     31 
     32 #include "z_zone.h"
     33 #include "p_local.h"
     34 
     35 #include "doomstat.h"
     36 
     37 
     38 
     39 //
     40 // THINKERS
     41 // All thinkers should be allocated by Z_Malloc
     42 // so they can be operated on uniformly.
     43 // The actual structures will vary in size,
     44 // but the first element must be thinker_t.
     45 //
     46 
     47 
     48 
     49 // Both the head and tail of the thinker list.
     50 
     51 
     52 //
     53 // P_InitThinkers
     54 //
     55 void P_InitThinkers (void)
     56 {
     57     ::g->thinkercap.prev = ::g->thinkercap.next  = &::g->thinkercap;
     58 }
     59 
     60 
     61 
     62 
     63 //
     64 // P_AddThinker
     65 // Adds a new thinker at the end of the list.
     66 //
     67 void P_AddThinker (thinker_t* thinker)
     68 {
     69     ::g->thinkercap.prev->next = thinker;
     70     thinker->next = &::g->thinkercap;
     71     thinker->prev = ::g->thinkercap.prev;
     72     ::g->thinkercap.prev = thinker;
     73 }
     74 
     75 
     76 
     77 //
     78 // P_RemoveThinker
     79 // Deallocation is lazy -- it will not actually be freed
     80 // until its thinking turn comes up.
     81 //
     82 void P_RemoveThinker (thinker_t* thinker)
     83 {
     84   // FIXME: NOP.
     85   thinker->function.acv = (actionf_v)(-1);
     86 }
     87 
     88 
     89 
     90 //
     91 // P_AllocateThinker
     92 // Allocates memory and adds a new thinker at the end of the list.
     93 //
     94 void P_AllocateThinker (thinker_t*	thinker)
     95 {
     96 }
     97 
     98 
     99 
    100 //
    101 // P_RunThinkers
    102 //
    103 void P_RunThinkers (void)
    104 {
    105     thinker_t*	currentthinker;
    106 
    107     currentthinker = ::g->thinkercap.next;
    108     while (currentthinker != &::g->thinkercap)
    109     {
    110 		 if ( currentthinker->function.acv == (actionf_v)(-1) )
    111 		 {
    112 			 // time to remove it
    113 			 currentthinker->next->prev = currentthinker->prev;
    114 			 currentthinker->prev->next = currentthinker->next;
    115 			 Z_Free(currentthinker);
    116 		 }
    117 		 else
    118 		 {
    119 			 if (currentthinker->function.acp1)
    120 				 currentthinker->function.acp1 ((mobj_t*)currentthinker);
    121 		 }
    122 	currentthinker = currentthinker->next;
    123     }
    124 }
    125 
    126 
    127 
    128 //
    129 // P_Ticker
    130 //
    131 extern byte demoversion;
    132 
    133 void P_Ticker (void)
    134 {
    135     int		i;
    136     
    137     // run the tic
    138     if (::g->paused)
    139 		return;
    140 
    141 	// don't think during wipe
    142 	if ( !::g->netgame && (!::g->demoplayback || demoversion == VERSION ) && ::g->wipe ) {
    143 		return;
    144 	}
    145 
    146     // pause if in menu and at least one tic has been run
    147     if ( !::g->netgame
    148 	 && ::g->menuactive
    149 	 && !::g->demoplayback
    150 	 && ::g->players[::g->consoleplayer].viewz != 1)
    151     {
    152 	return;
    153     }
    154 
    155 
    156 	for (i=0 ; i<MAXPLAYERS ; i++) {
    157 		if (::g->playeringame[i]) {
    158 		    P_PlayerThink (&::g->players[i]);
    159 		}
    160 	}
    161 
    162     P_RunThinkers ();
    163     P_UpdateSpecials ();
    164     P_RespawnSpecials ();
    165 
    166     // for par times
    167     ::g->leveltime++;	
    168 }
    169