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

Add a very basic time span API #657

Closed
MatthiasWM opened this issue Jan 20, 2023 · 4 comments
Closed

Add a very basic time span API #657

MatthiasWM opened this issue Jan 20, 2023 · 4 comments
Assignees

Comments

@MatthiasWM
Copy link
Contributor

For doing anything animated, it is useful to have a method to measure time spans that is independent on the actual execution time of timeout-callbacks. I would like to add Fl::time_now_ms() and Fl::time_span_ms(t0, t1=0) in a cross-platform way.

http://www.firstobject.com/getmillicount-milliseconds-portable-c++.htm

@MatthiasWM
Copy link
Contributor Author

See: fl_gettime(long*, long*); in FL/forms.H and Fl::system_driver()->gettime(&sec, &usec);, also static double elapsed_time() in Fl_Timeout.H which is not public.

@MatthiasWM MatthiasWM self-assigned this Jan 21, 2023
@Albrecht-S
Copy link
Member

Yes, the one in Fl_Timeout is not public and I looked for a better solution at that time. I'd like to see a method that can be used reliably also in timeout handling. IIRC the problem was (as most of the time ;-) ) Windows.

Without using multimedia timers it's hard to find a Windows function that can reliably deliver a timer stamp that doesn't wrap around after some time (maybe 49 days IIRC, too lazy to check or calculate now). This must be taken into account for such a delta time calculation.

I remember that I also found this getmillicount stuff, it might be worth a look.

... just took a quick look, it's "public domain", seems like we could use it.

Anyway, if you can find a proper solution:

+1 👍 for such a new feature.

@MatthiasWM
Copy link
Contributor Author

MatthiasWM commented Feb 1, 2023

Brainstorm for myself:

  • FL_Point_In_Time or Fl_Timepoint or Fl_Time_Point as an abstract type, so users don't expect a time or date

  • FL_Point_In_Time Fl::now() sets the time now as a point in time, alternative Fl::time_now()

  • double Fl::seconds_since(FL_Point_In_Time some_time_earlier) returns the elapsed time between now and earlier

  • maybe long Fl::ticks_since(FL_Point_In_Time some_time_earlier) returns the elapsed time in 60th of a second

  • possibly ms_since() because milliseconds are relatively common

  • double Fl::seconds_between(FL_Point_In_Time a, FL_Point_In_Time b) may be useful, and ticks_between

  • I don't want to publish any calendar or time-of-day functionality here, or make the user issue that he can derive a time of day from FL_Point_In_Time.

  • I want to avoid using timer because we already use the timer callbacks, and this is not directly related.

  • I don't want to use chromo either, because we don't emulate C++11 std::chronologically either.

  • I don't think that returning a timer resolution or precision is needed if we promise to be at least a common screen frame rate. This is not meant to be a performance timer, but to be used to time animations.

@MatthiasWM
Copy link
Contributor Author

Implemented in PR #670

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

2 participants