feat: configure() now uses specialised application config struct

This commit is contained in:
Sara Gerretsen 2025-09-04 19:24:07 +02:00
parent 25df4d9f3d
commit 574116fb09
3 changed files with 26 additions and 9 deletions

View file

@ -1,15 +1,13 @@
#include "defs.h"
#include <SFML/Graphics.hpp> #include <SFML/Graphics.hpp>
#include <SFML/Window.hpp> #include <SFML/Window.hpp>
#include <imgui-SFML.h> #include <imgui-SFML.h>
#include <imgui.h> #include <imgui.h>
sf::String const window_name{ "mywindow" }; void configure(AppConfig &config) {
config.window_title = "MYPROJECT";
void configure(sf::Window &window) { config.frame_rate_limit = 60;
window.setTitle("MYPROJECT"); config.vsync = true;
// choose one or the other, both doesn't really do much
//window.setFramerateLimit(0);
window.setVerticalSyncEnabled(true);
} }
void setup() { void setup() {

13
src/defs.h Normal file
View file

@ -0,0 +1,13 @@
#ifndef LLCS_DEFS_H
#define LLCS_DEFS_H
#include <optional>
#include <SFML/System/String.hpp>
struct AppConfig {
sf::String window_title{ "UNNAMED WINDOW" };
bool vsync{};
std::optional<int> frame_rate_limit{std::nullopt};
};
#endif // !LLCS_DEFS_H

View file

@ -1,3 +1,4 @@
#include "defs.h"
#include <SFML/Graphics.hpp> #include <SFML/Graphics.hpp>
#include <SFML/Window.hpp> #include <SFML/Window.hpp>
#include <imgui-SFML.h> #include <imgui-SFML.h>
@ -5,11 +6,16 @@
static sf::RenderWindow window{}; static sf::RenderWindow window{};
static sf::Clock deltaClock{}; static sf::Clock deltaClock{};
extern void configure(sf::Window &window); extern void configure(AppConfig &config);
void initialize_window() { void initialize_window() {
window.create(sf::VideoMode({ 1280, 720 }),"UNNAMED WINDOW"); window.create(sf::VideoMode({ 1280, 720 }),"UNNAMED WINDOW");
configure(window); AppConfig cfg{};
configure(cfg);
if (cfg.frame_rate_limit)
window.setFramerateLimit(cfg.frame_rate_limit.value_or(0));
window.setVerticalSyncEnabled(cfg.vsync);
window.setTitle(cfg.window_title);
} }
void initialize_imgui() { void initialize_imgui() {