SA-MP Forums

SA-MP Forums (https://forum.sa-mp.com/index.php)
-   Plugin Development (https://forum.sa-mp.com/forumdisplay.php?f=18)
-   -   [Plugin] Timer Fix (https://forum.sa-mp.com/showthread.php?t=650736)

KashCherry 05/03/2018 04:13 PM

Timer Fix
 
Timer Fix v1.02


Description
This plugin makes timers more accurate


Natives
PHP Code:

native SetTimer(funcname[], intervalbool:repeat);
native SetTimerEx(funcname[], intervalbool:repeat, const format[], {Float,_}:...);
native KillTimer(const id);
native KillAllTimers();
native IsValidTimer(timerid);
native GetTimerInterval(timerid);
native SetTimerInterval(timeridinterval); 


Example
PHP Code:

#include <timerfix>

new num 0;
new 
timer;

main() {
  
timer SetTimer("callback",1000,true)
}

forward callback();
public 
callback() {
  if(++
num >= 5) {
    if(
IsValidTimer(timer)) KillTimer(timer);
    
SetTimerEx("callbackEx",1000,false,"d",num);
  }
}

forward callbackEx(num);
public 
callbackEx(num) {
  
printf("Num: %d",num);
  
KillAllTimers();



Download
Binaries(Windows, Linux)
Source code

Sting. 05/03/2018 05:22 PM

Re: Timer Fix - Do not miss a one second
 
Looks nice. Have you tested it out? Is it very accurate?

KashCherry 05/03/2018 05:31 PM

Re: Timer Fix - Do not miss a one second
 
Quote:

Originally Posted by Sting. (Post 4000152)
Looks nice. Have you tested it out? Is it very accurate?

+- 5ms.

iKarim 05/03/2018 06:28 PM

Re: Timer Fix - Do not miss a one second
 
I'd suggest hooking the SetTimer functions and call the plugin's instead in the include, and provide an option to disable that as it's either to use as a plug-play instead of replacing function names, ...

Other than that, good job!

KashCherry 05/03/2018 07:17 PM

Re: Timer Fix - Do not miss a one second
 
Plugin updated to version 0.6

- Added hook Timer's natives

Y_Less 06/03/2018 01:09 PM

Re: Timer Fix - Do not miss a one second
 
What's the advantage of this version over udan's, YSF's, Slice's, or any other?

I had a quick look at the code:

1) Strings are not done properly. You need to copy them to storage entirely, you can't just store the address, which may be inaccurate or have expired.

2) Arrays aren't handled at all.

3) There's no error checking on any of the `amx_` functions - what if `amx_Push` fails?

4) Public functions can actually change their index with some includes. Caching that may call the wrong function in some cases.

5) Why `end_time - 5`? That seems to be introducing artificial inaccuracies.

6) You can't call `_timer_map.erase(iter);` inside a loop using that iterator. That call invalidates the iterator, thus meaning that trying to move on to the next item is undefined behaviour. The common solution is:

PHP Code:

for (auto it _timer_map.begin(); it != _timer_map.end(); )
{
    if (
done)
        
_timer_map.erase(it++);
    else
        
it++;



KashCherry 06/03/2018 07:07 PM

Re: Timer Fix - Do not miss a one second
 
Quote:

Originally Posted by Y_Less
What's the advantage of this version over udan's, YSF's, Slice's, or any other?

As I saw Slice deleted his fix?

Comparisons with this plugin & udan's plugin (5 seconds, Windows x64):
PHP Code:

// this plugin (v0.7)
5000ms
5000ms
5000ms
5000ms
5000ms

// udan's plugin (v1.5)
5004ms
4997ms
5000ms
5004ms
5000ms 

About YSF: I don't know how to test this, can you please do it?

1.) Fixed
2.) Fixed
3.) Fixed
4.) Fixed
5.) Fixed
6.) Fixed

Plugin updated to version 0.7

- Fixed some bugs
- Improved accuracy

Dim4Shift 16/03/2018 02:39 PM

Re: Timer Fix - Do not miss a one second
 
Quote:

Originally Posted by KashCherry (Post 4000122)
Timer Fix v0.7


Description
This plugin makes timers more accurate


Natives
PHP Code:

