openplanet-nl / issues

Issue tracker for Openplanet.
10 stars 0 forks source link

add argument to `yield()` #452

Closed ezio416 closed 4 months ago

ezio416 commented 5 months ago

small convenience thing, would just like to be able to yield for multiple frames by passing in a uint like yield(10) similar to how sleep works

of course it would need to be defined like yield(uint frames = 1) {} to keep compatibility

XertroV commented 5 months ago

Why not just copy paste this?

void yield_n(int n) {
  while ((n = n - 1) >= 0) yield();
}
ezio416 commented 5 months ago

That's essentially what I've been doing, it's why I say it's just a small convenience thing so I don't need a snippet and it would feel more consistent with sleep

codecat commented 5 months ago

Interesting, for some reason I thought I already had this implemented, but I guess not 🤔 I wonder if there's a reason for that..

codecat commented 4 months ago

I have added yieldframes: (if you have a better name for this please let me know, I kinda hate this function name)

void yieldframes(uint frames)

Additionally, passing 0 here will produce a no-op.

I am also considering changing the behavior of sleep() to produce a no-op when 0 is passed. The verdict on whether that's a good idea or not is still out. Feedback welcome. I am also opening a Discord thread to discuss this.

ezio416 commented 4 months ago

Thanks, yeah I agree the name is not the best - I think keeping it yield with a default value of 1 would be fine, that way we just have one function for it and it shouldn't break any existing code. It makes sense to me to have yield(0) and sleep(0) be no-ops, but I see there's a lot of discussion about that in the discord already

codecat commented 4 months ago

I'm a little nervous about making it the same function name as it could create some confusion, but maybe we could make it an overload instead of a default parameter to reduce potential confusion.