So I did some work on a timer. There’s actually some timer stuff in SDL which I’ve read about and decided not to go for and there is also a timer object in the SDL_gfx lib I’ve been thinking about using, but in the end I thought it would be best if I did what I wanted regardless of everyone’s experience in the matter. How glad I am that I did!
Actually, I’ll probably abandon my timer when it proves to be as shit as I suspect, but I’ll forge along and try it in the game anyway because;
A. it actually does what I intended it to, and
B. the alternative in SDL_gfx is actually fairly straightforward to implement and I think its important to see why mine is a bad idea before abandoning it first.
Why do I think I did a bad job? Well, what I understand of timing is after all the game logic is called, you call the timer, this takes the framerate you desire, works out the fractions of a second this splits into then halts the loop till it hits the next interval this corresponds to.
Looking back, I guess that’s fine, people use this method for a reason and its not like games are a new technology that’s full of unproven concepts, but without a clear understanding of what it was all about, it seemed a waste of computing power. Instead, I came up with this fantastic idea where the computer just runs the game as fast as is possible, and only updates when that fractional timing trigger is fired. This I was sure was the winner and so I set off to implement it. And in fairness, it works exactly as I intended, except obviously its using awe inspiring quantities of cpu time.
I’m in the process of turning my prototype into a class which I can use, one of the nice things about it is that I’ll be able to have multiple timers with different framerates within the code without any real complexity, I’m not sure if there’s any benefit to that at all, its why I’m going to carry on and see what a real-world implementation does.
One thing it did teach me, which makes the whole exercise worthwhile, is how timing in C++ and game programming works, this more than any tutorial I could find was very useful.