Best way to optimize (i < MAX_PLAYERS )
#1

Hello all,
I know that existing more ways to optimize server for playerids
but which is best?
1)Foreach
2):
Код:
#define MAX_PLAYERS 100
for(new i = 0; i < MAX_PLAYERS; i++)
3)
Код:
for(new i = 0, j = GetPlayerPoolSize(); i <= j; i++)
4)
Код:
for(new i = 0; i < GetMaxPlayers(); i++)
Please help me
Reply
#2

i've seen some people doing something like that - but im almost sure this isnt the best way to do this:
Код:
#define SLOTS 50
#undef MAX_PLAYERS
#define MAX_PLAYERS SLOTS
Reply
#3

I use both:

1. Foreach

2. for(new i = 0; i < MAX_PLAYERS; i++) (FOR loop)

So actually, its your choice. (I guess both works almost same)
Reply
#4

Use foreach where possible, all other methods you showed would loop abit longer than foreach.


lets say you have 2 players on your server with id 1 and id 9,
MAX_PLAYERS would go to 0-100
GetPlayerPoolSize would go to 0-9
GetMaxPlayers would also go from 0-100

while foreach would go 0-1
Reply
#5

Redefining MAX_PLAYERS is a good way to start. I reckon that a plain player loop would be faster than foreach if the server is full or nearly full all the time because there is no additional processing overhead from foreach in that case. But if your server isn't always full then foreach is probably the way to go. The poolsize loop is a viable alternative if you do not want to use foreach.
Reply
#6

Use
PHP код:
 for(new 0GetPlayerPoolSize(); <= ji++) 
Reply
#7

Hello!

GetPlayerPoolSize ist a good method, but redefining MAX_PLAYERS is also a good way.
PHP код:
#undef MAX_PLAYERS
#define MAX_PLAYERS 100 
If you use redefining MAX_PLAYERS, you should do it like this way (look to the code). With this code MAX_PLAYERS will be 100.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)