collision_crisis/src/main.cpp
2025-09-04 22:17:56 +02:00

71 lines
1.8 KiB
C++

#include "defs.h"
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <imgui-SFML.h>
#include <imgui.h>
static sf::RenderWindow window{};
static sf::Clock deltaClock{};
static AppConfig cfg{};
static sf::View view{};
extern void configure(AppConfig &config);
void initialize_window() {
configure(cfg);
window.create(cfg.mode, cfg.window_title);
if (cfg.frame_rate_limit)
window.setFramerateLimit(cfg.frame_rate_limit.value_or(0));
window.setVerticalSyncEnabled(cfg.vsync);
view = window.getDefaultView();
}
void initialize_imgui() {
if (!ImGui::SFML::Init(window))
exit(-1);
}
void poll_events() {
while (std::optional const event{ window.pollEvent() })
{
ImGui::SFML::ProcessEvent(window, *event);
// "close requested" event: we close the window
if (event->is<sf::Event::Closed>()) {
window.close();
} else if (sf::Event::Resized const *resized{ event->getIf<sf::Event::Resized>()}) {
view.setSize({ static_cast<float>(resized->size.x), static_cast<float>(resized->size.y) });
window.setView(view);
}
}
}
extern void setup(void);
extern void loop(void);
extern void draw_scene(sf::RenderTarget &target);
extern void draw_main_menu_bar(void);
extern void draw_gui(void);
int main() {
initialize_window();
initialize_imgui();
setup();
while (window.isOpen()) {
// Event Polling
poll_events();
// Update
loop();
draw_scene(window);
ImGui::SFML::Update(window, deltaClock.restart());
if(ImGui::BeginMainMenuBar()) {
draw_main_menu_bar();
ImGui::EndMainMenuBar();
}
draw_gui();
// Render
window.clear();
ImGui::SFML::Render(window);
window.display();
}
return 0;
}