Burgershot
  • Home
  • Members
  • Team
  • Help
  • Search
  • Register
  • Login
  • Home
  • Members
  • Help
  • Search
Burgershot open.mp Development Updates Timers module

 
  • 3 Vote(s) - 5 Average
Timers module
Y_Less
Offline

Administrator

Posts: 323
Threads: 16
Joined: Feb 2019
Reputation: 90
#1
2019-05-22, 03:15 PM (This post was last modified: 2019-05-22, 03:20 PM by Y_Less.)
This is a sneak-peek at one of the improved modules we've done, for timers in open.mp:

PHP Code:
native SetTimer(const func[], msInterval, bool:repeat) = SetTimerEx;
native SetTimerEx(const func[], msInterval, bool:repeat, const params[], GLOBAL_TAG_TYPES:...);
native KillTimer(timer) = Timer_Kill;

// CreateTimer
native Timer:Timer_Create(const func[], usDelay, usInterval, repeatCount, const params[] = "", GLOBAL_TAG_TYPES:...);

// KillTimer
native bool:Timer_Kill(Timer:timer);

// Return time till next call.
native Timer_GetTimeRemaining(Timer:timer);

// Get number of calls left to make (0 for unlimited).
native Timer_GetCallsRemaining(Timer:timer);

// Get `repeatCount` parameter.
native Timer_GetTotalCalls(Timer:timer);

//  Get `usInterval` parameter.
native Timer_GetInterval(Timer:timer);

// Reset time remaining till next call to `usInterval`.
native bool:Timer_Restart(Timer:timer); 

The first two are just for backwards-compatibility, the rest are the improved API:

PHP Code:
native Timer:Timer_Create(const func[], usDelay, usInterval, repeatCount, const params[] = "", GLOBAL_TAG_TYPES:...); 
  • `func` - Fairly obvious; what to call.
  • `usDelay` - Again obvious, the delay before the call (in microseconds).
  • `usInterval` - What to reset `usDelay` to after the first call.  So if you wanted a timer on the hour every hour, but it was 8:47am right now, the call would be `Timer_Create("OnTheHour", 780 SECONDS, 3600 SECONDS, 0);`
  • `repeatCount` - Unlike the old functions, which are just "once" or "forever", this instead takes the number of times to call the function.  "once" would be `1`, `500` would stop after 500 calls, and (backwards from the old API) `0` means "forever".
  • `GLOBAL_TAG_TYPES` - Like `{Float, ...}`, but with more tags.
JustMichael
Offline

Forum Manager

Posts: 189
Threads: 3
Joined: Feb 2019
Reputation: 17
Location: England
#2
2019-05-22, 03:18 PM
It's so pretty uwu

I definitely prefer this over how timers are handled in SA-MP. Even the little things can make a big difference.
Remember to always refer to J0sh as `J0sh...`

@ Networks/Servers
San Andreas Gaming Network (Owner/Founder)
San Andreas Gaming (Owner/Founder)
Grand Theft Cop's n Robber's (Owner)
Britannia Roleplay (Owner/Founder)
Alpine RP (Owner/Founder)
Aluminium Network (Maintainer)
AlphaDM (Tech Support)

# Services
Burgershot.gg (Forum Manager)
open.mp (Member)

~ Languages/Frameworks
Pawn, C, C++, C#, Javascript, Typescript, Lua, Python, Go, Rust, PHP, SQL,
Angular, React, Vue, Svelte, Laravel, Rocket
Freeze
Offline

Burgershot Member
Posts: 21
Threads: 1
Joined: May 2019
Reputation: 2
Location: Brazil
#3
2019-05-22, 03:48 PM
Very good!
I'm looking forward to what's coming soon
Afisiado
Offline

Burgershot Member
Posts: 15
Threads: 0
Joined: Apr 2019
Reputation: 0
#4
2019-05-22, 05:23 PM
Finally, decent functions with timers!
CRHStudios
Offline

Burgershot Member
Posts: 3
Threads: 0
Joined: Apr 2019
Reputation: 0
#5
2019-05-22, 11:28 PM
Pretty good features and improvements with the timers.
2PAC_
Offline

Burgershot Member
Posts: 6
Threads: 3
Joined: May 2019
Reputation: 0
Location: Istanbul, Turkey
#6
2019-05-23, 10:13 AM
Very nice, good job!
Max_Andolini
Offline

Burgershot Member
Posts: 3
Threads: 0
Joined: May 2019
Reputation: 0
Location: Turkey
#7
2019-05-23, 02:06 PM
This is great!!!
Verc
Offline

Burgershot Member
Posts: 11
Threads: 1
Joined: Apr 2019
Reputation: 0
#8
2019-05-23, 03:11 PM
What a great news!
Koplan
Offline

Burgershot Member
Posts: 3
Threads: 0
Joined: May 2019
Reputation: 0
Location: Portugal
#9
2019-05-23, 05:49 PM
Good Job!
Hawkins
Offline

