<commit_before>#include <iostream>
#include <iostream>
#include <libgen.h>
#include "SDL/SDL.h"
#include "world.hpp"
#include "graphics/graphics.hpp"

#include "tmxparser.h"


namespace Polarity {
World *world = nullptr;

World::World(const std::string& tmxFile)
        : physics(b2Vec2(0.0f, -10.0f)),
        keyState(SDLK_LAST),
        layers(nullptr) {
    std::cerr << "World has started"<<std::endl;
    for (int i=0; i< SDLK_LAST; ++i) {
      keyState[i] = false;
    }
    load(tmxFile);
}

void World::init() {
    world = new World("assets/levels/level1.tmx");
}

  GameObject* World::addObject(Behavior *behavior, const b2BodyDef&bdef, const b2FixtureDef&fixture) {
    GameObject * object = new GameObject(&physics, behavior, bdef, fixture);
    objects.emplace_back(object);
    return objects.back().get();
}

bool World::isKeyDown(int keyCode) {
    return keyState[keyCode];
}

void World::keyEvent(int keyCode, bool pressed) {
    if (keyCode < SDLK_LAST) {
        keyState[keyCode] = pressed;
    }else {
        std::cerr << "Key code out of range "<<keyCode<<"\n";
    }
}

void World::tick() {
    // timeStep, velocityIterations, positionIterations
    physics.Step(0.0166666, 1, 1);
    for (auto &obj : objects) {
      obj->tick(this);
      // std::cerr << obj->printPosition()<<std::endl;
    }
    //for(auto &gameObject:objects){
    //  
    //}
    
    // Gets called every frame
}

void World::draw(SDL_Surface *screen) {
    for (auto& layer : layers->layers) {
        layer->draw(screen, 0, 0);
    }
    for (auto& object : objects) {
        object->draw(screen);
    }
}

void World::load(const std::string &tmxFile) {
    char *filecpy = new char[tmxFile.length() + 1];
    strncpy(filecpy, tmxFile.c_str(), tmxFile.length() + 1);
    std::string dir (dirname(filecpy));
    delete []filecpy;

    std::cerr << "Loading: " << tmxFile << " from directory " << dir << std::endl;
    tmxparser::TmxMap map;
    tmxparser::TmxReturn error = tmxparser::parseFromFile(tmxFile, &map);

    layers = std::unique_ptr<LayerCollection>(new LayerCollection(dir, map));
    for (auto &it : map.tilesetCollection) {
        std::cerr << "Found tileset: " << it.name << std::endl;
    }
    for (auto &it : map.layerCollection) {
        std::cerr << "Found layer: " << it.name << std::endl;
    }
    for (auto &it : map.objectGroupCollection) {
        std::cerr << "Found object group (name): " << it.name << std::endl;
        std::cerr << "Found object group (objects): " << it.objects.size() << std::endl;
        for (auto &oit : it.objects) {
            b2BodyDef body_def;
            body_def.type = b2_dynamicBody;
            body_def.position.Set(oit.x, oit.y);
            b2PolygonShape dynamic_box;
            dynamic_box.SetAsBox(oit.width, oit.height);
            b2FixtureDef fixture_def;
            fixture_def.shape = &dynamic_box;
            fixture_def.density = 1.0f;
            fixture_def.friction = 0.3f;
            GameObject* game_obj = addObject(new Polarity::KeyboardBehavior(), body_def, fixture_def);

            std::cerr << "object name = " << oit.name << std::endl;
        }
    }
}
}
<commit_msg>clean up<commit_after>#include <iostream>
#include <iostream>
#include <libgen.h>
#include "SDL/SDL.h"
#include "world.hpp"
#include "graphics/graphics.hpp"

#include "tmxparser.h"


namespace Polarity {
World *world = nullptr;

World::World(const std::string& tmxFile)
        : physics(b2Vec2(0.0f, -10.0f)),
        keyState(SDLK_LAST),
        layers(nullptr) {
    std::cerr << "World has started"<<std::endl;
    for (int i=0; i< SDLK_LAST; ++i) {
      keyState[i] = false;
    }
    load(tmxFile);
}

void World::init() {
    world = new World("assets/levels/level1.tmx");
}

  GameObject* World::addObject(Behavior *behavior, const b2BodyDef&bdef, const b2FixtureDef&fixture) {
    GameObject * object = new GameObject(&physics, behavior, bdef, fixture);
    objects.emplace_back(object);
    return objects.back().get();
}

bool World::isKeyDown(int keyCode) {
    return keyState[keyCode];
}

void World::keyEvent(int keyCode, bool pressed) {
    if (keyCode < SDLK_LAST) {
        keyState[keyCode] = pressed;
    }else {
        std::cerr << "Key code out of range "<<keyCode<<"\n";
    }
}

void World::tick() {
    // timeStep, velocityIterations, positionIterations
    physics.Step(0.0166666, 1, 1);
    for (auto &obj : objects) {
      obj->tick(this);
      std::cerr << obj->printPosition()<<std::endl;
    }
    //for(auto &gameObject:objects){
    //  
    //}
    
    // Gets called every frame
}

void World::draw(SDL_Surface *screen) {
    for (auto& layer : layers->layers) {
        layer->draw(screen, 0, 0);
    }
    for (auto& object : objects) {
        object->draw(screen);
    }
}

void World::load(const std::string &tmxFile) {
    char *filecpy = new char[tmxFile.length() + 1];
    strncpy(filecpy, tmxFile.c_str(), tmxFile.length() + 1);
    std::string dir (dirname(filecpy));
    delete []filecpy;

    std::cerr << "Loading: " << tmxFile << " from directory " << dir << std::endl;
    tmxparser::TmxMap map;
    tmxparser::TmxReturn error = tmxparser::parseFromFile(tmxFile, &map);

    layers = std::unique_ptr<LayerCollection>(new LayerCollection(dir, map));
    for (auto &it : map.tilesetCollection) {
        std::cerr << "Found tileset: " << it.name << std::endl;
    }
    for (auto &it : map.layerCollection) {
        std::cerr << "Found layer: " << it.name << std::endl;
    }
    for (auto &it : map.objectGroupCollection) {
        std::cerr << "Found object group: " << it.name << std::endl;
        for (auto &oit : it.objects) {
            b2BodyDef body_def;
            body_def.type = b2_dynamicBody;
            body_def.position.Set(oit.x, oit.y);
            b2PolygonShape dynamic_box;
            dynamic_box.SetAsBox(oit.width, oit.height);
            b2FixtureDef fixture_def;
            fixture_def.shape = &dynamic_box;
            fixture_def.density = 1.0f;
            fixture_def.friction = 0.3f;
            GameObject* game_obj = addObject(new Polarity::KeyboardBehavior(), body_def, fixture_def);

            std::cerr << "object name = " << oit.name << std::endl;
        }
    }
}
}

{'fraction_non_alphanumeric': 0.15774286630330234, 'fraction_numerical': 0.01058031420327028, 'mean_word_length': 2.887227414330218, 'pattern_counts': {'":': 0, '<': 117, '<?xml version=': 0, '>': 21, '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': '1725813', 'n_tokens_mistral': 2186, 'n_tokens_neox': 2137, 'n_words': 441}