GetTickCount
#1

pawn Код:
CMD:usercp ( playerid, params[] )
{
    new count = GetTickCount();
   
    switch ( CPActive [ playerid ] )
    {
        case 0:
        {
            // It's not active - enable it.
            TextDrawShowForPlayer ( playerid, UserCP_Title );
            TextDrawShowForPlayer ( playerid, UserCP_TopLine );
            TextDrawShowForPlayer ( playerid, UserCP_ChangePW );
            TextDrawShowForPlayer ( playerid, UserCP_ChangeUsername );
            TextDrawShowForPlayer ( playerid, UserCP_Resync );
            TextDrawShowForPlayer ( playerid, UserCP_ViewMap );
            TextDrawShowForPlayer ( playerid, UserCP_ViewAccInfo );
            TextDrawShowForPlayer ( playerid, UserCP_BottomLine );
           
            SelectTextDraw ( playerid, 0x7EBA1EFF );
            CPActive [ playerid ] = 1;
           
            SendClientMessage ( playerid, -1, ""#INT_CONSOLE"~ "#INT_SILVER"Type "#INT_YELLOW"/usercp "#INT_SILVER"again to disable the User Control Panel!" );
        }
       
        case 1:
        {
            // It's active - disable it.
            TextDrawHideForPlayer ( playerid, UserCP_Title );
            TextDrawHideForPlayer ( playerid, UserCP_TopLine );
            TextDrawHideForPlayer ( playerid, UserCP_ChangePW );
            TextDrawHideForPlayer ( playerid, UserCP_ChangeUsername );
            TextDrawHideForPlayer ( playerid, UserCP_Resync );
            TextDrawHideForPlayer ( playerid, UserCP_ViewMap );
            TextDrawHideForPlayer ( playerid, UserCP_ViewAccInfo );
            TextDrawHideForPlayer ( playerid, UserCP_BottomLine );
           
            CancelSelectTextDraw ( playerid );
            CPActive [ playerid ] = 0;
           
            SendClientMessage ( playerid, -1, ""#INT_CONSOLE"~ "#INT_SILVER"Type "#INT_YELLOW"/usercp "#INT_SILVER"again to enable the User Control Panel!" );
        }
    }
   
    printf("Time taken to execute /usercp: %d", GetTickCount() - count);
    return true;
}
Does anyone see anything wrong with this? I'm messing around with GetTickCount just to figure out how it works, and the result is always 0.
Reply
#2

I don't know much about GetTickCount(), but as you do:

pawn Код:
GetTickCount() - count
Won't it be the same as:

pawn Код:
GetTickCount() - GetTickCount()
So won't it just always display 0?

(It could be that I'm wrong, never worked with GetTickCount)
Reply
#3

Quote:
Originally Posted by Da_Noob
Посмотреть сообщение
I don't know much about GetTickCount(), but as you do:

pawn Код:
GetTickCount() - count
Won't it be the same as:

pawn Код:
GetTickCount() - GetTickCount()
So won't it just always display 0?

(It could be that I'm wrong, never worked with GetTickCount)
Assuming the time is different, it shouldn't.
Reply
#4

11 commands in a switch, needing 0 ms to execute, seems legit. any value >0 would make me think you underclocked your pc ^^

oh, try 1000 or more iterations. and divide the returned value by that amount. it will be *really* close to 0.000000000000000000000000000000000000000000000000 0000000000000000000000000000000000
Код:
for(new i=0;i<10000;i++){
            TextDrawShowForPlayer ( playerid, UserCP_Title );
            TextDrawShowForPlayer ( playerid, UserCP_TopLine );
            TextDrawShowForPlayer ( playerid, UserCP_ChangePW );
            TextDrawShowForPlayer ( playerid, UserCP_ChangeUsername );
            TextDrawShowForPlayer ( playerid, UserCP_Resync );
            TextDrawShowForPlayer ( playerid, UserCP_ViewMap );
            TextDrawShowForPlayer ( playerid, UserCP_ViewAccInfo );
            TextDrawShowForPlayer ( playerid, UserCP_BottomLine );
}
ok, srsly: copy all the command code into a callback, let it get called from within the command then, and dont forget to use the performance profiler, it will give you accurate results: estimating short routines in milliseconds is not precise enough - your code is too fast for the "low" 0.001 sec timers' resolution. it needs 0.000001 precision.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)