<commit_before>#include <sdl_renderer.h>

#include <cstring>

void draw_nam(SDL_Texture* tex, const PPU & ppu)
{
    void* pixels;
    int pitch = 0;

    SDL_LockTexture(tex, nullptr, &pixels, &pitch);
    ppu.nametable_img((byte_t*)pixels, pitch, 0);
    SDL_UnlockTexture(tex);
}

void draw_pat(SDL_Texture* tex, const PPU & ppu)
{
    void* pixels;
    int pitch = 0;

    // PAT 0000
    SDL_Rect rect = {0, 0, 128, 128};
    SDL_LockTexture(tex, &rect, &pixels, &pitch);
    ppu.patterntable_img((byte_t*)pixels, pitch, 0);
    SDL_UnlockTexture(tex);

    // PAT 1000
    rect.y += 128 + 10;
    SDL_LockTexture(tex, &rect, &pixels, &pitch);
    ppu.patterntable_img((byte_t*)pixels, pitch, 1);
    SDL_UnlockTexture(tex);
}

void draw_oam(SDL_Texture* tex, const PPU & ppu)
{   
    void* pixels;
    int pitch = 0;

    SDL_LockTexture(tex, nullptr, &pixels, &pitch);
    ppu.sprite_img((byte_t*)pixels, pitch);
    SDL_UnlockTexture(tex);
}

Viewport::Viewport(SDL_Window* window)
{
    if ((renderer_ = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED)) == nullptr)
        throw std::runtime_error("Can't initialize SDL renderer.");
}

Viewport::~Viewport()
{
    if (tex_ != nullptr)
    {
        SDL_DestroyTexture(tex_);
    }

    SDL_DestroyRenderer(renderer_);
}

void Viewport::init_texture(int width, int height)
{
    if (tex_ != nullptr)
    {
        SDL_DestroyTexture(tex_);
    }

    tex_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGB24, SDL_TEXTUREACCESS_STREAMING, width, height);
}

void Viewport::flip()
{
    SDL_SetRenderDrawColor(renderer_, 0x0, 0x0, 0x0, 0xFF);
    SDL_RenderClear(renderer_);
    SDL_RenderCopy(renderer_, tex_, nullptr, nullptr);
    SDL_RenderPresent(renderer_);
}

SDLRenderer::SDLRenderer()
    : lastUpdate_(0ul)
{
    if (SDL_Init(SDL_INIT_VIDEO) < 0)
        throw std::runtime_error("Can't initialize SDL.");

    Viewport *v;

    // Main game
    // TODO

    // Name table (debug)
    v = init_window(256*3, 256*3);
    v->init_texture(256, 256);
    resources_.emplace_back(std::make_pair(draw_nam, v->get_texture()));

    // Pattern table (debug)
    v = init_window(128*3, (128*2+10)*3);
    v->init_texture(128, 128*2+10);
    resources_.emplace_back(std::make_pair(draw_pat, v->get_texture()));
}<commit_msg>fixed resolution and reduced window sizes<commit_after>#include <sdl_renderer.h>

#include <cstring>

void draw_nam(SDL_Texture* tex, const PPU & ppu)
{
    void* pixels;
    int pitch = 0;

    SDL_LockTexture(tex, nullptr, &pixels, &pitch);
    ppu.nametable_img((byte_t*)pixels, pitch, 0);
    SDL_UnlockTexture(tex);
}

void draw_pat(SDL_Texture* tex, const PPU & ppu)
{
    void* pixels;
    int pitch = 0;

    // PAT 0000
    SDL_Rect rect = {0, 0, 128, 128};
    SDL_LockTexture(tex, &rect, &pixels, &pitch);
    ppu.patterntable_img((byte_t*)pixels, pitch, 0);
    SDL_UnlockTexture(tex);

    // PAT 1000
    rect.y += 128 + 10;
    SDL_LockTexture(tex, &rect, &pixels, &pitch);
    ppu.patterntable_img((byte_t*)pixels, pitch, 1);
    SDL_UnlockTexture(tex);
}

void draw_oam(SDL_Texture* tex, const PPU & ppu)
{   
    void* pixels;
    int pitch = 0;

    SDL_LockTexture(tex, nullptr, &pixels, &pitch);
    ppu.sprite_img((byte_t*)pixels, pitch);
    SDL_UnlockTexture(tex);
}

Viewport::Viewport(SDL_Window* window)
{
    if ((renderer_ = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED)) == nullptr)
        throw std::runtime_error("Can't initialize SDL renderer.");
}

Viewport::~Viewport()
{
    if (tex_ != nullptr)
    {
        SDL_DestroyTexture(tex_);
    }

    SDL_DestroyRenderer(renderer_);
}

void Viewport::init_texture(int width, int height)
{
    if (tex_ != nullptr)
    {
        SDL_DestroyTexture(tex_);
    }

    tex_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGB24, SDL_TEXTUREACCESS_STREAMING, width, height);
}

void Viewport::flip()
{
    SDL_SetRenderDrawColor(renderer_, 0x0, 0x0, 0x0, 0xFF);
    SDL_RenderClear(renderer_);
    SDL_RenderCopy(renderer_, tex_, nullptr, nullptr);
    SDL_RenderPresent(renderer_);
}

SDLRenderer::SDLRenderer()
    : lastUpdate_(0ul)
{
    if (SDL_Init(SDL_INIT_VIDEO) < 0)
        throw std::runtime_error("Can't initialize SDL.");

    Viewport *v;

    // Main game
    // TODO

    // Name table (debug)
    v = init_window(256*2, 240*2);
    v->init_texture(256, 240);
    resources_.emplace_back(std::make_pair(draw_nam, v->get_texture()));

    // Pattern table (debug)
    v = init_window(128*2, (128*2+10)*2);
    v->init_texture(128, 128*2+10);
    resources_.emplace_back(std::make_pair(draw_pat, v->get_texture()));
}
{'fraction_non_alphanumeric': 0.1436008676789588, 'fraction_numerical': 0.0316702819956616, 'mean_word_length': 3.7931392931392933, 'pattern_counts': {'":': 0, '<': 9, '<?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': '6397482', 'n_tokens_mistral': 1878, 'n_tokens_neox': 1678, 'n_words': 329}