fixes2 - Updated 13/01/13 -
zeax - 16.04.2015
fixes2 - Updated 13/01/13
So I decided to write some more function fixes in a plugin as it's simpler. The first on my list were "SetTimer" and "SetTimerEx". Namely the fact that they are not very accurate and that they don't correctly support strings and arrays. Both these problems are now fixed to the best of my ability. I should note that the accuracy is still a little off because of the "sleep" call in the server internally, but they're MUCH better now.
I've also improved their performance through the use of "std:
riority_queue" so the next timers to trigger are always at the top of the list.
A note when passing arrays, as with "CallLocalFunction" you MUST follow the array with its length as an extra parameter or the system has no way to know how big it is:
Код:
SetTimerEx("func", 1000, 0, "ai", arr, sizeof (arr));
These functions are not changed in ANY way, "0" still means "run once", anything else still means "run forever". You don't even need to recompile to use the new versions, just use the plugin.
I've also added two new functions:
Код:
SetTimer_("func", 100, 1000, -1);
SetTimerEx_("func", 100, 1000, -1, "i", 42);
These versions of the function have more control over exactly what you can do. There are now two time parameters - initial delay and interval. So the functions above will be called after 100ms and then every 1000ms after that. This is useful if you have a few global timers so they don't all run at the same time:
Код:
SetTimer_("global1", 250, 1000, -1);
SetTimer_("global2", 500, 1000, -1);
SetTimer_("global3", 750, 1000, -1);
SetTimer_("global4", 1000, 1000, -1);
Those timers will all run once every 1 second, but will all be offset from each other by 250ms. This feature was already provided by y_timers, but is now more native. Additionally, the "repeat" parameter ("-1" above) is now a COUNT. So if you do:
Код:
SetTimer_("global1", 250, 1000, 4);
Then that function will run EXACTLY FOUR times and no more. You can set this parameter to "0", but unlike the normal versions, this means "never run" and is thus pointless! "-1" means "run forever". The natives for these functions are:
Код:
native SetTimer_(const func[], const delay, const interval, const count);
native SetTimerEx_(const func[], const delay, const interval, const count, const format[], {Float, _}:...);
native KillTimer_(timer) = KillTimer;
This plugin is slightly magical: if you use it you don't need to recompile your mode at all. Just add this to your "plugins" line and it will improve all existing timers in all existing modes. Obviously if you want to use the "_" versions of the functions you'll need to change things.
Download source, .dll and .so:
http://dl.dropbox.com/u/21683085/fixes2.rar
(repost of ******'s old thread)