-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDebugMenuManager.cpp
174 lines (143 loc) · 3.7 KB
/
DebugMenuManager.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#include "DebugMenuManager.hpp"
#include "Psx.hpp"
#include "AssemblyMenu.hpp"
#include "MemoryMenu.hpp"
#include "CpuMenu.hpp"
#include "GpuMenu.hpp"
#include "CdromMenu.hpp"
#include "InterruptMenu.hpp"
#include "DebugConsole.hpp"
#include "CircularBuffer.hpp"
#include <iostream>
#include <sstream>
static DebugMenuManager * instance = nullptr;
DebugMenuManager * DebugMenuManager::get_instance()
{
if (instance == nullptr)
{
instance = new DebugMenuManager();
}
return instance;
}
void DebugMenuManager::init(GLFWwindow* window)
{
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO();
ImGui::StyleColorsDark();
ImGui_ImplGlfw_InitForOpenGL(window, true);
ImGui_ImplOpenGL3_Init(nullptr);
menus.push_back(std::make_shared<AssemblyMenu>());
menus.push_back(std::make_shared<MemoryMenu>());
menus.push_back(std::make_shared<CpuMenu>());
menus.push_back(std::make_shared<GpuMenu>());
menus.push_back(std::make_shared<CdromMenu>());
menus.push_back(std::make_shared<InterruptMenu>());
menus.push_back(std::make_shared<DebugConsole>());
}
void DebugMenuManager::uninit()
{
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext();
for (auto iter : backward_states)
{
delete iter;
}
backward_states.clear();
}
void DebugMenuManager::draw()
{
// draw imgui debug menu
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
draw_main_menu();
for (auto& iter : menus)
{
iter->draw_menu();
}
ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
}
void DebugMenuManager::tick()
{
if (recording_states)
{
if (backward_states.size() > static_cast<unsigned int>(max_saved_states))
{
delete backward_states.front();
backward_states.pop_front();
}
std::stringstream * state = new std::stringstream();
Psx::get_instance()->save_state(*state, ignore_vram_when_recording);
backward_states.push_back(state);
}
for (auto& iter : menus)
{
iter->tick();
}
}
void DebugMenuManager::draw_main_menu()
{
ImGui::BeginMainMenuBar();
if (ImGui::BeginMenu("File"))
{
if (ImGui::MenuItem("Reset")) { Psx::get_instance()->reset(); }
if (ImGui::MenuItem("Save state")) { save_state_requested = true; }
if (ImGui::MenuItem("Load state")) { load_state_requested = true; }
for (auto& iter : menus)
{
iter->draw_in_category(DebugMenu::menubar_category::FILE);
}
ImGui::EndMenu();
}
if (ImGui::BeginMenu("View"))
{
for (auto& iter : menus)
{
iter->draw_in_category(DebugMenu::menubar_category::VIEW);
}
ImGui::EndMenu();
}
if (ImGui::BeginMenu("Options"))
{
ImGui::InputInt("Number of backward steps to record", &max_saved_states);
ImGui::Checkbox("Ignore VRAM when recording", &ignore_vram_when_recording);
if (max_saved_states < 0)
{
max_saved_states = 0;
}
for (auto& iter : menus)
{
iter->draw_in_category(DebugMenu::menubar_category::OPTIONS);
}
ImGui::EndMenu();
}
ImGui::Separator();
// step backwards
if (ImGui::MenuItem("<-", nullptr, nullptr, backward_states.empty() == false)) {
std::stringstream * state = backward_states.back();
Psx::get_instance()->load_state(*state, ignore_vram_when_recording);
delete state;
backward_states.pop_back();
}
// stop start
if (ImGui::MenuItem(paused_requested ? "|>" : "||")) { paused_requested = !paused_requested; }
// recording to enable backward steps
if (ImGui::MenuItem(recording_states ? "[]" : "()")) {
recording_states = !recording_states;
if (recording_states == false)
{
for (auto iter : backward_states)
{
delete iter;
}
backward_states.clear();
}
}
// step forwards
if (ImGui::MenuItem("->")) { step_forward_requested = true; }
ImGui::Separator();
ImGui::EndMainMenuBar();
}