<commit_before>#ifdef EMSCRIPTEN
#include "emscripten.h"
#endif

#include "audio/audio.hpp"
#include "main/main.hpp"
#include "world/world.hpp"
#include "physics/behavior.hpp"
using namespace std;

const int AUDIO_RATE = 44100; // FIXME: Does this matter?
const int CANVAS_WIDTH = 1280;
const int CANVAS_HEIGHT = 720;


static SDL_Surface *screen;

namespace Polarity {

std::shared_ptr<AudioChannelPlayer> audioPlayer;
std::shared_ptr<PlayerState> playerState (new PlayerState());
std::shared_ptr<GameState> gameState;

extern void loadAssets();

#ifdef EMSCRIPTEN
void emLoopIter() {
    if (!loopIter(screen)) {
        SDL_Quit();
    }
}

void mainloop() {
    emscripten_set_main_loop(&emLoopIter, 0, 1);
}

#else
void mainloop() {
    atexit(SDL_Quit);
    while (true) {
        if (!loopIter(screen)) {
            break;
        }
    }
}
#endif
}

int main() {
    int retval = SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO |
                          SDL_INIT_TIMER);
    if (retval) {
        cerr << "Failed to init SDL" << endl;
        return 1;
    }
    if (TTF_Init()) {
        cerr << "Failed to init TTF" << endl;
        return 1;
    }
    SDL_EnableUNICODE(SDL_ENABLE);
    if (Mix_OpenAudio(AUDIO_RATE, AUDIO_S16, 2, 4096)) {
        cerr << "Failed to init Audio" << endl;
        return 1;
    }
    screen = SDL_SetVideoMode(
            CANVAS_WIDTH, CANVAS_HEIGHT, 0,
            SDL_HWSURFACE | SDL_RESIZABLE);

    SDL_MapRGB(screen->format, 65, 65, 65);
    srand(time(NULL));
    Polarity::loadAssets();
    Polarity::World::init(Polarity::audioPlayer, Polarity::playerState, Polarity::gameState);
/*
    b2BodyDef bodyDef;
    bodyDef.type = b2_dynamicBody;
    bodyDef.position.Set(0.0f, 40.0f);
    b2PolygonShape dynamicBox;
    dynamicBox.SetAsBox(2.0f, 2.0f);

    b2FixtureDef fixtureDef;
    fixtureDef.shape = &dynamicBox;
    fixtureDef.density = 1.0f;
    fixtureDef.friction = 0.3f;

    Polarity::world->addObject(new Polarity::KeyboardBehavior(), bodyDef, fixtureDef);

    b2BodyDef bodyDef2;
    bodyDef2.type = b2_staticBody;
    bodyDef2.position.Set(0.0f, 10.0f);
    Polarity::world->addObject(new Polarity::KeyboardBehavior(), bodyDef2, fixtureDef);
*/
    Polarity::mainloop();
}
<commit_msg>added flip buffer call to SDL<commit_after>#ifdef EMSCRIPTEN
#include "emscripten.h"
#endif

#include "audio/audio.hpp"
#include "main/main.hpp"
#include "world/world.hpp"
#include "physics/behavior.hpp"
using namespace std;

const int AUDIO_RATE = 44100; // FIXME: Does this matter?
const int CANVAS_WIDTH = 1280;
const int CANVAS_HEIGHT = 720;


static SDL_Surface *screen;

namespace Polarity {

std::shared_ptr<AudioChannelPlayer> audioPlayer;
std::shared_ptr<PlayerState> playerState (new PlayerState());
std::shared_ptr<GameState> gameState;

extern void loadAssets();

#ifdef EMSCRIPTEN
void emLoopIter() {
    if (!loopIter(screen)) {
        SDL_Quit();
    }
}

void mainloop() {
    emscripten_set_main_loop(&emLoopIter, 0, 1);
}

#else
void mainloop() {
    atexit(SDL_Quit);
    while (true) {
        if (!loopIter(screen)) {
            break;
        } else {
            SDL_Flip(screen);
        }
    }
}
#endif
}

int main() {
    int retval = SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO |
                          SDL_INIT_TIMER);
    if (retval) {
        cerr << "Failed to init SDL" << endl;
        return 1;
    }
    if (TTF_Init()) {
        cerr << "Failed to init TTF" << endl;
        return 1;
    }
    SDL_EnableUNICODE(SDL_ENABLE);
    if (Mix_OpenAudio(AUDIO_RATE, AUDIO_S16, 2, 4096)) {
        cerr << "Failed to init Audio" << endl;
        return 1;
    }
    screen = SDL_SetVideoMode(
            CANVAS_WIDTH, CANVAS_HEIGHT, 0,
            SDL_HWSURFACE | SDL_RESIZABLE);

    SDL_MapRGB(screen->format, 65, 65, 65);
    srand(time(NULL));
    Polarity::loadAssets();
    Polarity::World::init(Polarity::audioPlayer, Polarity::playerState, Polarity::gameState);
/*
    b2BodyDef bodyDef;
    bodyDef.type = b2_dynamicBody;
    bodyDef.position.Set(0.0f, 40.0f);
    b2PolygonShape dynamicBox;
    dynamicBox.SetAsBox(2.0f, 2.0f);

    b2FixtureDef fixtureDef;
    fixtureDef.shape = &dynamicBox;
    fixtureDef.density = 1.0f;
    fixtureDef.friction = 0.3f;

    Polarity::world->addObject(new Polarity::KeyboardBehavior(), bodyDef, fixtureDef);

    b2BodyDef bodyDef2;
    bodyDef2.type = b2_staticBody;
    bodyDef2.position.Set(0.0f, 10.0f);
    Polarity::world->addObject(new Polarity::KeyboardBehavior(), bodyDef2, fixtureDef);
*/
    Polarity::mainloop();
}

{'fraction_non_alphanumeric': 0.12810371346956712, 'fraction_numerical': 0.025928367391782024, 'mean_word_length': 3.2304832713754648, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 15, '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': '6384851', 'n_tokens_mistral': 1726, 'n_tokens_neox': 1631, 'n_words': 327}