Frame limit flag added to config

This commit is contained in:
Maximilian Giller 2023-06-30 20:38:41 +02:00
parent b5d7dfede9
commit 23fb9d4fd5
2 changed files with 17 additions and 7 deletions

View file

@ -19,6 +19,7 @@
// FPS
#define FRAME_RATE 60
#define FRAME_TIME sf::Time(sf::seconds(1.0f / FRAME_RATE))
#define FRAME_LIMIT_ENABLED false
// Window settings
#define ANTIALIASINGLEVEL 8

View file

@ -3,7 +3,8 @@
#include "../config.h"
std::shared_ptr<Game> GameFactory::createWindowed(const std::string &title, int width, int height) {
std::shared_ptr<Game> GameFactory::createWindowed(const std::string &title, int width, int height)
{
auto window = std::make_shared<sf::RenderWindow>(sf::VideoMode(width, height), title,
sf::Style::Default,
getAdditionalSettings());
@ -11,13 +12,16 @@ std::shared_ptr<Game> GameFactory::createWindowed(const std::string &title, int
return Game::constructInstance(window);
}
std::shared_ptr<Game> GameFactory::createFullscreen(const std::string &title) {
std::shared_ptr<Game> GameFactory::createFullscreen(const std::string &title)
{
sf::VideoMode fullScreenMode;
auto availableModes = sf::VideoMode::getFullscreenModes();
if (availableModes.empty()) {
if (availableModes.empty())
{
LOG(INFO) << "No fullscreen modes available, falling back to Desktop Mode.";
fullScreenMode = sf::VideoMode::getDesktopMode();
} else {
} else
{
fullScreenMode = availableModes[0];
fullScreenMode.bitsPerPixel = sf::VideoMode::getDesktopMode().bitsPerPixel;
}
@ -30,7 +34,8 @@ std::shared_ptr<Game> GameFactory::createFullscreen(const std::string &title) {
return Game::constructInstance(window);
}
sf::ContextSettings GameFactory::getAdditionalSettings() {
sf::ContextSettings GameFactory::getAdditionalSettings()
{
sf::ContextSettings settings = sf::ContextSettings();
settings.antialiasingLevel = ANTIALIASINGLEVEL;
@ -38,7 +43,11 @@ sf::ContextSettings GameFactory::getAdditionalSettings() {
return settings;
}
void GameFactory::applyAdditionalWindowConfig(sf::RenderWindow *window) {
// window->setFramerateLimit(FRAME_RATE);
void GameFactory::applyAdditionalWindowConfig(sf::RenderWindow *window)
{
if (FRAME_LIMIT_ENABLED)
{
window->setFramerateLimit(FRAME_RATE);
}
window->setKeyRepeatEnabled(KEY_REPEAT_ENABLED);
}