I am currently implementing a facility in my game where the speed of everything can be speeded up or slowed down (eg. by rotating the mousewheel).
In order to implement this, I have to change the rate at which my timer-function is called. Does anyone know if it is a good idea to do the following in my code...
remove_int(my_int_callback); /* Stop the tick-timer */
install_int_ex(my_int_callback, BPS_TO_TIMER(new_ticks_per_second)); /* Start the tick-timer at the new speed */
Is the call to remove_int needed? This would mean the code to change the tick-speed would just be
install_int_ex(my_int_callback, BPS_TO_TIMER(new_ticks_per_second)); /* Tell the tick-timer to tick at the new speed */
While reading the changelog from Allegro 1.2 to Allegro 2.0, I noticed this snippet:
The timer routines now have better than millisecond accuracy, and it is possible to alter the speed of a user timer callback in realtime (by reinstalling it with a different speed value).
Is this still true now that Allegro has not only transitioned from 2.0 to 4.2, but also gone from being a DOS-only library to a multi-platform library? If it is still true, that would mean I would not need to call remove_int. I've heard that the Windows version of Allegro uses a separate thread for timers, so changing the timer-value might be problematic - especially if I have a second timer running (although I only need one timer unless I want to measuer the FPS as well).
Also, if I alter the speed of a timer-callback in realtime (be it by re-installing it, or un-installing it and then installing it), would the timer go at the new speed immediately, or would it wait until the next tick, and then adjust itself? Also, does it set off the new tick immediately, or wait until the first tick-interval is complete and then do a tick?
When changing, I would like the gap between ticks to be no slower than the slower of the two tick-speeds. This is because if it was, then the player could cheat and slow down the game by constantly changing it's speed. Ideally, the gap between the two ticks should be as long as the length of time as either one of them (or somewhere in between), although it would be OK for the gap to be any length shorter than than the slowest tick-speed, but if the gap becomes too small, then the game will speed up if constantly changing speed.
Just in case calling install_int_ex() creates a tick that is longer than either of the two tick-speeds, is it reccommended that instead of calling install_int_ex() in the logic-loop, the logic-loop sets a flag, and the if the flag is set, the interrupt-callback calls install_int_ex(), or is calling install_int_ex() inside it's own callback just asking for trouble?
Also, I've heard that the accuracy of the Allegro timers is not very accurate past 100 ticks per second. Is that just an upper-bound limit, or does that mean that once the timer goes above 100, the ticks start to become irregular but over the long-term, the average tick-speed is more or less correct. Does this also mean that 100 ticks per second is the last 'island of stability' in the linear 'ticks-space', or are tick-speeds of 99, 98, 97, 96 etc. accurate as well? Also, is it better to change the tick-speed to a discrete number of ticks-per-second, or is it better to set it to something like (K/n)*m where n and m are integers and K is a standard ticks-per-second rate such as 60 or 100. Another way of saying this is is it more accurate to specify the time in ticks-per-second, or is it better to specify it as an interval between two ticks in milliseconds?
And finally, if I wanted to create a timer that ticked in time to the monitor's refresh (obiously, this will be a fixed speed timer), is it enough to call install_int_ex() immediately after a vsync()?
PS. My game does everything in discrete steps, so please don't tell me to use a delta-time based logic-updating mechanism instead.