mirror of
https://github.com/narzoul/DDrawCompat
synced 2024-12-30 08:55:36 +01:00
Added StatsUpdateRate setting
This commit is contained in:
parent
b083a04ac3
commit
29665e9238
@ -32,6 +32,7 @@
|
||||
#include <Config/Settings/StatsColumns.h>
|
||||
#include <Config/Settings/StatsHotKey.h>
|
||||
#include <Config/Settings/StatsRows.h>
|
||||
#include <Config/Settings/StatsUpdateRate.h>
|
||||
#include <Config/Settings/SupportedResolutions.h>
|
||||
#include <Config/Settings/SupportedDepthFormats.h>
|
||||
#include <Config/Settings/SupportedTextureFormats.h>
|
||||
@ -78,6 +79,7 @@ namespace Config
|
||||
Settings::StatsColumns statsColumns;
|
||||
Settings::StatsHotKey statsHotKey;
|
||||
Settings::StatsRows statsRows;
|
||||
Settings::StatsUpdateRate statsUpdateRate;
|
||||
Settings::SupportedResolutions supportedResolutions;
|
||||
Settings::SupportedDepthFormats supportedDepthFormats;
|
||||
Settings::SupportedTextureFormats supportedTextureFormats;
|
||||
|
39
DDrawCompat/Config/IntSetting.h
Normal file
39
DDrawCompat/Config/IntSetting.h
Normal file
@ -0,0 +1,39 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <Config/Parser.h>
|
||||
#include <Config/Setting.h>
|
||||
|
||||
namespace Config
|
||||
{
|
||||
class IntSetting : public Setting
|
||||
{
|
||||
public:
|
||||
int get() const { return m_value; }
|
||||
|
||||
virtual std::string getValueStr() const override
|
||||
{
|
||||
return std::to_string(m_value);
|
||||
}
|
||||
|
||||
protected:
|
||||
IntSetting(const std::string& name, const std::string& default, int min, int max)
|
||||
: Setting(name, default)
|
||||
, m_min(min)
|
||||
, m_max(max)
|
||||
, m_value(min)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void setValue(const std::string& value) override
|
||||
{
|
||||
m_value = Parser::parseInt(value, m_min, m_max);
|
||||
}
|
||||
|
||||
private:
|
||||
int m_min;
|
||||
int m_max;
|
||||
int m_value;
|
||||
};
|
||||
}
|
20
DDrawCompat/Config/Settings/StatsUpdateRate.h
Normal file
20
DDrawCompat/Config/Settings/StatsUpdateRate.h
Normal file
@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include <Config/IntSetting.h>
|
||||
|
||||
namespace Config
|
||||
{
|
||||
namespace Settings
|
||||
{
|
||||
class StatsUpdateRate : public IntSetting
|
||||
{
|
||||
public:
|
||||
StatsUpdateRate()
|
||||
: IntSetting("StatsUpdateRate", "5", 1, 10)
|
||||
{
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
extern Settings::StatsUpdateRate statsUpdateRate;
|
||||
}
|
@ -158,6 +158,7 @@
|
||||
<ClInclude Include="Config\EnumSetting.h" />
|
||||
<ClInclude Include="Config\FormatListSetting.h" />
|
||||
<ClInclude Include="Config\HotKeySetting.h" />
|
||||
<ClInclude Include="Config\IntSetting.h" />
|
||||
<ClInclude Include="Config\ListSetting.h" />
|
||||
<ClInclude Include="Config\MappedSetting.h" />
|
||||
<ClInclude Include="Config\Parser.h" />
|
||||
@ -196,6 +197,7 @@
|
||||
<ClInclude Include="Config\Settings\StatsColumns.h" />
|
||||
<ClInclude Include="Config\Settings\StatsHotKey.h" />
|
||||
<ClInclude Include="Config\Settings\StatsRows.h" />
|
||||
<ClInclude Include="Config\Settings\StatsUpdateRate.h" />
|
||||
<ClInclude Include="Config\Settings\SupportedDepthFormats.h" />
|
||||
<ClInclude Include="Config\Settings\SupportedResolutions.h" />
|
||||
<ClInclude Include="Config\Settings\SupportedTextureFormats.h" />
|
||||
|
@ -678,6 +678,12 @@
|
||||
<ClInclude Include="Config\Settings\StatsRows.h">
|
||||
<Filter>Header Files\Config\Settings</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Config\IntSetting.h">
|
||||
<Filter>Header Files\Config</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Config\Settings\StatsUpdateRate.h">
|
||||
<Filter>Header Files\Config\Settings</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Gdi\Gdi.cpp">
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include <Overlay/StatsEventCount.h>
|
||||
|
||||
StatsEventCount::StatsEventCount()
|
||||
: m_sampleCounts(TICKS_PER_SEC)
|
||||
: m_sampleCounts(s_update_rate)
|
||||
, m_sampleCount(0)
|
||||
, m_totalSampleCount(0)
|
||||
{
|
||||
@ -17,7 +17,7 @@ void StatsEventCount::add(TickCount tickCount)
|
||||
|
||||
void StatsEventCount::finalize(SampleCount& sampleCount, Stat& sum, Stat& min, Stat& max)
|
||||
{
|
||||
const uint32_t index = getCurrentTickCount() % TICKS_PER_SEC;
|
||||
const uint32_t index = getCurrentTickCount() % s_update_rate;
|
||||
m_totalSampleCount += m_sampleCount;
|
||||
m_totalSampleCount -= m_sampleCounts[index];
|
||||
m_sampleCounts[index] = m_sampleCount;
|
||||
|
@ -9,7 +9,7 @@ StatsEventTime::StatsEventTime()
|
||||
|
||||
void StatsEventTime::add(TickCount tickCount, long long qpcNow)
|
||||
{
|
||||
if (0 != m_qpcLast && qpcNow - m_qpcLast < HISTORY_TIME * Time::g_qpcFrequency)
|
||||
if (0 != m_qpcLast && qpcNow - m_qpcLast < s_history_time * Time::g_qpcFrequency)
|
||||
{
|
||||
addSample(tickCount, qpcNow - m_qpcLast);
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
#include <Config/Settings/StatsUpdateRate.h>
|
||||
#include <Overlay/StatsQueue.h>
|
||||
|
||||
namespace
|
||||
@ -13,9 +14,20 @@ namespace
|
||||
}
|
||||
}
|
||||
|
||||
StatsQueueInitializer::StatsQueueInitializer()
|
||||
{
|
||||
s_update_rate = Config::statsUpdateRate.get();
|
||||
s_history_time = 3;
|
||||
s_history_size = s_history_time * s_update_rate;
|
||||
}
|
||||
|
||||
uint32_t StatsQueueInitializer::s_history_size = 0;
|
||||
uint32_t StatsQueueInitializer::s_history_time = 0;
|
||||
uint32_t StatsQueueInitializer::s_update_rate = 0;
|
||||
|
||||
StatsQueue::StatsQueue()
|
||||
: m_sums(HISTORY_SIZE)
|
||||
, m_sampleCounts(HISTORY_SIZE)
|
||||
: m_sums(s_history_size)
|
||||
, m_sampleCounts(s_history_size)
|
||||
, m_currentTickCount(0)
|
||||
, m_sampleCount(0)
|
||||
, m_sum(0)
|
||||
@ -57,7 +69,7 @@ StatsQueue::Stats StatsQueue::getRawStats(TickCount tickCount)
|
||||
{
|
||||
setTickCount(tickCount);
|
||||
Stats stats = {};
|
||||
const uint32_t index = (m_currentTickCount - 1) % HISTORY_SIZE;
|
||||
const uint32_t index = (m_currentTickCount - 1) % s_history_size;
|
||||
stats.cur = getAvg(m_sums[index], m_sampleCounts[index]);
|
||||
stats.avg = getAvg(m_totalSum, m_totalSampleCount);
|
||||
stats.min = m_minQueue.empty() ? NAN : m_minQueue.front().stat;
|
||||
@ -67,7 +79,7 @@ StatsQueue::Stats StatsQueue::getRawStats(TickCount tickCount)
|
||||
|
||||
StatsQueue::SampleCount StatsQueue::getSampleCount(TickCount tickCount) const
|
||||
{
|
||||
return m_sampleCounts[tickCount % HISTORY_SIZE];
|
||||
return m_sampleCounts[tickCount % s_history_size];
|
||||
}
|
||||
|
||||
StatsQueue::Stats StatsQueue::getStats(TickCount tickCount)
|
||||
@ -84,7 +96,7 @@ void StatsQueue::push()
|
||||
{
|
||||
finalize(m_sampleCount, m_sum, m_min, m_max);
|
||||
|
||||
uint32_t index = m_currentTickCount % HISTORY_SIZE;
|
||||
uint32_t index = m_currentTickCount % s_history_size;
|
||||
m_totalSampleCount -= m_sampleCounts[index];
|
||||
m_totalSampleCount += m_sampleCount;
|
||||
m_totalSum -= m_sums[index];
|
||||
@ -112,7 +124,7 @@ void StatsQueue::pushToMinMaxQueue(std::deque<TimestampedStat>& queue, Stat stat
|
||||
}
|
||||
}
|
||||
|
||||
while (!queue.empty() && m_currentTickCount - queue.front().tickCount >= HISTORY_SIZE)
|
||||
while (!queue.empty() && m_currentTickCount - queue.front().tickCount >= s_history_size)
|
||||
{
|
||||
queue.pop_front();
|
||||
}
|
||||
@ -125,9 +137,9 @@ void StatsQueue::pushToMinMaxQueue(std::deque<TimestampedStat>& queue, Stat stat
|
||||
|
||||
void StatsQueue::setTickCount(TickCount tickCount)
|
||||
{
|
||||
if (tickCount - m_currentTickCount > HISTORY_SIZE)
|
||||
if (tickCount - m_currentTickCount > s_history_size)
|
||||
{
|
||||
m_currentTickCount = tickCount - HISTORY_SIZE;
|
||||
m_currentTickCount = tickCount - s_history_size;
|
||||
resetTickCount();
|
||||
}
|
||||
|
||||
|
@ -5,13 +5,19 @@
|
||||
|
||||
#include <Common/Time.h>
|
||||
|
||||
class StatsQueue
|
||||
class StatsQueueInitializer
|
||||
{
|
||||
protected:
|
||||
StatsQueueInitializer();
|
||||
|
||||
static uint32_t s_history_size;
|
||||
static uint32_t s_history_time;
|
||||
static uint32_t s_update_rate;
|
||||
};
|
||||
|
||||
class StatsQueue : protected StatsQueueInitializer
|
||||
{
|
||||
public:
|
||||
static const uint32_t TICKS_PER_SEC = 5;
|
||||
static const uint32_t HISTORY_TIME = 3;
|
||||
static const uint32_t HISTORY_SIZE = HISTORY_TIME * TICKS_PER_SEC;
|
||||
|
||||
typedef uint32_t SampleCount;
|
||||
typedef uint64_t Stat;
|
||||
typedef uint64_t TickCount;
|
||||
@ -33,12 +39,12 @@ public:
|
||||
|
||||
static long long getQpc(TickCount tickCount)
|
||||
{
|
||||
return tickCount * Time::g_qpcFrequency / TICKS_PER_SEC;
|
||||
return tickCount * Time::g_qpcFrequency / s_update_rate;
|
||||
}
|
||||
|
||||
static TickCount getTickCount(long long qpc = Time::queryPerformanceCounter())
|
||||
{
|
||||
return qpc * TICKS_PER_SEC / Time::g_qpcFrequency;
|
||||
return qpc * s_update_rate / Time::g_qpcFrequency;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
@ -8,7 +8,7 @@ StatsTimer::StatsTimer()
|
||||
|
||||
double StatsTimer::convert(double stat)
|
||||
{
|
||||
return 100 * stat * StatsQueue::TICKS_PER_SEC / Time::g_qpcFrequency;
|
||||
return 100 * stat * s_update_rate / Time::g_qpcFrequency;
|
||||
}
|
||||
|
||||
void StatsTimer::finalize(SampleCount& sampleCount, Stat& sum, Stat& min, Stat& max)
|
||||
|
Loading…
x
Reference in New Issue
Block a user