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

pawn Код:
SetTimer( "UpdateSpeedo", 50, true );
pawn Код:
forward UpdateSpeedo( );
public UpdateSpeedo ( )
{
    for( new u; u < MAX_PLAYERS; u ++ )
    {
        if( InCar [ u ] == true )
        {
            new
                Float:  oldspeed,
                        newspeed,
                        str [ 64 ];
               
            oldspeed = GetPlayerSpeed( u, true );
            newspeed = floatround( oldspeed, floatround_ceil );
           
            format( str, 64, "~b~MPH: ~w~%d",  newspeed );
            PlayerTextDrawSetString( u, Speedo [ u ], str );
        }
    }
    return true;
}
I mean, it's not very difficult math being performed so it really shouldn't, but there's still that possibility.. any ideas on if it will, and if it will, have any solutions without the speedo being skippy?
Reply
#2

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;
}
Reply
#3

Without timer 50ms!

pawn Код:
public OnPlayerUpdate(playerid)
{
    if (GetTickCount()%3 == 0) return 1;

    if( InCar [ playerid ] )
    {
        new
            Float:oldspeed,
            newspeed,
            str [ 16 ];

        oldspeed = GetPlayerSpeed( playerid, true );
        newspeed = floatround( oldspeed, floatround_ceil );

        format( str, 16, "~b~MPH: ~w~%d",  newspeed );
        PlayerTextDrawSetString( playerid, Speedo [ playerid ], str );
    }

    return 1;
}
Reply
#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
#5

remove new just put static
Код:
static Float:oldspeed;
Reply
#6

Why do you want to call it 20 times a second? OnPlayerUpdate is called 10 times per second.
Reply
#7

Quote:
Originally Posted by Blasphemy
Посмотреть сообщение
Why do you want to call it 20 times a second? OnPlayerUpdate is called 10 times per second.
I believe it was stated in the original post...He's trying to do that for more fluidity. Though it will never be fluid unless you're using a controller. Unless he's talking acceleration then all that needs to be done is what I gave him before.
Reply
#8

Quote:
Originally Posted by [ABK]Antonio
Посмотреть сообщение
I believe it was stated in the original post...He's trying to do that for more fluidity. Though it will never be fluid unless you're using a controller. Unless he's talking acceleration then all that needs to be done is what I gave him before.

All i see is a title saying: "Will this cause lag with say.. 100 players?" and a loop called 20 times per second for up to 500 times.

My answer is:


YES
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)