-
Notifications
You must be signed in to change notification settings - Fork 843
Expand file tree
/
Copy pathGameProfileWindow.cpp
More file actions
406 lines (321 loc) · 15.6 KB
/
GameProfileWindow.cpp
File metadata and controls
406 lines (321 loc) · 15.6 KB
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
#include "wxgui/GameProfileWindow.h"
#include <wx/statbox.h>
#include <wx/sizer.h>
#include <wx/panel.h>
#include <wx/notebook.h>
#include <wx/stattext.h>
#include <wx/wupdlock.h>
#include <wx/slider.h>
#include "wxgui/helpers/wxHelpers.h"
#include "input/InputManager.h"
#if BOOST_OS_LINUX || BOOST_OS_MACOS || BOOST_OS_BSD
#include "resource/embedded/resources.h"
#endif
GameProfileWindow::GameProfileWindow(wxWindow* parent, uint64_t title_id)
: wxFrame(parent, wxID_ANY, _("Edit game profile"), wxDefaultPosition, wxDefaultSize, wxCLOSE_BOX | wxCLIP_CHILDREN | wxCAPTION | wxRESIZE_BORDER | wxTAB_TRAVERSAL | wxSYSTEM_MENU), m_title_id(title_id)
{
SetIcon(wxICON(X_GAME_PROFILE));
SetSize(FromDIP(wxSize(390, 350)));
m_game_profile.Reset();
m_game_profile.Load(title_id);
this->SetSizeHints(wxDefaultSize, wxDefaultSize);
auto* main_sizer = new wxBoxSizer(wxVERTICAL);
auto* m_notebook = new wxNotebook(this, wxID_ANY);
// general
{
auto* panel = new wxPanel(m_notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
auto* sizer = new wxBoxSizer(wxVERTICAL);
{
auto* box_sizer = new wxStaticBoxSizer(new wxStaticBox(panel, wxID_ANY, _("General")), wxVERTICAL);
auto* box = box_sizer->GetStaticBox();
m_load_libs = new wxCheckBox(box, wxID_ANY, _("Load shared libraries"));
m_load_libs->SetToolTip(_("EXPERT OPTION\nThis option will load libraries from the cafeLibs directory"));
box_sizer->Add(m_load_libs, 0, wxALL, 5);
m_start_with_padview = new wxCheckBox(box, wxID_ANY, _("Launch with gamepad view"));
m_start_with_padview->SetToolTip(_("Games will be launched with gamepad view toggled as default. The view can be toggled with CTRL + TAB"));
box_sizer->Add(m_start_with_padview, 0, wxALL, 5);
sizer->Add(box_sizer, 0, wxEXPAND, 5);
}
// cpu
{
auto* box_sizer = new wxStaticBoxSizer(new wxStaticBox(panel, wxID_ANY, _("CPU")), wxVERTICAL);
auto* box = box_sizer->GetStaticBox();
auto* first_row = new wxFlexGridSizer(0, 2, 0, 0);
first_row->SetFlexibleDirection(wxBOTH);
first_row->SetNonFlexibleGrowMode(wxFLEX_GROWMODE_SPECIFIED);
first_row->Add(new wxStaticText(box, wxID_ANY, _("Mode")), 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
wxString cpu_modes[] = { _("Single-core interpreter"), _("Single-core recompiler"), _("Multi-core recompiler"), _("Auto (recommended)") };
const sint32 m_cpu_modeNChoices = std::size(cpu_modes);
m_cpu_mode = new wxChoice(box, wxID_ANY, wxDefaultPosition, wxDefaultSize, m_cpu_modeNChoices, cpu_modes, 0);
m_cpu_mode->SetToolTip(_("Set the CPU emulation mode"));
first_row->Add(m_cpu_mode, 0, wxALL, 5);
first_row->Add(new wxStaticText(box, wxID_ANY, _("Thread quantum")), 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
auto* quantum_sizer = new wxFlexGridSizer(0, 2, 0, 0);
quantum_sizer->SetFlexibleDirection(wxBOTH);
quantum_sizer->SetNonFlexibleGrowMode(wxFLEX_GROWMODE_SPECIFIED);
wxString quantum_values[] = { "20000", "45000", "60000", "80000" ,"100000" };
m_thread_quantum = new wxChoice(box, wxID_ANY, wxDefaultPosition, wxDefaultSize, std::size(quantum_values), quantum_values);
m_thread_quantum->SetMinSize(FromDIP(wxSize(85, -1)));
m_thread_quantum->SetToolTip(_("EXPERT OPTION\nSet the maximum thread slice runtime (in virtual cycles)"));
quantum_sizer->Add(m_thread_quantum, 0, wxALL, 5);
quantum_sizer->Add(new wxStaticText(box, wxID_ANY, _("cycles")), 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
first_row->Add(quantum_sizer, 0, wxEXPAND, 5);
box_sizer->Add(first_row, 0, wxEXPAND, 5);
sizer->Add(box_sizer, 0, wxEXPAND, 5);
}
panel->SetSizer(sizer);
panel->Layout();
sizer->Fit(panel);
m_notebook->AddPage(panel, _("General"), true);
}
// graphic
{
auto* panel = new wxPanel(m_notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
auto* sizer = new wxBoxSizer(wxVERTICAL);
//m_extended_texture_readback = new wxCheckBox(panel, wxID_ANY, _("Extended texture readback"));
//m_extended_texture_readback->SetToolTip(_("Improves emulation accuracy of CPU to GPU memory access at the cost of performance. Required for some games."));
//sizer->Add(m_extended_texture_readback, 0, wxALL, 5);
auto* first_row = new wxFlexGridSizer(0, 2, 0, 0);
first_row->SetNonFlexibleGrowMode(wxFLEX_GROWMODE_SPECIFIED);
/*first_row->Add(new wxStaticText(panel, wxID_ANY, _("Precompiled shaders")), 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
wxString precompiled_modes[] = { _("auto"), _("enable"), _("disable") };
const sint32 precompiled_count = std::size(precompiled_modes);
m_precompiled = new wxChoice(panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, precompiled_count, precompiled_modes, 0);
m_precompiled->SetToolTip(_("Precompiled shaders can speed up the load time on the shader loading screen.\nAuto will enable it for AMD/Intel but disable it for NVIDIA GPUs as a workaround for a driver bug.\n\nRecommended: Auto"));
first_row->Add(m_precompiled, 0, wxALL, 5);*/
first_row->Add(new wxStaticText(panel, wxID_ANY, _("Graphics API")), 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
wxString gapi_values[] = { "", "OpenGL", "Vulkan",
#if ENABLE_METAL
"Metal"
#endif
};
m_graphic_api = new wxChoice(panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, (int)std::size(gapi_values), gapi_values);
first_row->Add(m_graphic_api, 0, wxALL, 5);
first_row->Add(new wxStaticText(panel, wxID_ANY, _("Shader multiplication accuracy")), 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
wxString mul_values[] = { _("false"), _("true")};
m_shader_mul_accuracy = new wxChoice(panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, (int)std::size(mul_values), mul_values);
m_shader_mul_accuracy->SetToolTip(_("EXPERT OPTION\nControls the accuracy of floating point multiplication in shaders.\n\nRecommended: true"));
first_row->Add(m_shader_mul_accuracy, 0, wxALL, 5);
#if ENABLE_METAL
first_row->Add(new wxStaticText(panel, wxID_ANY, _("Shader fast math")), 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
wxString math_values[] = { _("false"), _("true") };
m_shader_fast_math = new wxChoice(panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, (int)std::size(math_values), math_values);
m_shader_fast_math->SetToolTip(_("EXPERT OPTION\nEnables fast math for all shaders. May (rarely) cause graphical bugs.\n\nMetal only\n\nRecommended: true"));
first_row->Add(m_shader_fast_math, 0, wxALL, 5);
first_row->Add(new wxStaticText(panel, wxID_ANY, _("Metal buffer cache mode")), 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
wxString cache_values[] = { _("auto"), _("device private"), _("device shared"), _("host") };
m_metal_buffer_cache_mode = new wxChoice(panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, (int)std::size(cache_values), cache_values);
m_metal_buffer_cache_mode->SetToolTip(_("EXPERT OPTION\nDecides how the buffer cache memory will be managed.\n\nMetal only\n\nRecommended: auto"));
first_row->Add(m_metal_buffer_cache_mode, 0, wxALL, 5);
first_row->Add(new wxStaticText(panel, wxID_ANY, _("Position invariance")), 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
wxString pos_values[] = { _("auto"), _("false"), _("true") };
m_position_invariance = new wxChoice(panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, (int)std::size(pos_values), pos_values);
m_position_invariance->SetToolTip(_("EXPERT OPTION\nDisables most optimizations for vertex positions. May fix polygon cutouts or flickering in some games.\n\nMetal only\n\nRecommended: auto"));
first_row->Add(m_position_invariance, 0, wxALL, 5);
#endif
/*first_row->Add(new wxStaticText(panel, wxID_ANY, _("GPU buffer cache accuracy")), 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
wxString accuarcy_values[] = { _("high"), _("medium"), _("low") };
m_cache_accuracy = new wxChoice(panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, (int)std::size(accuarcy_values), accuarcy_values);
m_cache_accuracy->SetToolTip(_("Lower value results in higher performance, but may cause graphical issues"));
first_row->Add(m_cache_accuracy, 0, wxALL, 5);*/
sizer->Add(first_row, 0, wxEXPAND, 5);
panel->SetSizer(sizer);
panel->Layout();
sizer->Fit(panel);
m_notebook->AddPage(panel, _("Graphic"), false);
}
//// audio
//{
// auto panel = new wxPanel(m_notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
// wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
// m_disable_audio = new wxCheckBox(panel, wxID_ANY, _("Disable Audio"), wxDefaultPosition, wxDefaultSize, wxCHK_3STATE | wxCHK_ALLOW_3RD_STATE_FOR_USER);
// sizer->Add(m_disable_audio, 0, wxALL, 5);
// panel->SetSizer(sizer);
// panel->Layout();
// sizer->Fit(panel);
// m_notebook->AddPage(panel, _("Audio"), false);
//}
// controller
{
auto panel = new wxPanel(m_notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
wxBoxSizer* sizer;
sizer = new wxBoxSizer(wxVERTICAL);
wxFlexGridSizer* profile_sizer;
profile_sizer = new wxFlexGridSizer(0, 2, 0, 0);
profile_sizer->SetFlexibleDirection(wxBOTH);
profile_sizer->SetNonFlexibleGrowMode(wxFLEX_GROWMODE_SPECIFIED);
for (int i = 0; i < 8; ++i)
{
profile_sizer->Add(new wxStaticText(panel, wxID_ANY, formatWxString(_("Controller {}"), i + 1)), 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
m_controller_profile[i] = new wxComboBox(panel, wxID_ANY,"", wxDefaultPosition, wxDefaultSize, 0, nullptr, wxCB_DROPDOWN| wxCB_READONLY);
m_controller_profile[i]->SetMinSize(FromDIP(wxSize(250, -1)));
m_controller_profile[i]->Bind(wxEVT_COMBOBOX_DROPDOWN, &GameProfileWindow::OnControllerProfileDropdown, this);
m_controller_profile[i]->SetToolTip(_("Forces a given controller profile"));
profile_sizer->Add(m_controller_profile[i], 0, wxALL, 5);
}
sizer->Add(profile_sizer, 0, wxEXPAND, 5);
panel->SetSizer(sizer);
panel->Layout();
sizer->Fit(panel);
m_notebook->AddPage(panel, _("Controller"), false);
}
main_sizer->Add(m_notebook, 1, wxEXPAND | wxALL, 5);
this->SetSizer(main_sizer);
this->Layout();
this->Centre(wxBOTH);
ApplyProfile();
}
GameProfileWindow::~GameProfileWindow()
{
SaveProfile();
}
void GameProfileWindow::OnStreamoutSizeChange(wxCommandEvent& event)
{
wxSlider* slider = wxDynamicCast(event.GetEventObject(), wxSlider);
wxASSERT(slider);
wxStaticText* text = wxDynamicCast(slider->GetClientData(), wxStaticText);
wxASSERT(text);
text->SetLabelText(fmt::format("{} MB", slider->GetValue()));
event.Skip();
}
void GameProfileWindow::OnControllerProfileDropdown(wxCommandEvent& event)
{
wxComboBox* cb = wxDynamicCast(event.GetEventObject(), wxComboBox);
wxASSERT(cb);
wxWindowUpdateLocker lock(cb);
const auto selected_value = cb->GetStringSelection();
cb->Clear();
cb->Append(wxEmptyString);
auto profiles = InputManager::get_profiles();
for (const auto& profile : profiles)
{
cb->Append(wxString::FromUTF8(profile));
}
cb->SetStringSelection(selected_value);
}
void GameProfileWindow::SetProfileInt(gameProfileIntegerOption_t& option, wxCheckBox* checkbox, sint32 value) const
{
const auto state = checkbox->GetValue();
if (state)
{
option.isPresent = true;
option.value = value;
}
else
option.isPresent = false;
}
void GameProfileWindow::ApplyProfile()
{
if(m_game_profile.m_gameName)
this->SetTitle(_("Edit game profile") + " - " + m_game_profile.m_gameName.value());
// general
m_load_libs->SetValue(m_game_profile.m_loadSharedLibraries.value());
m_start_with_padview->SetValue(m_game_profile.m_startWithPadView);
// cpu
// wxString cpu_modes[] = { _("Singlecore-Interpreter"), _("Singlecore-Recompiler"), _("Triplecore-Recompiler"), _("Auto (recommended)") };
switch(m_game_profile.m_cpuMode.value())
{
case CPUMode::SinglecoreInterpreter: m_cpu_mode->SetSelection(0); break;
case CPUMode::SinglecoreRecompiler: m_cpu_mode->SetSelection(1); break;
case CPUMode::DualcoreRecompiler: m_cpu_mode->SetSelection(2); break;
case CPUMode::MulticoreRecompiler: m_cpu_mode->SetSelection(2); break;
default: m_cpu_mode->SetSelection(3);
}
m_thread_quantum->SetStringSelection(fmt::format("{}", m_game_profile.m_threadQuantum));
// gpu
if (!m_game_profile.m_graphics_api.has_value())
m_graphic_api->SetSelection(0); // selecting ""
else
m_graphic_api->SetSelection(1 + m_game_profile.m_graphics_api.value()); // "", OpenGL, Vulkan, Metal
m_shader_mul_accuracy->SetSelection((int)m_game_profile.m_accurateShaderMul);
#if ENABLE_METAL
m_shader_fast_math->SetSelection((int)m_game_profile.m_shaderFastMath);
m_metal_buffer_cache_mode->SetSelection((int)m_game_profile.m_metalBufferCacheMode);
m_position_invariance->SetSelection((int)m_game_profile.m_positionInvariance);
#endif
//// audio
//m_disable_audio->Set3StateValue(GetCheckboxState(m_game_profile.disableAudio));
// controller
auto profiles = InputManager::get_profiles();
for (const auto& cb : m_controller_profile)
{
cb->Clear();
for (const auto& profile : profiles)
{
cb->Append(wxString::FromUTF8(profile));
}
}
for (int i = 0; i < InputManager::kMaxController; ++i)
{
const bool has_value = m_game_profile.m_controllerProfile[i].has_value();
if (has_value)
{
const auto& v = m_game_profile.m_controllerProfile[i].value();
m_controller_profile[i]->SetStringSelection(wxString::FromUTF8(v));
}
else
m_controller_profile[i]->SetSelection(wxNOT_FOUND);
}
}
void GameProfileWindow::SaveProfile()
{
// update game profile struct
m_game_profile.Reset();
// general
m_game_profile.m_loadSharedLibraries = m_load_libs->GetValue();
m_game_profile.m_startWithPadView = m_start_with_padview->GetValue();
// cpu
switch(m_cpu_mode->GetSelection())
{
case 0: m_game_profile.m_cpuMode = CPUMode::SinglecoreInterpreter; break;
case 1: m_game_profile.m_cpuMode = CPUMode::SinglecoreRecompiler; break;
case 2: m_game_profile.m_cpuMode = CPUMode::MulticoreRecompiler; break;
default:
m_game_profile.m_cpuMode = CPUMode::Auto;
}
const wxString thread_quantum = m_thread_quantum->GetStringSelection();
if (!thread_quantum.empty())
{
m_game_profile.m_threadQuantum = ConvertString<uint32>(thread_quantum.ToStdString());
m_game_profile.m_threadQuantum = std::min<uint32>(m_game_profile.m_threadQuantum, 536870912);
m_game_profile.m_threadQuantum = std::max<uint32>(m_game_profile.m_threadQuantum, 5000);
}
// gpu
m_game_profile.m_accurateShaderMul = (AccurateShaderMulOption)m_shader_mul_accuracy->GetSelection();
if (m_game_profile.m_accurateShaderMul != AccurateShaderMulOption::False && m_game_profile.m_accurateShaderMul != AccurateShaderMulOption::True)
m_game_profile.m_accurateShaderMul = AccurateShaderMulOption::True; // force a legal value
#if ENABLE_METAL
m_game_profile.m_shaderFastMath = (bool)m_shader_fast_math->GetSelection();
m_game_profile.m_metalBufferCacheMode = (MetalBufferCacheMode)m_metal_buffer_cache_mode->GetSelection();
m_game_profile.m_positionInvariance = (PositionInvariance)m_position_invariance->GetSelection();
#endif
if (m_graphic_api->GetSelection() == 0)
m_game_profile.m_graphics_api = {};
else
m_game_profile.m_graphics_api = (GraphicAPI)(m_graphic_api->GetSelection() - 1); // "", OpenGL, Vulkan, Metal
// controller
for (int i = 0; i < 8; ++i)
{
if(m_controller_profile[i]->GetSelection() == wxNOT_FOUND)
{
m_game_profile.m_controllerProfile[i].reset();
continue;
}
const wxString profile_name = m_controller_profile[i]->GetStringSelection();
if (profile_name.empty())
m_game_profile.m_controllerProfile[i].reset();
else
m_game_profile.m_controllerProfile[i] = profile_name.ToUTF8();
}
// update game profile file
m_game_profile.Save(m_title_id);
}
void GameProfileWindow::SetSliderValue(wxSlider* slider, sint32 new_value) const
{
wxASSERT(slider);
slider->SetValue(new_value);
wxCommandEvent slider_event(wxEVT_SLIDER, slider->GetId());
slider_event.SetEventObject(slider);
slider_event.SetClientData((void*)IsFrozen());
wxPostEvent(slider->GetEventHandler(), slider_event);
}