2015-05-23 22:55:12 -06:00
|
|
|
// Copyright 2008 Dolphin Emulator Project
|
2015-05-17 17:08:10 -06:00
|
|
|
// Licensed under GPLv2+
|
2013-04-17 21:09:55 -06:00
|
|
|
// Refer to the license.txt file included.
|
2008-12-07 21:46:09 -07:00
|
|
|
|
2014-02-10 11:54:46 -07:00
|
|
|
#pragma once
|
2008-12-07 21:46:09 -07:00
|
|
|
|
2009-01-15 04:46:09 -07:00
|
|
|
#include <string>
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "Common/CommonTypes.h"
|
2010-01-21 12:55:01 -07:00
|
|
|
|
2008-12-07 21:46:09 -07:00
|
|
|
namespace Common
|
|
|
|
{
|
|
|
|
class Timer
|
|
|
|
{
|
2009-02-22 05:43:25 -07:00
|
|
|
public:
|
|
|
|
Timer();
|
|
|
|
|
|
|
|
void Start();
|
|
|
|
void Stop();
|
|
|
|
void Update();
|
|
|
|
|
|
|
|
// The time difference is always returned in milliseconds, regardless of alternative internal
|
|
|
|
// representation
|
2010-01-07 13:01:41 -07:00
|
|
|
u64 GetTimeDifference();
|
2009-02-22 05:43:25 -07:00
|
|
|
void AddTimeDifference();
|
|
|
|
|
2020-07-01 13:29:30 -06:00
|
|
|
bool IsRunning() const { return m_Running; }
|
|
|
|
|
2009-02-22 05:43:25 -07:00
|
|
|
static void IncreaseResolution();
|
|
|
|
static void RestoreResolution();
|
|
|
|
static u64 GetTimeSinceJan1970();
|
|
|
|
static u64 GetLocalTimeSinceJan1970();
|
2015-07-11 17:49:12 -06:00
|
|
|
// Returns a timestamp with decimals for precise time comparisons
|
2009-08-25 00:34:58 -06:00
|
|
|
static double GetDoubleTime();
|
2009-02-22 05:43:25 -07:00
|
|
|
|
|
|
|
static std::string GetTimeFormatted();
|
2015-07-11 17:49:12 -06:00
|
|
|
// Formats a timestamp from GetDoubleTime() into a date and time string
|
|
|
|
static std::string GetDateTimeFormatted(double time);
|
2009-02-22 05:43:25 -07:00
|
|
|
std::string GetTimeElapsedFormatted() const;
|
|
|
|
u64 GetTimeElapsed();
|
|
|
|
|
2010-01-21 12:55:01 -07:00
|
|
|
static u32 GetTimeMs();
|
2014-11-19 11:57:12 -07:00
|
|
|
static u64 GetTimeUs();
|
2010-01-21 12:55:01 -07:00
|
|
|
|
2015-07-11 17:49:12 -06:00
|
|
|
// Arbitrarily chosen value (38 years) that is subtracted in GetDoubleTime()
|
|
|
|
// to increase sub-second precision of the resulting double timestamp
|
2020-07-12 11:36:58 -06:00
|
|
|
static constexpr int DOUBLE_TIME_OFFSET = (38 * 365 * 24 * 60 * 60);
|
2015-07-11 17:49:12 -06:00
|
|
|
|
2010-01-21 12:55:01 -07:00
|
|
|
private:
|
2009-02-22 05:43:25 -07:00
|
|
|
u64 m_LastTime;
|
|
|
|
u64 m_StartTime;
|
|
|
|
bool m_Running;
|
2008-12-07 21:46:09 -07:00
|
|
|
};
|
2009-02-22 05:43:25 -07:00
|
|
|
|
2009-03-28 02:57:34 -06:00
|
|
|
} // Namespace Common
|