Revert to using ftime() on Windows which doesn't have gettimeofday(). Untested.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5937 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
parent
48abd94113
commit
35395366bd
|
@ -16,11 +16,13 @@
|
||||||
// http://code.google.com/p/dolphin-emu/
|
// http://code.google.com/p/dolphin-emu/
|
||||||
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <sys/time.h>
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#include <mmsystem.h>
|
#include <mmsystem.h>
|
||||||
|
#include <sys/timeb.h>
|
||||||
|
#else
|
||||||
|
#include <sys/time.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "Common.h"
|
#include "Common.h"
|
||||||
|
@ -30,19 +32,16 @@
|
||||||
namespace Common
|
namespace Common
|
||||||
{
|
{
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
u32 Timer::GetTimeMs() {
|
|
||||||
return timeGetTime();
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
u32 Timer::GetTimeMs()
|
u32 Timer::GetTimeMs()
|
||||||
{
|
{
|
||||||
|
#ifdef _WIN32
|
||||||
|
return timeGetTime();
|
||||||
|
#else
|
||||||
struct timeval t;
|
struct timeval t;
|
||||||
(void)gettimeofday(&t, NULL);
|
(void)gettimeofday(&t, NULL);
|
||||||
return((u32)(t.tv_sec * 1000 + t.tv_usec / 1000));
|
return((u32)(t.tv_sec * 1000 + t.tv_usec / 1000));
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
// --------------------------------------------
|
// --------------------------------------------
|
||||||
// Initiate, Start, Stop, and Update the time
|
// Initiate, Start, Stop, and Update the time
|
||||||
|
@ -81,8 +80,6 @@ void Timer::Update()
|
||||||
//TODO(ector) - QPF
|
//TODO(ector) - QPF
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// -------------------------------------
|
// -------------------------------------
|
||||||
// Get time difference and elapsed time
|
// Get time difference and elapsed time
|
||||||
// -------------------------------------
|
// -------------------------------------
|
||||||
|
@ -93,12 +90,13 @@ u64 Timer::GetTimeDifference()
|
||||||
return GetTimeMs() - m_LastTime;
|
return GetTimeMs() - m_LastTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Add the time difference since the last Update() to the starting time. This is used to compensate
|
// Add the time difference since the last Update() to the starting time.
|
||||||
for a paused game. */
|
// This is used to compensate for a paused game.
|
||||||
void Timer::AddTimeDifference()
|
void Timer::AddTimeDifference()
|
||||||
{
|
{
|
||||||
m_StartTime += GetTimeDifference();
|
m_StartTime += GetTimeDifference();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wind back the starting time to a custom time
|
// Wind back the starting time to a custom time
|
||||||
void Timer::WindBackStartingTime(u64 WindBack)
|
void Timer::WindBackStartingTime(u64 WindBack)
|
||||||
{
|
{
|
||||||
|
@ -108,8 +106,8 @@ void Timer::WindBackStartingTime(u64 WindBack)
|
||||||
// Get the time elapsed since the Start()
|
// Get the time elapsed since the Start()
|
||||||
u64 Timer::GetTimeElapsed()
|
u64 Timer::GetTimeElapsed()
|
||||||
{
|
{
|
||||||
/* If we have not started yet return 1 (because then I don't have to change the FPS
|
// If we have not started yet, return 1 (because then I don't
|
||||||
calculation in CoreRerecording.cpp */
|
// have to change the FPS calculation in CoreRerecording.cpp .
|
||||||
if (m_StartTime == 0) return 1;
|
if (m_StartTime == 0) return 1;
|
||||||
|
|
||||||
// Rrturn the final timer time if the timer is stopped
|
// Rrturn the final timer time if the timer is stopped
|
||||||
|
@ -125,7 +123,8 @@ std::string Timer::GetTimeElapsedFormatted() const
|
||||||
if (m_StartTime == 0)
|
if (m_StartTime == 0)
|
||||||
return "00:00:00:000";
|
return "00:00:00:000";
|
||||||
|
|
||||||
// The number of milliseconds since the start, use a different value if the timer is stopped
|
// The number of milliseconds since the start.
|
||||||
|
// Use a different value if the timer is stopped.
|
||||||
u64 Milliseconds;
|
u64 Milliseconds;
|
||||||
if (m_Running)
|
if (m_Running)
|
||||||
Milliseconds = GetTimeMs() - m_StartTime;
|
Milliseconds = GetTimeMs() - m_StartTime;
|
||||||
|
@ -138,7 +137,8 @@ std::string Timer::GetTimeElapsedFormatted() const
|
||||||
// Hours
|
// Hours
|
||||||
u32 Hours = Minutes / 60;
|
u32 Hours = Minutes / 60;
|
||||||
|
|
||||||
std::string TmpStr = StringFromFormat("%02i:%02i:%02i:%03i", Hours, Minutes % 60, Seconds % 60, Milliseconds % 1000);
|
std::string TmpStr = StringFromFormat("%02i:%02i:%02i:%03i",
|
||||||
|
Hours, Minutes % 60, Seconds % 60, Milliseconds % 1000);
|
||||||
return TmpStr;
|
return TmpStr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,7 +150,6 @@ void Timer::IncreaseResolution()
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Timer::RestoreResolution()
|
void Timer::RestoreResolution()
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
@ -158,7 +157,6 @@ void Timer::RestoreResolution()
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
void _time64(u64* t)
|
void _time64(u64* t)
|
||||||
{
|
{
|
||||||
|
@ -166,7 +164,6 @@ void _time64(u64* t)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
// Get the number of seconds since January 1 1970
|
// Get the number of seconds since January 1 1970
|
||||||
u64 Timer::GetTimeSinceJan1970()
|
u64 Timer::GetTimeSinceJan1970()
|
||||||
{
|
{
|
||||||
|
@ -188,7 +185,8 @@ u64 Timer::GetLocalTimeSinceJan1970()
|
||||||
return (u64)(sysTime + tzDiff);
|
return (u64)(sysTime + tzDiff);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the current time formatted as Minutes:Seconds:Milliseconds in the form 00:00:000
|
// Return the current time formatted as Minutes:Seconds:Milliseconds
|
||||||
|
// in the form 00:00:000.
|
||||||
std::string Timer::GetTimeFormatted()
|
std::string Timer::GetTimeFormatted()
|
||||||
{
|
{
|
||||||
time_t sysTime;
|
time_t sysTime;
|
||||||
|
@ -202,36 +200,49 @@ std::string Timer::GetTimeFormatted()
|
||||||
strftime(tmp, 6, "%M:%S", gmTime);
|
strftime(tmp, 6, "%M:%S", gmTime);
|
||||||
|
|
||||||
// Now tack on the milliseconds
|
// Now tack on the milliseconds
|
||||||
|
#ifdef _WIN32
|
||||||
|
struct timeb tp;
|
||||||
|
(void)::ftime(&tp);
|
||||||
|
sprintf(formattedTime, "%s:%03i", tmp, tp.millitm);
|
||||||
|
#else
|
||||||
struct timeval t;
|
struct timeval t;
|
||||||
(void)gettimeofday(&t, NULL);
|
(void)gettimeofday(&t, NULL);
|
||||||
sprintf(formattedTime, "%s:%03ld", tmp, t.tv_usec / 1000);
|
sprintf(formattedTime, "%s:%03d", tmp, (int)(t.tv_usec / 1000));
|
||||||
|
#endif
|
||||||
|
|
||||||
return std::string(formattedTime);
|
return std::string(formattedTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Returns a timestamp with decimals for precise time comparisons
|
// Returns a timestamp with decimals for precise time comparisons
|
||||||
// ----------------
|
// ----------------
|
||||||
double Timer::GetDoubleTime()
|
double Timer::GetDoubleTime()
|
||||||
{
|
{
|
||||||
|
#ifdef _WIN32
|
||||||
|
struct timeb tp;
|
||||||
|
(void)::ftime(&tp);
|
||||||
|
#else
|
||||||
struct timeval t;
|
struct timeval t;
|
||||||
(void)gettimeofday(&t, NULL);
|
(void)gettimeofday(&t, NULL);
|
||||||
u64 TmpSeconds = Common::Timer::GetTimeSinceJan1970(); // Get continous timestamp
|
#endif
|
||||||
|
// Get continous timestamp
|
||||||
|
u64 TmpSeconds = Common::Timer::GetTimeSinceJan1970();
|
||||||
|
|
||||||
/* Remove a few years. We only really want enough seconds to make sure that we are
|
// Remove a few years. We only really want enough seconds to make
|
||||||
detecting actual actions, perhaps 60 seconds is enough really, but I leave a
|
// sure that we are detecting actual actions, perhaps 60 seconds is
|
||||||
year of seconds anyway, in case the user's clock is incorrect or something like that */
|
// enough really, but I leave a year of seconds anyway, in case the
|
||||||
|
// user's clock is incorrect or something like that.
|
||||||
TmpSeconds = TmpSeconds - (38 * 365 * 24 * 60 * 60);
|
TmpSeconds = TmpSeconds - (38 * 365 * 24 * 60 * 60);
|
||||||
|
|
||||||
//if (TmpSeconds < 0) return 0; // Check the the user's clock is working somewhat
|
// Make a smaller integer that fits in the double
|
||||||
|
u32 Seconds = (u32)TmpSeconds;
|
||||||
u32 Seconds = (u32)TmpSeconds; // Make a smaller integer that fits in the double
|
#ifdef _WIN32
|
||||||
double ms = t.tv_usec / 1000.0 / 1000.0;
|
double ms = t.tv_usec / 1000.0 / 1000.0;
|
||||||
|
#else
|
||||||
|
double ms = t.tv_usec / 1000.0 / 1000.0;
|
||||||
|
#endif
|
||||||
double TmpTime = Seconds + ms;
|
double TmpTime = Seconds + ms;
|
||||||
|
|
||||||
return TmpTime;
|
return TmpTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} // Namespace Common
|
} // Namespace Common
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue