Guest User

Untitled

a guest
Apr 22nd, 2015
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 37.39 KB | None | 0 0
  1. #if defined __foreach_inc
  2. #endinput
  3. #endif
  4.  
  5. #define __foreach_inc
  6.  
  7. /*----------------------------------------------------------------------------*\
  8. ===========================
  9. foreach efficient looping
  10. ===========================
  11. Description:
  12. Provides efficient looping through sparse data sets, such as connected
  13. players. Significantly improved from the original version to be a generic
  14. loop system, rather then purely a player loop system. When used for
  15. players this has constant time O(n) for number of connected players (n),
  16. unlike standard player loops which are O(MAX_PLAYERS), regardless of the
  17. actual number of connected players. Even when n is MAX_PLAYERS this is
  18. still faster.
  19. Legal:
  20. Version: MPL 1.1
  21.  
  22. The contents of this file are subject to the Mozilla Public License Version
  23. 1.1 (the "License"); you may not use this file except in compliance with
  24. the License. You may obtain a copy of the License at
  25. http://www.mozilla.org/MPL/
  26.  
  27. Software distributed under the License is distributed on an "AS IS" basis,
  28. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  29. for the specific language governing rights and limitations under the
  30. License.
  31.  
  32. The Original Code is the YSI foreach include.
  33.  
  34. The Initial Developer of the Original Code is Alex "Y_Less" Cole.
  35. Portions created by the Initial Developer are Copyright (C) 2011
  36. the Initial Developer. All Rights Reserved.
  37.  
  38. Contributors:
  39. ZeeX, koolk, JoeBullet/Google63, g_aSlice/Slice
  40.  
  41. Thanks:
  42. JoeBullet/Google63 - Handy arbitrary ASM jump code using SCTRL.
  43. ZeeX - Very productive conversations.
  44. koolk - IsPlayerinAreaEx code.
  45. TheAlpha - Danish translation.
  46. breadfish - German translation.
  47. Fireburn - Dutch translation.
  48. yom - French translation.
  49. 50p - Polish translation.
  50. Zamaroht - Spanish translation.
  51. Dracoblue, sintax, mabako, Xtreme, other coders - Producing other modes
  52. for me to strive to better.
  53. Pixels^ - Running XScripters where the idea was born.
  54. Matite - Pestering me to release it and using it.
  55.  
  56. Very special thanks to:
  57. Thiadmer - PAWN, whose limits continue to amaze me!
  58. Kye/Kalcor - SA:MP.
  59. SA:MP Team past, present and future - SA:MP.
  60.  
  61. Version:
  62. 0.4.1
  63. Changelog:
  64. 16/07/12:
  65. Fixed a bug with "loadfs" blocking callbacks.
  66. Slightly reduced the memory consumption of constant strings.
  67. 25/05/12:
  68. Added a delay timer to remove players for "Kick" crashes.
  69. 05/01/12:
  70. Fixed multi-dimensional iterators.
  71. Fixed "FOREACH_NO_BOTS".
  72. Made "Iterator:" support multi-dimensional arrays.
  73. 07/12/11:
  74. Underlying implementation tweak for more consistent code.
  75. Added Iter_Contains.
  76. 06/12/11:
  77. Minor fixes.
  78. 31/10/11:
  79. Changed the underlying loop code to be slightly faster.
  80. Added support for Iter_SafeRemove, prompting refactoring.
  81. 17/09/11:
  82. Fixed arrays under the new syntax.
  83. 28/04/11:
  84. Moved iterator identifiers to end of variables.
  85. Rewrote "foreach" to accept two syntaxes for "foreach (new i : Iter)".
  86. 16/08/10:
  87. Removed all the "2" versions of the functions.
  88. 14/08/10:
  89. Added Iter_Clear to reset an array.
  90. 06/08/10:
  91. Added special array declaration format.
  92. 18/12/09:
  93. Added Itter_Func2 functions for multi-dimensional iterators.
  94. Renamed foreact et al as keywords in the documentation.
  95. Changed licensing from GPL to MPL.
  96. 02/09/09:
  97. Fixed (again) for 0.3.
  98. Added free slot finding.
  99. 21/08/09:
  100. Updated to include random functions.
  101. Made entirely stand alone.
  102. Ported to 0.3 (separate version).
  103. Added automatic callback hook code.
  104. Removed debug information from stand alone version.
  105. 06/01/08:
  106. Added debug information.
  107. 09/10/07:
  108. Moved to system.
  109. 16/09/07:
  110. Added list sorting.
  111. Made this part of Y SeRver Includes, not Y Sever Includes.
  112. Made list sorting optional.
  113. Fixed version number.
  114. 08/09/07:
  115. First version.
  116. Functions:
  117. Public:
  118. OnPlayerDisconnect - Called when a player leaves to remove them.
  119. OnPlayerConnect - Called when a player connects to add them.
  120. Core:
  121. -
  122. Stock:
  123. Itter_ShowArray - Displays the contents of the array.
  124. Itter_AddInternal - Add a value to an itterator.
  125. Itter_RemoveInternal - Remove a value from an itterator.
  126. Itter_RandomInternal - Get a random item from an itterator.
  127. Itter_FreeInternal - Gets the first free slot in the itterator.
  128. Itter_InitInternal - Initialises a multi-dimensional itterator.
  129. Itter_ContainsInternal - Checks if a value is in an iterator.
  130. Static:
  131. -
  132. Inline:
  133. Itter_Create - Create a new itterator value set.
  134. Itter_Add - Wraps Itter_AddInternal.
  135. Itter_SafeRemove - Wraps Itter_SafeRemoveInternal.
  136. Itter_Remove - Wraps Itter_RemoveInternal.
  137. Itter_Random - Wraps Itter_RandomInternal.
  138. Itter_Count - Gets the number of items in an itterator.
  139. Itter_Debug - Wraps around Itter_ShowArray.
  140. Itter_Free - Wraps around Itter_FreeInternal.
  141. Itter_Contains - Wraps around Itter_ContainsInternal.
  142. API:
  143. -
  144. Callbacks:
  145. -
  146. Hooks:
  147. Itter_OnPlayerConnect - Hook for the OnPlayerConnect callback.
  148. Itter_OnPlayerDisconnect - Hook for the OnPlayerDisconnect callback.
  149. Itter_OnGameModeInit - Only exists to make the code compile correctly...
  150. Definitions:
  151. -
  152. Enums:
  153. -
  154. Macros:
  155. -
  156. Keywords:
  157. foreach - Command to loop an iterator.
  158. foreachex - Like foreach but without a new variable.
  159. foreach2 - Command to loop through an iterator array.
  160. foreachex - Like foreach2 but without a new variable.
  161. Tags:
  162. Iterator - Declare an iterator.
  163. Variables:
  164. Global:
  165. -
  166. Static:
  167. YSI_g_OPC - Records wether Itter_OnPlayerConnect exists for speed.
  168. YSI_g_OPDC - Records wether Itter_OnPlayerDisconnect exists for speed.
  169. Commands:
  170. -
  171. Compile options:
  172. YSI_ITTER_NO_SORT - Removed.
  173. FOREACH_NO_BOTS - Remove the bot iterators for smaller code.
  174. FOREACH_NO_PLAYERS - Remove all default code for player itteration.
  175. Operators:
  176. -
  177. Iterators:
  178. Player - List of all players connected.
  179. Bot - List of all bots (npcs) connected.
  180. NPC - Alias of Bot.
  181. Character - All players and bots.
  182. \*----------------------------------------------------------------------------*/
  183.  
  184. #define _FOREACH_LOCAL_VERSION 17
  185.  
  186. // Foreach is testing us.
  187. #if defined _FOREACH_INC_TEST
  188. #define _FOREACH_CUR_VERSION _FOREACH_LOCAL_VERSION
  189. #endinput
  190. #endif
  191. #if !defined _FOREACH_NO_TEST
  192. #define _FOREACH_INC_TEST
  193. #tryinclude <YSI\y_iterate>
  194. #undef _FOREACH_INC_TEST
  195. // <foreach> exists - test which is newer.
  196. #if defined _inc_y_iterate
  197. #if _FOREACH_CUR_VERSION > _FOREACH_LOCAL_VERSION
  198. // Foreach is newer.
  199. #undef _inc_y_iterate
  200. #define _FOREACH_NO_TEST
  201. #include <YSI\y_iterate>
  202. #endinput
  203. #endif
  204. #endif
  205. #endif
  206.  
  207. #if !defined _samp_included
  208. #error "Please include a_samp or a_npc before foreach"
  209. #endif
  210.  
  211. //#include <YSI\y_debug>
  212. //#include <YSI\y_hooks>
  213.  
  214. #if defined SendChat || defined FOREACH_NO_PLAYERS
  215. #define BOTSYNC_IS_BOT (true)
  216. #endif
  217.  
  218. #if defined IsPlayerNPC
  219. #define _FOREACH_BOT
  220. #endif
  221.  
  222. #if defined YSI_ITTER_NO_SORT
  223. #error YSI_ITTER_NO_SORT is no longer supported by foreach.
  224. #endif
  225.  
  226. #define _Y_ITER_ARRAY: _:_Y_ITER_C0:
  227. #define _Y_ITER_ARRAY_SIZE(%1) _:_Y_ITER_C1:_Y_ITER_C2:sizeof %1@YSII_Ag-1
  228.  
  229. #define _Y_ITER_C0:%0[%1]@YSII_%4g%3) %0@YSII_%4g[%1]%3)
  230. #define _Y_ITER_C1:_Y_ITER_C2:%0[%1]@YSII_Ag%3) %0@YSII_Ag[]%3)
  231. #define _Y_ITER_C2:sizeof%0(%1)@YSII_Ag-1;_:(%2=_Y_ITER_ARRAY:%3(%4)@YSII_Ag[%5])!=_Y_ITER_ARRAY_SIZE(%6);) -1;_:(%2=%3@YSII_Ag(%4,%5))!=-1;)
  232.  
  233. #define _Y_ITER_C3:%0[%1]@YSII_Cg,%2[%3]@YSII_Ag[%4]={%5} _Y_ITER_C3:%0@YSII_Cg[%1],%0@YSII_Ag[%1][%4]
  234.  
  235. #if !defined BOTSYNC_IS_BOT
  236. static stock
  237. YSI_g_sCallbacks = 0;
  238. #endif
  239.  
  240. #if !defined BOTSYNC_IS_BOT
  241. forward Itter_OPDCInternal(playerid);
  242. #endif
  243.  
  244. /*----------------------------------------------------------------------------*\
  245. Function:
  246. Itter_Create2
  247. Params:
  248. name - Itterator identifier.
  249. size0 - Number of iterators.
  250. size1 - Number of items per iterator.
  251. Return:
  252. -
  253. Notes:
  254. Creates a new array of itterator start/array pair.
  255. \*----------------------------------------------------------------------------*/
  256.  
  257. // If this ever changes, update the size reference in y_users.
  258. /*#define Iter_Create2 Itter_Create2
  259. #define Itter_Create2(%1,%2,%3) \
  260. new \
  261. %1@YSII_Sg[%2] = {-1, ...}, \
  262. %1@YSII_Cg[%2] = {0}, \
  263. %1@YSII_Ag[%2][%3]*/
  264.  
  265. #define IteratorArray:%1[%2]<%3> %1@YSII_Cg[%2],%1@YSII_Ag[%2][%3+1]//,%1@YSII_Rg[%2][%3+1]
  266.  
  267. /*----------------------------------------------------------------------------*\
  268. Array:
  269. Iterator
  270. Notes:
  271. Creates a new itterator start/array pair.
  272. \*----------------------------------------------------------------------------*/
  273.  
  274. #define Iterator:%1<%2> _Y_ITER_C3:%1@YSII_Cg,%1@YSII_Ag[(%2)+1]={(%2)*2,(%2)*2-1,...}
  275. #define iterator%0<%1> Iterator:%0<%1>
  276.  
  277. /*----------------------------------------------------------------------------*\
  278. Function:
  279. Itter_Init2
  280. Params:
  281. itter - Name of the itterator array to initialise.
  282. Return:
  283. -
  284. Notes:
  285. Wrapper for Itter_InitInternal.
  286.  
  287. native Iter_Init(IteratorArray:Name[]<>);
  288.  
  289. \*----------------------------------------------------------------------------*/
  290.  
  291. #define Iter_Init Itter_Init
  292. #define Itter_Init(%1) \
  293. Itter_InitInternal(%1@YSII_Ag,sizeof %1@YSII_Ag,sizeof %1@YSII_Ag[]-1)
  294.  
  295. /*----------------------------------------------------------------------------*\
  296. Function:
  297. Itter_Create
  298. Params:
  299. name - Itterator identifier.
  300. size - Number of values.
  301. Return:
  302. -
  303. Notes:
  304. Creates a new itterator start/array pair.
  305. \*----------------------------------------------------------------------------*/
  306.  
  307. // If this ever changes, update the size reference in y_users.
  308. /*#define Iter_Create Itter_Create
  309. #define Itter_Create(%1,%2) \
  310. new \
  311. %1@YSII_Sg = -1, \
  312. %1@YSII_Cg = 0, \
  313. %1@YSII_Ag[%2] = {-1, ...}*/
  314.  
  315. /*----------------------------------------------------------------------------*\
  316. Function:
  317. Itter_Add
  318. Params:
  319. itter - Name of the itterator to add the data to.
  320. value - Value to add to the itterator.
  321. Return:
  322. -
  323. Notes:
  324. Wrapper for Itter_AddInternal.
  325.  
  326. native Iter_Add(Iterator:Name<>, value);
  327.  
  328. \*----------------------------------------------------------------------------*/
  329.  
  330. #define Iter_Add Itter_Add
  331. #define Itter_Add(%1,%2) Itter_AddInternal(_Y_ITER_ARRAY:%1@YSII_Cg,_Y_ITER_ARRAY:%1@YSII_Ag,%2,_Y_ITER_ARRAY_SIZE(%1))
  332.  
  333. /*#define Iter_AddSafe Itter_AddSafe
  334. #define Itter_AddSafe(%1,%2) \
  335. Itter_AddSafeInternal(%1@YSII_Sg, %1@YSII_Cg, %1@YSII_Ag, %1@YSII_Rg, %2)*/
  336.  
  337. /*----------------------------------------------------------------------------*\
  338. Function:
  339. Itter_Free
  340. Params:
  341. itter - Name of the itterator to get the first free slot in.
  342. Return:
  343. -
  344. Notes:
  345. Wrapper for Itter_FreeInternal.
  346.  
  347. native Iter_Free(Iterator:Name<>);
  348.  
  349. \*----------------------------------------------------------------------------*/
  350.  
  351. #define Iter_Free Itter_Free
  352. #define Itter_Free(%1) Itter_FreeInternal(_Y_ITER_ARRAY:%1@YSII_Ag,_Y_ITER_ARRAY_SIZE(%1))
  353.  
  354. /*----------------------------------------------------------------------------*\
  355. Function:
  356. Itter_Remove
  357. Params:
  358. itter - Name of the itterator to remove data from.
  359. value - Data to remove.
  360. Return:
  361. -
  362. Notes:
  363. Wrapper for Itter_RemoveInternal.
  364.  
  365. native Iter_Remove(Iterator:Name<>, value);
  366.  
  367. \*----------------------------------------------------------------------------*/
  368.  
  369. #define Iter_Remove Itter_Remove
  370. #define Itter_Remove(%1,%2) Itter_RemoveInternal(_Y_ITER_ARRAY:%1@YSII_Cg,_Y_ITER_ARRAY:%1@YSII_Ag,%2,_Y_ITER_ARRAY_SIZE(%1))
  371.  
  372. /*----------------------------------------------------------------------------*\
  373. Function:
  374. Itter_Contains
  375. Params:
  376. itter - Name of the itterator to check membership of.
  377. value - Value to check.
  378. Return:
  379. -
  380. Notes:
  381. Checks if the given value is in the given iterator.
  382.  
  383. native Iter_Remove(Iterator:Name<>, value);
  384.  
  385. \*----------------------------------------------------------------------------*/
  386.  
  387. #define Iter_Contains Itter_Contains
  388. #define Itter_Contains(%1,%2) Itter_ContainsInternal(_Y_ITER_ARRAY:%1@YSII_Ag,%2,_Y_ITER_ARRAY_SIZE(%1))
  389.  
  390. /*----------------------------------------------------------------------------*\
  391. Function:
  392. Itter_SafeRemove
  393. Params:
  394. itter - Name of the itterator to remove data from.
  395. value - Data to remove.
  396. next - Container for the pointer to the next element.
  397. Return:
  398. -
  399. Notes:
  400. Wrapper for Itter_SafeRemoveInternal. Common use:
  401.  
  402. Iter_SafeRemove(iter, i, i);
  403.  
  404. native Iter_SafeRemove(Iterator:Name<>, value, &next);
  405.  
  406. \*----------------------------------------------------------------------------*/
  407.  
  408. #define Iter_SafeRemove Itter_SafeRemove
  409. #define Itter_SafeRemove(%1,%2,%3) Itter_SafeRemoveInternal(_Y_ITER_ARRAY:%1@YSII_Cg,_Y_ITER_ARRAY:%1@YSII_Ag,%2,%3,_Y_ITER_ARRAY_SIZE(%1))
  410.  
  411. /*----------------------------------------------------------------------------*\
  412. Function:
  413. Itter_Random
  414. Params:
  415. itter - Name of the itterator to get a random slot from.
  416. Return:
  417. -
  418. Notes:
  419. Wrapper for Itter_RandomInternal.
  420.  
  421. native Iter_Random(Iterator:Name<>);
  422.  
  423. \*----------------------------------------------------------------------------*/
  424.  
  425. #define Iter_Random Itter_Random
  426. #define Itter_Random(%1) Itter_RandomInternal(_Y_ITER_ARRAY:%1@YSII_Cg,_Y_ITER_ARRAY:%1@YSII_Ag,_Y_ITER_ARRAY_SIZE(%1))
  427.  
  428. /*----------------------------------------------------------------------------*\
  429. Function:
  430. Itter_Debug
  431. Params:
  432. itter - Name of the itterator to output debug information from.
  433. Return:
  434. -
  435. Notes:
  436. Wrapper for Itter_ShowArray.
  437. \*----------------------------------------------------------------------------*/
  438.  
  439. //#define Iter_Debug Itter_Debug
  440. //#define Itter_Debug(%1) Itter_ShowArray(_Y_ITER_ARRAY:%1@YSII_Cg,_Y_ITER_ARRAY:%1@YSII_Ag)
  441.  
  442. /*----------------------------------------------------------------------------*\
  443. Function:
  444. Itter_Count
  445. Params:
  446. itter - Name of the itterator to get a random slot from4.
  447. Return:
  448. -
  449. Notes:
  450. Returns the number of items in this itterator.
  451.  
  452. native Iter_Count(Iterator:Name<>);
  453.  
  454. \*----------------------------------------------------------------------------*/
  455.  
  456. #define Iter_Count Itter_Count
  457. #define Itter_Count(%1) (_Y_ITER_ARRAY:%1@YSII_Cg)
  458.  
  459. /*----------------------------------------------------------------------------*\
  460. Function:
  461. Itter_Clear
  462. Params:
  463. itter - Name of the itterator empty.
  464. Return:
  465. -
  466. Notes:
  467. Wrapper for Itter_ClearInternal.
  468.  
  469. native Iter_Clear(IteratorArray:Name[]<>);
  470.  
  471. \*----------------------------------------------------------------------------*/
  472.  
  473. #define Iter_Clear Itter_Clear
  474. #define Itter_Clear(%1) Itter_ClearInternal(_Y_ITER_ARRAY:%1@YSII_Cg,_Y_ITER_ARRAY:%1@YSII_Ag,_Y_ITER_ARRAY_SIZE(%1))
  475.  
  476. /*----------------------------------------------------------------------------*\
  477. Create the internal itterators.
  478. \*----------------------------------------------------------------------------*/
  479.  
  480. #if !defined BOTSYNC_IS_BOT
  481. new
  482. Iterator:Player<MAX_PLAYERS>;
  483.  
  484. #if defined _FOREACH_BOT && !defined FOREACH_NO_BOTS
  485. new
  486. Iterator:Bot<MAX_PLAYERS>,
  487. Iterator:Character<MAX_PLAYERS>;
  488.  
  489. //#define NPC@YSII_Sg Bot@YSII_Sg
  490. #define NPC@YSII_Cg Bot@YSII_Cg
  491. #define NPC@YSII_Ag Bot@YSII_Ag
  492. //#define NPC@YSII_Eg Bot@YSII_Eg
  493. //#define NPC@YSII_Rg Bot@YSII_Rg
  494. #endif
  495. #endif
  496.  
  497. /*----------------------------------------------------------------------------*\
  498. Variables to optimise memory usage by only having one copy of each string.
  499. Note that only strings used more than once are put here because only they
  500. have any gain to being located in only one place.
  501. \*----------------------------------------------------------------------------*/
  502.  
  503. static stock
  504. YSI_gsOnPlayerConnect[] = "Itter_OnPlayerConnect",
  505. YSI_gsOnPlayerDisconnect[] = "Itter_OnPlayerDisconnect",
  506. YSI_gsOnGameModeInit[] = "Itter_OnGameModeInit",
  507. YSI_gsSpecifier@[] = "",
  508. YSI_gsSpecifier@i[] = "i";
  509.  
  510. /*----------------------------------------------------------------------------*\
  511. Function:
  512. foreach
  513. Params:
  514. data - Data to itterate through.
  515. as - Variable to set value to.
  516. Return:
  517. -
  518. Notes:
  519. Not exactly the same as PHP foreach, just itterates through a list and
  520. returns the value of the current slot but uses that slot as the next index
  521. too. Variables must be in the form @YSII_<gname>S for the start index and
  522. @YSII_<gname>A for the data array where <name> is what's entered in data.
  523. \*----------------------------------------------------------------------------*/
  524.  
  525. //#define foreach(%1,%2)
  526. // for (new %2 = %1@YSII_Sg; _:%2 != -1; %2 = %1@YSII_Ag[%2])
  527. #define foreach%1(%0) for(new Y_FOREACH_SECOND|||Y_FOREACH_THIRD|||%0|||)
  528. // This allows us to use "new" multiple times - stripping off ONLY whole words.
  529. #define new%0|||%9|||%1:%2||| %9|||%0|||%1|||%2|||
  530.  
  531. // This one is called if the new syntax is required, but the state of "new" is
  532. // as-yet unknown. This attempts to call "%1" as a macro, if it starts with
  533. // "new" as a whole word then it will (and will also helpfully strip off the
  534. // "new" keyword for us).
  535. #define Y_FOREACH_THIRD|||%0|||%1|||%2||| %1=Y_FOREACH_FIFTH|||Y_FOREACH_FOURTH|||%1:%2|||
  536.  
  537. // This is called if the "new" macro is called for a second time.
  538. #define Y_FOREACH_FOURTH|||%0=Y_FOREACH_FIFTH|||%1|||%2||| new Y_FOREACH_SIXTH;%0|||Y_FOREACH_SEVENTH|||%2|||
  539.  
  540. // This is called when there are tags on the "new" declaration.
  541. #define Y_FOREACH_SEVENTH|||%9Y_FOREACH_SIXTH;%0|||%1|||%2||| new %0:%1=%0:_Y_ITER_ARRAY_SIZE(%2);_:(%1=_Y_ITER_ARRAY:%2@YSII_Ag[%1])!=_Y_ITER_ARRAY_SIZE(%2);
  542.  
  543. // This is called when there aren't.
  544. #define Y_FOREACH_SIXTH;%0|||Y_FOREACH_SEVENTH|||%2||| %0=_Y_ITER_ARRAY_SIZE(%2);_:(%0=_Y_ITER_ARRAY:%2@YSII_Ag[%0])!=_Y_ITER_ARRAY_SIZE(%2);
  545. //hta:%0=hta:%2@YSII_Sg;_:%0!=-1;%0=hta:%2@YSII_Ag[%0]
  546. //#define Y_FOREACH_FOURTH|||%0=Y_FOREACH_FIFTH|||%1|||%2||| new hta:%0=hta:%2@YSII_Sg;_:%0!=-1;%0=hta:%2@YSII_Ag[%0]
  547.  
  548. // Move any tags from the second half to the first half.
  549. //#define hta:%0=hta:%1:%2;_:%3!=-1;%4=hta:%5:%6[%7] %0:%1=%2;_:%1!=-1;%1=%6[%1]
  550.  
  551. // This is called if "%1" didn't have "new" at the start.
  552. #define Y_FOREACH_FIFTH|||Y_FOREACH_FOURTH|||%1:%2||| _Y_ITER_ARRAY_SIZE(%2);_:(%1=_Y_ITER_ARRAY:%2@YSII_Ag[%1])!=_Y_ITER_ARRAY_SIZE(%2);
  553.  
  554. //%1=%2@YSII_Sg;_:Y_FOREACH_NONEW:%1!=-1;%1=%2@YSII_Ag[%1]
  555. // This is the old version, but DON'T add "new" because that already exists from
  556. // the failed "new" macro call above.
  557. #define Y_FOREACH_SECOND|||Y_FOREACH_THIRD|||%1,%2||| %2=_Y_ITER_ARRAY_SIZE(%1);_:(%2=_Y_ITER_ARRAY:%1@YSII_Ag[%2])!=_Y_ITER_ARRAY_SIZE(%1);
  558. //#define Y_FOREACH_NONEW:new%0!=-1;new%1=%2[new%3] %0!=-1;%1=%2[%3]
  559.  
  560. //#define Y_FOREACH_EIGHTH:%0[%1]@YSII_Sg;%2;%3=%4[%5]@YSII_Ag[%6] %0@YSII_Sg[%1];%2;%3=%4@YSII_Ag[%5][%6]
  561.  
  562. /*----------------------------------------------------------------------------*\
  563. Function:
  564. foreachex
  565. Params:
  566. data - Data to itterate through.
  567. as - Variable to set value to.
  568. Return:
  569. -
  570. Notes:
  571. Similar to foreach but doesn't declare a new variable for the itterator.
  572. \*----------------------------------------------------------------------------*/
  573.  
  574. #define foreachex(%1,%2) foreach(%2:%1)
  575. //for (%2=_Y_ITER_ARRAY_SIZE(%1);(%2=_Y_ITER_ARRAY:%1@YSII_Ag[%2])!=_Y_ITER_ARRAY_SIZE(%1);)
  576.  
  577. /*----------------------------------------------------------------------------*\
  578. Function:
  579. Itter_OnPlayerConnect
  580. Params:
  581. playerid - Player who joined.
  582. Return:
  583. -
  584. Notes:
  585. Adds a player to the loop data. Now sorts the list too. Note that I found
  586. the most bizzare bug ever (I *think* it may be a compiler but, but it
  587. requires further investigation), basically it seems that multiple variables
  588. were being treated as the same variable (namely @YSII_EgotS and
  589. @YSII_CgharacterS were the same and @YSII_EgotC and @YSII_CgharacterC were the
  590. same). Adding print statements which reference these variables seem to fix
  591. the problem, and I've tried to make sure that the values will never actually
  592. get printed.
  593. \*----------------------------------------------------------------------------*/
  594.  
  595. #if !defined BOTSYNC_IS_BOT
  596. public OnPlayerConnect(playerid)
  597. {
  598. #if defined _FOREACH_BOT
  599. if (!IsPlayerNPC(playerid))
  600. {
  601. Itter_Add(Player, playerid);
  602. }
  603. #if !defined FOREACH_NO_BOTS
  604. else
  605. {
  606. Itter_Add(Bot, playerid);
  607. }
  608. #pragma tabsize 4
  609. Itter_Add(Character, playerid);
  610. #endif
  611. #else
  612. Itter_Add(Player, playerid);
  613. #endif
  614. if (YSI_g_sCallbacks & 2)
  615. {
  616. CallLocalFunction(YSI_gsOnPlayerConnect, YSI_gsSpecifier@i, playerid);
  617. }
  618. return 1;
  619. }
  620.  
  621. #if defined _ALS_OnPlayerConnect
  622. #undef OnPlayerConnect
  623. #else
  624. #define _ALS_OnPlayerConnect
  625. #endif
  626. #define OnPlayerConnect Itter_OnPlayerConnect
  627. forward OnPlayerConnect(playerid);
  628. #endif
  629.  
  630. /*----------------------------------------------------------------------------*\
  631. Function:
  632. Itter_OnFilterScriptInit
  633. Params:
  634. -
  635. Return:
  636. -
  637. Notes:
  638. Fixes a bug where callbacks are not detected when "loadfs" is used after the
  639. GM has already started. If this is a GM this is just never used called.
  640. \*----------------------------------------------------------------------------*/
  641.  
  642. #if !defined BOTSYNC_IS_BOT
  643. public OnFilterScriptInit()
  644. {
  645. //if (funcidx(YSI_gsOnPlayerDisconnect) != -1)
  646. //{
  647. // YSI_g_sCallbacks |= 1;
  648. //}
  649. //if (funcidx(YSI_gsOnPlayerConnect) != -1)
  650. //{
  651. // YSI_g_sCallbacks |= 2;
  652. //}
  653. //CallLocalFunction("Itter_OnFilterScriptInit", YSI_gsSpecifier@);
  654. #if defined _FOREACH_BOT && !defined FOREACH_NO_BOTS
  655. Bot@YSII_Cg = _Y_ITER_C3:0;
  656. Character@YSII_Cg = _Y_ITER_C3:0;
  657. new
  658. lastBot = MAX_PLAYERS,
  659. lastCharacter = MAX_PLAYERS;
  660. #endif
  661. Player@YSII_Cg = _Y_ITER_C3:0;
  662. new
  663. lastPlayer = MAX_PLAYERS;
  664. for (new i = 0; i != MAX_PLAYERS; ++i)
  665. {
  666. if (IsPlayerConnected(i))
  667. {
  668. #if defined _FOREACH_BOT
  669. // Had to do "if ! else" due to compile options.
  670. if (!IsPlayerNPC(i))
  671. {
  672. Player@YSII_Ag[lastPlayer] = i;
  673. ++Player@YSII_Cg;
  674. lastPlayer = i;
  675. }
  676. #if !defined FOREACH_NO_BOTS
  677. else
  678. {
  679. Bot@YSII_Ag[lastBot] = i;
  680. ++Bot@YSII_Cg;
  681. lastBot = i;
  682. }
  683. #pragma tabsize 4
  684. Character@YSII_Ag[lastCharacter] = i;
  685. ++Character@YSII_Cg;
  686. lastCharacter = i;
  687. #endif
  688. #else
  689. Player@YSII_Ag[lastPlayer] = i;
  690. ++Player@YSII_Cg;
  691. lastPlayer = i;
  692. #endif
  693. }
  694. else
  695. {
  696. #if defined _FOREACH_BOT && !defined FOREACH_NO_BOTS
  697. Bot@YSII_Ag[i] = MAX_PLAYERS + 1;
  698. //Bot@YSII_Rg[i] = -1;
  699. Character@YSII_Ag[i] = MAX_PLAYERS + 1;
  700. //Character@YSII_Rg[i] = -1;
  701. #endif
  702. Player@YSII_Ag[i] = MAX_PLAYERS + 1;
  703. //Player@YSII_Rg[i] = -1;
  704. }
  705. }
  706. #if defined _FOREACH_BOT && !defined FOREACH_NO_BOTS
  707. Bot@YSII_Ag[lastPlayer] = MAX_PLAYERS;
  708. Character@YSII_Ag[lastPlayer] = MAX_PLAYERS;
  709. #endif
  710. Player@YSII_Ag[lastPlayer] = MAX_PLAYERS;
  711. //CallLocalFunction("Itter_OnFilterScriptInit", YSI_gsSpecifier@);
  712. #if defined Itter_OnFilterScriptInit
  713. return Itter_OnFilterScriptInit();
  714. #else
  715. return 1;
  716. #endif
  717. //return 1;
  718. }
  719.  
  720. /*#if defined _ALS_OnFilterScriptInit
  721. #undef OnFilterScriptInit
  722. #else
  723. #define _ALS_OnFilterScriptInit
  724. #endif
  725. #define OnFilterScriptInit Itter_OnFilterScriptInit
  726. forward OnFilterScriptInit();*/
  727.  
  728. #if defined _ALS_OnFilterScriptInit
  729. #undef OnFilterScriptInit
  730. #else
  731. #define _ALS_OnFilterScriptInit
  732. #endif
  733. #define OnFilterScriptInit Itter_OnFilterScriptInit
  734. #if defined Itter_OnFilterScriptInit
  735. forward Itter_OnFilterScriptInit();
  736. #endif
  737. #endif
  738.  
  739. /*----------------------------------------------------------------------------*\
  740. Function:
  741. Itter_OnGameModeInit
  742. Params:
  743. -
  744. Return:
  745. -
  746. Notes:
  747. There are WIERD bugs in this script, seemingly caused by the compiler, so
  748. this hopefully fixes them. The OnFilterScriptInit code is written to be
  749. very fast by utilising the internal array structure instead of the regular
  750. Add functions.
  751. \*----------------------------------------------------------------------------*/
  752.  
  753. #if !defined BOTSYNC_IS_BOT
  754. public OnGameModeInit()
  755. {
  756. // Clear everything.
  757. if (funcidx(YSI_gsOnPlayerDisconnect) != -1)
  758. {
  759. YSI_g_sCallbacks |= 1;
  760. }
  761. if (funcidx(YSI_gsOnPlayerConnect) != -1)
  762. {
  763. YSI_g_sCallbacks |= 2;
  764. }
  765. if (!Player@YSII_Cg)
  766. {
  767. #if defined _FOREACH_BOT && !defined FOREACH_NO_BOTS
  768. CallLocalFunction(YSI_gsOnGameModeInit, YSI_gsSpecifier@, Bot@YSII_Cg, Character@YSII_Cg, Player@YSII_Cg);
  769. #else
  770. CallLocalFunction(YSI_gsOnGameModeInit, YSI_gsSpecifier@, Player@YSII_Cg);
  771. #endif
  772. return 1;
  773. }
  774. // Do the forward iterator list.
  775. #if defined _FOREACH_BOT && !defined FOREACH_NO_BOTS
  776. Bot@YSII_Cg = _Y_ITER_C3:0;
  777. Bot@YSII_Ag[MAX_PLAYERS] = MAX_PLAYERS;
  778. Character@YSII_Ag[MAX_PLAYERS] = MAX_PLAYERS;
  779. Character@YSII_Cg = _Y_ITER_C3:0;
  780. new
  781. lastBot = MAX_PLAYERS,
  782. lastCharacter = MAX_PLAYERS;
  783. #endif
  784. Player@YSII_Cg = _Y_ITER_C3:0;
  785. Player@YSII_Ag[MAX_PLAYERS] = MAX_PLAYERS;
  786. new
  787. lastPlayer = MAX_PLAYERS;
  788. for (new i = 0; i != MAX_PLAYERS; ++i)
  789. {
  790. if (IsPlayerConnected(i))
  791. {
  792. #if defined _FOREACH_BOT
  793. // Had to do "if ! else" due to compile options.
  794. if (!IsPlayerNPC(i))
  795. {
  796. Player@YSII_Ag[lastPlayer] = i;
  797. ++Player@YSII_Cg;
  798. lastPlayer = i;
  799. }
  800. #if !defined FOREACH_NO_BOTS
  801. else
  802. {
  803. Bot@YSII_Ag[lastBot] = i;
  804. ++Bot@YSII_Cg;
  805. lastBot = i;
  806. }
  807. #pragma tabsize 4
  808. Character@YSII_Ag[lastCharacter] = i;
  809. ++Character@YSII_Cg;
  810. lastCharacter = i;
  811. #endif
  812. #else
  813. Player@YSII_Ag[lastPlayer] = i;
  814. ++Player@YSII_Cg;
  815. lastPlayer = i;
  816. #endif
  817. }
  818. else
  819. {
  820. #if defined _FOREACH_BOT && !defined FOREACH_NO_BOTS
  821. Bot@YSII_Ag[i] = MAX_PLAYERS + 1;
  822. //Bot@YSII_Rg[i] = -1;
  823. Character@YSII_Ag[i] = MAX_PLAYERS + 1;
  824. //Character@YSII_Rg[i] = -1;
  825. #endif
  826. Player@YSII_Ag[i] = MAX_PLAYERS + 1;
  827. //Player@YSII_Rg[i] = -1;
  828. }
  829. }
  830. #if defined _FOREACH_BOT && !defined FOREACH_NO_BOTS
  831. Bot@YSII_Ag[lastPlayer] = MAX_PLAYERS;
  832. Character@YSII_Ag[lastPlayer] = MAX_PLAYERS;
  833. #endif
  834. Player@YSII_Ag[lastPlayer] = MAX_PLAYERS;
  835. CallLocalFunction(YSI_gsOnGameModeInit, YSI_gsSpecifier@);
  836. return 1;
  837. }
  838.  
  839. #if defined _ALS_OnGameModeInit
  840. #undef OnGameModeInit
  841. #else
  842. #define _ALS_OnGameModeInit
  843. #endif
  844. #define OnGameModeInit Itter_OnGameModeInit
  845. forward OnGameModeInit();
  846. #endif
  847.  
  848. /*----------------------------------------------------------------------------*\
  849. Function:
  850. Itter_OnPlayerDisconnect
  851. Params:
  852. playerid - Player who left.
  853. Return:
  854. -
  855. Notes:
  856. Removes a player from the loop data. No longer uses "hook" to ENSURE that
  857. this is always last. Previously I think that the order of evaluation in
  858. y_hooks meant that this got called before the user "OnPlayerDisconnect".
  859. \*----------------------------------------------------------------------------*/
  860.  
  861. #if !defined BOTSYNC_IS_BOT
  862. public OnPlayerDisconnect(playerid, reason)
  863. {
  864. if (YSI_g_sCallbacks & 1)
  865. {
  866. CallLocalFunction(YSI_gsOnPlayerDisconnect, "ii", playerid, reason);
  867. }
  868. SetTimerEx("Itter_OPDCInternal", 0, false, YSI_gsSpecifier@i, playerid);
  869. return 1;
  870. }
  871.  
  872. #if defined _ALS_OnPlayerDisconnect
  873. #undef OnPlayerDisconnect
  874. #else
  875. #define _ALS_OnPlayerDisconnect
  876. #endif
  877. #define OnPlayerDisconnect Itter_OnPlayerDisconnect
  878. forward OnPlayerDisconnect(playerid, reason);
  879. #endif
  880.  
  881. /*----------------------------------------------------------------------------*\
  882. Function:
  883. Itter_OPDCInternal
  884. Params:
  885. playerid - Player who left.
  886. Return:
  887. -
  888. Notes:
  889. Called AFTER "OnPlayerDisconnect" so that using "Kick" inside a "foreach"
  890. loop doesn't crash the server due to an OOB error.
  891. \*----------------------------------------------------------------------------*/
  892.  
  893. #if !defined BOTSYNC_IS_BOT
  894. public Itter_OPDCInternal(playerid)
  895. {
  896. if (IsPlayerConnected(playerid))
  897. {
  898. return;
  899. }
  900. #if defined _FOREACH_BOT
  901. if (!IsPlayerNPC(playerid))
  902. {
  903. Itter_Remove(Player, playerid);
  904. }
  905. #if !defined FOREACH_NO_BOTS
  906. else
  907. {
  908. Itter_Remove(Bot, playerid);
  909. }
  910. #pragma tabsize 4
  911. Itter_Remove(Character, playerid);
  912. #endif
  913. #else
  914. Itter_Remove(Player, playerid);
  915. #endif
  916. }
  917. #endif
  918.  
  919. /*----------------------------------------------------------------------------*\
  920. Function:
  921. Itter_ShowArray
  922. Params:
  923. start - Itterator start point.
  924. members[] - Itterator contents.
  925. size - Number of itterator values
  926. Return:
  927. -
  928. Notes:
  929. Pure debug function. Has regular prints not debug prints
  930. as it's only called when debug is on.
  931. \*----------------------------------------------------------------------------*/
  932.  
  933. /*stock
  934. Itter_ShowArray(size, members[])
  935. {
  936. static
  937. sString[61];
  938. new
  939. i,
  940. j = 10;
  941. printf("Start: %d", start);
  942. printf("Size: %d", size);
  943. while (i < size)
  944. {
  945. sString[0] = '\0';
  946. while (i < j && i < size)
  947. {
  948. format(sString, sizeof (sString), "%s, %d", sString, members[i]);
  949. i++;
  950. }
  951. printf("Array (%d): %s", j, sString);
  952. j += 10;
  953. }
  954. }*/
  955.  
  956. /*----------------------------------------------------------------------------*\
  957. Function:
  958. Itter_RandomInternal
  959. Params:
  960. count - Number of items in the itterator.
  961. array[] - Itterator data.
  962. size - Size of the iterator.
  963. Return:
  964. -
  965. Notes:
  966. Returns a random value from an iterator.
  967. \*----------------------------------------------------------------------------*/
  968.  
  969. stock
  970. Itter_RandomInternal(count, array[], size)
  971. {
  972. if (count == 0)
  973. {
  974. return -1;
  975. }
  976. new
  977. rnd = random(count),
  978. cur = array[size];
  979. while (cur != size)
  980. {
  981. if (rnd-- == 0)
  982. {
  983. return cur;
  984. }
  985. cur = array[cur];
  986. }
  987. return -1;
  988. }
  989.  
  990. /*----------------------------------------------------------------------------*\
  991. Function:
  992. Itter_FreeInternal
  993. Params:
  994. count - Number of items in the itterator.
  995. array[] - Itterator data.
  996. size - Size of the itterator.
  997. Return:
  998. -
  999. Notes:
  1000. Finds the first free slot in the itterator. Itterators now HAVE to be
  1001. sorted for this function to work correctly as it uses that fact to decide
  1002. wether a slot is unused or the last one. If you want to use the slot
  1003. straight after finding it the itterator will need to re-find it to add in
  1004. the data.
  1005. \*----------------------------------------------------------------------------*/
  1006.  
  1007. stock
  1008. Itter_FreeInternal(array[], size)
  1009. {
  1010. for (new i = 0; i != size; ++i)
  1011. {
  1012. if (array[i] > size)
  1013. {
  1014. return i;
  1015. }
  1016. }
  1017. return -1;
  1018. }
  1019.  
  1020. /*----------------------------------------------------------------------------*\
  1021. Function:
  1022. Itter_AddInternal
  1023. Params:
  1024. &start - Array start index.
  1025. &count - Number of items in the itterator.
  1026. array[] - Itterator data.
  1027. value - Item to add.
  1028. Return:
  1029. -
  1030. Notes:
  1031. Adds a value to a given itterator set. Now detects when you try and add the
  1032. last item multiple times, as well as all the other items. Now simplified even
  1033. further with the new internal representation.
  1034. \*----------------------------------------------------------------------------*/
  1035.  
  1036. stock
  1037. Itter_AddInternal(&count, array[], value, size)
  1038. {
  1039. if (0 <= value < size && array[value] > size)
  1040. {
  1041. new
  1042. last = size,
  1043. next = array[last];
  1044. while (next < value)
  1045. {
  1046. last = next;
  1047. next = array[last];
  1048. }
  1049. array[last] = value;
  1050. array[value] = next;
  1051. ++count;
  1052. return 1;
  1053. }
  1054. return 0;
  1055. }
  1056.  
  1057. /*----------------------------------------------------------------------------*\
  1058. Function:
  1059. Itter_RemoveInternal
  1060. Params:
  1061. &count - Number of items in the itterator.
  1062. array[] - Itterator data.
  1063. value - Item to remove.
  1064. Return:
  1065. -
  1066. Notes:
  1067. Removes a value from an itterator.
  1068. \*----------------------------------------------------------------------------*/
  1069.  
  1070. stock
  1071. Itter_RemoveInternal(&count, array[], value, size)
  1072. {
  1073. new
  1074. last;
  1075. return Itter_SafeRemoveInternal(count, array, value, last, size);
  1076. }
  1077.  
  1078. /*----------------------------------------------------------------------------*\
  1079. Function:
  1080. Itter_SafeRemoveInternal
  1081. Params:
  1082. &count - Number of items in the itterator.
  1083. array[] - Iterator data.
  1084. back[] - Reverse iterator data.
  1085. value - Item to remove.
  1086. &last - Pointer in which to store the last pointer.
  1087. Return:
  1088. -
  1089. Notes:
  1090. Removes a value from an itterator safely.
  1091. \*----------------------------------------------------------------------------*/
  1092.  
  1093. stock
  1094. Itter_SafeRemoveInternal(&count, array[], value, &last, size)
  1095. {
  1096. if (0 <= value < size && array[value] <= size)
  1097. {
  1098. last = size;
  1099. new
  1100. next = array[last];
  1101. while (next != value)
  1102. {
  1103. last = next;
  1104. next = array[last];
  1105. }
  1106. array[last] = array[value];
  1107. array[value] = size + 1;
  1108. --count;
  1109. return 1;
  1110. }
  1111. return 0;
  1112. }
  1113.  
  1114. /*----------------------------------------------------------------------------*\
  1115. Function:
  1116. Itter_ContainsInternal
  1117. Params:
  1118. array[] - Itterator data.
  1119. value - Item to check.
  1120. size - Size of the iterator.
  1121. Return:
  1122. -
  1123. Notes:
  1124. Checks if this item is in the iterator.
  1125. \*----------------------------------------------------------------------------*/
  1126.  
  1127. stock
  1128. Itter_ContainsInternal(array[], value, size)
  1129. {
  1130. return 0 <= value < size && array[value] <= size;
  1131. }
  1132.  
  1133. /*----------------------------------------------------------------------------*\
  1134. Function:
  1135. Itter_ClearInternal
  1136. Params:
  1137. &count - Number of items in the itterator.
  1138. array[] - Itterator data.
  1139. size - Size of the iterator.
  1140. Return:
  1141. -
  1142. Notes:
  1143. Resets an iterator.
  1144. \*----------------------------------------------------------------------------*/
  1145.  
  1146. stock
  1147. Itter_ClearInternal(&count, array[], size)
  1148. {
  1149. for (new i = 0, t = size + 1; i < size; ++i)
  1150. {
  1151. array[i] = t;
  1152. }
  1153. array[size] = size;
  1154. count = 0;
  1155. }
  1156.  
  1157. /*----------------------------------------------------------------------------*\
  1158. Function:
  1159. Itter_InitInternal
  1160. Params:
  1161. array[][] - Itterator array to initialise.
  1162. s0 - Size of first dimension.
  1163. s1 - Size of second dimension.
  1164. Return:
  1165. -
  1166. Notes:
  1167. Multi-dimensional arrays can't be initialised at compile time, so need to be
  1168. done at run time, which is slightly annoying.
  1169. \*----------------------------------------------------------------------------*/
  1170.  
  1171. stock
  1172. Itter_InitInternal(arr[][], s0, s1)
  1173. {
  1174. for (new i = 0, t = s1 + 1; i < s0; ++i)
  1175. {
  1176. for (new j = 0; j < s1; ++j)
  1177. {
  1178. arr[i][j] = t;
  1179. }
  1180. arr[i][s1] = s1;
  1181. }
  1182. }
  1183.  
  1184. /*----------------------------------------------------------------------------*\
  1185. Function:
  1186. Itter_PrevInternal
  1187. Params:
  1188. array[] - Itterator data.
  1189. size - Size of the iterator.
  1190. slot - The current slot.
  1191. Return:
  1192. -
  1193. Notes:
  1194. Gets the element in an iterator that points to the current element.
  1195. \*----------------------------------------------------------------------------*/
  1196.  
  1197. stock
  1198. Itter_PrevInternal(array[], size, slot)
  1199. {
  1200. if (0 <= slot <= size && array[slot] <= size)
  1201. {
  1202. new
  1203. last = size;
  1204. //for (new next = array[size]; next != size; next = array[next])
  1205. for ( ; ; )
  1206. {
  1207. new
  1208. next = array[last];
  1209. if (next == slot)
  1210. {
  1211. return last;
  1212. }
  1213. last = next;
  1214. }
  1215. }
  1216. return size;
  1217. }
  1218.  
  1219. /*----------------------------------------------------------------------------*\
  1220. Function:
  1221. Iter_Begin
  1222. Params:
  1223. iter - Name of the iterator to get the start of.
  1224. Return:
  1225. -
  1226. Notes:
  1227. Gets a point BEFORE the start of the iterator (the theoretical beginning).
  1228. \*----------------------------------------------------------------------------*/
  1229.  
  1230. #define Iter_Begin(%1) (_Y_ITER_ARRAY_SIZE(%1))
  1231. #define Itter_Begin(%1) (_Y_ITER_ARRAY_SIZE(%1))
  1232.  
  1233. /*----------------------------------------------------------------------------*\
  1234. Function:
  1235. Iter_End
  1236. Params:
  1237. iter - Name of the iterator to
  1238. Return:
  1239. -
  1240. Notes:
  1241. Gets a point AFTER the end of the iterator (think "MAX_PLAYERS").
  1242. \*----------------------------------------------------------------------------*/
  1243.  
  1244. #define Iter_End(%1) (_Y_ITER_ARRAY_SIZE(%1))
  1245. #define Itter_End(%1) (_Y_ITER_ARRAY_SIZE(%1))
  1246.  
  1247. /*----------------------------------------------------------------------------*\
  1248. Function:
  1249. Iter_First
  1250. Params:
  1251. iter - Name of the iterator to
  1252. Return:
  1253. -
  1254. Notes:
  1255. Gets the first element in an iterator.
  1256. \*----------------------------------------------------------------------------*/
  1257.  
  1258. #define Iter_First(%1) (_Y_ITER_ARRAY:%1@YSII_Ag[_Y_ITER_ARRAY_SIZE(%1)])
  1259. #define Itter_First(%1) (_Y_ITER_ARRAY:%1@YSII_Ag[_Y_ITER_ARRAY_SIZE(%1)])
  1260.  
  1261. /*----------------------------------------------------------------------------*\
  1262. Function:
  1263. Iter_Last
  1264. Params:
  1265. iter - Name of the iterator to
  1266. Return:
  1267. -
  1268. Notes:
  1269. Gets the last element in an iterator.
  1270. \*----------------------------------------------------------------------------*/
  1271.  
  1272. #define Iter_Last(%1) Itter_PrevInternal(_Y_ITER_ARRAY:%1@YSII_Ag,_Y_ITER_ARRAY_SIZE(%1),_Y_ITER_ARRAY_SIZE(%1))
  1273. #define Itter_Last(%1) Itter_PrevInternal(_Y_ITER_ARRAY:%1@YSII_Ag,_Y_ITER_ARRAY_SIZE(%1),_Y_ITER_ARRAY_SIZE(%1))
  1274.  
  1275. /*----------------------------------------------------------------------------*\
  1276. Function:
  1277. Iter_Next
  1278. Params:
  1279. iter - Name of the iterator to
  1280. Return:
  1281. -
  1282. Notes:
  1283. Gets the element in an interator after the current one.
  1284. \*----------------------------------------------------------------------------*/
  1285.  
  1286. #define Iter_Next(%1,%2) (_Y_ITER_ARRAY:%1@YSII_Ag[(%2)])
  1287. #define Itter_Next(%1,%2) (_Y_ITER_ARRAY:%1@YSII_Ag[(%2)])
  1288.  
  1289. /*----------------------------------------------------------------------------*\
  1290. Function:
  1291. Iter_Prev
  1292. Params:
  1293. iter - Name of the iterator to
  1294. Return:
  1295. -
  1296. Notes:
  1297. Gets the element in an iterator before the current one. Slow.
  1298. \*----------------------------------------------------------------------------*/
  1299.  
  1300. #define Iter_Prev(%1,%2) Itter_PrevInternal(_Y_ITER_ARRAY:%1@YSII_Ag,_Y_ITER_ARRAY_SIZE(%1),(%2))
  1301. #define Itter_Prev(%1,%2) Itter_PrevInternal(_Y_ITER_ARRAY:%1@YSII_Ag,_Y_ITER_ARRAY_SIZE(%1),(%2))
Advertisement
Add Comment
Please, Sign In to add comment