-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
95 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,36 @@ | ||
#pragma once | ||
#include <Siv3D/IAddon.hpp> | ||
#include <abyss/utils/Singleton/AddonSingleton.hpp> | ||
#include <abyss/values/Fps.hpp> | ||
|
||
namespace abyss | ||
{ | ||
class FrameRateController : public IAddon | ||
class FrameRateController : | ||
public AddonSingleton<FrameRateController>, | ||
public s3d::IAddon | ||
{ | ||
friend class AddonSingleton<FrameRateController>; | ||
private: | ||
using Clock = std::chrono::steady_clock; | ||
using TimePoint = std::chrono::time_point<Clock>; | ||
public: | ||
static void Set(const s3d::Optional<Fps>& value) | ||
{ | ||
Instance()->set(value); | ||
} | ||
private: | ||
static s3d::StringView UniqueName() | ||
{ | ||
return U"FrameRateController"; | ||
} | ||
protected: | ||
void set(const s3d::Optional<Fps>& value); | ||
void postPresent() override; | ||
private: | ||
FrameRateController() = default; | ||
private: | ||
s3d::Optional<Fps> m_value; | ||
|
||
Clock::duration m_sleepTime; | ||
TimePoint m_sleepUntil; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#pragma once | ||
#include <Siv3D/Addon.hpp> | ||
#include <concepts> | ||
|
||
namespace abyss | ||
{ | ||
template<class Type> | ||
class AddonSingleton | ||
{ | ||
public: | ||
static Type* Setup() | ||
{ | ||
return Instance(); | ||
} | ||
static Type* Instance() | ||
{ | ||
static Type* instance = [] { | ||
std::unique_ptr<Type> unique(new Type); | ||
Addon::Register(Type::UniqueName(), std::move(unique)); | ||
return Addon::GetAddon<Type>(Type::UniqueName()); | ||
}(); | ||
return instance; | ||
} | ||
protected: | ||
AddonSingleton() {} | ||
virtual ~AddonSingleton() {} | ||
private: | ||
AddonSingleton(const AddonSingleton& other) = delete; | ||
AddonSingleton& operator=(const AddonSingleton& other) = delete; | ||
}; | ||
} |