ID:574015
 
(See the best response by Forum_account.)
Code:
world
New()
spawn() GenerateFlowers()
..()

obj/Supplemental/Flower
icon='Flowers.dmi';layer=TURF_LAYER;mouse_opacity=0
proc/GenerateFlowers()
set background=1
for(var/turf/Jungle/Grass/G in world)
if(rand(1,20)==1)
var/counter=0
if(G.contents.len || G.overlays.len) continue
while(counter<rand(0,19))
counter+=1
var/obj/Supplemental/Flower/NF=new(G)
NF.pixel_x=rand(-12,12)
NF.pixel_y=rand(-12,12)
NF.icon_state="Flower[rand(1,25)]"


Problem description:
I am just wondering ... Can something like this leads to lagging ?

Best response
Can something like this leads to lagging ?

Not really. It's a one-time thing (I'm guessing). Even if it causes a spike in CPU usage to generate the flowers, it's only done once. If you have many instances of /turf/Jungle/Grass then it could take a while, but once it's done it'll be fine.

For things like this, I sometimes generate them for one z level at a time. That way you're not creating all of the flowers when the game starts, you're just creating them for each z level as they're needed. If your map is one big z level, this doesn't really help.

The only other way it'll cause problems is by having lots of objects on the map. When a player walks into the jungle, the more flowers there are, the more data has to be sent from the server to the client. However, you're placing flowers on about 5% of the jungle turfs, so it shouldn't be that bad.

One thing that you could do is to only create one flower object per tile. Instead of creating multiple objects, just make some icons that have multiple flowers on them. That way you can do something like this:

var/obj/Supplemental/Flower/NF = new(G)
NF.icon_state = "flower-[rand(1,3)]-[rand(1,25)]"

The first random number is the number of flowers, the second random number picks a variation.

Also, in this line:

while(counter<rand(0,19))

I think rand() is going to be called every iteration of the loop. I'm not sure if that's intentional - it's not creating between zero and 19 flowers.