p_tick.cpp 3.9 KB

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