19.09.2012, 23:30
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):
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;
}