doom

a minimalistic implementation of doom
git clone git://ssnf.xyz/doom
Log | Files | Refs

p_tick.c (1462B)


      1 #include "z_zone.h"
      2 #include "p_local.h"
      3 
      4 #include "doomstat.h"
      5 
      6 
      7 int	leveltime;
      8 
      9 
     10 
     11 
     12 
     13 
     14 
     15 
     16 
     17 
     18 
     19 
     20 thinker_t	thinkercap;
     21 
     22 
     23 
     24 
     25 
     26 void P_InitThinkers (void)
     27 {
     28     thinkercap.prev = thinkercap.next  = &thinkercap;
     29 }
     30 
     31 
     32 
     33 
     34 
     35 
     36 
     37 
     38 void P_AddThinker (thinker_t* thinker)
     39 {
     40     thinkercap.prev->next = thinker;
     41     thinker->next = &thinkercap;
     42     thinker->prev = thinkercap.prev;
     43     thinkercap.prev = thinker;
     44 }
     45 
     46 
     47 
     48 
     49 
     50 
     51 
     52 
     53 void P_RemoveThinker (thinker_t* thinker)
     54 {
     55   
     56   thinker->function.acv = (actionf_v)(-1);
     57 }
     58 
     59 
     60 
     61 
     62 
     63 
     64 
     65 void P_AllocateThinker (thinker_t*	thinker)
     66 {
     67 }
     68 
     69 
     70 
     71 
     72 
     73 
     74 void P_RunThinkers (void)
     75 {
     76     thinker_t*	currentthinker;
     77 
     78     currentthinker = thinkercap.next;
     79     while (currentthinker != &thinkercap)
     80     {
     81 	if ( currentthinker->function.acv == (actionf_v)(-1) )
     82 	{
     83 	    
     84 	    currentthinker->next->prev = currentthinker->prev;
     85 	    currentthinker->prev->next = currentthinker->next;
     86 	    Z_Free (currentthinker);
     87 	}
     88 	else
     89 	{
     90 	    if (currentthinker->function.acp1)
     91 		currentthinker->function.acp1 (currentthinker);
     92 	}
     93 	currentthinker = currentthinker->next;
     94     }
     95 }
     96 
     97 
     98 
     99 
    100 
    101 
    102 
    103 void P_Ticker (void)
    104 {
    105     int		i;
    106     
    107     
    108     if (paused)
    109 	return;
    110 		
    111     
    112     if ( !netgame
    113 	 && menuactive
    114 	 && !demoplayback
    115 	 && players[consoleplayer].viewz != 1)
    116     {
    117 	return;
    118     }
    119     
    120 		
    121     for (i=0 ; i<MAXPLAYERS ; i++)
    122 	if (playeringame[i])
    123 	    P_PlayerThink (&players[i]);
    124 			
    125     P_RunThinkers ();
    126     P_UpdateSpecials ();
    127     P_RespawnSpecials ();
    128 
    129     
    130     leveltime++;	
    131 }