Use the new high performance counter instead of date time class

This commit is contained in:
zilmar 2016-09-17 07:37:27 +10:00
parent 8036bdcd73
commit 4bc957bb3b
12 changed files with 91 additions and 111 deletions

View File

@ -137,6 +137,10 @@
RelativePath=".\FileClass.cpp"
>
</File>
<File
RelativePath=".\HighResTimeStamp.cpp"
>
</File>
<File
RelativePath=".\IniFileClass.cpp"
>
@ -222,6 +226,10 @@
RelativePath=".\FileClass.h"
>
</File>
<File
RelativePath=".\HighResTimeStamp.h"
>
</File>
<File
RelativePath=".\IniFileClass.h"
>

View File

@ -33,7 +33,9 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ItemGroup>
<ClCompile Include="CriticalSection.cpp" />
<ClCompile Include="DateTimeClass.cpp" />
<ClCompile Include="FileClass.cpp" />
<ClCompile Include="HighResTimeStamp.cpp" />
<ClCompile Include="IniFileClass.cpp" />
<ClCompile Include="LogClass.cpp" />
<ClCompile Include="md5.cpp" />
@ -46,14 +48,15 @@
</ClCompile>
<ClCompile Include="StdString.cpp" />
<ClCompile Include="SyncEvent.cpp" />
<ClCompile Include="DateTimeClass.cpp" />
<ClCompile Include="Thread.cpp" />
<ClCompile Include="Trace.cpp" />
<ClCompile Include="Util.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="CriticalSection.h" />
<ClInclude Include="DateTimeClass.h" />
<ClInclude Include="FileClass.h" />
<ClInclude Include="HighResTimeStamp.h" />
<ClInclude Include="IniFileClass.h" />
<ClInclude Include="LogClass.h" />
<ClInclude Include="md5.h" />
@ -66,7 +69,6 @@
<ClInclude Include="StdString.h" />
<ClInclude Include="stdtypes.h" />
<ClInclude Include="SyncEvent.h" />
<ClInclude Include="DateTimeClass.h" />
<ClInclude Include="Thread.h" />
<ClInclude Include="Trace.h" />
<ClInclude Include="TraceModulesCommon.h" />

View File

@ -53,10 +53,13 @@
<ClCompile Include="MemoryManagement.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="DateTimeClass.cpp">
<ClCompile Include="Thread.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Thread.cpp">
<ClCompile Include="HighResTimeStamp.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="DateTimeClass.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
@ -112,10 +115,13 @@
<ClInclude Include="MemoryManagement.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="DateTimeClass.h">
<ClInclude Include="Thread.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Thread.h">
<ClInclude Include="HighResTimeStamp.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="DateTimeClass.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>

View File

@ -1,51 +1,15 @@
#include "stdafx.h"
#include "DateTimeClass.h"
#ifdef ANDROID
#include <math.h>
#else
#include <sys/timeb.h>
#endif
#include <time.h>
CDateTime::CDateTime()
{
m_time = 0;
}
CDateTime & CDateTime::SetToNow(void)
{
#ifdef ANDROID
struct timespec now;
clock_gettime(CLOCK_REALTIME, &now);
m_time = (now.tv_sec * 1000l) + round(now.tv_nsec / 1.0e6);
#else
struct timeb now;
(void)::ftime(&now);
m_time = (now.time * 1000l) + now.millitm;
#endif
return *this;
m_time = time(NULL);
}
std::string CDateTime::Format(const char * format)
{
char buffer[100];
time_t TimeValue = m_time / 1000l;
strftime(buffer, sizeof(buffer), format, localtime(&TimeValue));
strftime(buffer, sizeof(buffer), format, localtime(&m_time));
return std::string(buffer);
}
double CDateTime::DiffernceMilliseconds(const CDateTime & compare)
{
double diff = (double)(m_time - compare.m_time);
return diff / 1000.0;
}
uint64_t CDateTime::Value(void)
{
return m_time;
}
void CDateTime::SetValue(uint64_t value)
{
m_time = value;
}

View File

@ -7,10 +7,7 @@ public:
CDateTime();
CDateTime & SetToNow (void);
std::string Format (const char * format);
double DiffernceMilliseconds (const CDateTime & compare);
uint64_t Value(void);
void SetValue(uint64_t value);
private:
uint64_t m_time;
time_t m_time;
};

View File

