Skip to content
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

Stop shadowing haxe.Timer #1874

Open
joshtynjala opened this issue Dec 10, 2024 · 1 comment
Open

Stop shadowing haxe.Timer #1874

joshtynjala opened this issue Dec 10, 2024 · 1 comment

Comments

@joshtynjala
Copy link
Member

Similar to #1765, where we stop shadowing the haxe.io.Bytes class, we should also stop shadowing haxe.Timer. Future changes to Haxe's official implementation of haxe.Timer could cause our custom implementation to completely break or to diverge in functionality. We can probably tweak our implementation to handle those changes, if they happen, but if we weren't shadowing things in the Haxe standard library in the first place, that wouldn't even be a concern.

I don't have a specific suggestion for how to do it right now, but I wanted to have a single issue to reference and consolidate discussion and notes.


There was some discussion about our shadowed haxe.Timer on the Haxe Discord in February 2024. Zeta (Apprentice-Alchemist) mentioned the following, and I wanted to save it somewhere because searching Discord for old discussions is terrible.

Well the proper way to make Timer work would be to integrate the haxe event loop into the Lime event loop, see for example how Heaps does it: https://github.com/HeapsIO/heaps/blob/72291843057abb58af5e7490377d60f6c6c001f0/hxd/System.hl.hx#L146-L157

#if ( target.threaded && (haxe_ver >= 4.2) )
// Due to how 4.2+ timers work, instead of MainLoop, thread events have to be updated.
// Unsafe events rely on internal implementation of EventLoop, but utilize the recycling feature
// which in turn provides better optimization.
#if heaps_unsafe_events
@:privateAccess mainThread.events.__progress(Sys.time(), eventRecycle);
#else
mainThread.events.progress();
#end
#else
@:privateAccess haxe.MainLoop.tick();
#end
@joshtynjala
Copy link
Member Author

Relevant comment by me #1763 (comment)

I discovered that Lime's custom haxe.Timer implementation causes openfl.utils.Timer to behave differently than flash.utils.Timer. Lime limits haxe.Timer to the frame rate, but flash.utils.Timer is allowed to update more frequently than flash.events.Event.ENTER_FRAME is dispatched.

In Flash, you can set the stage frame rate to a low value, like 1 FPS, but then call TimerEvent.updateAfterEvent() to force a rendering update on demand. Because Lime and OpenFL's Timers are limited to the frame rate, this (admittedly advanced) use case is not possible in OpenFL, like it is in Flash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant