<commit_before>#include "gamelib/core/Game.hpp"
#include <SFML/Graphics.hpp>
#include <climits>
#include "gamelib/core/GameState.hpp"
#include "gamelib/utils/log.hpp"
#include "gamelib/core/event/EventManager.hpp"
#include "gamelib/events/SFMLEvent.hpp"
#include "gamelib/core/input/InputSystem.hpp"

namespace gamelib
{
    Game::Game() :
        bgcolor(sf::Color::Black),
        closebutton(true),
        escclose(true),
        unfocusPause(true),
        _frametime(0),
        _rendertime(0),
        _updatetime(0),
        _size(640, 480),
        _maxfps(60),
        _title("Unnamed Game"),
        _repeatkeys(false),
        _vsync(true)
    {
        auto setSize = +[](const math::Vec2i* val, Game* self) {
            self->resize(sf::Vector2u(val->x, val->y));
        };
        auto setFPS = +[](const int* val, Game* self) {
            self->_maxfps = *val;
            if (self->_window.isOpen())
                self->_window.setFramerateLimit(*val);
        };
        auto setVsync = +[](const bool* val, Game* self) {
            self->_vsync = *val;
            if (self->_window.isOpen())
                self->_window.setVerticalSyncEnabled(*val);
        };
        auto setTitle = +[](const std::string* val, Game* self) {
            self->_title = *val;
            if (self->_window.isOpen())
                self->_window.setTitle(*val);
        };
        auto setRepeat = +[](const bool* val, Game* self) {
            self->_repeatkeys = *val;
            if (self->_window.isOpen())
                self->_window.setKeyRepeatEnabled(*val);
        };

        _props.registerProperty("bgcolor", bgcolor);
        _props.registerProperty("closebutton", closebutton);
        _props.registerProperty("escclose", escclose);
        _props.registerProperty("unfocusPause", unfocusPause);
        _props.registerProperty("size", _size, setSize, this);
        _props.registerProperty("maxfps", _maxfps, setFPS, this, 0, INT_MAX);
        _props.registerProperty("vsync", _vsync, setVsync, this);
        _props.registerProperty("title", _title, setTitle, this);
        _props.registerProperty("repeatkeys", _repeatkeys, setRepeat, this);
    }

    Game::~Game()
    {
        destroy();
    }


    bool Game::init()
    {
        LOG("Initializing game...");
        _window.create(sf::VideoMode(_size.x, _size.y), _title, sf::Style::Close);
        _window.setFramerateLimit(_maxfps);
        _window.setVerticalSyncEnabled(_vsync);
        _window.setKeyRepeatEnabled(_repeatkeys);
        return true;
    }

