Advertisement
Y_Less

foreach.inc test

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