2015-03-18 22:00:27 +00:00
|
|
|
// Copyright 2015 Dolphin Emulator Project
|
2015-05-17 23:08:10 +00:00
|
|
|
// Licensed under GPLv2+
|
2015-03-18 22:00:27 +00:00
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2016-11-05 12:29:29 +00:00
|
|
|
#include "DolphinWX/Config/AdvancedConfigPane.h"
|
|
|
|
|
2015-03-18 22:00:27 +00:00
|
|
|
#include <cmath>
|
|
|
|
|
|
|
|
#include <wx/checkbox.h>
|
2016-07-13 20:46:14 +00:00
|
|
|
#include <wx/datectrl.h>
|
|
|
|
#include <wx/dateevt.h>
|
2015-03-18 22:00:27 +00:00
|
|
|
#include <wx/sizer.h>
|
|
|
|
#include <wx/stattext.h>
|
2016-07-13 20:46:14 +00:00
|
|
|
#include <wx/time.h>
|
|
|
|
#include <wx/timectrl.h>
|
2015-03-18 22:00:27 +00:00
|
|
|
|
|
|
|
#include "Core/ConfigManager.h"
|
2016-07-19 18:21:29 +00:00
|
|
|
#include "Core/Core.h"
|
2017-01-29 14:25:27 +00:00
|
|
|
#include "Core/HW/SystemTimers.h"
|
2016-08-02 06:22:37 +00:00
|
|
|
#include "DolphinWX/DolphinSlider.h"
|
2016-11-05 12:29:29 +00:00
|
|
|
#include "DolphinWX/WxEventUtils.h"
|
2015-03-18 22:00:27 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
AdvancedConfigPane::AdvancedConfigPane(wxWindow* parent, wxWindowID id) : wxPanel(parent, id)
|
2015-03-18 22:00:27 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
InitializeGUI();
|
|
|
|
LoadGUIValues();
|
2016-11-05 12:29:29 +00:00
|
|
|
BindEvents();
|
2015-03-18 22:00:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AdvancedConfigPane::InitializeGUI()
|
|
|
|
{
|
2017-10-30 03:03:32 +00:00
|
|
|
m_clock_override_checkbox =
|
|
|
|
new wxCheckBox(this, wxID_ANY, _("Enable Emulated CPU Clock Override"));
|
2016-06-24 08:43:46 +00:00
|
|
|
m_clock_override_slider =
|
2016-08-02 06:22:37 +00:00
|
|
|
new DolphinSlider(this, wxID_ANY, 100, 0, 150, wxDefaultPosition, FromDIP(wxSize(200, -1)));
|
2016-06-24 08:43:46 +00:00
|
|
|
m_clock_override_text = new wxStaticText(this, wxID_ANY, "");
|
|
|
|
|
2016-07-13 20:46:14 +00:00
|
|
|
m_custom_rtc_checkbox = new wxCheckBox(this, wxID_ANY, _("Enable Custom RTC"));
|
|
|
|
m_custom_rtc_date_picker = new wxDatePickerCtrl(this, wxID_ANY);
|
2017-07-06 14:19:08 +00:00
|
|
|
// The Wii System Menu only allows configuring a year between 2000 and 2035.
|
|
|
|
// However, the GameCube main menu (IPL) allows setting a year between 2000 and 2099,
|
|
|
|
// which is why we use that range here. The Wii still deals OK with dates beyond 2035
|
|
|
|
// and simply clamps them to 2035-12-31.
|
|
|
|
m_custom_rtc_date_picker->SetRange(wxDateTime(1, wxDateTime::Jan, 2000),
|
|
|
|
wxDateTime(31, wxDateTime::Dec, 2099));
|
2016-07-13 20:46:14 +00:00
|
|
|
m_custom_rtc_time_picker = new wxTimePickerCtrl(this, wxID_ANY);
|
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
wxStaticText* const clock_override_description =
|
2017-10-30 03:03:32 +00:00
|
|
|
new wxStaticText(this, wxID_ANY, _("Adjusts the emulated CPU's clock rate.\n\n"
|
|
|
|
"Higher values may make variable-framerate games run "
|
|
|
|
"at a higher framerate, at the expense of performance. "
|
|
|
|
"Lower values may activate a game's internal "
|
|
|
|
"frameskip, potentially improving performance.\n\n"
|
2016-06-24 08:43:46 +00:00
|
|
|
"WARNING: Changing this from the default (100%) "
|
|
|
|
"can and will break games and cause glitches. "
|
|
|
|
"Do so at your own risk. Please do not report "
|
2017-11-02 13:32:16 +00:00
|
|
|
"bugs that occur with a non-default clock."));
|
2016-06-23 11:26:47 +00:00
|
|
|
|
2016-07-13 20:46:14 +00:00
|
|
|
wxStaticText* const custom_rtc_description = new wxStaticText(
|
|
|
|
this, wxID_ANY,
|
|
|
|
_("This setting allows you to set a custom real time clock (RTC) separate "
|
|
|
|
"from your current system time.\n\nIf you're unsure, leave this disabled."));
|
|
|
|
|
2016-06-23 11:26:47 +00:00
|
|
|
#ifdef __APPLE__
|
2016-06-24 08:43:46 +00:00
|
|
|
clock_override_description->Wrap(550);
|
2016-07-13 20:46:14 +00:00
|
|
|
custom_rtc_description->Wrap(550);
|
2016-06-23 11:26:47 +00:00
|
|
|
#else
|
2016-08-02 06:22:37 +00:00
|
|
|
clock_override_description->Wrap(FromDIP(400));
|
|
|
|
custom_rtc_description->Wrap(FromDIP(400));
|
2016-06-23 11:26:47 +00:00
|
|
|
#endif
|
2015-03-18 22:00:27 +00:00
|
|
|
|
2016-08-02 06:22:37 +00:00
|
|
|
const int space5 = FromDIP(5);
|
2015-03-18 22:00:27 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
wxBoxSizer* const clock_override_slider_sizer = new wxBoxSizer(wxHORIZONTAL);
|
2016-08-02 06:22:37 +00:00
|
|
|
clock_override_slider_sizer->Add(m_clock_override_slider, 1);
|
|
|
|
clock_override_slider_sizer->Add(m_clock_override_text, 1, wxLEFT, space5);
|
2015-03-18 22:00:27 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
wxStaticBoxSizer* const cpu_options_sizer =
|
|
|
|
new wxStaticBoxSizer(wxVERTICAL, this, _("CPU Options"));
|
2016-08-02 06:22:37 +00:00
|
|
|
cpu_options_sizer->AddSpacer(space5);
|
|
|
|
cpu_options_sizer->Add(m_clock_override_checkbox, 0, wxEXPAND | wxLEFT | wxRIGHT, space5);
|
|
|
|
cpu_options_sizer->AddSpacer(space5);
|
|
|
|
cpu_options_sizer->Add(clock_override_slider_sizer, 0, wxEXPAND | wxLEFT | wxRIGHT, space5);
|
|
|
|
cpu_options_sizer->AddSpacer(space5);
|
|
|
|
cpu_options_sizer->Add(clock_override_description, 0, wxEXPAND | wxLEFT | wxRIGHT, space5);
|
|
|
|
cpu_options_sizer->AddSpacer(space5);
|
|
|
|
|
|
|
|
wxFlexGridSizer* const custom_rtc_date_time_sizer =
|
|
|
|
new wxFlexGridSizer(2, wxSize(space5, space5));
|
|
|
|
custom_rtc_date_time_sizer->Add(m_custom_rtc_date_picker, 0, wxEXPAND);
|
|
|
|
custom_rtc_date_time_sizer->Add(m_custom_rtc_time_picker, 0, wxEXPAND);
|
2016-07-13 20:46:14 +00:00
|
|
|
|
|
|
|
wxStaticBoxSizer* const custom_rtc_sizer =
|
|
|
|
new wxStaticBoxSizer(wxVERTICAL, this, _("Custom RTC Options"));
|
2016-08-02 06:22:37 +00:00
|
|
|
custom_rtc_sizer->AddSpacer(space5);
|
|
|
|
custom_rtc_sizer->Add(m_custom_rtc_checkbox, 0, wxLEFT | wxRIGHT, space5);
|
|
|
|
custom_rtc_sizer->AddSpacer(space5);
|
|
|
|
custom_rtc_sizer->Add(custom_rtc_date_time_sizer, 0, wxLEFT | wxRIGHT, space5);
|
|
|
|
custom_rtc_sizer->AddSpacer(space5);
|
|
|
|
custom_rtc_sizer->Add(custom_rtc_description, 0, wxLEFT | wxRIGHT, space5);
|
|
|
|
custom_rtc_sizer->AddSpacer(space5);
|
2016-07-13 20:46:14 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
wxBoxSizer* const main_sizer = new wxBoxSizer(wxVERTICAL);
|
2016-08-02 06:22:37 +00:00
|
|
|
main_sizer->AddSpacer(space5);
|
|
|
|
main_sizer->Add(cpu_options_sizer, 0, wxEXPAND | wxLEFT | wxRIGHT, space5);
|
|
|
|
main_sizer->AddSpacer(space5);
|
|
|
|
main_sizer->Add(custom_rtc_sizer, 0, wxEXPAND | wxLEFT | wxRIGHT, space5);
|
|
|
|
main_sizer->AddSpacer(space5);
|
2015-03-18 22:00:27 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
SetSizer(main_sizer);
|
2015-03-18 22:00:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AdvancedConfigPane::LoadGUIValues()
|
|
|
|
{
|
2017-06-28 04:36:27 +00:00
|
|
|
int ocFactor =
|
|
|
|
static_cast<int>(std::ceil(std::log2f(SConfig::GetInstance().m_OCFactor) * 25.f + 100.f));
|
2016-06-24 08:43:46 +00:00
|
|
|
bool oc_enabled = SConfig::GetInstance().m_OCEnable;
|
|
|
|
m_clock_override_checkbox->SetValue(oc_enabled);
|
|
|
|
m_clock_override_slider->SetValue(ocFactor);
|
|
|
|
m_clock_override_slider->Enable(oc_enabled);
|
|
|
|
UpdateCPUClock();
|
2016-07-13 20:46:14 +00:00
|
|
|
LoadCustomRTC();
|
2015-03-18 22:00:27 +00:00
|
|
|
}
|
|
|
|
|
2016-11-05 12:29:29 +00:00
|
|
|
void AdvancedConfigPane::BindEvents()
|
|
|
|
{
|
|
|
|
m_clock_override_checkbox->Bind(wxEVT_CHECKBOX,
|
|
|
|
&AdvancedConfigPane::OnClockOverrideCheckBoxChanged, this);
|
|
|
|
m_clock_override_checkbox->Bind(wxEVT_UPDATE_UI, &AdvancedConfigPane::OnUpdateCPUClockControls,
|
|
|
|
this);
|
|
|
|
|
|
|
|
m_clock_override_slider->Bind(wxEVT_SLIDER, &AdvancedConfigPane::OnClockOverrideSliderChanged,
|
|
|
|
this);
|
|
|
|
m_clock_override_slider->Bind(wxEVT_UPDATE_UI, &AdvancedConfigPane::OnUpdateCPUClockControls,
|
|
|
|
this);
|
|
|
|
|
|
|
|
m_custom_rtc_checkbox->Bind(wxEVT_CHECKBOX, &AdvancedConfigPane::OnCustomRTCCheckBoxChanged,
|
|
|
|
this);
|
|
|
|
m_custom_rtc_checkbox->Bind(wxEVT_UPDATE_UI, &WxEventUtils::OnEnableIfCoreNotRunning);
|
|
|
|
|
|
|
|
m_custom_rtc_date_picker->Bind(wxEVT_DATE_CHANGED, &AdvancedConfigPane::OnCustomRTCDateChanged,
|
|
|
|
this);
|
|
|
|
m_custom_rtc_date_picker->Bind(wxEVT_UPDATE_UI, &AdvancedConfigPane::OnUpdateRTCDateTimeEntries,
|
|
|
|
this);
|
|
|
|
|
|
|
|
m_custom_rtc_time_picker->Bind(wxEVT_TIME_CHANGED, &AdvancedConfigPane::OnCustomRTCTimeChanged,
|
|
|
|
this);
|
|
|
|
m_custom_rtc_time_picker->Bind(wxEVT_UPDATE_UI, &AdvancedConfigPane::OnUpdateRTCDateTimeEntries,
|
|
|
|
this);
|
|
|
|
}
|
|
|
|
|
2015-03-18 22:00:27 +00:00
|
|
|
void AdvancedConfigPane::OnClockOverrideCheckBoxChanged(wxCommandEvent& event)
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
SConfig::GetInstance().m_OCEnable = m_clock_override_checkbox->IsChecked();
|
|
|
|
m_clock_override_slider->Enable(SConfig::GetInstance().m_OCEnable);
|
|
|
|
UpdateCPUClock();
|
2015-03-18 22:00:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AdvancedConfigPane::OnClockOverrideSliderChanged(wxCommandEvent& event)
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
// Vaguely exponential scaling?
|
|
|
|
SConfig::GetInstance().m_OCFactor =
|
|
|
|
std::exp2f((m_clock_override_slider->GetValue() - 100.f) / 25.f);
|
|
|
|
UpdateCPUClock();
|
2015-03-18 22:00:27 +00:00
|
|
|
}
|
|
|
|
|
2017-07-06 14:19:08 +00:00
|
|
|
static wxDateTime GetCustomRTCDateTime()
|
|
|
|
{
|
|
|
|
time_t timestamp = SConfig::GetInstance().m_customRTCValue;
|
|
|
|
return wxDateTime(timestamp).ToUTC();
|
|
|
|
}
|
|
|
|
|
|
|
|
static wxDateTime CombineDateAndTime(const wxDateTime& date, const wxDateTime& time)
|
2016-08-19 21:16:28 +00:00
|
|
|
{
|
2017-07-06 14:19:08 +00:00
|
|
|
wxDateTime datetime = date;
|
|
|
|
datetime.SetHour(time.GetHour());
|
|
|
|
datetime.SetMinute(time.GetMinute());
|
|
|
|
datetime.SetSecond(time.GetSecond());
|
|
|
|
|
|
|
|
return datetime;
|
2016-08-19 21:16:28 +00:00
|
|
|
}
|
|
|
|
|
2016-07-13 20:46:14 +00:00
|
|
|
void AdvancedConfigPane::OnCustomRTCCheckBoxChanged(wxCommandEvent& event)
|
|
|
|
{
|
|
|
|
const bool checked = m_custom_rtc_checkbox->IsChecked();
|
|
|
|
SConfig::GetInstance().bEnableCustomRTC = checked;
|
|
|
|
m_custom_rtc_date_picker->Enable(checked);
|
|
|
|
m_custom_rtc_time_picker->Enable(checked);
|
|
|
|
}
|
|
|
|
|
2017-07-06 14:19:08 +00:00
|
|
|
void AdvancedConfigPane::OnCustomRTCDateChanged(wxDateEvent& event)
|
2016-07-13 20:46:14 +00:00
|
|
|
{
|
2017-07-06 14:19:08 +00:00
|
|
|
wxDateTime datetime = CombineDateAndTime(event.GetDate(), GetCustomRTCDateTime());
|
|
|
|
UpdateCustomRTC(datetime);
|
2016-07-13 20:46:14 +00:00
|
|
|
}
|
|
|
|
|
2017-07-06 14:19:08 +00:00
|
|
|
void AdvancedConfigPane::OnCustomRTCTimeChanged(wxDateEvent& event)
|
2016-07-13 20:46:14 +00:00
|
|
|
{
|
2017-07-06 14:19:08 +00:00
|
|
|
wxDateTime datetime = CombineDateAndTime(GetCustomRTCDateTime(), event.GetDate());
|
|
|
|
UpdateCustomRTC(datetime);
|
2016-07-13 20:46:14 +00:00
|
|
|
}
|
|
|
|
|
2015-03-18 22:00:27 +00:00
|
|
|
void AdvancedConfigPane::UpdateCPUClock()
|
|
|
|
{
|
2017-06-28 04:36:27 +00:00
|
|
|
int core_clock = SystemTimers::GetTicksPerSecond() / std::pow(10, 6);
|
2017-01-29 14:25:27 +00:00
|
|
|
int percent = static_cast<int>(std::round(SConfig::GetInstance().m_OCFactor * 100.f));
|
|
|
|
int clock = static_cast<int>(std::round(SConfig::GetInstance().m_OCFactor * core_clock));
|
2015-03-18 22:00:27 +00:00
|
|
|
|
2017-08-22 11:35:20 +00:00
|
|
|
m_clock_override_text->SetLabel(SConfig::GetInstance().m_OCEnable ?
|
|
|
|
wxString::Format("%d %% (%d MHz)", percent, clock) :
|
|
|
|
wxString());
|
2015-03-18 22:00:27 +00:00
|
|
|
}
|
2016-07-13 20:46:14 +00:00
|
|
|
|
|
|
|
void AdvancedConfigPane::LoadCustomRTC()
|
|
|
|
{
|
|
|
|
bool custom_rtc_enabled = SConfig::GetInstance().bEnableCustomRTC;
|
|
|
|
m_custom_rtc_checkbox->SetValue(custom_rtc_enabled);
|
2017-07-06 14:19:08 +00:00
|
|
|
|
|
|
|
wxDateTime datetime = GetCustomRTCDateTime();
|
|
|
|
if (datetime.IsValid())
|
2016-07-13 20:46:14 +00:00
|
|
|
{
|
2017-07-06 14:19:08 +00:00
|
|
|
m_custom_rtc_date_picker->SetValue(datetime);
|
|
|
|
m_custom_rtc_time_picker->SetValue(datetime);
|
2016-07-13 20:46:14 +00:00
|
|
|
}
|
2017-07-06 14:19:08 +00:00
|
|
|
|
|
|
|
// Make sure we have a valid custom RTC date and time
|
|
|
|
// both when it was out of range as well as when it was invalid to begin with.
|
|
|
|
datetime = CombineDateAndTime(m_custom_rtc_date_picker->GetValue(),
|
|
|
|
m_custom_rtc_time_picker->GetValue());
|
|
|
|
UpdateCustomRTC(datetime);
|
2016-07-13 20:46:14 +00:00
|
|
|
}
|
|
|
|
|
2017-07-06 14:19:08 +00:00
|
|
|
void AdvancedConfigPane::UpdateCustomRTC(const wxDateTime& datetime)
|
2016-07-13 20:46:14 +00:00
|
|
|
{
|
2017-07-06 14:19:08 +00:00
|
|
|
// We need GetValue() as GetTicks() only works up to 0x7ffffffe, which is in 2038.
|
|
|
|
u32 timestamp = datetime.FromUTC().GetValue().GetValue() / 1000;
|
|
|
|
SConfig::GetInstance().m_customRTCValue = timestamp;
|
2016-07-13 20:46:14 +00:00
|
|
|
}
|
2016-08-19 20:40:04 +00:00
|
|
|
|
2016-11-05 12:29:29 +00:00
|
|
|
void AdvancedConfigPane::OnUpdateCPUClockControls(wxUpdateUIEvent& event)
|
2016-08-19 20:40:04 +00:00
|
|
|
{
|
2016-11-05 12:29:29 +00:00
|
|
|
if (!Core::IsRunning())
|
2016-08-19 20:40:04 +00:00
|
|
|
{
|
2016-11-05 12:29:29 +00:00
|
|
|
event.Enable(true);
|
|
|
|
return;
|
2016-08-19 20:40:04 +00:00
|
|
|
}
|
2016-11-05 12:29:29 +00:00
|
|
|
|
2017-04-03 17:30:58 +00:00
|
|
|
event.Enable(!Core::WantsDeterminism());
|
2016-11-05 12:29:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AdvancedConfigPane::OnUpdateRTCDateTimeEntries(wxUpdateUIEvent& event)
|
|
|
|
{
|
|
|
|
event.Enable(!Core::IsRunning() && m_custom_rtc_checkbox->IsChecked());
|
2016-08-19 20:40:04 +00:00
|
|
|
}
|