Reflex – Dev Diary 29

Optimisation and fixing the laser fences has been my focus for this week.

The laser fences, if you’ve been following along, had a habit of using up too much processing power each frame (tick). The reason for this was due to the continuous check to see if the connected laser fence was still operational.

Basically the laser towers will fire a collision test line in four directions each frame to see if it can find another laser tower. If it can it allows the laser wire to bridge the gap, if it can’t then the laser wire is destroyed.

This all sounds fine until you factor in that collision checks can be costly and if you have 3, 4 or more laser fences that’s a lot of collision checks.

So, now the checks are done when the tower is first created to set up the wires. The connected towers ID is stored with each tower so that it can quickly check to see if the connected tower still exists (hasn’t been blown up), if it has then the wire can be terminated. This process is massively faster.

The laser turret also needed some TLC this week. Some of the code was out of sequence and that allowed the turret to fire on the same missile twice, even after the missile had been destroyed. This was mainly because the motion and tracking for the turret is performed first, so the turret finds the missile, fires at it, the missile is destroyed (but this doesn’t actually happen until the end of the frame), and then the turret checks to see if any missiles are in it’s sights – at this point it located the same missile again because it hadn’t been removed from the game yet, and so it fired a second time.

A simple reordering of the code fixed it.

With these optimisations complete I should now be able to get on with designing World 4 levels.