<commit_before>#include <sstream>
#include <iostream>

#include "wx/msgdlg.h"
#include "wx/filedlg.h"
#include "wx/dcclient.h"
#include "wx/dcmemory.h"
#include "boost/filesystem.hpp"

#include "nes.h"
#include "main_window.h"
#include "settings_window.h"
#include "utilities/app_settings.h"

wxDEFINE_EVENT(wxEVT_NES_UNEXPECTED_SHUTDOWN, wxThreadEvent);

void MainWindow::OnEmulatorFrameComplete(uint8_t* frameBuffer)
{
	using namespace std::chrono;

    wxImage image(256, 240, frameBuffer, true);
    wxBitmap bitmap(image, 24);
    wxMemoryDC mdc(bitmap);
    wxClientDC cdc(this);
    cdc.StretchBlit(0, 0, GetVirtualSize().GetWidth(), GetVirtualSize().GetHeight(), &mdc, 0, 0, 256, 240);

    if (ppuDebugWindow != nullptr)
    {
        std::lock_guard<std::mutex> lock(PpuDebugMutex);

        if (ppuDebugWindow != nullptr)
        {
            for (int i = 0; i < 64; ++i)
            {
                if (i < 2)
                {
                    uint8_t patternTable[256 * 128 * 3];
                    nes->GetPatternTable(i, ppuDebugWindow->GetCurrentPalette(), patternTable);
                    ppuDebugWindow->UpdatePatternTable(i, patternTable);
                }

                if (i < 4)
                {
                    uint8_t nameTable[256 * 240 * 3];
                    nes->GetNameTable(i, nameTable);
                    ppuDebugWindow->UpdateNameTable(i, nameTable);
                }

                if (i < 8)
                {
                    uint8_t palette[64 * 16 * 3];
                    nes->GetPalette(i, palette);
                    ppuDebugWindow->UpdatePalette(i, palette);
                }

                uint8_t sprite[8 * 8 * 3];
                nes->GetPrimarySprite(i, sprite);
                ppuDebugWindow->UpdatePrimarySprite(i, sprite);
            }
        }
    }

    fpsCounter++;

    steady_clock::time_point now = steady_clock::now();
    microseconds time_span = duration_cast<microseconds>(now - intervalStart);
    if (time_span.count() >= 1000000)
    {
        currentFPS = fpsCounter;
        fpsCounter = 0;
        intervalStart = steady_clock::now();

        std::ostringstream oss;
        oss << currentFPS << " FPS - " << nes->GetGameName();
        SetTitle(oss.str());
    }
}

void MainWindow::OnEmulatorError(std::string err)
{
    wxThreadEvent evt(wxEVT_NES_UNEXPECTED_SHUTDOWN);<commit_msg>Moved using namespace line in MainWindow::OnEmulatorFrameComplete<commit_after>#include <sstream>
#include <iostream>

#include "wx/msgdlg.h"
#include "wx/filedlg.h"
#include "wx/dcclient.h"
#include "wx/dcmemory.h"
#include "boost/filesystem.hpp"

#include "nes.h"
#include "main_window.h"
#include "settings_window.h"
#include "utilities/app_settings.h"

wxDEFINE_EVENT(wxEVT_NES_UNEXPECTED_SHUTDOWN, wxThreadEvent);

void MainWindow::OnEmulatorFrameComplete(uint8_t* frameBuffer)
{
    wxImage image(256, 240, frameBuffer, true);
    wxBitmap bitmap(image, 24);
    wxMemoryDC mdc(bitmap);
    wxClientDC cdc(this);
    cdc.StretchBlit(0, 0, GetVirtualSize().GetWidth(), GetVirtualSize().GetHeight(), &mdc, 0, 0, 256, 240);

    if (ppuDebugWindow != nullptr)
    {
        std::lock_guard<std::mutex> lock(PpuDebugMutex);

        if (ppuDebugWindow != nullptr)
        {
            for (int i = 0; i < 64; ++i)
            {
                if (i < 2)
                {
                    uint8_t patternTable[256 * 128 * 3];
                    nes->GetPatternTable(i, ppuDebugWindow->GetCurrentPalette(), patternTable);
                    ppuDebugWindow->UpdatePatternTable(i, patternTable);
                }

                if (i < 4)
                {
                    uint8_t nameTable[256 * 240 * 3];
                    nes->GetNameTable(i, nameTable);
                    ppuDebugWindow->UpdateNameTable(i, nameTable);
                }

                if (i < 8)
                {
                    uint8_t palette[64 * 16 * 3];
                    nes->GetPalette(i, palette);
                    ppuDebugWindow->UpdatePalette(i, palette);
                }

                uint8_t sprite[8 * 8 * 3];
                nes->GetPrimarySprite(i, sprite);
                ppuDebugWindow->UpdatePrimarySprite(i, sprite);
            }
        }
    }

	fpsCounter++;

	using namespace std::chrono;

    steady_clock::time_point now = steady_clock::now();
    microseconds time_span = duration_cast<microseconds>(now - intervalStart);
    if (time_span.count() >= 1000000)
    {
        currentFPS = fpsCounter;
        fpsCounter = 0;
        intervalStart = steady_clock::now();

        std::ostringstream oss;
        oss << currentFPS << " FPS - " << nes->GetGameName();
        SetTitle(oss.str());
    }
}

void MainWindow::OnEmulatorError(std::string err)
{
    wxThreadEvent evt(wxEVT_NES_UNEXPECTED_SHUTDOWN);
{'fraction_non_alphanumeric': 0.12176434044315593, 'fraction_numerical': 0.024435700973286394, 'mean_word_length': 2.1061093247588425, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 33, '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': '3598413', 'n_tokens_mistral': 1664, 'n_tokens_neox': 1495, 'n_words': 278}