Will this cause lag with say.. 100 players?
#4

Quote:
Originally Posted by Mauzen
Посмотреть сообщение
This should work, but theres a handful of things to optimize. You could use foreach instead of for to make it a lot faster. You could also reduce the timer interval to like 100ms, that should still be fine.
Anyways you should reduce the size of str, that string wont ever go about 16 characters. And move the variable declaration outside the loop. Your way it creates the same variables for everyone again and again, creating them once (or making them static) is way more efficient.

Heres an optimized version that will already run way better (foreach would even speed it up 2-3x times):
pawn Код:
forward UpdateSpeedo( );
public UpdateSpeedo ( )
{
    new static Float: oldspeed; // Outsourced from the loop and made static
    new static newspeed; // static variables will only be allocated once
    new static str[16]; // and so not again for every timer call
    for( new u; u < MAX_PLAYERS; u ++ )
    {
        if( InCar [ u ] == true )
        {
            oldspeed = GetPlayerSpeed( u, true );
            newspeed = floatround( oldspeed, floatround_ceil );
           
            format( str, 16, "~b~MPH: ~w~%d",  newspeed );
            PlayerTextDrawSetString( u, Speedo [ u ], str );
        }
    }
    return true;
}
I'm getting a ton of errors with that for some reason. :3

pawn Код:
C:\Users\Sky\Desktop\SAMP 0.3e R2\gamemodes\rp.pwn(1009) : error 001: expected token: "-identifier-", but found "static"
C:\Users\Sky\Desktop\SAMP 0.3e R2\gamemodes\rp.pwn(1010) : error 001: expected token: "-identifier-", but found "static"
C:\Users\Sky\Desktop\SAMP 0.3e R2\gamemodes\rp.pwn(1011) : error 001: expected token: "-identifier-", but found "static"
C:\Users\Sky\Desktop\SAMP 0.3e R2\gamemodes\rp.pwn(1017) : error 017: undefined symbol "oldspeed"
C:\Users\Sky\Desktop\SAMP 0.3e R2\gamemodes\rp.pwn(1018) : error 017: undefined symbol "newspeed"
C:\Users\Sky\Desktop\SAMP 0.3e R2\gamemodes\rp.pwn(1018) : error 017: undefined symbol "oldspeed"
C:\Users\Sky\Desktop\SAMP 0.3e R2\gamemodes\rp.pwn(1020) : error 017: undefined symbol "str"
C:\Users\Sky\Desktop\SAMP 0.3e R2\gamemodes\rp.pwn(1021) : error 017: undefined symbol "str"
Reply


Messages In This Thread
Will this cause lag with say.. 100 players? - by 2KY - 19.09.2012, 23:24
Re: Will this cause lag with say.. 100 players? - by Mauzen - 19.09.2012, 23:30
Re: Will this cause lag with say.. 100 players? - by Jefff - 20.09.2012, 00:03
Re: Will this cause lag with say.. 100 players? - by 2KY - 20.09.2012, 00:09
Re: Will this cause lag with say.. 100 players? - by Johndaonee - 20.09.2012, 00:33
Re: Will this cause lag with say.. 100 players? - by Blasphemy - 20.09.2012, 02:50
Re: Will this cause lag with say.. 100 players? - by [ABK]Antonio - 20.09.2012, 02:54
Re: Will this cause lag with say.. 100 players? - by Blasphemy - 20.09.2012, 03:02

Forum Jump:


Users browsing this thread: 3 Guest(s)