From 75273c06c5e8e5b1a73bd8897d5265a87dbf30ca Mon Sep 17 00:00:00 2001 From: ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> Date: Tue, 26 Sep 2023 12:30:36 +0200 Subject: Add Fl_Timestamp Fl::distant_past() Can be handy when Fl::seconds_since() is used early at program startup --- FL/Fl.H | 1 + src/Fl_Timeout.cxx | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/FL/Fl.H b/FL/Fl.H index 25d5dcabd..da6d8191e 100644 --- a/FL/Fl.H +++ b/FL/Fl.H @@ -476,6 +476,7 @@ public: static double seconds_between(Fl_Timestamp& back, Fl_Timestamp& further_back); static long ticks_since(Fl_Timestamp& then); static long ticks_between(Fl_Timestamp& back, Fl_Timestamp& further_back); + static const Fl_Timestamp distant_past(); // private static void run_idle(); diff --git a/src/Fl_Timeout.cxx b/src/Fl_Timeout.cxx index e52573ff0..a707e554e 100644 --- a/src/Fl_Timeout.cxx +++ b/src/Fl_Timeout.cxx @@ -19,6 +19,7 @@ #include "Fl_System_Driver.H" #include +#include // for LONG_MIN /** \file Fl_Timeout.cxx @@ -64,9 +65,10 @@ static int num_timers = 0; // DEBUG \return this moment in time as an opaque time stamp \see Fl::seconds_since(Fl_Timestamp& then) - Fl::seconds_between(Fl_Timestamp& back, Fl_Timestamp& further_back) - Fl::ticks_since(Fl_Timestamp& then) - Fl::ticks_between(Fl_Timestamp& back, Fl_Timestamp& further_back) + \see Fl::seconds_between(Fl_Timestamp& back, Fl_Timestamp& further_back) + \see Fl::ticks_since(Fl_Timestamp& then) + \see Fl::ticks_between(Fl_Timestamp& back, Fl_Timestamp& further_back) + \see Fl::distant_past() */ Fl_Timestamp Fl::now() { Fl_Timestamp ts; @@ -78,6 +80,9 @@ Fl_Timestamp Fl::now() { return ts; // C++ will copy the result into the lvalue for us } +/** The time stamp of a time point in the distant past */ +const Fl_Timestamp Fl::distant_past() { return {LONG_MIN/10, 0}; } + /** Return the time in seconds between now and a previously taken time stamp. @@ -85,7 +90,7 @@ Fl_Timestamp Fl::now() { \return elapsed seconds and fractions of a second \see Fl::seconds_between(Fl_Timestamp& back, Fl_Timestamp& further_back) - Fl::now() + \see Fl::now() \see Fl::distant_past() */ double Fl::seconds_since(Fl_Timestamp& then) { Fl_Timestamp ts_now = Fl::now(); @@ -99,7 +104,7 @@ double Fl::seconds_since(Fl_Timestamp& then) { \param[in] further_back an even earlier time stamp \return elapsed seconds and fractions of a second - \see Fl::seconds_since(Fl_Timestamp& then), Fl::now() + \see Fl::seconds_since(Fl_Timestamp& then) \see Fl::now() */ double Fl::seconds_between(Fl_Timestamp& back, Fl_Timestamp& further_back) { return double((back.sec - further_back.sec) + (back.usec - further_back.usec) / 1000000.); @@ -115,7 +120,7 @@ double Fl::seconds_between(Fl_Timestamp& back, Fl_Timestamp& further_back) { \param[in] then a previously taken time stamp \return elapsed ticks in 60th of a second - \see Fl::ticks_between(Fl_Timestamp& back, Fl_Timestamp& further_back), Fl::now() + \see Fl::ticks_between(Fl_Timestamp& back, Fl_Timestamp& further_back) \see Fl::now() */ long Fl::ticks_since(Fl_Timestamp& then) { Fl_Timestamp ts_now = Fl::now(); @@ -129,7 +134,7 @@ long Fl::ticks_since(Fl_Timestamp& then) { \param[in] further_back an even earlier time stamp \return elapsed ticks in 60th of a second - \see Fl::ticks_since(Fl_Timestamp& then), Fl::now() + \see Fl::ticks_since(Fl_Timestamp& then) \see Fl::now() */ long Fl::ticks_between(Fl_Timestamp& back, Fl_Timestamp& further_back) { return (back.sec-further_back.sec)*60 + (back.usec-further_back.usec)/16666; -- cgit v1.2.3