ID:1208336
 
I have a world proc which checks every mob in the world every tick to perform their movement (it's a sidescroller made with ForumAccount's library), and I wondered if it would make a difference to change for(var/mob/M in world) to something like for(var/mob/M in Active_Mobs).

Any tip?
Potentially yes, only looping a smaller list of mobs could be considered an optimization. It mostly depends on how large your world is and how many mobs you have.
If you want to get technical (and stray from efficiency), you don't need in world. The world is the default list to be checked, so just doing for(var/mob/M) will do the exact same thing.
In response to Albro1
Albro1 wrote:
If you want to get technical (and stray from efficiency), you don't need in world. The world is the default list to be checked, so just doing for(var/mob/M) will do the exact same thing.

Not entirely correct.

for(var/client/c in world)
world<<c
//Gets nothing, clients are not present in the 'world'
for(var/client/c)
world<<c
// Gets the clients

What does using for() with no parameters do?

Edit: Just one example where I've seen it used is in world/New() of this snippet: http://www.byond.com/forum/?post=1202998#comment4232426
In response to Emasym
Emasym wrote:
Albro1 wrote:
If you want to get technical (and stray from efficiency), you don't need in world. The world is the default list to be checked, so just doing for(var/mob/M) will do the exact same thing.

Not entirely correct.

> for(var/client/c in world)
> world<<c
> //Gets nothing, clients are not present in the 'world'
> for(var/client/c)
> world<<c
> // Gets the clients
>


In the case of for(var/mob/M), which was all I was talking about, it is correct. You make a valid point though on how it cannot be applied to everything.
Honestly, if there were a more efficient way of sorting through lists of data, we wouldn't ever need to use for() in the first place. The fact that it's probably the most widely used function for that purpose should tell you something.
Forum_account's Pixel Movement library (it applies to Sidescroller as well) demonstrates an optimization that involves looping through a relatively small list of active mobs, not because of the loop itself, but what the library calls for each mob over which the loop iterates.

Basically, you can check Forum_account's Pixel Movement library's "performance-demo" to see exactly what you're asking about.
In response to TheLionsRoar
TheLionsRoar wrote:
What does using for() with no parameters do?

It creates an infinite loop. It's the same as while(true). As the reference states:

for(Init, Test, Inc)

Init and Inc may be omitted. If Test is omitted, the loop will continue forever (unless a break, goto, or return instruction is used to get out of the loop).