native SetTimer(funcname[], intervalbool:repeat);
native SetTimerEx(funcname[], intervalbool:repeat, const format[], {Float,_}:...);
native KillTimer(const id);
native KillAllTimers(); 


Example
PHP Code:

#include <timerfix>

new num 0;
new 
timer;

main() {
  
timer SetTimer("callback",1000,true)
}

forward callback();
public 
callback() {
  if(++
num >= 5) {
    
KillTimer(timer);
    
SetTimerEx("callbackEx",1000,false,"d",num);
  }
}

forward callbackEx(num);
public 
callbackEx(num) {
  
printf("Num: %d",num);
  
KillAllTimers();



Download
Binaries(Windows, Linux)
Source code

the idea is good ... but when I put this plugin the server blocks the players from connecting.

Code:

[10:57:29]  Loading plugin: timerfix.so
[10:57:29]  Timer Fix plugin v0.7 by KashCherry loaded
[10:57:29]  Loaded.
[10:57:29]  Loaded 9 plugins.

[10:57:29]
[10:57:29] Filterscripts
[10:57:29] ---------------
[10:57:29]  Loaded 0 filterscripts.

[10:57:30] MySQL baza, a fost conectata!
[10:57:30]
-----------
Vehicle: 156
MaterialObjects: 112
Objects: 750
DynamicObjects: 2424
Pickps: 20
-----------
[10:57:30] Number of vehicle models: 46
[10:58:24] Kicking 92.119.39.147 because they didn't logon to the game.
[10:58:24] Kicking 200.53.203.103 because they didn't logon to the game.
[10:58:30] [connection] incoming connection: 200.53.203.103:29209 id: 0
[10:58:30] Invalid client connecting from 200.53.203.103
[10:58:30] [connection] incoming connection: 92.119.39.147:54599 id: 1
[10:58:30] [connection] incoming connection: 200.53.203.103:29217 id: 2
[10:58:30] Invalid client connecting from 92.119.39.147
[10:58:30] Invalid client connecting from 200.53.203.103


KashCherry 16/03/2018 04:06 PM

Re: Timer Fix - Do not miss a one second
 
Quote:

Originally Posted by Dim4Shift (Post 4003537)
the idea is good ... but when I put this plugin the server blocks the players from connecting.

Code:

[10:57:29]  Loading plugin: timerfix.so
[10:57:29]  Timer Fix plugin v0.7 by KashCherry loaded
[10:57:29]  Loaded.
[10:57:29]  Loaded 9 plugins.

[10:57:29]
[10:57:29] Filterscripts
[10:57:29] ---------------
[10:57:29]  Loaded 0 filterscripts.

[10:57:30] MySQL baza, a fost conectata!
[10:57:30]
-----------
Vehicle: 156
MaterialObjects: 112
Objects: 750
DynamicObjects: 2424
Pickps: 20
-----------
[10:57:30] Number of vehicle models: 46
[10:58:24] Kicking 92.119.39.147 because they didn't logon to the game.
[10:58:24] Kicking 200.53.203.103 because they didn't logon to the game.
[10:58:30] [connection] incoming connection: 200.53.203.103:29209 id: 0
[10:58:30] Invalid client connecting from 200.53.203.103
[10:58:30] [connection] incoming connection: 92.119.39.147:54599 id: 1
[10:58:30] [connection] incoming connection: 200.53.203.103:29217 id: 2
[10:58:30] Invalid client connecting from 92.119.39.147
[10:58:30] Invalid client connecting from 200.53.203.103


Fixed, download from here.

Dim4Shift 16/03/2018 04:22 PM

Re: Timer Fix - Do not miss a one second
 
Quote:

Originally Posted by KashCherry (Post 4003560)
Fixed, download from here.

WOW nice ++! is posible add native IsValidTimer(timerid); ? to bypass this error:

Code:

[12:15:08] [Timer Fix] KillTimer: cannot find timer with id 0
exemple pawn code:
Code:

#define INVALID_TIMER_ID    (0xFFFF)

stock IsValidTimer(timerid) {
        if(timerid != INVALID_TIMER_ID) return true;
        return false;
}



All times are GMT. The time now is 04:31 PM.

Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.