p_tick.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. // Emacs style mode select -*- C++ -*-
  2. //-----------------------------------------------------------------------------
  3. //
  4. // $Id:$
  5. //
  6. // Copyright (C) 1993-1996 by id Software, Inc.
  7. //
  8. // This source is available for distribution and/or modification
  9. // only under the terms of the DOOM Source Code License as
  10. // published by id Software. All rights reserved.
  11. //
  12. // The source is distributed in the hope that it will be useful,
  13. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License
  15. // for more details.
  16. //
  17. // $Log:$
  18. //
  19. // DESCRIPTION:
  20. // Archiving: SaveGame I/O.
  21. // Thinker, Ticker.
  22. //
  23. //-----------------------------------------------------------------------------
  24. static const char
  25. rcsid[] = "$Id: p_tick.c,v 1.4 1997/02/03 16:47:55 b1 Exp $";
  26. #include "z_zone.h"
  27. #include "p_local.h"
  28. #include "doomstat.h"
  29. int leveltime;
  30. //
  31. // THINKERS
  32. // All thinkers should be allocated by Z_Malloc
  33. // so they can be operated on uniformly.
  34. // The actual structures will vary in size,
  35. // but the first element must be thinker_t.
  36. //
  37. // Both the head and tail of the thinker list.
  38. thinker_t thinkercap;
  39. //
  40. // P_InitThinkers
  41. //
  42. void P_InitThinkers (void)
  43. {
  44. thinkercap.prev = thinkercap.next = &thinkercap;
  45. }
  46. //
  47. // P_AddThinker
  48. // Adds a new thinker at the end of the list.
  49. //
  50. void P_AddThinker (thinker_t* thinker)
  51. {
  52. thinkercap.prev->next = thinker;
  53. thinker->next = &thinkercap;
  54. thinker->prev = thinkercap.prev;
  55. thinkercap.prev = thinker;
  56. }
  57. //
  58. // P_RemoveThinker
  59. // Deallocation is lazy -- it will not actually be freed
  60. // until its thinking turn comes up.
  61. //
  62. void P_RemoveThinker (thinker_t* thinker)
  63. {
  64. // FIXME: NOP.
  65. thinker->function.acv = (actionf_v)(-1);
  66. }
  67. //
  68. // P_AllocateThinker
  69. // Allocates memory and adds a new thinker at the end of the list.
  70. //
  71. void P_AllocateThinker (thinker_t* thinker)
  72. {
  73. }
  74. //
  75. // P_RunThinkers
  76. //
  77. void P_RunThinkers (void)
  78. {
  79. thinker_t* currentthinker;
  80. currentthinker = thinkercap.next;
  81. while (currentthinker != &thinkercap)
  82. {
  83. if ( currentthinker->function.acv == (actionf_v)(-1) )
  84. {
  85. // time to remove it
  86. currentthinker->next->prev = currentthinker->prev;
  87. currentthinker->prev->next = currentthinker->next;
  88. Z_Free (currentthinker);
  89. }
  90. else
  91. {
  92. if (currentthinker->function.acp1)
  93. currentthinker->function.acp1 (currentthinker);
  94. }
  95. currentthinker = currentthinker->next;
  96. }
  97. }
  98. //
  99. // P_Ticker
  100. //
  101. void P_Ticker (void)
  102. {
  103. int i;
  104. // run the tic
  105. if (paused)
  106. return;
  107. // pause if in menu and at least one tic has been run
  108. if ( !netgame
  109. && menuactive
  110. && !demoplayback
  111. && players[consoleplayer].viewz != 1)
  112. {
  113. return;
  114. }
  115. for (i=0 ; i<MAXPLAYERS ; i++)
  116. if (playeringame[i])
  117. P_PlayerThink (&players[i]);
  118. P_RunThinkers ();
  119. P_UpdateSpecials ();
  120. P_RespawnSpecials ();
  121. // for par times
  122. leveltime++;
  123. }