Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // -> l_list.inc
- ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- //
- // Linked List V2 (fast loop ir arrays pawn)
- // Author: Bruno da Silva (thanks SlashPT)
- // www.brunodasilva.com.br
- //
- ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- #define Iterator:%0<%1> ipsArray%0[%1] = {-1, ...}, ipsInit%0 = -1, ipsFinal%0 = 0, ipsItens%0 = 0
- #define Iter_Add(%0,%1) functionChangeIter(ipsArray%0, %1, ipsInit%0, ipsFinal%0, ipsItens%0)
- #define Iter_Remove(%0,%1) functionDeleteIter(ipsArray%0, %1, ipsInit%0, ipsFinal%0, ipsItens%0)
- #define Iter_Count(%0) _:ipsItens%0
- #define Iter_Random(%0) functionRandomIterArray(ipsInit%0, ipsFinal%0, ipsArray%0)
- #define Iter_Get(%0, %1) ipsArray%0[%1]
- #define llist(%0,%1) for(new %1 = ipsInit%0 ; %1 != -1; %1 = ipsArray%0[%1])
- #define llistex(%0,%1) for(%1 = ipsInit%0 ; %1 != -1; %1 = ipsArray%0[%1])
- new Iterator:Player<MAX_PLAYERS>;
- stock functionArray_Init(array[][], max1, max2)
- {
- for (new i; max1 != i; ++i) for (new j; max2 != i; ++j) {
- array[i][j] = -1;
- }
- return true;
- }
- stock functionRandomIterArray(iniciar, finalizar,array[])
- {
- if(iniciar == -1) return -1; // não deixar travar servidor
- new retornarValor = -1;
- inicializarBusca:
- retornarValor = array[random(finalizar)];
- if(retornarValor == -1) goto inicializarBusca;
- return retornarValor;
- }
- stock functionChangeIter(array[], valor, &inicio, &ultimoNumeroVar, &count)
- {
- if(valor == -1 || array[valor] != -1) {
- return false;
- }
- ++count;
- if(inicio == -1) {
- return inicio = valor, ultimoNumeroVar = valor;
- }
- if(valor < inicio) {
- return array[valor] = inicio, inicio = valor, true;
- }
- if(array[inicio] == -1) {
- return array[inicio] = valor, ultimoNumeroVar = valor;
- }
- return array[ultimoNumeroVar] = valor, ultimoNumeroVar = valor, true;
- }
- stock functionDeleteIter(array[], value, &inicio, &ultimoNumeroVar, &count)
- {
- if(inicio == -1 || value == -1) {
- return false;
- }
- --count;
- new i = inicio, j;
- if(ultimoNumeroVar == value) {
- for( ; array[i] != -1; i = array[i]) {
- if(array[i] == value) {
- array[ultimoNumeroVar] = -1;
- ultimoNumeroVar = array[j];
- array[ultimoNumeroVar] = -1;
- return true;
- }
- j = i;
- }
- }
- for( ; array[i] != -1; i = array[i]) {
- if(array[i] == value) {
- j = array[array[i]];
- array[array[i]] = -1;
- array[i] = j;
- return true;
- }
- }
- if(value == inicio) {
- j = inicio,
- inicio = array[inicio];
- array[j] = -1;
- }
- if(ultimoNumeroVar == value) ultimoNumeroVar = j;
- return true;
- }
- public OnPlayerConnect(playerid)
- {
- Iter_Add(Player, playerid);
- return CallLocalFunction("CallOnPlayerConnect", "i", playerid);
- }
- public OnPlayerDisconnect(playerid, reason)
- {
- Iter_Remove(Player, playerid);
- return CallLocalFunction("CallOnPlayerDisconnect", "ii", playerid, reason);
- }
- #if defined HookOnPlayerConnect
- #undef OnPlayerConnect
- #else
- #define HookOnPlayerConnect
- #endif
- #define OnPlayerConnect CallOnPlayerConnect
- #if defined HookOnPlayerDisconnect
- #undef OnPlayerDisconnect
- #else
- #define HookOnPlayerDisconnect
- #endif
- #define OnPlayerDisconnect CallOnPlayerDisconnect
- forward OnPlayerConnect(playerid);
- forward OnPlayerDisconnect(playerid, reason);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement