foreach.inc 35 KB

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