10-19-2011, 03:49 PM
As seen on SA-MP forums..
I've recently been struggling with timers, and the fact that they aren't accurate by a damn sight. Here's an include that will make your timers accurate by ~5ms.
For example, it will turn this output from one 250ms timer and one 1500ms timer:
As you can see, the timer is roughly 25% off!
into this:
Usage
You just have to add one single line of code after you included a_samp:
Limitations
You can, by default, have only 128 timers running at the same time. If you feel the need to increase this, define TIMER_FIX_TIMER_SLOTS before you include the script.
Something to keep in mind is this include causes PAWN to work harder; therefore, you shouldn't have loads of timers running at the same time as it will require higher CPU usage.
Compatibility
Here: timerfix.inc
I've recently been struggling with timers, and the fact that they aren't accurate by a damn sight. Here's an include that will make your timers accurate by ~5ms.
For example, it will turn this output from one 250ms timer and one 1500ms timer:
Code:
[17:54:33] Time since last call: 293ms (43 ms off)
[17:54:34] Time since last call: 292ms (42ms off)
[17:54:34] Time since last call: 292ms (42ms off)
[17:54:34] Time since last call: 292ms (42ms off)
[17:54:35] Time since last call: 292ms (42ms off)
[17:54:35] Time since last call: 1786ms (286ms off)
[17:54:37] Time since last call: 1756ms (256ms off)
[17:54:38] Time since last call: 1756ms (256ms off)
[17:54:40] Time since last call: 1756ms (256ms off)
[17:54:42] Time since last call: 1756ms (256ms off)
into this:
Code:
[17:55:11] Time since last call: 251ms (1ms off)
[17:55:11] Time since last call: 252ms (2ms off)
[17:55:12] Time since last call: 252ms (2ms off)
[17:55:12] Time since last call: 251ms (1ms off)
[17:55:12] Time since last call: 251ms (1ms off)
[17:55:12] Time since last call: 1498ms (2ms off)
[17:55:14] Time since last call: 1499ms (1ms off)
[17:55:15] Time since last call: 1499ms (1ms off)
[17:55:17] Time since last call: 1500ms (0ms off)
[17:55:18] Time since last call: 1499ms (1ms off)
Usage
You just have to add one single line of code after you included a_samp:
Code:
#include <timerfix>
Limitations
You can, by default, have only 128 timers running at the same time. If you feel the need to increase this, define TIMER_FIX_TIMER_SLOTS before you include the script.
Something to keep in mind is this include causes PAWN to work harder; therefore, you shouldn't have loads of timers running at the same time as it will require higher CPU usage.
Compatibility
- Even though the KillTimer function is hooked, it works just fine for timers that weren't created by the hooked SetTimer function.
- Currently, it works for SetTimerEx without strings and arrays. If you need to use strings and arrays in your timers, put this before you include timerfix:
Code:
#define TIMER_FIX_DISABLE_EX true
- It works well with YSI only if you disable hooking SetTimer Ex (as described right above this). In fact, it increases the accuracy of tasks significantly.
Here: timerfix.inc