Simple Timers: a one day project that turned out to quite fun and useful

Let's start out by saying I had a lot of fun working on this and this was mostly an excuse to see how I could make delegates work in modern C++. Also a disclaimer this is a very basic library which has a lot of limitations and isn't in any way special, but it does its job and could be useful when prototyping or developing a game. Most of the things are based on the Lua implementation in Garry's Mod, so that's why this implementation looks an awful lot like it.

Let me tell you something more about the functionality about this library and let's start with the Timers itself. There is a SimpleTimer and an ExtendedTimer with the only difference being, is that the ExtendedTimer has an Identifier, so if you request the timer object and change the values of it at any time. The timers themselves have the functionallity to adjust their settings, like the interval, the total amount of repititions and the function that needs to be called. It can also be paused and unpaused and you can request the timeLeft and repetitionsLeft as well as the intervalTime and the TotalRepetitions.

If you want to hook your timer up to your update loop or something else you can call the Update function on the timers with the milliseconds delta as argument. One improvement could be to change the ITimer class to a templated class so you could change the accuracy of the timer, but for now and for my purposes this is accurate enough.

Then there is a TimerManager class which is a class that keeps track of every timer that you register trough that class, updates all the registered timers and if you have ExtendedTimers you could also request them by their identifier, nothing fancy here.

Last but not least I have two very simple classes that do exactly what they say they do. the TimeSince and TimeTill and this idea came from a blog I read and is dead simple. But it's a way to get the time since something happened or a time till something happens with a simple if(timeSince >= 10.0f) or if (timeTill <= 0.0f) you can check if the statement is true or false.

I uploaded this little and unfinished library onto github so you can check it out and here's a link to it.. There is also a little bit more documentation over there.

Ps: I'll try to upload more to github from now on.

Till next time.