Skip to content

Commit

Permalink
update FrameRateController
Browse files Browse the repository at this point in the history
  • Loading branch information
tyanmahou committed Jan 5, 2024
1 parent 00bf83a commit 3f270fb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
19 changes: 15 additions & 4 deletions Re-Abyss/app/utils/FPS/FrameRateController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,26 @@ namespace abyss
void FrameRateController::set(const s3d::Optional<Fps>& 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<Clock::duration>(value->duration());
s3d::Graphics::SetVSyncEnabled(false);
} else {
s3d::Graphics::SetVSyncEnabled(true);
}
}
bool FrameRateController::setIfLessThanRefreshRate(const s3d::Optional<Fps>& 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()
Expand Down
7 changes: 4 additions & 3 deletions Re-Abyss/app/utils/FPS/FrameRateController.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ namespace abyss
{
Instance()->set(value);
}
private:
constexpr static s3d::StringView UniqueName()
static bool SetIfLessThanRefreshRate(const s3d::Optional<Fps>& value)
{
return U"FrameRateController";
return Instance()->setIfLessThanRefreshRate(value);
}
protected:
void set(const s3d::Optional<Fps>& value);
bool setIfLessThanRefreshRate(const s3d::Optional<Fps>& value);

void postPresent() override;
private:
FrameRateController() = default;
Expand Down
5 changes: 3 additions & 2 deletions Re-Abyss/app/utils/Singleton/AddonSingleton.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once
#include <Siv3D/Addon.hpp>
#include <abyss/utils/NameOf/NameOf.hpp>
#include <concepts>

namespace abyss
Expand All @@ -16,8 +17,8 @@ namespace abyss
{
static Type* instance = [] {
std::unique_ptr<Type> unique(new Type);
Addon::Register(Type::UniqueName(), std::move(unique));
return Addon::GetAddon<Type>(Type::UniqueName());
Addon::Register(NameOf::nameof<Type>(), std::move(unique));
return Addon::GetAddon<Type>(NameOf::nameof<Type>());
}();
return instance;
}
Expand Down

0 comments on commit 3f270fb

Please sign in to comment.