44 lines
1.7 KiB
C++
44 lines
1.7 KiB
C++
#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 Game::constructInstance(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 Game::constructInstance(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);
|
|
window->setKeyRepeatEnabled(KEY_REPEAT_ENABLED);
|
|
}
|