Burgershot Member
Posts: 2
Threads: 0
Joined: May 2019
Reputation: 0
Location: Russia
#10
2019-05-23, 06:47 PM
Continue in the same spirit
Manyula
Offline

Burgershot Member
Posts: 52
Threads: 5
Joined: Apr 2019
Reputation: 5
Location: Germany
#11
2019-05-23, 06:56 PM (This post was last modified: 2019-05-23, 06:59 PM by Manyula.)
Absolutely love the new API, great job! Not really a fan of the prefixing of the functions, though. Is that scheme gonna be applied to all of the new API?
BigETI
Offline

open.mp Developer

Posts: 107
Threads: 5
Joined: Feb 2019
Reputation: 12
Location: Germany
#12
2019-05-23, 06:59 PM (This post was last modified: 2019-05-23, 07:00 PM by BigETI.)
Think it having two names: The prefix is the library or module the function is from and the suffix is the actual function name. The underscore just seperates both names.
[Image: github-samp-icon.png]
JustMichael
Offline

Forum Manager

Posts: 189
Threads: 3
Joined: Feb 2019
Reputation: 17
Location: England
#13
2019-05-23, 07:01 PM (This post was last modified: 2019-05-24, 10:08 AM by JustMichael.)
(2019-05-23, 06:59 PM)BigETI Wrote: Think it having two names: The prefix is the library or module the function is from and the suffix is the actual function name. The underscore just seperates both names.

Well said, sir. Have a box of cookies :)

I do prefer this to how SA-MP does it, and I wouldn't want to have mixed casing.
Remember to always refer to J0sh as `J0sh...`

@ Networks/Servers
San Andreas Gaming Network (Owner/Founder)
San Andreas Gaming (Owner/Founder)
Grand Theft Cop's n Robber's (Owner)
Britannia Roleplay (Owner/Founder)
Alpine RP (Owner/Founder)
Aluminium Network (Maintainer)
AlphaDM (Tech Support)

# Services
Burgershot.gg (Forum Manager)
open.mp (Member)

~ Languages/Frameworks
Pawn, C, C++, C#, Javascript, Typescript, Lua, Python, Go, Rust, PHP, SQL,
Angular, React, Vue, Svelte, Laravel, Rocket
Manyula
Offline

Burgershot Member
Posts: 52
Threads: 5
Joined: Apr 2019
Reputation: 5
Location: Germany
#14
2019-05-23, 07:11 PM
I understand that the prefix is there to be able to quickly identify the module it belongs to, but imho I don't think that's necessary. But then again, I think this comes down to personal taste.

One more thing: I think some of the timer functions lack a certain consistency in terms of naming.

Code:
native Timer_Get[b]Time[/b][i]Remaining[/i](Timer:timer);
native Timer_Get[b]Calls[/b][i]Remaining[/i](Timer:timer);

should be...

Code:
native Timer_Get[i]Remaining[/i][b]Time[/b](Timer:timer);
native Timer_Get[i]Remaining[/i][b]Calls[/b](Timer:timer);

to be in line with...

Code:
native Timer_GetTotalCalls(Timer:timer);

as the latter sounds more natural.
BigETI
Offline

open.mp Developer

