Optimizing this code
#1

Need help on optimizing this code which used for pos compensation.

Код:
static Float:TP_GetDistanceFromAwaiting(playerid)
{
	new Float:pX, Float:pY, Float:pZ;
	GetPlayerPos(playerid, pX, pY, pZ);
	return (floatsqroot(floatpower(pX - TP_AwaitingPos[playerid][0], 2.0) + floatpower(pY - TP_AwaitingPos[playerid][1], 2.0) + floatpower(pZ - TP_AwaitingPos[playerid][2], 2.0)));
}
AFAIK, the usage of floatsqroot/floatpower is very inefficient. Would be grateful if anyone could help me on optimizing this code because based on my profiler results, "operator<(Float:,Float" is 28.42% (the highest) which gives a huge impact on my script performance.
Reply
#2

Use GetPlayerDistanceFromPoint().

It does the same math but with 6 less native calls (you don't need to do GetPlayerPos(), furthermore each float operation is one native call, since PAWN can't do that).
Reply
#3

Quote:
Originally Posted by NaS
Посмотреть сообщение
Use GetPlayerDistanceFromPoint().

It does the same math but with 6 less native calls (you don't need to do GetPlayerPos(), furthermore each float operation is one native call, since PAWN can't do that).
Thank you very much!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)