Repeat after me: "Premature optimization is the root of all evil"

Day 2, Monday, was a working day, so I had no real time to look at this until the evening. During my drive home I figured that I could do with a collision grid to speed up collision detection - anything to reduce the number of collision tests.

So, when I finally got time to myself in the evening, I sat down and wrote a nice collision grid class. I even unit tested it to make sure that it did what it said on the tin. And then I fired it up to see what would happen. And guess what. It was slower! I took some timings and found that the overhead of maintaining the grid was just too much compared with iterating through a list and comparing a few thousand rectangles.

So day 2 ended with a whimper.

I feel a bit better about it now, as this morning I got up early and did a quick and rather more successful spike before heading off to work, ending up with a reasonably competent implementation of doors.

(log in to comment)

Comments

agree+1 if something already (somewhat) works in my game, i force myself to NOT tinker with that part again, unless it brings gameplay-value.
With my last pyweek entry (nelly) I used a uniform grid, but it took quite a bit of tweaking of the number of rows and columns for it to work efficiently; I ended up using wide columns but narrow rows (perhaps because this suited the general shape of many of the placeables). I say: don't throw it out yet, you may find use for it later down the track.

I've definitely kept the code. It certainly reduces the number of collision tests that are necessary, but rect/rect tests aren't all that expensive and that's all I'm going for.

You'd think I'd know better by now though.