[Include] Southclaw INI file
#5

Coloquei algumas vбriaveis para simular alguns players conectados em IsPlayerConnect.

Deixei 4 Mil e os resultados dos testes nгo foram nada diferentes, ambos sгo уtimos sistemas mas pelo que vi Fini parece ser ainda um pouco mais veloz

pawn Код:
///
#include    a_samp
#include    fini
#include    shot

//gambiarras
#define     IsPlayerConnected(%0) ppa[%0]
#define     MaxClients 4000
#define     LoopClients(%0) for(new %0; %0 < MaxClients; %0++) if(IsPlayerConnected(%0))

main(){OnInit();}
static stock bool:ppa[MaxClients] = {true,...};

OnInit();public OnInit()
{
///===
    new tickfile = GetTickCount();
    file_Create("File.ini");
    file_OS(WINDOWS); file_Open("File.ini");
    {
        LoopClients(i) {
            file_SetVal("ValueTeste", random(91891));
            file_SetStr("StringTeste", RandomString(12,true));
            file_Save("File.ini");
        }
    }
    file_Close();
    tickfile = GetTickCount() - tickfile;

///===
    new tickfini = GetTickCount();
    Fini_Create("Fini.ini");
    Fini_OpenFile("Fini.ini");
    {
        LoopClients(i) {
            Fini_SetVal("ValueTeste", random(91891));
            Fini_SetStr("StringTeste",RandomString(12,true));
            Fini_SaveFile("Fini.ini");
        }
    }
    Fini_CloseFile();
    tickfini = GetTickCount() - tickfini;

//===
    printf("FINI %d ms",tickfini);
    printf("FILE %d ms",tickfile);
    return true;
}


RandomString(len,bool:lowercase)
{
    new
        string[26]                                // maxchars ...
        ;

    for(new i = 0; i < len; i++) {
        string[i] = lowercase? tolower(random(25)+65) : (random(25)+65);
    }
    return string;
}
Ambos abriram o arquivo e fizeram a funзгo conforme o prometido, acredito que o lag deste sistema atual й devido a funзгo de operar no sistema operacional

(o desenvolvedor fez algo com variбveis para checar isto, quando nгo era necessбrio)

pawn Код:
#define WINDOWS
Logo exclua a definiзгo se estiver usando linux, caso contrбrio deixe em seu game mode.

pawn Код:
stock Fini_SaveFile(sFile[])
{
    iFile = fopen(sFile,io_write),
        sTemp[0] = EOS;

    iLoop = 0x0;
    while((sCacheKeys[iLoop][0x0]) && (iLoop < MaxLines)) {

        #if defined WINDOWS
        format(sTemp,MaxKeys,"%s=%s\r\n",sCacheKeys[iLoop],sCacheValue[iLoop]);
        #else
        format(sTemp,MaxKeys,"%s=%s\n",sCacheKeys[iLoop],sCacheValue[iLoop]);
        #endif
        fwrite(iFile,sTemp);
        ++iLoop;
    }
    return fclose(iFile);
}
Parabйns, neste momento o Fini estarб aptado para funcionar em linux ou windows sem perder a mнnima velocidade.

pawn Код:
/*////////////////////////////////////////////////////////////////////////////////

                     _ ____        _____          __  __
                    (_)  _ \ ___  |_   _|__  __ _|  \/  |
                    | | |_) / __|   | |/ _ \/ _` | |\/| |
                    | |  __/\__ \   | |  __/ (_| | |  | |
                    |_|_|   |___/   |_|\___|\__,_|_|  |_|

                        Intelligent Programming Style ®

                         ____________________________
http://www.ips-team.blogspot.com
http://www.ips-team.forumeiros.com
____________________________

Created By DraKiNs & SlashPT
Thanks to [iPs]TeaM and Jhony

*/

////////////////////////////////////////////////////////////////////////////////

//========= [ Configs of Read/Write Files ] ====================================

#define MaxLines    (999)
#define MaxKeys     (064)

#define Fini_GetBool(%0)    (bool:strval(Fini_GetStr(%0)))
#define Fini_GetValue(%0)   (strval(Fini_GetStr(%0)))
#define Fini_Exists(%0)     (fexist(%0))
#define Fini_GetFloat(%0)   floatstr(Fini_GetStr(%0))
#define Fini_Remove(%0)     (fremove(%0))

#define WINDOWS //delete if use linux
//========= [ Variables of Set/Get Ini ] ========================================

new
sCacheKeys[MaxLines][MaxKeys],
sCacheValue[MaxLines][MaxKeys],
iLoop           = 0x0,
iFind           = 0x0,
iKeySet         = 0x0,
File:iFile      = File:0,
sTemp[MaxKeys]  = " ";

