<commit_before>#include <cstdio>
#include <string>
#include <allegro5/allegro.h>
#include <allegro5/allegro_image.h>

#include "inputcatcher.h"
#include "engine.h"
#include "renderer.h"
#include "datastructures.h"
#include "global_constants.h"

long int getmillisec();

int main(int argc, char **argv)
{
    // Initialize Allegro
    if (!al_init())
    {
        fprintf(stderr, "Fatal Error: Allegro initialization failed!\n");
        return -1;
    }

    // Initialize the Allegro Image addon, used to load sprites and maps
    if (!al_init_image_addon())
    {
        fprintf(stderr, "Fatal Error: Allegro Image Addon initialization failed!\n");
        return -1;
    }

    InputCatcher *inputcatcher;
    Engine *engine;
    Renderer *renderer;

    try
    {
        // Initialize everything
        // The various allegro initializations can throw errors
        engine = new Engine();
        renderer = new Renderer();
        inputcatcher = new InputCatcher(renderer->display);
    }
    catch (int e)
    {
        if (e == -1)
        {
            fprintf(stderr, "\nAllegro initialization failed.");
        }
        else
        {
            fprintf(stderr, "\nUNKNOWN ERROR HAPPENED");
        }
        return -1;
    }
    engine->loadmap("conflict");
    PlayerPtr myself = engine->newplayer();

    double lasttimeupdated = al_get_time();
    while (true)
    {
        while (al_get_time() - lasttimeupdated >= ENGINE_TIMESTEP)
        {
            inputcatcher->run(myself, engine, renderer);
            engine->update(ENGINE_TIMESTEP);

            lasttimeupdated += ENGINE_TIMESTEP;
        }
        renderer->render(&(engine->currentstate), myself);
    }
    return 0;
}<commit_msg>Fixed main input catching and window closing gracefully.<commit_after>#include <cstdio>
#include <string>
#include <allegro5/allegro.h>
#include <allegro5/allegro_image.h>

#include "inputcatcher.h"
#include "engine.h"
#include "renderer.h"
#include "datastructures.h"
#include "global_constants.h"

long int getmillisec();

int main(int argc, char **argv)
{
    // Initialize Allegro
    if (!al_init())
    {
        fprintf(stderr, "Fatal Error: Allegro initialization failed!\n");
        return -1;
    }

    // Initialize the Allegro Image addon, used to load sprites and maps
    if (!al_init_image_addon())
    {
        fprintf(stderr, "Fatal Error: Allegro Image Addon initialization failed!\n");
        return -1;
    }

    InputCatcher *inputcatcher;
    Engine *engine;
    Renderer *renderer;

    try
    {
        // Initialize everything
        // The various allegro initializations can throw errors
        engine = new Engine();
        renderer = new Renderer();
        inputcatcher = new InputCatcher(renderer->display);
    }
    catch (int e)
    {
        if (e == -1)
        {
            fprintf(stderr, "\nAllegro initialization failed.");
        }
        else
        {
            fprintf(stderr, "\nUNKNOWN ERROR HAPPENED");
        }
        return -1;
    }
    engine->loadmap("conflict");
    PlayerPtr myself = engine->newplayer();

    double lasttimeupdated = al_get_time();
    while (true)
    {
        try
        {
            while (al_get_time() - lasttimeupdated >= ENGINE_TIMESTEP)
            {
                inputcatcher->run(myself, engine, renderer);
                engine->update(ENGINE_TIMESTEP);

                lasttimeupdated += ENGINE_TIMESTEP;
            }
            renderer->render(&(engine->currentstate), myself);
        }
        catch (int e)
        {
            if (e != 0)
            {
                fprintf(stderr, "\nError during regular loop.");
                fprintf(stderr, "\nExiting..");
            }
            return 0;
        }
    }
    return 0;
}
{'fraction_non_alphanumeric': 0.11591511936339523, 'fraction_numerical': 0.004244031830238726, 'mean_word_length': 2.0884520884520885, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 27, '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': '6655680', 'n_tokens_mistral': 1158, 'n_tokens_neox': 1119, 'n_words': 275}