P_TICK.C 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. //**************************************************************************
  2. //**
  3. //** p_tick.c : Heretic 2 : Raven Software, Corp.
  4. //**
  5. //** $RCSfile: p_tick.c,v $
  6. //** $Revision: 1.5 $
  7. //** $Date: 95/10/08 21:53:00 $
  8. //** $Author: bgokey $
  9. //**
  10. //**************************************************************************
  11. // HEADER FILES ------------------------------------------------------------
  12. #include "h2def.h"
  13. #include "p_local.h"
  14. // MACROS ------------------------------------------------------------------
  15. // TYPES -------------------------------------------------------------------
  16. // EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
  17. // PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
  18. // PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
  19. static void RunThinkers(void);
  20. // EXTERNAL DATA DECLARATIONS ----------------------------------------------
  21. // PUBLIC DATA DEFINITIONS -------------------------------------------------
  22. int leveltime;
  23. int TimerGame;
  24. thinker_t thinkercap; // The head and tail of the thinker list
  25. // PRIVATE DATA DEFINITIONS ------------------------------------------------
  26. // CODE --------------------------------------------------------------------
  27. //==========================================================================
  28. //
  29. // P_Ticker
  30. //
  31. //==========================================================================
  32. void P_Ticker(void)
  33. {
  34. int i;
  35. if(paused)
  36. {
  37. return;
  38. }
  39. for(i = 0; i < MAXPLAYERS; i++)
  40. {
  41. if(playeringame[i])
  42. {
  43. P_PlayerThink(&players[i]);
  44. }
  45. }
  46. if(TimerGame)
  47. {
  48. if(!--TimerGame)
  49. {
  50. G_Completed(P_TranslateMap(P_GetMapNextMap(gamemap)), 0);
  51. }
  52. }
  53. RunThinkers();
  54. P_UpdateSpecials();
  55. P_AnimateSurfaces();
  56. leveltime++;
  57. }
  58. //==========================================================================
  59. //
  60. // RunThinkers
  61. //
  62. //==========================================================================
  63. static void RunThinkers(void)
  64. {
  65. thinker_t *currentthinker;
  66. currentthinker = thinkercap.next;
  67. while(currentthinker != &thinkercap)
  68. {
  69. if(currentthinker->function == (think_t)-1)
  70. { // Time to remove it
  71. currentthinker->next->prev = currentthinker->prev;
  72. currentthinker->prev->next = currentthinker->next;
  73. Z_Free(currentthinker);
  74. }
  75. else if(currentthinker->function)
  76. {
  77. currentthinker->function(currentthinker);
  78. }
  79. currentthinker = currentthinker->next;
  80. }
  81. }
  82. //==========================================================================
  83. //
  84. // P_InitThinkers
  85. //
  86. //==========================================================================
  87. void P_InitThinkers(void)
  88. {
  89. thinkercap.prev = thinkercap.next = &thinkercap;
  90. }
  91. //==========================================================================
  92. //
  93. // P_AddThinker
  94. //
  95. // Adds a new thinker at the end of the list.
  96. //
  97. //==========================================================================
  98. void P_AddThinker(thinker_t *thinker)
  99. {
  100. thinkercap.prev->next = thinker;
  101. thinker->next = &thinkercap;
  102. thinker->prev = thinkercap.prev;
  103. thinkercap.prev = thinker;
  104. }
  105. //==========================================================================
  106. //
  107. // P_RemoveThinker
  108. //
  109. // Deallocation is lazy -- it will not actually be freed until its
  110. // thinking turn comes up.
  111. //
  112. //==========================================================================
  113. void P_RemoveThinker(thinker_t *thinker)
  114. {
  115. thinker->function = (think_t)-1;
  116. }