-
Notifications
You must be signed in to change notification settings - Fork 331
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lambda timers #3142
Lambda timers #3142
Conversation
What about nutimer? |
You able to review this one @Vurv78 ? |
|
Yep, never forked it as I've never found it :D |
From what I know, unless you found another workaround, the E2 lambda needs to be called surrounded in an E2 context, which Vurv accomplished by extending My suggestion would be to copy #2843, which I was intending to do before I took a brief vacation.. |
Unfortunately I think the local changes I had I never ended up pushing into the PR, which are now lost since I switched off windows. I don't really care how you implement it, but I'd prefer if the API was the same as my PR, which just adds |
I believe the problems that may occur from calling a lambda outside of its context were solved by the ExtCall | UnsafeExtCall methods for the lambdas, which this PR is using. You pass ExtCall / UnsafeExtCall the context and it'll pcall the lambda and it'll error the context / chip if an error occurs. |
Oh, you're correct. I didn't notice such a change was made. |
While I would love to make timer overloads, I believe there will be misunderstandments from user for such functions as timerRepsLeft(s), timerTimeLeft, etc as work for both lambda and regular timers. + I wanted to use seconds, instead of miliseconds |
There's nothing stopping you from using seconds for the new overloads and deprecating the old functions. Well, I'm not, anyway. |
Yes, as denniesk said, you'd be deprecating all of the old timer functions and pushing them onto the new ones regardless. So there shouldn't be any confusion, unless someone is mixing the two, which absolutely shouldn't be done. And yeah the new api would use seconds as to not have another pointless conversion wasting perf in E2. |
Redid the naming, made most og timer functions depracted except for getTimers, stopAllTimers and stoptimer. Three of them now works for both timers. E2 I've used to test it
|
Seems to be ready for review |
Need to stress test it with tons of timers. That was what I was blocked on with my PR, iirc, with how I implemented it. I was also trying to make the original timers less laggy & limiting them. Could be misremembering. Would be nice if the integration tests could run timers, too, maybe not too hard to extend but not entirely necessary here. |
Came around to a problem.
Will result in same ops count as same code with old timers, but 0 cpu time. Don't seem to find a reason |
Hmm. I never looked into the ExtCall function that was added and figured it did more than what it actually does which is just pcalling and erroring the chip entity if it fails.. :\ It needs to run everything the chip does when executing, ie have everything in :Execute() run. I actually did have some progress in the PR for this, I made Idr if that was all that's needed for proper perf handling though. |
Thank you @Vurv78. Thanks to you, now it works. Seems to be ready for testing/review.
|
You could probably convert the two extcall functions to do the chip:Execute instead now since this implementation seems better. Could also be done as a separate PR if it feels out of scope. |
Yeah, separate PR should be made, but nice idea. |
If you were feeling really motivated you could write this api in pure E2. I did that some time ago albeit with string calls (probably posted in the discord somewhere). Just have a library you include at the top that uses the traditional timer() underneath, calling the lambdas, and then |
Yeah, I thought about that. Didn't think of the exit() part tho, so I've scrapped it. Oh well lol |
Will wait for Vurv to review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not a real review cause I can't test the actual code, but api is fine to me
-- Lambda timers | ||
|
||
local luaTimers = { | ||
/*EXAMPLE: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no c comments
also this is good but i'd prefer emmylua annotations
Subjects to discuss/change:
Having a delay(nf) function -> A lot of players intuitively think that it exist. Well now it does, even if they don't know about timers.Currently timers don't have stop/start functions, as I think that will not be used by end user. Am I wrong? (Their naming is confusing, so I've made timerRestart for their single useful IMHO usage)