[SOLVED] CPU Usage increases with more houses defined - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: [SOLVED] CPU Usage increases with more houses defined (
/showthread.php?tid=119939)
[SOLVED] CPU Usage increases with more houses defined -
KnooL - 10.01.2010
This is what makes my server use more CPU
OnGameModeInit:
pawn Код:
for(new i = 0; i <= MAX_PLAYERS; i++)
{
Timer[0] = SetTimerEx("ReadPlayerHouseData", 1000, true, "%i", i);
}
for(new h = 0; h <= MAX_HOUSES; h++) // Player Homes
{
LoadPlayerHouse(h);
}
Is there any way to decrease the cpu usage?
Re: CPU Usage increases with more houses defined -
Correlli - 10.01.2010
I would say that this is the main problem:
Quote:
Originally Posted by KnooL
pawn Код:
for(new i = 0; i <= MAX_PLAYERS; i++) { Timer[0] = SetTimerEx("ReadPlayerHouseData", 1000, true, "%i", i); }
|
If your MAX_PLAYERS is defined as 500 (by default at a_samp.inc) then there's no wonder that your CPU is crying. 500 timers.. that's not good.
Use one timer for all players (SetTimer function).
Also, you should use
< MAX_PLAYERS instead of
<= MAX_PLAYERS in the player loops or just use the foreach from ******.
Also, you can't use
"%i" in SetTimerEx, use just
"i"
Re: CPU Usage increases with more houses defined -
introzen - 10.01.2010
You should add IsPlayerConnected function aswell.
Re: CPU Usage increases with more houses defined -
KnooL - 10.01.2010
Quote:
Originally Posted by IntrozeN
You should add IsPlayerConnected function aswell.
|
Quote:
Originally Posted by Don Correlli
I would say that this is the main problem:
Quote:
Originally Posted by KnooL
pawn Код:
for(new i = 0; i <= MAX_PLAYERS; i++) { Timer[0] = SetTimerEx("ReadPlayerHouseData", 1000, true, "%i", i); }
|
If your MAX_PLAYERS is defined as 500 (by default at a_samp.inc) then there's no wonder that your CPU is crying. 500 timers.. that's not good.
Use one timer for all players (SetTimer function).
Also, you should use < MAX_PLAYERS instead of <= MAX_PLAYERS in the player loops or just use the foreach from ******.
Also, you can't use "%i" in SetTimerEx, use just "i"
|
Thank you both,
this is how it looks like now:
pawn Код:
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i)) {
Timer[0] = SetTimerEx("ReadPlayerHouseData", 1000, true, "i", i);
}
}
Now no lags and no increasing CPU usage. I consider it as fixed, thank you.
Re: [SOLVED] CPU Usage increases with more houses defined -
Donny_k - 10.01.2010
Is that a typo "Timer[ 0 ]", should it be "Timer[ i ]" or something ?
Just thought I'd ask as it looks like you're tracking the timer id and it won't work like that (all [ 0 ], only the last one will store).