holesome/src/game/game_factory.cpp

48 lines
1.7 KiB
C++
Raw Normal View History

//
// Created by max on 28.04.23.
//
#include <SFML/Graphics/RenderWindow.hpp>
#include "game_factory.hpp"
#include "../config.h"
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());
applyAdditionalWindowConfig(window.get());
return std::make_shared<Game>(window);
}
std::shared_ptr<Game> GameFactory::createFullscreen(const std::string &title) {
sf::VideoMode fullScreenMode;
auto availableModes = sf::VideoMode::getFullscreenModes();
if (availableModes.empty()) {
LOG(INFO) << "No fullscreen modes available, falling back to Desktop Mode.";
fullScreenMode = sf::VideoMode::getDesktopMode();
} else {
fullScreenMode = availableModes[0];
fullScreenMode.bitsPerPixel = sf::VideoMode::getDesktopMode().bitsPerPixel;
}
auto window = std::make_shared<sf::RenderWindow>(fullScreenMode, title,
sf::Style::Fullscreen,
getAdditionalSettings());
applyAdditionalWindowConfig(window.get());
return std::make_shared<Game>(window);
}
sf::ContextSettings GameFactory::getAdditionalSettings() {
sf::ContextSettings settings = sf::ContextSettings();
settings.antialiasingLevel = ANTIALIASINGLEVEL;
return settings;
}
void GameFactory::applyAdditionalWindowConfig(sf::RenderWindow *window) {
window->setFramerateLimit(FRAME_RATE);
}