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.
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) [Retired]
Alpine RP (Owner/Founder)
Aluminium Network (Maintainer) [Disbanded]
AlphaDM (Tech Support) [Disbanded]
# Services
forum.open.mp (Forum Manager) (Formerly Burgershot.gg)
open.mp (Member)
~ Languages/Frameworks
Pawn, C, C, C#, Javascript, Typescript, Lua, Python, Go, Rust, PHP, SQL,
Angular, React, Vue, Svelte, Laravel, Rocket
Very good!
I'm looking forward to what's coming soon
Finally, decent functions with timers!
Pretty good features and improvements with the timers.
Location: Istanbul, Turkey
Continue in the same spirit
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?
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.
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) [Retired]
Alpine RP (Owner/Founder)
Aluminium Network (Maintainer) [Disbanded]
AlphaDM (Tech Support) [Disbanded]
# Services
forum.open.mp (Forum Manager) (Formerly Burgershot.gg)
open.mp (Member)
~ Languages/Frameworks
Pawn, C, C, C#, Javascript, Typescript, Lua, Python, Go, Rust, PHP, SQL,
Angular, React, Vue, Svelte, Laravel, Rocket
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.
The naming of the functions is more a convention we are going to use rather than personal taste. (I personally don't like it)
(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...
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.
It's a bug in the native, not a pawn limitation.
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
I'm not sure what that last line is.
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.
Callbacks start with "On".
*that's how i prefer to name my callbacks*
I started to name them like this because "OnPlayerLogin" was taken by y_users.
Incredible, very good job.
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.
Location: La Plata, Argentina
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.
So should I stop using y_timers?
Very nice improvements to the code. Thanks!
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?
|