//============ [ Functions ] ================================================

//Get ~ Read Functions
stock Fini_GetStr(sKey[])
{
    iLoop = 0x0;
    while((sCacheKeys[iLoop][0x0]) && (iLoop < MaxLines)) {
        if(!strcmp(sCacheKeys[iLoop],sKey,false))
            return sCacheValue[iLoop];
        ++iLoop;
    }
    return sCacheKeys[0];
}


//Others Funcions
stock   Fini_Create(sFile[])
{
    if(Fini_Exists(sFile)) return false;
    iFile = fopen(sFile,io_write);
    return fclose(iFile);
}


stock Fini_OpenFile(sFile[])
{
    iFile = fopen(sFile,io_read),
        iFind   = 0x0;
    iLoop = 0x0;

    while(fread(iFile,sTemp)) {
        sTemp[strlen(sTemp) - 2] = EOS;
        iFind   = strfind(sTemp,"=");
        format(sCacheValue[iLoop],MaxKeys,sTemp[iFind + 1]);
        sTemp[iFind] = EOS;
        format(sCacheKeys[iLoop],MaxKeys,sTemp);
        ++iLoop;
    }
    return fclose(iFile);
}


stock Fini_SaveFile(sFile[])
{
    iFile = fopen(sFile,io_write),
        sTemp[0] = EOS;

    iLoop = 0x0;
    while((sCacheKeys[iLoop][0x0]) && (iLoop < MaxLines)) {

        #if defined WINDOWS
        format(sTemp,MaxKeys,"%s=%s\r\n",sCacheKeys[iLoop],sCacheValue[iLoop]);
        #else
        format(sTemp,MaxKeys,"%s=%s\n",sCacheKeys[iLoop],sCacheValue[iLoop]);
        #endif
        fwrite(iFile,sTemp);
        ++iLoop;
    }
    return fclose(iFile);
}

stock Fini_CloseFile()
{
    sCacheKeys[0][0]    =   EOS;
    sCacheValue[0][0]   =   EOS;
    iLoop               =   0x0;
    iFind               =   0x0;
    iKeySet             =   0x0;
    sTemp[0]            =   EOS;
    return true;
}


stock Fini_IsSet(sTag[])
{
    iLoop = 0x0;
    while((sCacheKeys[iLoop][0x0]) && (iLoop < MaxLines)) {
        if(!strcmp(sCacheKeys[iLoop],sTag,false)) {
            return true;
        }
        iLoop++;
    }
    return false;
}


//Set ~ Write Functions

stock Fini_SetStr(sKey[],sValue[])
{
    iLoop = 0x0;
    while((sCacheKeys[iLoop][0x0]) && (iLoop < MaxLines)) {
        if(!strcmp(sCacheKeys[iLoop],sKey,false)) {
            sCacheValue[iLoop][0] = EOS;
            strcat(sCacheValue[iLoop],sValue);
            iKeySet = 1;
        }
        ++iLoop;
    }
    if(!iKeySet) {
        while(sCacheKeys[iLoop][0]) iLoop++;
        strcat(sCacheValue[iLoop],sValue);
        strcat(sCacheKeys[iLoop],sKey);
    }
    return EOS;
}


stock Fini_SetFloat(sTag[],Float:iVal)
{
    format(sTemp,MaxKeys,"%f",iVal);
    return Fini_SetStr(sTag,sTemp);
}


stock Fini_SetVal(sTag[],iVal)
{
    format(sTemp,MaxKeys,"%d",iVal);
    return Fini_SetStr(sTag,sTemp);
}


stock Fini_SetBool(sTag[],bool:iVal)
{
    format(sTemp,MaxKeys,"%d",iVal);
    return Fini_SetStr(sTag,sTemp);
}
Abraзos
Reply


Messages In This Thread
Southclaw INI file - by Ricop522 - 19.06.2011, 20:45
Respuesta: Southclaw INI file - by ScripterTroll - 19.06.2011, 20:49
Re: Southclaw INI file - by Ricop522 - 19.06.2011, 20:51
Respuesta: Southclaw INI file - by ScripterTroll - 19.06.2011, 21:23
Respuesta: Southclaw INI file - by ScripterTroll - 19.06.2011, 21:37
Re: Southclaw INI file - by RockFire - 19.06.2011, 22:16
Re: Southclaw INI file - by Ricop522 - 19.06.2011, 23:16
Re: Southclaw INI file - by Falcon. - 20.06.2011, 00:38
Re: Southclaw INI file - by DreeH - 20.06.2011, 00:50

Forum Jump:


Users browsing this thread: 2 Guest(s)