SA-MP Forums Archive
Optimizing this code - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Optimizing this code (/showthread.php?tid=654096)



Optimizing this code - Uberanwar - 20.05.2018

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.


Re: Optimizing this code - NaS - 21.05.2018

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).


Re: Optimizing this code - Uberanwar - 21.05.2018

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!