foreach.inc 34 KB

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