Game Design, Programming and running a one-man games business…

Optimising day

I’m taking an afternoon to optimise all the code that I added recently. A lot of stuff that makes the game looks cool was being done in a really inefficient way. In some cases, it was a matter of remembering to check somethings onscreen before going to any effort to draw it. In other cases, it’s a matter of caching data.

Caching means ‘keeping a copy of’ effectively. If I ask you the date, and you tell me, I could then ask you the date in 5 minutes time, or I could make a note of the information you gave me earlier, and not bother you. A lot of optimising comes down to caching data. In this case, I was calling the cos() (cosine) function several times in short succession, and getting the same answer. sin() and cos() are pretty slow, if you call them several thousand times a frame, so it really makes sense to cache them.

Things seem much faster now, even with tons going on :D

5 thoughts on Optimising day

  1. I demand screenshots!!! And cookies!!! Figure out a way to screenshot code optimization and I’ll bring the cookies…

  2. if you are doing sin and cos together a lot there’s an instruction “fsincos” which is faster than calling them independently.

  3. I looked into optimisation of sin and cos in actionscript a week or two back. Some guy had tested a look-up table of values and found it was slower than Math.sin and Math.cos! Basically, making flash do a single function call and look into an array was slower than just doing the Math call, amazing really. Don’t know if that says more about Flash than the cpu… :)

Comments are currently closed.