Indie game developer and creator of Ambience.

Dev Diary #14: An Itch That Must Be Scratched (More on Line of Sight!)

For some reason, line of sight and fog algorithms have just been an itch I always need to scratch. I’ve lost count of how many times I’ve revised that algorithm (but hopefully I’ve done so for the last time now!)

In particular, over the past week I began to notice that the line of sight would take a little while to update when moving from a corridor to a room, or vice versa. This caused a little bit of lag with each step. It wasn’t intolerable, but still noticeable when playing and so definitely not ideal.

After spending several hours tweaking and fine-tuning the line of sight updating algorithm, I figured out and managed to solve the problem. For some daft reason, I had originally told the game to update every tile on the screen with each step, which was slow and computationally intensive – hence the lag. So I re-designed the system (again!) to do what I should have done in the first place – only change the tiles that had actually changed visibility with that step. And, as expected, it worked! Walking smoothly through a dungeon corridor has never felt so good.

Moral of the story? Do things right the first time (if you can), so you don’t spend hours later down the track trying to fix up bugs from poorly implemented code.

(Incidentally, the function that was chewing up most of my processing time was the function used to find the ID of a tile on a particular layer. Which was unexpected, and a bit annoying…)