    void Game::run()
    {
        sf::Clock clock, detailclock;
        sf::Event ev;

        while (_window.isOpen())
        {
            clock.restart();
            detailclock.restart();

            auto inputsys = getSubsystem<InputSystem>();
            if (inputsys)
                inputsys->beginFrame();

            while (_window.pollEvent(ev))
            {
                if (inputsys)
                    inputsys->process(ev);

                auto evmgr = getSubsystem<EventManager>();
                if (evmgr)
                    evmgr->triggerEvent(SFMLEvent::create(ev));
            }

            if (_window.hasFocus() || !unfocusPause)
            {
                bool frozen = false;
                for (auto it = _states.rbegin(), end = _states.rend(); it != end; ++it)
                {
                    auto state = (*it).get();
                    if (state->flags & gamestate_paused)
                        continue;

                    if (!frozen || state->flags & gamestate_forceupdate)
                        state->update(_frametime);

                    if (state->flags & gamestate_freeze)
                        frozen = true;
                }

                if (escclose && inputsys && inputsys->isKeyPressed(sf::Keyboard::Escape))
                {
                    close();
                    return;
                }
            }<commit_msg>Fix closebutton not working<commit_after>#include "gamelib/core/Game.hpp"
#include <SFML/Graphics.hpp>
#include <climits>
#include "gamelib/core/GameState.hpp"
#include "gamelib/utils/log.hpp"
#include "gamelib/core/event/EventManager.hpp"
#include "gamelib/events/SFMLEvent.hpp"
#include "gamelib/core/input/InputSystem.hpp"

namespace gamelib
{
    Game::Game() :
        bgcolor(sf::Color::Black),
        closebutton(true),
        escclose(true),
        unfocusPause(true),
        _frametime(0),
        _rendertime(0),
        _updatetime(0),
        _size(640, 480),
        _maxfps(60),
        _title("Unnamed Game"),
        _repeatkeys(false),
        _vsync(true)
    {
        auto setSize = +[](const math::Vec2i* val, Game* self) {
            self->resize(sf::Vector2u(val->x, val->y));
        };
        auto setFPS = +[](const int* val, Game* self) {
            self->_maxfps = *val;
            if (self->_window.isOpen())
                self->_window.setFramerateLimit(*val);
        };
        auto setVsync = +[](const bool* val, Game* self) {
            self->_vsync = *val;
            if (self->_window.isOpen())
                self->_window.setVerticalSyncEnabled(*val);
        };
        auto setTitle = +[](const std::string* val, Game* self) {
            self->_title = *val;
            if (self->_window.isOpen())
                self->_window.setTitle(*val);
        };
        auto setRepeat = +[](const bool* val, Game* self) {
            self->_repeatkeys = *val;
            if (self->_window.isOpen())
                self->_window.setKeyRepeatEnabled(*val);
        };

        _props.registerProperty("bgcolor", bgcolor);
        _props.registerProperty("closebutton", closebutton);
        _props.registerProperty("escclose", escclose);
        _props.registerProperty("unfocusPause", unfocusPause);
        _props.registerProperty("size", _size, setSize, this);
        _props.registerProperty("maxfps", _maxfps, setFPS, this, 0, INT_MAX);
        _props.registerProperty("vsync", _vsync, setVsync, this);
        _props.registerProperty("title", _title, setTitle, this);
        _props.registerProperty("repeatkeys", _repeatkeys, setRepeat, this);
    }

    Game::~Game()
    {
        destroy();
    }


    bool Game::init()
    {
        LOG("Initializing game...");
        _window.create(sf::VideoMode(_size.x, _size.y), _title, sf::Style::Close);
        _window.setFramerateLimit(_maxfps);
        _window.setVerticalSyncEnabled(_vsync);
        _window.setKeyRepeatEnabled(_repeatkeys);
        return true;
    }

    void Game::run()
    {
        sf::Clock clock, detailclock;
        sf::Event ev;

        while (_window.isOpen())
        {
            clock.restart();
            detailclock.restart();

            auto inputsys = getSubsystem<InputSystem>();
            if (inputsys)
                inputsys->beginFrame();

            while (_window.pollEvent(ev))
            {
                if (inputsys)
                    inputsys->process(ev);

                auto evmgr = getSubsystem<EventManager>();
                if (evmgr)
                    evmgr->triggerEvent(SFMLEvent::create(ev));

                if (closebutton && ev.type == sf::Event::Closed)
                {
                    close();
                    return;
                }
            }

            if (_window.hasFocus() || !unfocusPause)
            {
                bool frozen = false;
                for (auto it = _states.rbegin(), end = _states.rend(); it != end; ++it)
                {
                    auto state = (*it).get();
                    if (state->flags & gamestate_paused)
                        continue;

                    if (!frozen || state->flags & gamestate_forceupdate)
                        state->update(_frametime);

                    if (state->flags & gamestate_freeze)
                        frozen = true;
                }

                if (escclose && inputsys && inputsys->isKeyPressed(sf::Keyboard::Escape))
                {
                    close();
                    return;
                }
            }
{'fraction_non_alphanumeric': 0.13477455219271156, 'fraction_numerical': 0.0034589252625077207, 'mean_word_length': 1.7406905890318212, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5417354', 'n_tokens_mistral': 2415, 'n_tokens_neox': 2304, 'n_words': 411}