Skip to content

Commit

Permalink
externals: added magic_enum
Browse files Browse the repository at this point in the history
  • Loading branch information
JaCzekanski committed Sep 3, 2019
1 parent be5fb14 commit 002766b
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 72 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@
[submodule "externals/EventBus"]
path = externals/EventBus
url = https://github.com/gelldur/EventBus.git
[submodule "externals/magic_enum"]
path = externals/magic_enum
url = https://github.com/Neargye/magic_enum.git
1 change: 1 addition & 0 deletions externals/magic_enum
Submodule magic_enum added at 3edfd5
4 changes: 3 additions & 1 deletion premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ project "core"
"externals/json/include",
"externals/miniz",
"externals/libchdr/src",
"externals/EventBus/lib/include",
"externals/EventBus/lib/include",
"externals/magic_enum/include",
}

files {
Expand Down Expand Up @@ -189,6 +190,7 @@ project "avocado"
"externals/libchdr/src",
"externals/filesystem/include",
"externals/EventBus/lib/include",
"externals/magic_enum/include",
}

links {
Expand Down
4 changes: 0 additions & 4 deletions src/device/gpu/gpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@
#include "utils/macros.h"

namespace gpu {

const char* CommandStr[] = {"None", "FillRectangle", "Polygon", "Line", "Rectangle",
"CopyCpuToVram1", "CopyCpuToVram2", "CopyVramToCpu", "CopyVramToVram", "Extra"};

GPU::GPU() {
busToken = bus.listen<Event::Config::Graphics>([&](auto) { reload(); });
reload();
Expand Down
2 changes: 0 additions & 2 deletions src/device/gpu/gpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ class OpenGL;

namespace gpu {

extern const char* CommandStr[];

const int VRAM_WIDTH = 1024;
const int VRAM_HEIGHT = 512;

Expand Down
6 changes: 4 additions & 2 deletions src/platform/windows/gui/debug.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <imgui.h>
#include <magic_enum.hpp>
#include <nlohmann/json.hpp>
#include <vector>
#include "../../../cpu/gte/gte.h"
Expand Down Expand Up @@ -236,7 +237,8 @@ void gpuLogWindow(System *sys) {
while (clipper.Step()) {
for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) {
auto &entry = sys->gpu.get()->gpuLogList[i];
bool nodeOpen = ImGui::TreeNode((void *)(intptr_t)i, "%4d cmd: 0x%02x %s", i, entry.command, gpu::CommandStr[(int)entry.cmd]);
bool nodeOpen = ImGui::TreeNode((void *)(intptr_t)i, "%4d cmd: 0x%02x %s", i, entry.command,
std::string(magic_enum::enum_name(entry.cmd)).c_str());
bool isHovered = ImGui::IsItemHovered();

if (isHovered) {
Expand Down Expand Up @@ -372,7 +374,7 @@ void gpuLogWindow(System *sys) {

for (size_t i = 0; i < gpuLog.size(); i++) {
auto e = gpuLog[i];
j.push_back({{"command", e.command}, {"cmd", (int)e.cmd}, {"name", gpu::CommandStr[(int)e.cmd]}, {"args", e.args}});
j.push_back({{"command", e.command}, {"cmd", (int)e.cmd}, {"name", magic_enum::enum_name(e.cmd)}, {"args", e.args}});
}

putFileContents(string_format("%s.json", filename), j.dump(2));
Expand Down
77 changes: 14 additions & 63 deletions src/platform/windows/gui/debug/timers/timers.cpp
Original file line number Diff line number Diff line change
@@ -1,84 +1,35 @@
#include "timers.h"
#include <imgui.h>
#include <magic_enum.hpp>
#include <numeric>
#include "platform/windows/gui/tools.h"
#include "system.h"
#include "utils/string.h"

namespace gui::debug::timers {

#define ENUM_NAME(x) (std::string(magic_enum::enum_name(x)))

std::string getSyncMode(Timer* timer) {
int which = timer->which;
timer::CounterMode mode = timer->mode;

if (which == 0) {
using modes = timer::CounterMode::SyncMode0;
auto mode0 = static_cast<modes>(mode.syncMode);

switch (mode0) {
case modes::pauseDuringHblank: return "pauseDuringHblank";
case modes::resetAtHblank: return "resetAtHblank";
case modes::resetAtHblankAndPauseOutside: return "resetAtHblankAndPauseOutside";
case modes::pauseUntilHblankAndFreerun: return "pauseUntilHblankAndFreerun";
}
switch (timer->which) {
case 0: return ENUM_NAME(static_cast<timer::CounterMode::SyncMode0>(mode.syncMode));
case 1: return ENUM_NAME(static_cast<timer::CounterMode::SyncMode1>(mode.syncMode));
case 2: return ENUM_NAME(static_cast<timer::CounterMode::SyncMode2>(mode.syncMode));
default: return "";
}
if (which == 1) {
using modes = timer::CounterMode::SyncMode1;
auto mode1 = static_cast<modes>(mode.syncMode);

switch (mode1) {
case modes::pauseDuringVblank: return "pauseDuringVblank";
case modes::resetAtVblank: return "resetAtVblank";
case modes::resetAtVblankAndPauseOutside: return "resetAtVblankAndPauseOutside";
case modes::pauseUntilVblankAndFreerun: return "pauseUntilVblankAndFreerun";
}
}
if (which == 2) {
using modes = timer::CounterMode::SyncMode2;
auto mode2 = static_cast<modes>(mode.syncMode);

switch (mode2) {
case modes::stopCounter:
case modes::stopCounter_: return "stopCounter";
case modes::freeRun:
case modes::freeRun_: return "freeRun";
}
}
return "";
}

std::string getClockSource(Timer* timer) {
int which = timer->which;
timer::CounterMode mode = timer->mode;
if (which == 0) {
using modes = timer::CounterMode::ClockSource0;
auto clock = static_cast<modes>(mode.clockSource & 1);

if (clock == modes::dotClock) {
return "Dotclock";
} else {
return "Sysclock";
}
} else if (which == 1) {
using modes = timer::CounterMode::ClockSource1;
auto clock = static_cast<modes>(mode.clockSource & 1);

if (clock == modes::hblank) {
return "HBlank";
} else {
return "Sysclock";
}
} else if (which == 2) {
using modes = timer::CounterMode::ClockSource2;
auto clock = static_cast<modes>((mode.clockSource >> 1) & 1);

if (clock == modes::systemClock_8) {
return "Sysclock/8";
} else {
return "Sysclock";
}

switch (timer->which) {
case 0: return ENUM_NAME(static_cast<timer::CounterMode::ClockSource0>(mode.clockSource & 1));
case 1: return ENUM_NAME(static_cast<timer::CounterMode::ClockSource1>(mode.clockSource & 1));
case 2: return ENUM_NAME(static_cast<timer::CounterMode::ClockSource2>((mode.clockSource >> 1) & 1));
default: return "";
}
return "";
}

struct Field {
Expand Down

0 comments on commit 002766b

Please sign in to comment.