#include "application.h" #include "classicgame/classicgame.h" #include #include const sf::Time TIME_PER_FRAME = sf::seconds(1.f / 60.f); Application::Application() : _game_window({1280, 720}, "Test"), _game(std::make_unique()) {} void Application::run() { _game_window.display(); _game->run(); exec(); } void Application::exec() { sf::Clock timer; sf::Time time_since_last_update = sf::Time::Zero; while (_game_window.isOpen()) { input(); time_since_last_update += timer.restart(); bool isOneFramePassed = time_since_last_update >= TIME_PER_FRAME; if (isOneFramePassed) { time_since_last_update -= TIME_PER_FRAME; update(); draw(); } } } void Application::input() { sf::Event event; while (_game_window.pollEvent(event)) { if (event.type == sf::Event::Closed) _game_window.close(); _game->input(event); } } void Application::update() { _game->update(); } void Application::draw() { _game_window.clear(); _game->draw(_game_window); _game_window.display(); }