From 4a6a20342de1c1702beb87d77488678c51d3eee2 Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Sun, 30 Apr 2023 23:02:16 +0200 Subject: [PATCH] Spectre/Math/Time: minor fixes and documentation --- include/Spectre/Math/Time.h | 4 ++-- source/Math/Time.cpp | 12 ++++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/include/Spectre/Math/Time.h b/include/Spectre/Math/Time.h index 9abb7d3..a2753c5 100644 --- a/include/Spectre/Math/Time.h +++ b/include/Spectre/Math/Time.h @@ -23,8 +23,8 @@ public : private : - // In microseconds. - long m_value; + // Microseconds (us) + long m_us; }; // ---------------------------- diff --git a/source/Math/Time.cpp b/source/Math/Time.cpp index 2e62b4c..f380817 100644 --- a/source/Math/Time.cpp +++ b/source/Math/Time.cpp @@ -5,23 +5,27 @@ namespace sp { Time::Time(long value) : -m_value(value) +m_us(value) { } double Time::seconds() const { - return ((double) m_value) / 1000000.0f; + // Faster way of calling milliseconds() / 1000 as + // ms = us / 1000 + // s = ms / 1000 = us / 1000 / 1000 = us / 10000000 + return ((double) m_us) / 1000000.0f; } int Time::milliseconds() const { - return ((double) m_value) / 1000; + // ms = us / 1000 + return ((double) m_us) / 1000; } long Time::microseconds() const { - return m_value; + return m_us; } // ----------------------------