@ -70,7 +70,7 @@ the plugin
#include <stddef.h> // offsetof
#include <glide.h>
#include <Common/MemTest.h>
#include <Common/DateTimeClass.h>
#include <Common/HighResTimeStamp.h>
#include <Settings/Settings.h>
#include "GlideExtensions.h"
#include "rdp.h"
@ -150,8 +150,8 @@ extern "C" {
#define COLORED_DEBUGGER // ;) pretty colors
#ifdef FPS
extern CDateTime fps_last;
extern CDateTime fps_next;
extern HighResTimeStamp fps_last;
extern HighResTimeStamp fps_next;
extern float fps;
extern uint32_t fps_count;
#endif

View File

@ -43,6 +43,7 @@
#include "Version.h"
#include <Settings/Settings.h>
#include <Common/CriticalSection.h>
#include <Common/DateTimeClass.h>
#include <Common/path.h>
#include <png/png.h>
#include <memory>
@ -91,8 +92,8 @@ int64 perf_next;
#endif
#ifdef FPS
CDateTime fps_last;
CDateTime fps_next;
HighResTimeStamp fps_last;
HighResTimeStamp fps_next;
float fps = 0.0f;
uint32_t fps_count = 0;
@ -1796,7 +1797,7 @@ void CALL UpdateScreen(void)
// Check frames per second
fps_next.SetToNow();
double diff_secs = fps_next.DiffernceMilliseconds(fps_last);
double diff_secs = (double)(fps_next.GetMicroSeconds() - fps_last.GetMicroSeconds()) / 1000000;
if (diff_secs > 0.5f)
{
fps = (float)(fps_count / diff_secs);
@ -2018,11 +2019,11 @@ void newSwapBuffers()
{
if (g_settings->clock_24_hr)
{
output(956.0f, 0, 1, CDateTime().SetToNow().Format("%H:%M:%S").c_str(), 0);
output(956.0f, 0, 1, CDateTime().Format("%H:%M:%S").c_str(), 0);
}
else
{
output(930.0f, 0, 1, CDateTime().SetToNow().Format("%I:%M:%S %p").c_str(), 0);
output(930.0f, 0, 1, CDateTime().Format("%I:%M:%S %p").c_str(), 0);
}
}
//hotkeys

View File

@ -11,16 +11,14 @@
#include "stdafx.h"
#include "FramePerSecondClass.h"
#include <Project64-core/N64System/N64Types.h>
#ifdef _WIN32
#include <Windows.h>
#endif
CFramePerSecond::CFramePerSecond() :
m_CurrentViFrame(0),
m_CurrentDlistFrame(0),
m_iFrameRateType(g_Settings->LoadDword(UserInterface_FrameDisplayType)),
m_ScreenHertz(g_Settings->LoadDword(GameRunning_ScreenHertz)),
m_ViFrameRate(0)
m_ViFrameRateWhole(0),
m_ViFrameRateFraction(0)
{
g_Settings->RegisterChangeCB(UserInterface_FrameDisplayType, this, (CSettings::SettingChangedFunc)FrameRateTypeChanged);
g_Settings->RegisterChangeCB(GameRunning_ScreenHertz, this, (CSettings::SettingChangedFunc)ScreenHertzChanged);
@ -42,7 +40,7 @@ void CFramePerSecond::Reset(bool ClearDisplay)
{
m_CurrentDlistFrame = 0;
m_CurrentViFrame = 0;
m_LastViFrame.SetValue(0);
m_LastViFrame.SetMicroSeconds(0);
for (int count = 0; count < NoOfFrames; count++)
{
@ -57,7 +55,7 @@ void CFramePerSecond::Reset(bool ClearDisplay)
if (m_iFrameRateType == FR_VIs)
{
DisplayViCounter(0);
DisplayViCounter(-1, 0);
}
}
@ -71,11 +69,13 @@ void CFramePerSecond::UpdateViCounter(void)
}
if ((m_CurrentViFrame & 7) == 0)
{
CDateTime Time;
HighResTimeStamp Time;
Time.SetToNow();
m_ViFrames[(m_CurrentViFrame >> 3) % NoOfFrames] = Time.Value() - m_LastViFrame.Value();
uint64_t time_diff = Time.GetMicroSeconds() - m_LastViFrame.GetMicroSeconds();
m_ViFrames[(m_CurrentViFrame >> 3) % NoOfFrames] = time_diff;
m_LastViFrame = Time;
DisplayViCounter(0);
DisplayViCounter(-1, 0);
}
m_CurrentViFrame += 1;
}
@ -85,11 +85,11 @@ void CFramePerSecond::UpdateDisplay(void)
std::string DisplayString;
if (m_iFrameRateType == FR_VIs || m_iFrameRateType == FR_VIs_DLs)
{
DisplayString = stdstr_f(m_ViFrameRate >= 0 ? "VI/s: %.2f" : "VI/s: -.--", m_ViFrameRate);
DisplayString = stdstr_f(m_ViFrameRateWhole >= 0 ? "VI/s: %d.%d" : "VI/s: -.--", m_ViFrameRateWhole, m_ViFrameRateFraction);
}
if (m_iFrameRateType == FR_PERCENT && m_ViFrameRate > 0)
if (m_iFrameRateType == FR_PERCENT && m_ViFrameRateWhole > 0)
{
float Percent = ((float)m_ViFrameRate) / m_ScreenHertz;
float Percent = ((float)m_ViFrameRateWhole + ((float)m_ViFrameRateFraction / 100)) / m_ScreenHertz;
DisplayString = stdstr_f("%.1f %%", Percent * 100).c_str();
}
if (m_iFrameRateType == FR_DLs || m_iFrameRateType == FR_VIs_DLs)
@ -100,15 +100,16 @@ void CFramePerSecond::UpdateDisplay(void)
g_Notify->DisplayMessage2(DisplayString.c_str());
}
void CFramePerSecond::DisplayViCounter(uint32_t FrameRate)
void CFramePerSecond::DisplayViCounter(int32_t FrameRateWhole, uint32_t FrameRateFraction)
{
if (m_iFrameRateType != FR_VIs && m_iFrameRateType != FR_VIs_DLs && m_iFrameRateType != FR_PERCENT)
{
return;
}
if (FrameRate != 0)
if (FrameRateWhole >= 0)
{
m_ViFrameRate = (float)FrameRate;
m_ViFrameRateWhole = FrameRateWhole;
m_ViFrameRateFraction = FrameRateFraction;
}
else
{
@ -121,11 +122,14 @@ void CFramePerSecond::DisplayViCounter(uint32_t FrameRate)
{
Total += m_ViFrames[count];
}
m_ViFrameRate = ((NoOfFrames << 3) / ((float)Total / 1000));
int baseFPS = (uint32_t)(((uint64_t)NoOfFrames << 3) * 100000000 / Total);
m_ViFrameRateWhole = baseFPS / 100;
m_ViFrameRateFraction = baseFPS % 100;
}
else
{
m_ViFrameRate = -1.0;
m_ViFrameRateWhole = -1;
m_ViFrameRateFraction = 0;
}
}
UpdateDisplay();
@ -151,10 +155,10 @@ void CFramePerSecond::UpdateDlCounter(void)
}
if ((m_CurrentDlistFrame & 3) == 0)
{
CDateTime Time;
Time.SetToNow();
m_FramesDlist[(m_CurrentDlistFrame >> 2) % NoOfFrames] = Time.Value() - m_LastDlistFrame.Value();
m_LastDlistFrame = Time;
HighResTimeStamp Now;
Now.SetToNow();
m_FramesDlist[(m_CurrentDlistFrame >> 2) % NoOfFrames] = Now.GetMicroSeconds() - m_LastDlistFrame.GetMicroSeconds();
m_LastDlistFrame = Now;
if (m_CurrentDlistFrame > (NoOfFrames << 2))
{
int64_t Total;
@ -164,7 +168,7 @@ void CFramePerSecond::UpdateDlCounter(void)
{
Total += m_FramesDlist[count];
}
m_DlistFrameRate = ((NoOfFrames << 2) / ((float)Total / 1000));
m_DlistFrameRate = ((NoOfFrames << 2) / ((float)Total / 1000000));
}
else
{

View File

@ -9,7 +9,7 @@
* *
****************************************************************************/
#pragma once
#include <Common/DateTimeClass.h>
#include <Common/HighResTimeStamp.h>
class CFramePerSecond
{
@ -21,7 +21,7 @@ public:
void UpdateDlCounter(void);
void UpdateViCounter(void);
void DisplayViCounter(uint32_t FrameRate);
void DisplayViCounter(int32_t FrameRateWhole, uint32_t FrameRateFraction);
private:
CFramePerSecond(const CFramePerSecond&); // Disable copy constructor
@ -35,14 +35,15 @@ private:
enum { NoOfFrames = 7 };
CDateTime m_LastViFrame;
int64_t m_ViFrames[NoOfFrames];
int32_t m_CurrentViFrame;
float m_ViFrameRate;
HighResTimeStamp m_LastViFrame;
uint64_t m_ViFrames[NoOfFrames];
uint32_t m_CurrentViFrame;
int32_t m_ViFrameRateWhole;
uint32_t m_ViFrameRateFraction;
//Dlist
CDateTime m_LastDlistFrame;
int64_t m_FramesDlist[NoOfFrames];
int32_t m_CurrentDlistFrame;
HighResTimeStamp m_LastDlistFrame;
uint64_t m_FramesDlist[NoOfFrames];
uint32_t m_CurrentDlistFrame;
float m_DlistFrameRate;
};

View File

@ -2089,7 +2089,7 @@ void CN64System::RefreshScreen()
uint32_t FrameRate;
if (m_Limiter.Timer_Process(&FrameRate) && bDisplayFrameRate())
{
m_FPS.DisplayViCounter(FrameRate);
m_FPS.DisplayViCounter(FrameRate, 0);
m_bCleanFrameBox = true;
}
}

View File

@ -11,17 +11,11 @@
#include "stdafx.h"
#include "SpeedLimiterClass.h"
#include <Common/Util.h>
#ifdef _WIN32
#include <Windows.h>
#include <Mmsystem.h>
#pragma comment(lib, "winmm.lib")
#endif
CSpeedLimiter::CSpeedLimiter() :
m_Frames(0),
m_Speed(60),
m_BaseSpeed(60),
m_Ratio(1000.0F / (float)m_Speed)
m_BaseSpeed(60)
{
}
@ -38,31 +32,37 @@ void CSpeedLimiter::SetHertz(uint32_t Hertz)
void CSpeedLimiter::FixSpeedRatio()
{
m_Ratio = 1000.0f / static_cast<double>(m_Speed);
m_MicroSecondsPerFrame = 1000000 / m_Speed;
m_Frames = 0;
}
bool CSpeedLimiter::Timer_Process(uint32_t * FrameRate)
{
m_Frames += 1;
CDateTime CurrentTime;
HighResTimeStamp CurrentTime;
CurrentTime.SetToNow();
/* Calculate time that should of elapsed for this frame */
uint64_t CalculatedTime = (m_LastTime.Value()) + (m_Ratio * (double)m_Frames);
if (CurrentTime.Value() < CalculatedTime)
uint64_t LastTime = m_LastTime.GetMicroSeconds(), CurrentTimeValue = CurrentTime.GetMicroSeconds();
if (LastTime == 0)
{
int32_t time = (int)(CalculatedTime - CurrentTime.Value());
m_Frames = 0;
m_LastTime = CurrentTime;
return true;
}
uint64_t CalculatedTime = LastTime + (m_MicroSecondsPerFrame * m_Frames);
if (CurrentTimeValue < CalculatedTime)
{
int32_t time = (int)(CalculatedTime - CurrentTimeValue);
if (time > 0)
{
#ifndef ANDROID
pjutil::Sleep(time);
#endif
pjutil::Sleep((time / 1000) + 1);
}
/* Refresh current time */
CurrentTime.SetToNow();
CurrentTimeValue = CurrentTime.GetMicroSeconds();
}
if (CurrentTime.Value() - m_LastTime.Value() >= 1000)
if (CurrentTimeValue - LastTime >= 1000000)
{
/* Output FPS */
if (FrameRate != NULL) { *FrameRate = m_Frames; }
@ -70,10 +70,7 @@ bool CSpeedLimiter::Timer_Process(uint32_t * FrameRate)
m_LastTime = CurrentTime;
return true;
}
else
{
return false;
}
return false;
}
void CSpeedLimiter::IncreaseSpeed()

View File

@ -11,7 +11,7 @@
#pragma once
#include <Project64-core/Settings/GameSettings.h>
#include <Common/DateTimeClass.h>
#include <Common/HighResTimeStamp.h>
class CSpeedLimiter :
private CGameSettings
@ -32,6 +32,6 @@ private:
void FixSpeedRatio();
uint32_t m_Speed, m_BaseSpeed, m_Frames;
CDateTime m_LastTime;
double m_Ratio;
HighResTimeStamp m_LastTime;
uint32_t m_MicroSecondsPerFrame;
};