Posts: 107
Threads: 5
Joined: Feb 2019
Reputation: 12
Location: Germany
#15
2019-05-23, 07:31 PM
The naming of the functions is more a convention we are going to use rather than personal taste. (I personally don't like it)
[Image: github-samp-icon.png]
NexoR
Offline

Burgershot Member
Posts: 15
Threads: 4
Joined: Apr 2019
Reputation: 0
Location: Turkey
#16
2019-05-23, 09:09 PM
Good job.
Y_Less
Offline

Administrator

Posts: 323
Threads: 16
Joined: Feb 2019
Reputation: 90
#17
2019-05-24, 01:23 AM
(2019-05-23, 07:11 PM)Manyula Wrote: I understand that the prefix is there to be able to quickly identify the module it belongs to, but imho I don't think that's necessary. But then again, I think this comes down to personal taste.

One more thing: I think some of the timer functions lack a certain consistency in terms of naming.

Code:
native Timer_Get[b]Time[/b][i]Remaining[/i](Timer:timer);
native Timer_Get[b]Calls[/b][i]Remaining[/i](Timer:timer);

should be...

Code:
native Timer_Get[i]Remaining[/i][b]Time[/b](Timer:timer);
native Timer_Get[i]Remaining[/i][b]Calls[/b](Timer:timer);

to be in line with...

Code:
native Timer_GetTotalCalls(Timer:timer);

as the latter sounds more natural.

You're right about the mixed verb/noun order, I'll fix that.

As for module prefixes, that's now quite well established. It gives a nice consistent naming scheme, and there's a longer-term goal you'll have to wait for to see...
Gravityfalls
Offline

Burgershot Member
Posts: 105
Threads: 7
Joined: Apr 2019
Reputation: 2
#18
2019-05-24, 10:48 AM
Amazing.
Riddick
Offline

Moderator

Posts: 31
Threads: 6
Joined: Apr 2019
Reputation: 5
Location: Poland
#19
2019-05-29, 05:44 AM
This seems to be all right. Is it PAWN limitation or bad SA-MP's SetTimer(Ex) functions coding that we are not allowed to pass strings in it? (or we are but it didn't work correctly - I can't remember now).

---
I still wish here for "IsValidTimer" function. I know that IDs could be assigned to a new timer where the other timer has finished its job and it doesn't guarantee that the timer in a give slot is still the same, but some internal IDs should be assigned once maybe? I guess maybe use versioned timer IDs?

Unless you are not going for it.
[Image: widget.png?style=banner2]
Y_Less
Offline

Administrator

Posts: 323
Threads: 16
Joined: Feb 2019
Reputation: 90
#20
2019-05-29, 12:01 PM
It's a bug in the native, not a pawn limitation.
Expert*
Offline

Burgershot Member
Posts: 61
Threads: 2
Joined: Apr 2019
Reputation: 4
#21
2019-05-30, 08:18 PM (This post was last modified: 2019-05-30, 08:22 PM by Expert*.)
I use module prefixes for fixed/protected/new functions so i love it. What i don't love is extra work to ensure compatibility.

global func: Player_SetSkin
static func: player_setskin
call: PLAYER_RequestSpawn
Y_Less
Offline

Administrator

Posts: 323
Threads: 16
Joined: Feb 2019
Reputation: 90
#22
2019-05-30, 09:20 PM
I'm not sure what that last line is.
Expert*
Offline

Burgershot Member
Posts: 61
Threads: 2
Joined: Apr 2019
Reputation: 4
#23
2019-05-31, 06:41 AM (This post was last modified: 2019-05-31, 06:57 AM by Expert*.)
Callback, starts with uppercase letters ( PLAYER_, VEHICLE_ ) ex: PLAYER_EnterVehicle.
Y_Less
Offline

Administrator

Posts: 323
Threads: 16
Joined: Feb 2019
Reputation: 90
#24
2019-05-31, 02:24 PM
Callbacks start with "On".
Expert*
Offline

Burgershot Member
Posts: 61
Threads: 2
Joined: Apr 2019
Reputation: 4
#25
2019-06-03, 08:35 PM
*that's how i prefer to name my callbacks*
I started to name them like this because "OnPlayerLogin" was taken by y_users.
Roth
Offline

Burgershot Member
Posts: 16
Threads: 2
Joined: May 2019
Reputation: 7
#26
2019-06-06, 02:47 AM
Incredible, very good job.
BoNNe
Offline

Burgershot Member
Posts: 14
Threads: 2
Joined: May 2019
Reputation: 1
Location: Bucharest
#27
2019-06-07, 06:17 PM
great job
TroyST
Offline

Burgershot Member
Posts: 1
Threads: 0
Joined: May 2019
Reputation: 0
Location: Albania
#28
2019-06-09, 02:13 PM
Well done wise man!
Sasino97
Offline

Software Developer
Posts: 108
Threads: 16
Joined: Apr 2019
Reputation: 7
Location: Tampa, FL
#29
2019-06-11, 06:40 AM
I hope this one to work when passing strings as parameters, lol.

(2019-05-23, 06:59 PM)BigETI Wrote: Think it having two names: The prefix is the library or module the function is from and the suffix is the actual function name. The underscore just seperates both names.

That is how it should be :D
Then I will
Code:
#define Timer. Timer_

Timer.Create(...);
and pretend to be using some high level OO programming language, like I always do.
Markski
Offline

Burgershot Clerk

Posts: 127
Threads: 6
Joined: Apr 2019
Reputation: 5
Location: La Plata, Argentina
#30
2019-06-11, 11:06 PM
This is really good. Just some days ago I was considering making an include (based on samp-precise-timers) for functions to have a limited loop lifetime without needing to have such logic to kill the timer on each public. Glad to see this is being done for the OG native.
Website
[SF]kAn3
Offline

Burgershot Member
Posts: 26
Threads: 7
Joined: Apr 2019
Reputation: 2
Location: Italia
#31
2019-10-02, 12:05 PM
So should I stop using y_timers?
2KY
Offline

Burgershot Member
Posts: 1
Threads: 0
Joined: Apr 2020
Reputation: 0
Location: United States
#32
2020-04-24, 11:07 PM
Very nice improvements to the code. Thanks!
EvilShadeZ
Offline

Burgershot Member
Posts: 21
Threads: 5
Joined: Apr 2019
Reputation: 2
#33
2020-04-25, 11:35 AM
I think this module is missing Timer_SetCallsRemaining(Timer:timer,calls);
This would be very useful for adjusting how many calls are left. Useful for shortening / extending repeating timers.

Absolutely loving timers in microseconds. How accurate are they compared to SA-MP timers?
[Image: qPwh60X.png]
« Next Oldest | Next Newest »



  • View a Printable Version
  • Subscribe to this thread
Forum Jump:

© Burgershot - Powered by our Community and MyBB Original Theme by Emerald

Linear Mode
Threaded Mode