ID:120250
 
Not a bug
BYOND Version:493
Operating System:Windows 7 Home Premium 64-bit
Web Browser:Chrome 14.0.835.202
Applies to:Dream Seeker
Status: Not a bug

This is not a bug. It may be an incorrect use of syntax or a limitation in the software. For further discussion on the matter, please consult the BYOND forums.
Descriptive Problem Summary:
Changing icons in rapid succession always bogs games down. I have all the icon files in the game's cache and I have to at certain points crop icons on players several times in a row. When I do that it bogs the game down horribly because when I crop the icon the only way I seem to know how to do so is to use a separate icon instance, then load the cropped icon instance back onto the target mob. Is there a particular reason why changing icons slow the game down so much? If there was a chance that changing icons could be sped up (I'm not talking about resource downloads. I'm just talking about changing icons that already have been downloaded) and not use so much overhead that would be a huge lifesaver. If you want a visual representation of what I'm talking about, I have uploaded a screen capture example onto Youtube: http://www.youtube.com/watch?v=Ly4kZ_eom-I

In short, I need to change icons in rapid succession, which appears to work just fine with a small test size. When it's done with several (about 10 or so, depending on how many times you change icons) atoms at once, it slows the whole game down.

This happens to me a lot, especially when I use the var/icon/ variables to alter a mob's icon.

Numbered Steps to Reproduce Problem:
1. Program a small game with loops that change an icon about 8 to 16 times in a single iteration (with a delay).
2. Iterate that loop several times.

Code Snippet (if applicable) to Reproduce Problem:
This is just the code part that I was using that tends to slow it down.
        proc/MoveThrough(mob/M,obj/o,obj/p) //M is the player moving through, o is the object to show the person going through on the other end, and p is the other portal.
var/icon/I=new(M.icon) // This is an icon that will hold the original.
var/icon/K=new(M.icon) // This icon can be modified, and will show the user
var/icon/L=new(M.icon) // This icon can be modified, and will show the placeholder object.
if(dir==EAST)
M.pixel_x+=2
while(K.Width()>=3)
if(K.Width()<=I.Width()/2) //If the person or thing going through is at or over halfway through, let them see the other side
if(istype(M,/mob))
if(M.client) //Make sure we're just getting players
M.client.eye=p.loc
M.client.perspective=EYE_PERSPECTIVE
K.Crop(3,1,K.Width(),K.Height())
L.icon=I
if(p.dir==EAST)
L.Crop(K.Width(),1,L.Width(),L.Height()) // Coming out!
if(p.dir==WEST)
L.Crop(1,1,L.Width()-K.Width(),K.Height())
o.pixel_x-=2
if(p.dir==NORTH)
L.Crop(1,3,I.Width(),I.Height())
if(p.dir==SOUTH)
L.Crop(1,1,I.Width(),K.Height())
M.icon=K
o.icon=L
sleep(0.5)


Expected Results:
Icons seamlessly and smoothly change, not bogging down the game.

Actual Results:
The entire game slows down, and the frame rate suffers.

Does the problem occur:
Every time? Or how often? Every time.
In other games? I haven't really seen people change icons in their games as much as I did, but I'm pretty sure it will happen if they try.
In other user accounts? Yes.
On other computers? Yes.

When does the problem NOT occur?
It always occurs, except it's just less noticeable if you don't change icons very frequently.

Did the problem NOT occur in any earlier versions? If so, what was the last version that worked? (Visit http://www.byond.com/download/build to download old versions for testing.)
As far as I am aware, it occurs in every version to date.

Workarounds:
There aren't really any workarounds. Icon changing just uses a very large amount of overhead for no apparent reason.
This is a developer issue, not a bug. Doing that much icon work is likely to cause slowdowns period, and the method you're using to go about the icon operations is a matter of poor technique. I suspect better code will improve the situation substantially though.

1) Do not rely on Width() and Height(). Grab those at the beginning of the loop, and do not use them thereafter--use vars instead. Those values have to be calculated.

2) Do not keep modifying the very last icon you worked on. Instead, start with a fresh copy of the original and crop it down to where you need it. The method you're using is creating longer and longer opcodes doing more and more work each time.