ID:140007
 
Code:
obj/geoglyph

name = "Dark Mark"
icon = 'geoglyphs.dmi'
layer = MOB_LAYER -1
condor/icon_state = "condor"

proc/make_dark_mark(mob/M,objtype,ico_state,cx,cy,cz,xsize,ysize,newname)
set background=1

var/obj/Z
var/xl = 0
var/yl = 0

while(1)
Z = new objtype(locate(cx+xl,cy+yl,cz))
Z.icon_state = "[ico_state] [xl],[yl]"
Z.name = "[newname] Geoglyph"

yl+=1

if(yl>ysize-1)
yl = 0
xl += 1

M.ObjGrid += Z

if(xl<xsize) continue

break

mob/verb/Make_Geoglyph()
make_dark_mark(usr,/obj/geoglyph/condor,"condor",src.x-14,src.y-15,src.z,29,30,"Condor")
//for(var/turf/T in view(30,usr)) if(T.z == z) T.overlays += /obj/geoglyph/shade

mob/verb/Del_Geoglyph()
for(var/obj/geoglyph/G in usr.ObjGrid) del G


Problem description:

When i press Make Geoglyph its almost instant as it appears on the map. However when i press Del Geoglyph Dream Seeker seems to pause for quite a few seconds before it finally vanishs.

I added the objects to a list connected to the mob (ObjGrid), to avoid it having to sweep the world for those objects and hopefully saving some processing time/lag etc.

I'm not sure why it takes longer to delete the objects than it does to create them. Any thoughts? I'm a little concerned how the removal is going to affect the world on a live server.

Additionally, ive noticed what when i hit Close on the Dream Seeker window (while one of these is placed down on the map) then it takes its sweet time to close! About 3-5 seconds. Where as, closing it in all other circumstances its instant. Some issue with the code? I'm not really sure what though i think its about as good as it can be for the purpose of drawing a rather large 928x928 pixel image on a game map in real-time.
Read up on garbage collection and how explicitly deleting objects can be much more resource intense.
In response to Schnitzelnagler
Aha!

Thankyou that is really helpful. So much to learn, seems like it could all never fit in my head :P not without pushing something else out lol.

That's very useful though, basically setting its loc to null will kill it. I just tried it and it was instant! So problem solved.

I never knew using Del() would be so resource intensive.
In response to EternalDuelistSoul
"Note that in the above list, loc does not count as a reference. If mob M is holding object O, O is referenced by M.contents but O doesn't necessarily have any references to M. The loc var doesn't need to add to the reference count, which is good because it means if you move the container to a null location and nothing else is using it anymore, all its contents can probably be deleted too."

Uh, huh.
In response to EternalDuelistSoul
Note that you'd also have to remove everything from the ObjGrid list, and the fastest way to do that is just to set it to list().
In response to Garthor
Garthor wrote:
Note that you'd also have to remove everything from the ObjGrid list, and the fastest way to do that is just to set it to list().

Good point, though the ObjGrid does store other objects so im just searching through types of what i want to remove.