[PName] - should be used?
#1

Today I have implemented a name getting method, which is faster than GetPlayerName.
What do you think? Is it significant?

Quote:

[join] Colonel_Vincent has joined the server (0:127.0.0.1)
Timer engaged for player 0
GetPlayerName time, for 100 000 000 run: 31993 ms
PName time, for 100 000 000 run: 20775 ms
GetPlayerName: 'Colonel_Vincent`[15] PName: 'Colonel_Vincent`[15]

pawn Code:
new playernames[MAX_PLAYERS][MAX_PLAYER_NAME];
#define PName(%1) playernames[(%1)]

public myhook_SetPlayerName(playerid, const name[])
{
    new r = SetPlayerName(playerid, name);
    if (r) format(playernames[playerid], MAX_PLAYER_NAME, "%s", name);
    return 1;
}

#if defined _ALS_SetPlayerName
    #undef SetPlayerName
#else
    #define _ALS_SetPlayerName
#endif
#define SetPlayerName myhook_SetPlayerName

forward myhook_SetPlayerName(playerid, const name[]);

public OnPlayerConnect(playerid)
{
    GetPlayerName(playerid, playernames[playerid], MAX_PLAYER_NAME);
    SetTimerEx("tmr", 2000, 0, "d", playerid);
    printf("Timer engaged for player %d", playerid);
    return 1;
}

forward tmr(playerid);
public tmr(playerid)
{
    new store_here[MAX_PLAYER_NAME], tmp[MAX_PLAYER_NAME];
    new tick_generic = GetTickCount();
    for (new i = 0; i < 100_000_000; i++) GetPlayerName(playerid, store_here, MAX_PLAYER_NAME);
    new generic_time = GetTickCount() - tick_generic;
    strcat(tmp, store_here);
    new tick_pname = GetTickCount();
    for (new i = 0; i < 100_000_000; i++) store_here = PName(playerid);
    new pname_time = GetTickCount() - tick_pname;
    printf("GetPlayerName time, for 100 000 000 run: %d ms", generic_time);
    printf("PName time, for 100 000 000 run: %d ms", pname_time);
    printf("GetPlayerName: '%s`[%d] PName: '%s`[%d]", tmp, strlen(tmp), store_here, strlen(store_here));
    return 1;
}
Reply
#2

its Abit Faster i now
Reply
#3

Obviously having names stored in strings/arrays is faster than calling a function. Hence why ****** made foreach.
Reply
#4

1: Yes, I should, that's right. In fact, it is done in an include but I did not release it yet.

2: I don't want to redefine GetPlayerName, because that would cause problems in existing scripts, which still uses GetPlayerName(playerid, name[], len)

3: This was just a test. Altough I don't know, is this a correct ALS for callback:
pawn Code:
public OnPlayerConnect(playerid)
{
    GetPlayerName(playerid, playernames[playerid], MAX_PLAYER_NAME);
    return CallLocalFunction("PName_OnPlayerConnect", "i", playerid);
}

#if defined _ALS_OnPlayerConnect
    #undef OnPlayerConnect
#else
    #define _ALS_OnPlayerConnect
#endif
#define OnPlayerConnect PName_OnPlayerConnect
?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)