area
Space
Enter(mob/m) // this is to add the background to the player
. = ..()
if(ismob(m))
if(m.client)
var image/i = image('nebula2wGalaxy.png', m, "", DC_TURF_LAYER - 0.1)
i.text = "spacebg"
m << i
Exit(mob/m) // when they leave remove the image
. = ..()
if(ismob(m))
if(m.client)
var client/c = m.client
for(var/image/i in c.images)
if(i.text == "spacebg")
c.images -= i
del i
Problem description:
So, I'm trying to create a 3D ish view of space, and I want this background image to move with the player's mob as they traverse space. The image is 1000x667 and is 923kb in size.
The problem I'm facing is, outputting the image has some wildly weird behavior. The game will not boot up. Normally, it boots up to about 96mb in the task manager, pauses for a moment, then rockets up to about 900mb, and stabilizes down to 225mb. With this, it slowly climbs after 96mb, and after like 5 minutes or so its barely reached 180mb. In short, the game is being lagged to hell by something, and that just baffles me. As far as I'm aware, there is no way for the code to get called to slow it down like that.
There are no mobs in space upon booting up, so this shouldn't get called even a single time. After commenting out the image output, the game works fine (but obviously without the goal achieved.)
Why is this happening?
When the player logs into the world, the engine tries to move to the first turf where Enter() returns true. It will try every tile until it finds one.
What's going on is that Enter() is being called a huge number of times trying to enter turfs, and also attempting to enter the area the turf is in.
This is creating thousands of image objects all at one time. Since Exit() is never called by Login(), you have a leak going on. These objects will never be destroyed. Also, every time the player fails to move into space, it will create a new image for the player regardless of whether they are actually standing in space. That's another leak.
Also, your entire method for handling these image objects is really, really messed up in the first place and eating way more CPU than it needs to.
Let me fix:
I say this a lot:
If you ever find yourself searching through a list for an object that you know is there, you are using the slowest method possible of grabbing that object, and the more you use this kind of a pattern, the slower your game will be.
You should NEVER be in a situation where you are searching a list when you only care about one object.
I also say this a lot:
You shouldn't ever find yourself creating and deleting objects over and over again unless there is a need for a different object every time. Create it once on demand and then hang on to it. There's no real negative to keeping objects around if you are going to use them again in the future. There's a huge negative to creating them over and over and over again --as you just found out.
Also: Enter() is not called when an object moves into a square. Enter() is called to ask if it can occupy a square. Exit() is called to ask if it can leave a square. Enter() and Exit() don't even imply that an object will try to enter or leave a tile. It's just asking if it can. Entered() and Exited() will always be called only after a movable has successfully exited a tile via the Move() function. Odds are if you are doing something in Enter() and Exit() that doesn't contribute to the answer to the question: "Can I come in/go out?", you shouldn't be doing it there.