From 789110208f44d12421f389eec184a32a68cedeb5 Mon Sep 17 00:00:00 2001 From: Joel Schumacher Date: Sun, 15 Mar 2020 16:18:37 +0100 Subject: [PATCH 1/7] Add GitHub action steps to build AppImage --- .github/workflows/main.yml | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c7ea9fc84..b8845af80 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -3,7 +3,7 @@ on: [push, pull_request] jobs: linux-os: - runs-on: ubuntu-latest + runs-on: ubuntu-16.04 steps: - name: Update APT run: sudo apt-get update @@ -20,6 +20,26 @@ jobs: run: mkdir build && cd build && ../configure - name: Build run: cd build && make -j2 + - name: Prepare appimagetool + run: | + cd build && + wget https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-x86_64.AppImage -O appimagetool && + chmod +x appimagetool && + sudo apt install -y appstream + - name: Clone love-appimages + uses: actions/checkout@v2 + with: + path: build/love-appimages + repository: pfirsich/love-appimages + - name: Build AppImage + run: | + cd build && + python3 love-appimages/build.py .. AppDir --builddir build --appimage love.AppImage + - name: Artifact + uses: actions/upload-artifact@v2-preview + with: + name: love.AppImage + path: build/love.AppImage windows-os: runs-on: windows-latest strategy: From b9dd24d3cede5aaa0f8df79c46a79d00739eb3b8 Mon Sep 17 00:00:00 2001 From: Joel Schumacher Date: Wed, 20 May 2020 23:05:11 +0200 Subject: [PATCH 2/7] Make getTime() relative to first invocation --- src/modules/timer/Timer.cpp | 8 +++++++- src/modules/timer/Timer.h | 10 +++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/modules/timer/Timer.cpp b/src/modules/timer/Timer.cpp index 66f1fcd6c..4f0745fe1 100644 --- a/src/modules/timer/Timer.cpp +++ b/src/modules/timer/Timer.cpp @@ -123,7 +123,7 @@ double Timer::getTimerPeriod() return 0; } -double Timer::getTime() +double Timer::getTimeAbsolute() { // The timer period (reciprocal of the frequency.) static const double timerPeriod = getTimerPeriod(); @@ -156,5 +156,11 @@ double Timer::getTime() #endif } +double Timer::getTime() +{ + static const double start = getTimeAbsolute(); + return getTimeAbsolute() - start; +} + } // timer } // love diff --git a/src/modules/timer/Timer.h b/src/modules/timer/Timer.h index 86eeae454..b7f24c0fb 100644 --- a/src/modules/timer/Timer.h +++ b/src/modules/timer/Timer.h @@ -72,9 +72,10 @@ public: double getAverageDelta() const; /** - * Gets the amount of time passed since an unspecified time. Useful for - * profiling code or measuring intervals. The time is microsecond-precise, - * and increases monotonically. + * Gets the amount of time in seconds passed since its first invocation + * (which happens as part of Timer::step at the start of love.run). + * Useful for profiling code or measuring intervals. + * The time is microsecond-precise, and increases monotonically. * @return The time (in seconds) **/ static double getTime(); @@ -102,6 +103,9 @@ private: // Returns the timer period on some platforms. static double getTimerPeriod(); + // Like getTime, but relative to an unspecified time. + static double getTimeAbsolute(); + }; // Timer } // timer From 8d627c88aeaf4a0c68dd9e06dd9feac716f13ffc Mon Sep 17 00:00:00 2001 From: Joel Schumacher Date: Thu, 21 May 2020 15:56:43 +0200 Subject: [PATCH 3/7] Fix comment regarding first invocation of getTime --- src/modules/timer/Timer.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/modules/timer/Timer.h b/src/modules/timer/Timer.h index b7f24c0fb..6e1346749 100644 --- a/src/modules/timer/Timer.h +++ b/src/modules/timer/Timer.h @@ -73,7 +73,8 @@ public: /** * Gets the amount of time in seconds passed since its first invocation - * (which happens as part of Timer::step at the start of love.run). + * (which happens as part of the Timer constructor, + * which is called when the module is first opened). * Useful for profiling code or measuring intervals. * The time is microsecond-precise, and increases monotonically. * @return The time (in seconds) From 0a5db1ba6d4d5b7ba5b5eb6e7214ea40c398a6f5 Mon Sep 17 00:00:00 2001 From: Joel Schumacher Date: Thu, 21 May 2020 15:56:57 +0200 Subject: [PATCH 4/7] Subtract start time before double conversion To preserve precision the subtraction of the start time happens with integer values now and the platform specific implementations have been split completely. --- src/modules/timer/Timer.cpp | 107 ++++++++++++++++++++++-------------- src/modules/timer/Timer.h | 6 -- 2 files changed, 66 insertions(+), 47 deletions(-) diff --git a/src/modules/timer/Timer.cpp b/src/modules/timer/Timer.cpp index 4f0745fe1..6b72be211 100644 --- a/src/modules/timer/Timer.cpp +++ b/src/modules/timer/Timer.cpp @@ -35,15 +35,6 @@ #include #endif -#if defined(LOVE_LINUX) -static inline double getTimeOfDay() -{ - timeval t; - gettimeofday(&t, NULL); - return (double) t.tv_sec + (double) t.tv_usec / 1000000.0; -} -#endif - namespace love { namespace timer @@ -109,58 +100,92 @@ double Timer::getAverageDelta() const return averageDelta; } -double Timer::getTimerPeriod() +#if defined(LOVE_LINUX) + +static inline timespec getTimeOfDay() { -#if defined(LOVE_MACOSX) || defined(LOVE_IOS) - mach_timebase_info_data_t info; - mach_timebase_info(&info); - return (double) info.numer / (double) info.denom / 1000000000.0; -#elif defined(LOVE_WINDOWS) - LARGE_INTEGER temp; - if (QueryPerformanceFrequency(&temp) != 0 && temp.QuadPart != 0) - return 1.0 / (double) temp.QuadPart; -#endif - return 0; + timeval t; + gettimeofday(&t, NULL); + return timespec { t.tv_sec, t.tv_usec * 1000 }; } -double Timer::getTimeAbsolute() +static timespec getTimeAbsolute() { - // The timer period (reciprocal of the frequency.) - static const double timerPeriod = getTimerPeriod(); - -#if defined(LOVE_LINUX) - (void) timerPeriod; // Unused on linux - - double mt; // Check for POSIX timers and monotonic clocks. If not supported, use the gettimeofday fallback. #if _POSIX_TIMERS > 0 && defined(_POSIX_MONOTONIC_CLOCK) \ && (defined(CLOCK_MONOTONIC_RAW) || defined(CLOCK_MONOTONIC)) - timespec t; + #ifdef CLOCK_MONOTONIC_RAW clockid_t clk_id = CLOCK_MONOTONIC_RAW; #else clockid_t clk_id = CLOCK_MONOTONIC; #endif + + timespec t; if (clock_gettime(clk_id, &t) == 0) - mt = (double) t.tv_sec + (double) t.tv_nsec / 1000000000.0; + return t; else + return getTimeOfDay(); #endif - mt = getTimeOfDay(); - return mt; -#elif defined(LOVE_MACOSX) || defined(LOVE_IOS) - return (double) mach_absolute_time() * timerPeriod; -#elif defined(LOVE_WINDOWS) - LARGE_INTEGER microTime; - QueryPerformanceCounter(µTime); - return (double) microTime.QuadPart * timerPeriod; -#endif + return getTimeOfDay(); } double Timer::getTime() { - static const double start = getTimeAbsolute(); - return getTimeAbsolute() - start; + static const timespec start = getTimeAbsolute(); + const timespec now = getTimeAbsolute(); + const timespec rel = timespec { + now.tv_sec - start.tv_sec, + now.tv_nsec - start.tv_nsec + }; + return (double) rel.tv_sec + (double) rel.tv_nsec / 1.0e9; } +#elif defined(LOVE_MACOSX) || defined(LOVE_IOS) + +static mach_timebase_info_data_t getTimebaseInfo() +{ + mach_timebase_info_data_t info; + mach_timebase_info(&info); + return info; +} + +double Timer::getTime() +{ + static const mach_timebase_info_data_t info = getTimebaseInfo(); + static const uint64_t start = mach_absolute_time(); + const uint64_t rel = mach_absolute_time() - start; + return ((double) rel * 1.0e-9) * (double) info.number / (double) info.denom; +} + +#elif defined(LOVE_WINDOWS) + +static LARGE_INTEGER getTimeAbsolute() +{ + LARGE_INTEGER t; + QueryPerformanceCounter(&t); + return t; +} + +static LARGE_INTEGER getFrequency() +{ + LARGE_INTEGER freq; + // "On systems that run Windows XP or later, the function will always succeed and will thus never return zero." + QueryPerformanceFrequency(&freq); + return freq; +} + +double Timer::getTime() +{ + static const LARGE_INTEGER freq = getFrequency(); + static const LARGE_INTEGER start = getTimeAbsolute(); + const LARGE_INTEGER now = getTimeAbsolute(); + LARGE_INTEGER rel; + rel.QuadPart = now.QuadPart - start.QuadPart; + return rel.QuadPart / freq.QuadPart; +} + +#endif + } // timer } // love diff --git a/src/modules/timer/Timer.h b/src/modules/timer/Timer.h index 6e1346749..cfd9ab180 100644 --- a/src/modules/timer/Timer.h +++ b/src/modules/timer/Timer.h @@ -101,12 +101,6 @@ private: // The current timestep. double dt; - // Returns the timer period on some platforms. - static double getTimerPeriod(); - - // Like getTime, but relative to an unspecified time. - static double getTimeAbsolute(); - }; // Timer } // timer From ba37b262c00cb3e08179227ff21575dde88fdb13 Mon Sep 17 00:00:00 2001 From: Joel Schumacher Date: Thu, 21 May 2020 16:02:12 +0200 Subject: [PATCH 5/7] Fix getTime for Windows --- src/modules/timer/Timer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/timer/Timer.cpp b/src/modules/timer/Timer.cpp index 6b72be211..6b4a215d7 100644 --- a/src/modules/timer/Timer.cpp +++ b/src/modules/timer/Timer.cpp @@ -182,7 +182,7 @@ double Timer::getTime() const LARGE_INTEGER now = getTimeAbsolute(); LARGE_INTEGER rel; rel.QuadPart = now.QuadPart - start.QuadPart; - return rel.QuadPart / freq.QuadPart; + return (double) rel.QuadPart / (double) freq.QuadPart; } #endif From 1c5b8431ca90ff32ce85a321ec53d88b8fe49511 Mon Sep 17 00:00:00 2001 From: Joel Schumacher Date: Fri, 22 May 2020 00:33:47 +0200 Subject: [PATCH 6/7] Remove usage of invalid timespec Also add a comment to clarify why the subtraction of timespec values should work. --- src/modules/timer/Timer.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/modules/timer/Timer.cpp b/src/modules/timer/Timer.cpp index 6b4a215d7..c3c020f38 100644 --- a/src/modules/timer/Timer.cpp +++ b/src/modules/timer/Timer.cpp @@ -24,6 +24,7 @@ #include "common/delay.h" #include "Timer.h" +#include #if defined(LOVE_WINDOWS) #include #elif defined(LOVE_MACOSX) || defined(LOVE_IOS) @@ -134,11 +135,10 @@ double Timer::getTime() { static const timespec start = getTimeAbsolute(); const timespec now = getTimeAbsolute(); - const timespec rel = timespec { - now.tv_sec - start.tv_sec, - now.tv_nsec - start.tv_nsec - }; - return (double) rel.tv_sec + (double) rel.tv_nsec / 1.0e9; + // tv_sec and tv_nsec should be signed on POSIX, so we are fine in just subtracting here. + const long sec = now.tv_sec - start.tv_sec; + const long nsec = now.tv_nsec - start.tv_nsec; + return (double) sec + (double) nsec / 1.0e9; } #elif defined(LOVE_MACOSX) || defined(LOVE_IOS) From 44033cd1431d7139c1fad9d542d9f1d7a516bb72 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Thu, 21 May 2020 20:08:43 -0300 Subject: [PATCH 7/7] Fix a compile error on macOS/iOS --- src/modules/timer/Timer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/timer/Timer.cpp b/src/modules/timer/Timer.cpp index c3c020f38..db0df8241 100644 --- a/src/modules/timer/Timer.cpp +++ b/src/modules/timer/Timer.cpp @@ -155,7 +155,7 @@ double Timer::getTime() static const mach_timebase_info_data_t info = getTimebaseInfo(); static const uint64_t start = mach_absolute_time(); const uint64_t rel = mach_absolute_time() - start; - return ((double) rel * 1.0e-9) * (double) info.number / (double) info.denom; + return ((double) rel * 1.0e-9) * (double) info.numer / (double) info.denom; } #elif defined(LOVE_WINDOWS)