y_playerarray_entry.inc 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. #if defined _INC_y_playerarray
  2. #endinput
  3. #endif
  4. #define _INC_y_playerarray
  5. /*
  6. Legal:
  7. Version: MPL 1.1
  8. The contents of this file are subject to the Mozilla Public License Version
  9. 1.1 the "License"; you may not use this file except in compliance with
  10. the License. You may obtain a copy of the License at
  11. http://www.mozilla.org/MPL/
  12. Software distributed under the License is distributed on an "AS IS" basis,
  13. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  14. for the specific language governing rights and limitations under the
  15. License.
  16. The Original Code is the YSI framework.
  17. The Initial Developer of the Original Code is Alex "Y_Less" Cole.
  18. Portions created by the Initial Developer are Copyright C 2011
  19. the Initial Developer. All Rights Reserved.
  20. Contributors:
  21. Y_Less
  22. koolk
  23. JoeBullet/Google63
  24. g_aSlice/Slice
  25. Misiur
  26. samphunter
  27. tianmeta
  28. maddinat0r
  29. spacemud
  30. Crayder
  31. Dayvison
  32. Ahmad45123
  33. Zeex
  34. irinel1996
  35. Yiin-
  36. Chaprnks
  37. Konstantinos
  38. Masterchen09
  39. Southclaws
  40. PatchwerkQWER
  41. m0k1
  42. paulommu
  43. udan111
  44. Thanks:
  45. JoeBullet/Google63 - Handy arbitrary ASM jump code using SCTRL.
  46. ZeeX - Very productive conversations.
  47. koolk - IsPlayerinAreaEx code.
  48. TheAlpha - Danish translation.
  49. breadfish - German translation.
  50. Fireburn - Dutch translation.
  51. yom - French translation.
  52. 50p - Polish translation.
  53. Zamaroht - Spanish translation.
  54. Los - Portuguese translation.
  55. Dracoblue, sintax, mabako, Xtreme, other coders - Producing other modes for
  56. me to strive to better.
  57. Pixels^ - Running XScripters where the idea was born.
  58. Matite - Pestering me to release it and using it.
  59. Very special thanks to:
  60. Thiadmer - PAWN, whose limits continue to amaze me!
  61. Kye/Kalcor - SA:MP.
  62. SA:MP Team past, present and future - SA:MP.
  63. Optional plugins:
  64. Gamer_Z - GPS.
  65. Incognito - Streamer.
  66. Me - sscanf2, fixes2, Whirlpool.
  67. */
  68. #include "..\..\YSI_Core\y_utils"
  69. #include "..\..\YSI_Data\y_bit"
  70. #define PA_TYPE_NONE (-1)
  71. #define PA_TYPE_BOOL (-2)
  72. #define PA_TYPE_ID (-3)
  73. #define PA_TYPE_PA (-4)
  74. #if defined _YSI_SPECIAL_DEBUG
  75. #define PS_IS_PLAYER_CONNECTED(%0) (%0 != INVALID_PLAYER_ID)
  76. #else
  77. #define PS_IS_PLAYER_CONNECTED IsPlayerConnected
  78. #endif
  79. // Redefined later on. This is just for internal use.
  80. #define PlayerArray:%0<%1> Bit:%0[%1]
  81. #define PA_INIT:%1, Bit:PA_TYPE_PA,Bit:(-1*_:%1),Bit:(-1*_:%1),
  82. stock PA_Init(Bit:a[], bool:init = false, s = bits<MAX_PLAYERS>)
  83. {
  84. P:3("PA_Init called: %i, %i, %i", _:a, _:init, s);
  85. //--s;
  86. new
  87. Bit:m = init ? (Bit:-1) : (Bit:0);
  88. a[0] = Bit:PA_TYPE_PA;
  89. while (s)
  90. {
  91. a[s--] = m;
  92. }
  93. }
  94. #define PA_FastInit(%0) %0[0]=Bit:PA_TYPE_PA
  95. #define PA_GetBit(%1,%2) (%1[((%2)>>>CELLSHIFT)+1]&Bit:(1<<((%2)&cellbits-1)))
  96. #define PA_Get(%1,%2) bool:PA_GetBit(Bit:%1,_:%2)
  97. #define PA_Let(%1,%2) %1[((%2)>>>CELLSHIFT)+1]|=Bit:(1<<((%2)&cellbits-1))
  98. #define PA_Vet(%1,%2) %1[((%2)>>>CELLSHIFT)+1]&=Bit:~(1<<((%2)&cellbits-1))
  99. #define PA_GetCount(%1) Bit_GetCount(%1[1],bits<MAX_PLAYERS>)
  100. #define PA_Slot(%0) (Bit_Slot(%0) + 1)
  101. #define PA_Mask(%0) (Bit_Mask(%0))
  102. //#define PA_Set(%0,%1,%2) ((%2)?Bit_Let(%0,(%1)):Bit_Vet(%0,(%1)))
  103. stock PA_Set(PlayerArray:d<>, slot, bool:set)
  104. {
  105. P:3("PA_Set called: %s, %i, %i", Bit_Display(Bit:d[1]), slot, _:set);
  106. if (set)
  107. {
  108. PA_Let(d, slot);
  109. return 1;
  110. }
  111. else
  112. {
  113. PA_Vet(d, slot);
  114. return 0;
  115. }
  116. }
  117. stock Iter_Func@PA(start, const PlayerArray:data<>)
  118. {
  119. P:3("YSI_gAPAFunc called: %s, %i", Bit_Display(Bit:data[1]), start);
  120. ++start;
  121. YSI_gAPAFunc_loop:
  122. new
  123. cur,
  124. i = Bit_Slot(start) + 1;
  125. if ((cur = (_:data[i] & (~((1 << start) - 1)))))
  126. {
  127. new
  128. ret = ((i - 1) * cellbits) + Cell_GetLowestBit(cur);
  129. // I'd like to replace this with code which doesn't call
  130. // IsPlayerConnected and doesn't use "goto", but it avoids massive tail
  131. // recursion (well, it is tail recursion which I've inlined).
  132. if (PS_IS_PLAYER_CONNECTED(ret))
  133. {
  134. return ret;
  135. }
  136. else
  137. {
  138. //return YSI_gAPAFunc(data, ret);
  139. start = ret + 1;
  140. goto YSI_gAPAFunc_loop;
  141. }
  142. }
  143. ++i;
  144. while (i != bits<MAX_PLAYERS> + 1)
  145. {
  146. if ((cur = _:data[i]))
  147. {
  148. new
  149. ret = ((i - 1) * cellbits) + Cell_GetLowestBit(cur);
  150. if (PS_IS_PLAYER_CONNECTED(ret))
  151. {
  152. return ret;
  153. }
  154. else
  155. {
  156. //return YSI_gAPAFunc(data, ret);
  157. start = ret + 1;
  158. goto YSI_gAPAFunc_loop;
  159. }
  160. }
  161. ++i;
  162. }
  163. return -1;
  164. }
  165. #define Iterator@PA iterstart(-1)
  166. #undef PlayerArray
  167. #define PlayerArray:%0<%1> Bit:%0[bits<%1>+1]//={Bit:-1}