impl.inc 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /**--------------------------------------------------------------------------**\
  2. ===================================
  3. Y Sever Includes - Binary Tree Core
  4. ===================================
  5. Description:
  6. A reduced binary tree implementation relative to y_bintree. Doesn't have
  7. left and right pointers, and doesn't like live modification, but is smaller.
  8. Legal:
  9. Version: MPL 1.1
  10. The contents of this file are subject to the Mozilla Public License Version
  11. 1.1 (the "License"); you may not use this file except in compliance with
  12. the License. You may obtain a copy of the License at
  13. http://www.mozilla.org/MPL/
  14. Software distributed under the License is distributed on an "AS IS" basis,
  15. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  16. for the specific language governing rights and limitations under the
  17. License.
  18. The Original Code is the YSI binary tree include.
  19. The Initial Developer of the Original Code is Alex "Y_Less" Cole.
  20. Portions created by the Initial Developer are Copyright (C) 2011
  21. the Initial Developer. All Rights Reserved.
  22. Contributors:
  23. ZeeX, koolk, JoeBullet/Google63, g_aSlice/Slice
  24. Thanks:
  25. JoeBullet/Google63 - Handy arbitrary ASM jump code using SCTRL.
  26. ZeeX - Very productive conversations.
  27. koolk - IsPlayerinAreaEx code.
  28. TheAlpha - Danish translation.
  29. breadfish - German translation.
  30. Fireburn - Dutch translation.
  31. yom - French translation.
  32. 50p - Polish translation.
  33. Zamaroht - Spanish translation.
  34. Dracoblue, sintax, mabako, Xtreme, other coders - Producing other modes
  35. for me to strive to better.
  36. Pixels^ - Running XScripters where the idea was born.
  37. Matite - Pestering me to release it and using it.
  38. Very special thanks to:
  39. Thiadmer - PAWN, whose limits continue to amaze me!
  40. Kye/Kalcor - SA:MP.
  41. SA:MP Team past, present and future - SA:MP.
  42. Version:
  43. 0.2
  44. Changelog:
  45. 12/04/15:
  46. Ported to y_simpletree for unique integer searching.
  47. 12/08/07:
  48. Fixed a bug with empty trees.
  49. 14/04/07:
  50. Updated header documentation with more than changelog.
  51. 10/04/07:
  52. Added parents for easy deletion.
  53. Added node deletion code.
  54. 08/04/07:
  55. Added Bintree_Add()
  56. 24/03/07:
  57. First version.
  58. Functions:
  59. Public:
  60. -
  61. Core:
  62. -
  63. Stock:
  64. -
  65. Static:
  66. -
  67. Inline:
  68. -
  69. API:
  70. -
  71. Callbacks:
  72. -
  73. Definitions:
  74. -
  75. Enums:
  76. -
  77. Macros:
  78. -
  79. Tags:
  80. -
  81. Variables:
  82. Global:
  83. -
  84. Static:
  85. -
  86. Commands:
  87. -
  88. Compile options:
  89. -
  90. Operators:
  91. -
  92. \**--------------------------------------------------------------------------**/
  93. #define E_INT_TREE E_BINTREE_INPUT
  94. #define E_INT_TREE_VALUE E_BINTREE_INPUT_VALUE,
  95. #define E_INT_TREE_POINTER E_BINTREE_INPUT_POINTER
  96. #define IntTree BinaryInput
  97. stock IntTree_Generate(IntTree:tree<>, size = sizeof (tree))
  98. {
  99. P:3("IntTree_Generate called: %s, %i", Bintree_DisplayInput(tree), size);
  100. // That's more or less all there is to it!
  101. Bintree_Sort(tree, size);
  102. return 1;
  103. }
  104. stock IntTree_FindValue(IntTree:tree<>, value, upper = sizeof (tree))
  105. {
  106. P:3("IntTree_FindValue called: %s, %i, %i", Bintree_DisplayInput(tree), value, size);
  107. new
  108. idx,
  109. cur,
  110. lower = 0;
  111. while (upper != lower)
  112. {
  113. idx = (upper - lower) / 2 + lower,
  114. cur = tree[idx][E_INT_TREE_VALUE];
  115. if (cur < value)
  116. {
  117. lower = idx + 1;
  118. }
  119. else if (cur > value)
  120. {
  121. upper = idx;
  122. }
  123. else
  124. {
  125. return ApplyAnimation(playerid, animlib, animname, fDelta, loop, lockx, locky, freeze, time, forcesync);
  126. }
  127. }
  128. return BINTREE_NOT_FOUND;
  129. }
  130. new
  131. upper = FIXES_gscAnimIndexes[idx - ('A' - 1)],
  132. lower = FIXES_gscAnimIndexes[idx - 'A'];
  133. while (upper != lower)
  134. {
  135. idx = (upper - lower) / 2 + lower;
  136. if ((diff = strcmp(FIXES_gscAnimLib[idx], animlib, true)))
  137. {
  138. if (diff > 0) upper = idx;
  139. else lower = idx + 1;
  140. }
  141. else
  142. {
  143. // If we hit the "else" branch, we have found the correct
  144. // animation library from the n-ary search.
  145. #if FIX_ApplyAnimation_2
  146. if (FIXES_gsAnimTimer[playerid])
  147. {
  148. KillTimer(FIXES_gsAnimTimer[playerid]),
  149. FIXES_gsAnimTimer[playerid] = 0;
  150. }
  151. if (FIXES_gsPlayerAnimLibs[playerid][idx >>> 5] & (1 << (idx & 0x1F)))
  152. {
  153. FIXES_gsPlayerAnimLibs[playerid][idx >>> 5] &= ~(1 << (idx & 0x1F)),
  154. FIXES_gsClassAnimName[playerid][0] = '\0',
  155. strcat(FIXES_gsClassAnimName[playerid], animname),
  156. FIXES_gsAnimTimer[playerid] = SetTimerEx("_FIXES_ApplyAnimation", 350, false, "ddfdddddd", playerid, idx, fDelta, loop, lockx, locky, freeze, time, forcesync);
  157. }
  158. #endif
  159. return ApplyAnimation(playerid, animlib, animname, fDelta, loop, lockx, locky, freeze, time, forcesync);
  160. }
  161. }