OnPlayerUpdate: How much is too much? -
Jonny5 - 16.04.2012
Im wondering how much is too much for OPU
the thing is I just dont know, I dont use it at all but seams like it could be good for some stuff.
is code like this too much?
pawn Код:
GetPlayerPos(playerid, aPlayerInfo[playerid][pLastX], aPlayerInfo[playerid][pLastY], aPlayerInfo[playerid][pLastZ]);
GetPlayerFacingAngle(playerid,aPlayerInfo[playerid][pLastA]);
aPlayerInfo[playerid][pInterior] = GetPlayerInterior(playerid);
aPlayerInfo[playerid][pVituralWorld] = GetPlayerVirtualWorld(playerid);
can I do more things here like some simple function-less checks in variables?
What functions should i stay away from using in OnPlayerUpdate?
I want to get an idea as to what I can use this callback for.
If i can remove a timer or 2 then I will.
Re: OnPlayerUpdate: How much is too much? -
AndreT - 16.04.2012
You should avoid having to call slow functions or larger calculations on every call. Doing them once in a while won't hurt. Functions don't hurt either, but I would recommend you not to run heavy calculations or such.
But the actual reason I decided to post is that I found that you can replace some of your code with even native callbacks!
For detecting interior changes, use
OnPlayerInteriorChange. Also, I'm quite sure your script can control when players change virtual worlds, so why not use function hooking (look around! :P) for that so you can assign it once SetPlayerVirtualWorld is called rather than use it in OnPlayerUpdate or a timer.
I don't know about the position storing, but I can't think of any code of mine which could benefit from having the position updated very very often.
Re: OnPlayerUpdate: How much is too much? -
Jonny5 - 16.04.2012
i did not even notice a callback OnPlayerInteriorChange
Thanks,
yeah the pos was really just an example, that actually runs in a timer and updates every 60 secs or so.
it wasn't really about that it was about the GetPlayerPos & GetPlayerFacingAngle or other functions alike.
I do use y_hooks. But thats only for callbacks, I guess I could write a marco that replaces the
SetPlayerVirtualWorld and changes my pInfo at the same time when used.
Im just trying to get an idea what functions are just taboo to use here.
Mostly for my own knowledge.
thanks!
Re: OnPlayerUpdate: How much is too much? -
Jonny5 - 16.04.2012
That was my concern thank you,
Iv read many places about not using OnPlayerUpdate
and seams some stuff can be used here.
My server is in a Lan Network only and has 3gb of ram,
Intel Pentium® @2.20 GHZ
at most 32 players but most of the time around 10 players.
Seams Im being to careful! I will just do some testing with what I want to add and see how it works out
The wiki shows making your own callbacks like OnWeaponChange as an example.
This is kinda what I want to use it for, Is that bad practice? Or would depend on my server like you said?
thanks.
Re: OnPlayerUpdate: How much is too much? -
Jonny5 - 25.04.2012
well I did not use the performance profiler plugin yet,
I did use Slices
bench marking marcos Just to test the code in question.
iv ran the test with different irritations
and generally im getting this number
Код:
START_BENCH( 10000 );
{
GetPlayerPos(playerid, aPlayerInfo[playerid][pLastX],aPlayerInfo[playerid][pLastY], aPlayerInfo[playerid][pLastZ]);
GetPlayerFacingAngle(playerid,aPlayerInfo[playerid][pLastA]);
aPlayerInfo[playerid][pInterior] = GetPlayerInterior(playerid);
aPlayerInfo[playerid][pVituralWorld] = GetPlayerVirtualWorld(playerid);
}
FINISH_BENCH( "without loop" );
Bench for without loop executes, by average, 564.80 times/ms.
or close to that number
if i loop that code 500(MAX_PLAYERS) times in each bench irritation i get
Код:
START_BENCH( 10000 );
{
for(new ixc=0;ixc<500;ixc++)
{
GetPlayerPos(playerid, aPlayerInfo[playerid][pLastX],aPlayerInfo[playerid][pLastY], aPlayerInfo[playerid][pLastZ]);
GetPlayerFacingAngle(playerid,aPlayerInfo[playerid][pLastA]);
aPlayerInfo[playerid][pInterior] = GetPlayerInterior(playerid);
aPlayerInfo[playerid][pVituralWorld] = GetPlayerVirtualWorld(playerid);
}
}
FINISH_BENCH( "with loop" );
Bench for with loop: executes, by average, 4.63 times/ms.
So I guess my question(s) are..
Have I bench marked this correctly?
If I can keep the second test code above 1 times/ms
I should not have any lag in OnPlayerUpdate?
My brain tells me I can probably take up to 100ms
and still be safe?
thanks for your input.