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
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.
simono on 2007/04/03 12:27:
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.