forked from pawn-lang/YSI-Includes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathy_iterate.inc
273 lines (261 loc) · 10.9 KB
/
y_iterate.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
/* *
* *
* _____ ______ ______ ____ ______ _ ______ __ ______ ____ _____ *
* / ____| ____| ____| | _ \| ____| | / __ \ \ / / | ____/ __ \| __ \ *
* | (___ | |__ | |__ | |_) | |__ | | | | | \ \ /\ / / | |__ | | | | |__) | *
* \___ \| __| | __| | _ <| __| | | | | | |\ \/ \/ / | __|| | | | _ / *
* ____) | |____| |____ | |_) | |____| |___| |__| | \ /\ / | | | |__| | | \ \ *
* |_____/|______|______| |____/|______|______\____/ \/ \/ |_| \____/|_| \_\ *
* *
* _____ ____ _____ _ _ __ __ ______ _ _ _______ _______ _____ ____ _ _ *
* | __ \ / __ \ / ____| | | | \/ | ____| \ | |__ __|/\|__ __|_ _/ __ \| \ | | *
* | | | | | | | | | | | | \ / | |__ | \| | | | / \ | | | || | | | \| | *
* | | | | | | | | | | | | |\/| | __| | . ` | | | / /\ \ | | | || | | | . ` | *
* | |__| | |__| | |____| |__| | | | | |____| |\ | | |/ ____ \| | _| || |__| | |\ | *
* |_____/ \____/ \_____|\____/|_| |_|______|_| \_| |_/_/ \_\_| |_____\____/|_| \_| *
* *
* This is required for technical reasons - to place it after `#endinput` to not generate *
* multiple copies of it in XML when compiling with `-r`. *
* *
*//*
Legal:
Version: MPL 1.1
The contents of this file are subject to the Mozilla Public License Version
1.1 the "License"; you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the
License.
The Original Code is the YSI framework.
The Initial Developer of the Original Code is Alex "Y_Less" Cole.
Portions created by the Initial Developer are Copyright (c) 2022
the Initial Developer. All Rights Reserved.
Contributors:
Y_Less
koolk
JoeBullet/Google63
g_aSlice/Slice
Misiur
samphunter
tianmeta
maddinat0r
spacemud
Crayder
Dayvison
Ahmad45123
Zeex
irinel1996
Yiin-
Chaprnks
Konstantinos
Masterchen09
Southclaws
PatchwerkQWER
m0k1
paulommu
udan111
Cheaterman
Thanks:
JoeBullet/Google63 - Handy arbitrary ASM jump code using SCTRL.
ZeeX - Very productive conversations.
koolk - IsPlayerinAreaEx code.
TheAlpha - Danish translation.
breadfish - German translation.
Fireburn - Dutch translation.
yom - French translation.
50p - Polish translation.
Zamaroht - Spanish translation.
Los - Portuguese translation.
Dracoblue, sintax, mabako, Xtreme, other coders - Producing other modes for
me to strive to better.
Pixels^ - Running XScripters where the idea was born.
Matite - Pestering me to release it and using it.
Very special thanks to:
Thiadmer - PAWN, whose limits continue to amaze me!
Kye/Kalcor - SA:MP.
SA:MP Team past, present and future - SA:MP.
Optional plugins:
Gamer_Z - GPS.
Incognito - Streamer.
Me - sscanf2, fixes2, Whirlpool.
*/
#if !defined _INC_y_iterate
#tryinclude "y_foreach\y_foreach_entry"
#endif
#if !defined _INC_y_iterate
#tryinclude "YSI_Data\y_foreach\y_foreach_entry"
#endif
#if !defined _INC_y_iterate
#tryinclude "YSI\YSI_Data\y_foreach\y_foreach_entry"
#endif
#if !defined _INC_y_iterate
#tryinclude <YSI_Data\y_foreach\y_foreach_entry>
#endif
#if !defined _INC_y_iterate
#tryinclude <YSI\YSI_Data\y_foreach\y_foreach_entry>
#endif
#if !defined _INC_y_iterate
#error Could not find y_iterate
#endif
/**
* <library
* name="y_iterate"
* version="0.4"
* license="(c) 2022 YSI contibutors, licensed under MPL 1.1"
* >
* <summary pawndoc="true">
* This library uses the enhanced <em>pawndoc.xsl</em> from
* <a href="https://github.com/pawn-lang/pawndoc">pawn-lang/pawndoc</a>.
* This XSL has features such as library and markdown support, and will not
* render this message when used.
* </summary>
* <remarks>
* <p>
* Provides efficient looping through sparse data sets, such as connected
* players. Significantly improved from the original version to be a generic
* loop system, rather then purely a player loop system. When used for
* players this has constant time O(n) for number of connected players (n),
* unlike standard player loops which are O(MAX_PLAYERS), regardless of the
* actual number of connected players. Even when n is MAX_PLAYERS this is
* still faster.
* </p>
*
* <p>
* For extensive documentation on writing and using iterators, see
* <a href="http://forum.sa-mp.com/showthread.php?t=481877">this topic</a>
* </p>
* </remarks>
* <section>
* Functions
* </section>
* <subsection>
* Public
* </subsection><ul>
* <symbol name="OnPlayerDisconnect">Called when a player leaves to remove them.</symbol>
* <symbol name="OnPlayerConnect">Called when a player connects to add them.</symbol>
* </ul><subsection>
* Stock
* </subsection><ul>
* <symbol name="Iter_ShowArray">Displays the contents of the array.</symbol>
* <symbol name="Iter_AddInternal">Add a value to an iterator.</symbol>
* <symbol name="Iter_RemoveInternal">Remove a value from an iterator.</symbol>
* <symbol name="Iter_RandomInternal">Get a random item from an iterator.</symbol>
* <symbol name="Iter_FreeInternal">Gets the first free slot in the iterator.</symbol>
* <symbol name="Iter_InitInternal">Initialises a multi-dimensional iterator.</symbol>
* </ul><subsection>
* Inline
* </subsection><ul>
* <symbol name="Iter_Create">Create a new iterator value set.</symbol>
* <symbol name="Iter_Add">Wraps Iter_AddInternal.</symbol>
* <symbol name="Iter_Remove">Wraps Iter_RemoveInternal.</symbol>
* <symbol name="Iter_Random">Wraps Iter_RandomInternal.</symbol>
* <symbol name="Iter_Count">Gets the number of items in an iterator.</symbol>
* <symbol name="Iter_Debug">Wraps around Iter_ShowArray.</symbol>
* <symbol name="Iter_Free">Wraps around Iter_FreeInternal.</symbol>
* <symbol name="Iter_Create2">Create a new iterator array value set.</symbol>
* <symbol name="Iter_Add2">Wraps Iter_AddInternal for arrays.</symbol>
* <symbol name="Iter_Remove2">Wraps Iter_RemoveInternal for arrays.</symbol>
* <symbol name="Iter_Random2">Wraps Iter_RandomInternal for arrays.</symbol>
* <symbol name="Iter_Count2">Gets the number of items in an iterator array.</symbol>
* <symbol name="Iter_Debug2">Wraps around Iter_ShowArray for arrays.</symbol>
* <symbol name="Iter_Free2">Wraps around Iter_FreeInternal for arrays.</symbol>
* </ul><section>
* Hooks
* </section><ul>
* <symbol name="Iter_OnPlayerConnect">Hook for the OnPlayerConnect callback.</symbol>
* <symbol name="Iter_OnPlayerDisconnect">Hook for the OnPlayerDisconnect callback.</symbol>
* <symbol name="Iter_OnGameModeInit">Only exists to make the code compile correctly...</symbol>
* </ul><section>
* Keywords
* </section><ul>
* <symbol name="foreach">Command to loop an iterator.</symbol>
* <symbol name="foreachex">Like foreach but without a new variable.</symbol>
* <symbol name="foreach2">Command to loop through an iterator array.</symbol>
* <symbol name="foreachex">Like foreach2 but without a new variable.</symbol>
* </ul><section>
* Tags
* </section><ul>
* <symbol name="Iterator">Declare an iterator.</symbol>
* </ul><section>
* Variables
* </section>
* <subsection>
* Static
* </subsection><ul>
* <symbol name="YSI_g_OPC">Records wether Iter_OnPlayerConnect exists for speed.</symbol>
* <symbol name="YSI_g_OPDC">Records wether Iter_OnPlayerDisconnect exists for speed.</symbol>
* </ul><section>Compile options</section><ul>
* <symbol name="YSI_ITTER_NO_SORT">Removed.</symbol>
* <symbol name="FOREACH_NO_BOTS">Remove the bot iterators for smaller code.</symbol>
* <symbol name="FOREACH_NO_PLAYERS">Remove all default code for player itteration.</symbol>
* </ul><section>
* Iterators
* </section><ul>
* <symbol name="Player">List of all players connected.</symbol>
* <symbol name="Bot">List of all bots (npcs) connected.</symbol>
* <symbol name="NPC">Alias of Bot.</symbol>
* <symbol name="Character">All players and bots.</symbol>
* </ul><section>
* Examples
* </section>
*
*
*
*
* <subsection>Basic Iterators</subsection>
*
* <p>
* Basic iterators are simply collections of numbers - little more than an array.
* A number is either in the array, or not in the array, <em>y_iterate</em> loops
* through only the <em>in</em> numbers.</p>
*
* <p><em>Players</em><br /><br />
*
* This code will loop through every player connected to the server.
*
* <code>
* foreach (new i : Player) <br />
* { <br /><indent />
* printf("player %d is connected", i); <br />
* }
* </code>
* </p>
*
* <p><em>Vehicles</em><br /><br />
*
* This code will loop through all the created vehicles on the server (including
* those made in other running scripts).
*
* <code>
* foreach (new vid : Vehicle) <br />
* { <br /><indent />
* printf("vehicleid %d has been created", vid); <br />
* }
* </code>
* </p>
*
* <p><em>Create An Iterator</em><br /><br />
*
* To create your own iterator, first declare it, then add things to it, then loop
* over it:
*
* <code>
* new <br /><indent />
* Iterator:MyIter<100>; // First declare it (this has room for 100 items numbered 0-99). <br />
* // Then add things to it. <br />
* Iter_Add(MyIter, 0); // Fine. <br />
* Iter_Add(MyIter, 55); // Fine. <br />
* Iter_Add(MyIter, 100); // Will fail. <br />
* // Then loop over it. <br />
* foreach (new i : MyIter) <br />
* { <br /><indent />
* printf("%d", i); // Will print "0" then "55". <br />
* }
* </code>
* </p>
*
* <subsection>Special Iterators</subsection>
* </library>
*//** */