From 3f270fbcecc0f04c83cb3014f58cd2af90391243 Mon Sep 17 00:00:00 2001 From: tyanmahou Date: Fri, 5 Jan 2024 21:21:59 +0900 Subject: [PATCH] update FrameRateController --- .../app/utils/FPS/FrameRateController.cpp | 19 +++++++++++++++---- .../app/utils/FPS/FrameRateController.hpp | 7 ++++--- .../app/utils/Singleton/AddonSingleton.hpp | 5 +++-- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/Re-Abyss/app/utils/FPS/FrameRateController.cpp b/Re-Abyss/app/utils/FPS/FrameRateController.cpp index eb6ea3b3..47f2b06a 100644 --- a/Re-Abyss/app/utils/FPS/FrameRateController.cpp +++ b/Re-Abyss/app/utils/FPS/FrameRateController.cpp @@ -6,15 +6,26 @@ namespace abyss void FrameRateController::set(const s3d::Optional& value) { m_value = value; - auto refreshRate = s3d::System::GetCurrentMonitor().refreshRate.map([](double x) { - return Fps{ x }; - }); - if (value && refreshRate && *refreshRate >= *value) { + if (value) { m_sleepTime = s3d::DurationCast(value->duration()); s3d::Graphics::SetVSyncEnabled(false); } else { + s3d::Graphics::SetVSyncEnabled(true); + } + } + bool FrameRateController::setIfLessThanRefreshRate(const s3d::Optional& value) + { + auto refreshRate = s3d::System::GetCurrentMonitor().refreshRate.map([](double x) { + return Fps{ x }; + }); + if (value && refreshRate && *value > *refreshRate) { + // モニタのリフレッシュレートを越える m_value = s3d::none; s3d::Graphics::SetVSyncEnabled(true); + return false; + } else { + this->set(value); + return true; } } void FrameRateController::postPresent() diff --git a/Re-Abyss/app/utils/FPS/FrameRateController.hpp b/Re-Abyss/app/utils/FPS/FrameRateController.hpp index fe7bfd53..7f8ba3b6 100644 --- a/Re-Abyss/app/utils/FPS/FrameRateController.hpp +++ b/Re-Abyss/app/utils/FPS/FrameRateController.hpp @@ -17,13 +17,14 @@ namespace abyss { Instance()->set(value); } - private: - constexpr static s3d::StringView UniqueName() + static bool SetIfLessThanRefreshRate(const s3d::Optional& value) { - return U"FrameRateController"; + return Instance()->setIfLessThanRefreshRate(value); } protected: void set(const s3d::Optional& value); + bool setIfLessThanRefreshRate(const s3d::Optional& value); + void postPresent() override; private: FrameRateController() = default; diff --git a/Re-Abyss/app/utils/Singleton/AddonSingleton.hpp b/Re-Abyss/app/utils/Singleton/AddonSingleton.hpp index 32f46a33..46107ae7 100644 --- a/Re-Abyss/app/utils/Singleton/AddonSingleton.hpp +++ b/Re-Abyss/app/utils/Singleton/AddonSingleton.hpp @@ -1,5 +1,6 @@ #pragma once #include +#include #include namespace abyss @@ -16,8 +17,8 @@ namespace abyss { static Type* instance = [] { std::unique_ptr unique(new Type); - Addon::Register(Type::UniqueName(), std::move(unique)); - return Addon::GetAddon(Type::UniqueName()); + Addon::Register(NameOf::nameof(), std::move(unique)); + return Addon::GetAddon(NameOf::nameof()); }(); return instance; }