diff --git a/DDrawCompat/Config/Config.cpp b/DDrawCompat/Config/Config.cpp index 8af367b..e694caa 100644 --- a/DDrawCompat/Config/Config.cpp +++ b/DDrawCompat/Config/Config.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -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; diff --git a/DDrawCompat/Config/IntSetting.h b/DDrawCompat/Config/IntSetting.h new file mode 100644 index 0000000..a3fca65 --- /dev/null +++ b/DDrawCompat/Config/IntSetting.h @@ -0,0 +1,39 @@ +#pragma once + +#include + +#include +#include + +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; + }; +} diff --git a/DDrawCompat/Config/Settings/StatsUpdateRate.h b/DDrawCompat/Config/Settings/StatsUpdateRate.h new file mode 100644 index 0000000..6ec0c9f --- /dev/null +++ b/DDrawCompat/Config/Settings/StatsUpdateRate.h @@ -0,0 +1,20 @@ +#pragma once + +#include + +namespace Config +{ + namespace Settings + { + class StatsUpdateRate : public IntSetting + { + public: + StatsUpdateRate() + : IntSetting("StatsUpdateRate", "5", 1, 10) + { + } + }; + } + + extern Settings::StatsUpdateRate statsUpdateRate; +} diff --git a/DDrawCompat/DDrawCompat.vcxproj b/DDrawCompat/DDrawCompat.vcxproj index 94c353f..969b8bc 100644 --- a/DDrawCompat/DDrawCompat.vcxproj +++ b/DDrawCompat/DDrawCompat.vcxproj @@ -158,6 +158,7 @@ + @@ -196,6 +197,7 @@ + diff --git a/DDrawCompat/DDrawCompat.vcxproj.filters b/DDrawCompat/DDrawCompat.vcxproj.filters index d96c10f..9041ba2 100644 --- a/DDrawCompat/DDrawCompat.vcxproj.filters +++ b/DDrawCompat/DDrawCompat.vcxproj.filters @@ -678,6 +678,12 @@ Header Files\Config\Settings + + Header Files\Config + + + Header Files\Config\Settings + diff --git a/DDrawCompat/Overlay/StatsEventCount.cpp b/DDrawCompat/Overlay/StatsEventCount.cpp index 42355af..9cf8e7f 100644 --- a/DDrawCompat/Overlay/StatsEventCount.cpp +++ b/DDrawCompat/Overlay/StatsEventCount.cpp @@ -3,7 +3,7 @@ #include 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; diff --git a/DDrawCompat/Overlay/StatsEventTime.cpp b/DDrawCompat/Overlay/StatsEventTime.cpp index c3deea5..24edc96 100644 --- a/DDrawCompat/Overlay/StatsEventTime.cpp +++ b/DDrawCompat/Overlay/StatsEventTime.cpp @@ -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); } diff --git a/DDrawCompat/Overlay/StatsQueue.cpp b/DDrawCompat/Overlay/StatsQueue.cpp index 6a957e9..e6de950 100644 --- a/DDrawCompat/Overlay/StatsQueue.cpp +++ b/DDrawCompat/Overlay/StatsQueue.cpp @@ -1,3 +1,4 @@ +#include #include 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& 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& 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(); } diff --git a/DDrawCompat/Overlay/StatsQueue.h b/DDrawCompat/Overlay/StatsQueue.h index 1d1b3a8..9441ea5 100644 --- a/DDrawCompat/Overlay/StatsQueue.h +++ b/DDrawCompat/Overlay/StatsQueue.h @@ -5,13 +5,19 @@ #include -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: diff --git a/DDrawCompat/Overlay/StatsTimer.cpp b/DDrawCompat/Overlay/StatsTimer.cpp index 40972ab..11a32c6 100644 --- a/DDrawCompat/Overlay/StatsTimer.cpp +++ b/DDrawCompat/Overlay/StatsTimer.cpp @@ -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)