#include "headers/core.hpp" namespace asloengine { static sf::RenderWindow *main_window; static Settings active_settings; void init(Scene *starting_scene, Settings _settings) { LOG("START Init"); main_window = new sf::RenderWindow(); apply_settings(_settings); SceneManager::load_scene(starting_scene); LOG("END Init"); } Settings get_active_settings() { return active_settings; } void apply_settings(Settings _settings) { active_settings = _settings; if (active_settings.fullscreen_enabled) { main_window->create(sf::VideoMode(active_settings.resolution_x, active_settings.resolution_y, active_settings.bit_depth), PROGRAM_INFO, sf::Style::Fullscreen); } else { main_window->create(sf::VideoMode(active_settings.resolution_x, active_settings.resolution_y, active_settings.bit_depth), PROGRAM_INFO, sf::Style::Close); } main_window->setPosition(_settings.window_position); main_window->setVerticalSyncEnabled(active_settings.vsync_enabled); main_window->setFramerateLimit(active_settings.max_framerate); } void start_main_game_loop() { LOG("START Main Game Loop"); sf::Clock clock; bool quitting = false; SceneManager::scene->start(main_window); // Main Game Loop while (main_window->isOpen()) { Keyboard::entered_text = 0; Mouse::mouse_wheel_delta = 0; // Process Events sf::Event event; while (main_window->pollEvent(event)) { switch (event.type) { case sf::Event::Closed: SceneManager::unload_scene(); quitting = true; main_window->close(); break; case sf::Event::TextEntered: Keyboard::entered_text = event.text.unicode; break; case sf::Event::MouseWheelScrolled: Mouse::mouse_wheel_delta = event.mouseWheelScroll.delta; break; } } main_window->clear(); // Scene Drawing if (SceneManager::scene != NULL) { SceneManager::scene->update(clock.restart().asSeconds()); SceneManager::scene->draw(); } else if (!quitting) { WARN("no scene loaded (pointer refering to nothing)"); } main_window->display(); // Load Next Scene if Requested if (SceneManager::next_scene != NULL) { SceneManager::load_scene(SceneManager::next_scene, main_window); SceneManager::next_scene = NULL; } } delete main_window; LOG("END Main Game Loop"); } }