Skip to content

Commit

Permalink
Reformat all the files
Browse files Browse the repository at this point in the history
  • Loading branch information
aceiii committed Apr 6, 2024
1 parent 9099da4 commit b174b71
Show file tree
Hide file tree
Showing 14 changed files with 160 additions and 219 deletions.
1 change: 1 addition & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ insert_final_newline = true
charset = utf-8
indent_style = space
indent_size = 2
trim_trailing_whitespace = true
67 changes: 26 additions & 41 deletions src/applog.cpp
Original file line number Diff line number Diff line change
@@ -1,40 +1,30 @@
#include "applog.h"

AppLog::AppLog() : auto_scroll(true)
{
clear();
}
AppLog::AppLog() : auto_scroll(true) { clear(); }

void AppLog::add_log(const std::string &log)
{
void AppLog::add_log(const std::string &log) {
int old_size = buffer.size();
buffer.append(log.c_str());
for (int new_size = buffer.size(); old_size < new_size; old_size += 1)
{
if (buffer[old_size] == '\n')
{
for (int new_size = buffer.size(); old_size < new_size; old_size += 1) {
if (buffer[old_size] == '\n') {
line_offsets.push_back(old_size + 1);
}
}
}

void AppLog::clear()
{
void AppLog::clear() {
buffer.clear();
line_offsets.clear();
line_offsets.push_back(0);
}

void AppLog::draw()
{
if (ImGui::BeginPopup("Options"))
{
void AppLog::draw() {
if (ImGui::BeginPopup("Options")) {
ImGui::Checkbox("Auto-scroll", &auto_scroll);
ImGui::EndPopup();
}

if (ImGui::Button("Options"))
{
if (ImGui::Button("Options")) {
ImGui::OpenPopup("Options");
}

Expand All @@ -47,52 +37,47 @@ void AppLog::draw()

ImGui::Separator();

if (ImGui::BeginChild("scrolling", ImVec2(0, 0), ImGuiChildFlags_None, ImGuiWindowFlags_HorizontalScrollbar))
{
if (should_clear)
{
if (ImGui::BeginChild("scrolling", ImVec2(0, 0), ImGuiChildFlags_None,
ImGuiWindowFlags_HorizontalScrollbar)) {
if (should_clear) {
clear();
}

if (did_copy)
{
if (did_copy) {
ImGui::LogToClipboard();
}

ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0));
const char *buf = buffer.begin();
const char *buf_end = buffer.end();
if (filter.IsActive())
{
for (int line_no = 0; line_no < line_offsets.Size; line_no++)
{
if (filter.IsActive()) {
for (int line_no = 0; line_no < line_offsets.Size; line_no++) {
const char *line_start = buf + line_offsets[line_no];
const char *line_end = (line_no + 1 < line_offsets.Size) ? (buf + line_offsets[line_no + 1] - 1) : buf_end;
if (filter.PassFilter(line_start, line_end))
{
const char *line_end = (line_no + 1 < line_offsets.Size)
? (buf + line_offsets[line_no + 1] - 1)
: buf_end;
if (filter.PassFilter(line_start, line_end)) {
ImGui::TextUnformatted(line_start, line_end);
}
}
}
else
{
} else {
ImGuiListClipper clipper;
clipper.Begin(line_offsets.Size);
while (clipper.Step())
{
for (int line_no = clipper.DisplayStart; line_no < clipper.DisplayEnd; line_no++)
{
while (clipper.Step()) {
for (int line_no = clipper.DisplayStart; line_no < clipper.DisplayEnd;
line_no++) {
const char *line_start = buf + line_offsets[line_no];
const char *line_end = (line_no + 1 < line_offsets.Size) ? (buf + line_offsets[line_no + 1] - 1) : buf_end;
const char *line_end = (line_no + 1 < line_offsets.Size)
? (buf + line_offsets[line_no + 1] - 1)
: buf_end;
ImGui::TextUnformatted(line_start, line_end);
}
}
clipper.End();
}
ImGui::PopStyleVar();

if (auto_scroll && ImGui::GetScrollY() >= ImGui::GetScrollMaxY())
{
if (auto_scroll && ImGui::GetScrollY() >= ImGui::GetScrollMaxY()) {
ImGui::SetScrollHereY(1.0f);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/applog.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class AppLog {
public:
AppLog();

void add_log(const std::string& string);
void add_log(const std::string &string);
void clear();
void draw();

Expand Down
30 changes: 15 additions & 15 deletions src/assembly.cpp
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
#include "assembly.h"

#include <spdlog/spdlog.h>
#include <cstdint>
#include <imgui.h>
#include <spdlog/spdlog.h>

#ifdef _MSC_VER
#define _PRISizeT "I"
#define ImSnprintf _snprintf
#define _PRISizeT "I"
#define ImSnprintf _snprintf
#else
#define _PRISizeT "z"
#define ImSnprintf snprintf
#define _PRISizeT "z"
#define ImSnprintf snprintf
#endif

void AssemblyViewer::initialize(const registers *regs_) {
spdlog::trace("Initialzing AssemblyViewer");
spdlog::trace("Initializing AssemblyViewer");
regs = regs_;
}

void AssemblyViewer::draw() {
if (ImGui::BeginPopup("Options")) {
ImGui::Checkbox("Auto-scroll", &auto_scroll);
ImGui::EndPopup();
ImGui::Checkbox("Auto-scroll", &auto_scroll);
ImGui::EndPopup();
}

if (ImGui::Button("Options")) {
ImGui::OpenPopup("Options");
}

if (ImGui::BeginChild("scrolling", ImVec2(0, 0), ImGuiChildFlags_None, ImGuiWindowFlags_HorizontalScrollbar))
{
if (ImGui::BeginChild("scrolling", ImVec2(0, 0), ImGuiChildFlags_None,
ImGuiWindowFlags_HorizontalScrollbar)) {
ImGuiStyle &style = ImGui::GetStyle();

const int line_total_count = regs->mem.size() / 2;
auto line_total_count = static_cast<int>(regs->mem.size() / 2);
float line_height = ImGui::GetTextLineHeight();

ImGuiListClipper clipper;
clipper.Begin(line_total_count, line_height);

const char* format_address = "%0*" _PRISizeT "X: ";
const char* format_data = " %0*" _PRISizeT "X";
const char *format_address = "%0*" _PRISizeT "X: ";
const char *format_data = " %0*" _PRISizeT "X";

ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0, 0));
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0));
Expand Down Expand Up @@ -81,7 +81,7 @@ void AssemblyViewer::draw() {
}

if (auto_scroll) {
float scroll_y = line_height * (regs->pc >> 1);
float scroll_y = line_height * static_cast<float>(regs->pc >> 1);
ImGui::SetScrollY(scroll_y);
}

Expand All @@ -91,5 +91,5 @@ void AssemblyViewer::draw() {
}

void AssemblyViewer::cleanup() {
spdlog::trace("Initialzing AssemblyViewer");
spdlog::trace("Initializing AssemblyViewer");
}
3 changes: 2 additions & 1 deletion src/assembly.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "registers.h"

class AssemblyViewer {
public:
void initialize(const registers *regs);
Expand All @@ -10,5 +11,5 @@ class AssemblyViewer {
private:
bool auto_scroll = true;

const registers *regs;
const registers *regs = nullptr;
};
6 changes: 3 additions & 3 deletions src/interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ float square(float val) {
}

Interface::Interface(std::shared_ptr<registers> regs, Interpreter *interpreter)
: interpreter{interpreter}, regs(regs) {}
: interpreter{interpreter}, regs(std::move(regs)) {}

void Interface::initialize() {
NFD_Init();
Expand All @@ -63,7 +63,7 @@ void Interface::initialize() {
const float frequency = 440.0f;

float incr = frequency / float(kAudioSampleRate);
short *d = static_cast<short*>(buffer);
auto d = static_cast<short*>(buffer);

for (unsigned int i = 0; i < frames; i++) {
if (!play_sound) {
Expand Down Expand Up @@ -151,7 +151,7 @@ bool Interface::update() {

rlImGuiBegin();

int dockspace_id = ImGui::DockSpaceOverViewport(ImGui::GetMainViewport());
ImGuiID dockspace_id = ImGui::DockSpaceOverViewport(ImGui::GetMainViewport());

if (init_dock) {
init_dock = false;
Expand Down
5 changes: 1 addition & 4 deletions src/interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Interface {

void initialize();
bool update();
void cleanup();
static void cleanup();

private:
void open_load_rom_dialog();
Expand All @@ -33,9 +33,6 @@ class Interface {
Screen screen;
AssemblyViewer assembly;

ImFont *font_default;
ImFont *font_icons;

std::vector<uint8_t> rom;

bool init_dock = true;
Expand Down
Loading

0 comments on commit b174b71

Please sign in to comment.