Compare commits

...

10 Commits

Author SHA1 Message Date
Dentomologist d671dc3f32
Merge 43b82b5fd8 into 1ba8541da9 2024-12-21 09:24:41 +01:00
JMC47 1ba8541da9
Merge pull request #13091 from mitaclaw/ranges-modernization-2-returns
Ranges Algorithms Modernization - Return
2024-12-20 12:50:19 -05:00
Dentomologist 43b82b5fd8 The rest 2024-12-03 17:13:17 -08:00
Dentomologist 305f1b0f3c Refactoring 2024-12-03 17:12:33 -08:00
Dentomologist 78ae2222ed Dummy Commit
This commit will prevent Github from automerging this PR if the other
changes in this testing branch are merged in a different PR.
2024-12-03 17:12:12 -08:00
mitaclaw 3d0d03b871 Modernize `std::partition` with ranges
The new return value is `std::ranges::subrange`.
2024-10-17 18:39:13 -07:00
mitaclaw 5f3a8ff0de Modernize `std::unique` with ranges
The new return value is `std::ranges::subrange`.
2024-10-17 18:39:12 -07:00
mitaclaw be0b13da97 Simplify `std::remove` with `std::erase`
`std::erase` is a replacement for the remove-erase idiom.

Changes to `OpenModeToAndroid` inadvertently revealed that the prior implementation had UB (potentially deleting the end iterator). This is now fixed.
2024-10-17 18:38:34 -07:00
mitaclaw 4fde0f2868 Modernize `std::search` with ranges
The new return value is `std::ranges::subrange`.
2024-10-17 18:38:34 -07:00
mitaclaw 0352f24a8e Modernize `std::mismatch` with ranges
The new return value is `std::ranges::mismatch_result`, an alias for the pair-like type `std::ranges::in_in_result`.
2024-10-17 18:38:34 -07:00
15 changed files with 120 additions and 48 deletions

View File

@ -62,7 +62,7 @@ bool IsPathAndroidContent(std::string_view uri)
std::string OpenModeToAndroid(std::string mode)
{
// The 'b' specifier is not supported by Android. Since we're on POSIX, it's fine to just skip it.
mode.erase(std::remove(mode.begin(), mode.end(), 'b'));
std::erase(mode, 'b');
if (mode == "r")
return "r";

View File

@ -98,7 +98,8 @@ std::vector<std::string> DoFileSearch(const std::vector<std::string>& directorie
// not because std::filesystem returns duplicates). Also note that this pathname-based uniqueness
// isn't as thorough as std::filesystem::equivalent.
std::ranges::sort(result);
result.erase(std::unique(result.begin(), result.end()), result.end());
const auto unique_result = std::ranges::unique(result);
result.erase(unique_result.begin(), unique_result.end());
// Dolphin expects to be able to use "/" (DIR_SEP) everywhere.
// std::filesystem uses the OS separator.

View File

@ -604,7 +604,7 @@ ExtensionNumber Wiimote::GetActiveExtensionNumber() const
bool Wiimote::IsMotionPlusAttached() const
{
return m_is_motion_plus_attached;
return m_motion_plus_setting.GetValue();
}
} // namespace WiimoteEmu

View File

@ -1085,10 +1085,10 @@ void WiiSockMan::UpdatePollCommands()
std::vector<int> original_order(pfds.size());
std::iota(original_order.begin(), original_order.end(), 0);
// Select indices with valid fds
auto mid = std::partition(original_order.begin(), original_order.end(), [&](auto i) {
const auto partition_result = std::ranges::partition(original_order, [&](auto i) {
return GetHostSocket(memory.Read_U32(pcmd.buffer_out + 0xc * i)) >= 0;
});
const auto n_valid = std::distance(original_order.begin(), mid);
const auto n_valid = std::distance(original_order.begin(), partition_result.begin());
// Move all the valid pollfds to the front of the vector
for (auto i = 0; i < n_valid; ++i)

View File

@ -1081,11 +1081,11 @@ void MovieManager::LoadInput(const std::string& movie_path)
std::vector<u8> movInput(m_current_byte);
t_record.ReadArray(movInput.data(), movInput.size());
const auto result = std::mismatch(movInput.begin(), movInput.end(), m_temp_input.begin());
const auto mismatch_result = std::ranges::mismatch(movInput, m_temp_input);
if (result.first != movInput.end())
if (mismatch_result.in1 != movInput.end())
{
const ptrdiff_t mismatch_index = std::distance(movInput.begin(), result.first);
const ptrdiff_t mismatch_index = std::distance(movInput.begin(), mismatch_result.in1);
// this is a "you did something wrong" alert for the user's benefit.
// we'll try to say what's going on in excruciating detail, otherwise the user might not

View File

@ -240,11 +240,9 @@ bool NANDImporter::ExtractCertificates()
for (const PEMCertificate& certificate : certificates)
{
const auto search_result =
std::search(content_bytes.begin(), content_bytes.end(), certificate.search_bytes.begin(),
certificate.search_bytes.end());
const auto search_result = std::ranges::search(content_bytes, certificate.search_bytes);
if (search_result == content_bytes.end())
if (search_result.empty())
{
ERROR_LOG_FMT(DISCIO, "ExtractCertificates: Could not find offset for certficate '{}'",
certificate.filename);
@ -252,7 +250,8 @@ bool NANDImporter::ExtractCertificates()
}
const std::string pem_file_path = m_nand_root + std::string(certificate.filename);
const ptrdiff_t certificate_offset = std::distance(content_bytes.begin(), search_result);
const ptrdiff_t certificate_offset =
std::distance(content_bytes.begin(), search_result.begin());
constexpr int min_offset = 2;
if (certificate_offset < min_offset)
{

View File

@ -15,6 +15,7 @@
#include "DolphinQt/Config/Mapping/MappingWindow.h"
#include "DolphinQt/Config/Mapping/WiimoteEmuExtension.h"
#include "DolphinQt/Settings.h"
#include "InputCommon/ControllerEmu/ControlGroup/Attachments.h"
#include "InputCommon/InputConfig.h"
@ -88,6 +89,8 @@ void WiimoteEmuGeneral::OnAttachmentChanged(int extension)
GetParent()->ShowExtensionMotionTabs(extension == WiimoteEmu::ExtensionNumber::NUNCHUK);
m_extension_widget->ChangeExtensionType(extension);
Settings::Instance().UpdateWiimoteExtension(GetPort(), extension);
}
void WiimoteEmuGeneral::OnAttachmentSelected(int extension)
@ -110,6 +113,7 @@ void WiimoteEmuGeneral::ConfigChanged()
m_extension_combo_dynamic_indicator->setVisible(
!ce_extension->GetSelectionSetting().IsSimpleValue());
OnMotionPlusUpdate();
}
void WiimoteEmuGeneral::Update()
@ -128,9 +132,18 @@ void WiimoteEmuGeneral::LoadSettings()
void WiimoteEmuGeneral::SaveSettings()
{
Wiimote::GetConfig()->SaveConfig();
OnMotionPlusUpdate();
}
InputConfig* WiimoteEmuGeneral::GetConfig()
{
return Wiimote::GetConfig();
}
void WiimoteEmuGeneral::OnMotionPlusUpdate()
{
const int port = GetPort();
const WiimoteEmu::Wiimote* const wiimote =
static_cast<WiimoteEmu::Wiimote*>(Wiimote::GetConfig()->GetController(port));
Settings::Instance().UpdateWiimoteMotionPlus(port, wiimote->IsMotionPlusAttached());
}

View File

@ -27,6 +27,7 @@ private:
void OnAttachmentChanged(int index);
// Selection chosen by user.
void OnAttachmentSelected(int index);
void OnMotionPlusUpdate();
void ConfigChanged();
void Update();

View File

@ -116,6 +116,9 @@ static bool QtMsgAlertHandler(const char* caption, const char* text, bool yes_no
int main(int argc, char* argv[])
{
// IF THIS COMMENT IS IN A NON-TESTING PR I'VE MADE A MISTAKE. It exists to prevent my testing PR
// from getting automerged by Github if its contents would be the same as a merged actual PR.
#ifdef _WIN32
const bool console_attached = AttachConsole(ATTACH_PARENT_PROCESS) != FALSE;
HANDLE stdout_handle = ::GetStdHandle(STD_OUTPUT_HANDLE);

View File

@ -519,6 +519,15 @@ void MainWindow::CreateComponents()
&MemoryWidget::SetAddress);
connect(m_cheats_manager, &CheatsManager::ShowMemory, m_memory_widget, &MemoryWidget::SetAddress);
connect(m_cheats_manager, &CheatsManager::RequestWatch, request_watch);
connect(&Settings::Instance(), &Settings::UpdateWiimoteExtension,
[this](const int controller_number, const int extension_index) {
m_wii_tas_input_windows[controller_number]->UpdateExtension(extension_index);
});
connect(&Settings::Instance(), &Settings::UpdateWiimoteMotionPlus,
[this](const int controller_number, const bool attached) {
m_wii_tas_input_windows[controller_number]->UpdateMotionPlus(attached);
});
}
void MainWindow::ConnectMenuBar()

View File

@ -309,11 +309,9 @@ void Settings::RemovePath(const QString& qpath)
std::string path = qpath.toStdString();
std::vector<std::string> paths = Config::GetIsoPaths();
auto new_end = std::remove(paths.begin(), paths.end(), path);
if (new_end == paths.end())
if (std::erase(paths, path) == 0)
return;
paths.erase(new_end, paths.end());
Config::SetIsoPaths(paths);
emit PathRemoved(qpath);
}

View File

@ -224,6 +224,8 @@ signals:
void USBKeyboardConnectionChanged(bool connected);
void EnableGfxModsChanged(bool enabled);
void HardcoreStateChanged();
void UpdateWiimoteExtension(int controller_number, int extension_index);
void UpdateWiimoteMotionPlus(int controller_number, bool attached);
private:
Settings();

View File

@ -347,32 +347,6 @@ WiiTASInputWindow::WiiTASInputWindow(QWidget* parent, int num) : TASInputWindow(
layout->addWidget(m_settings_box);
setLayout(layout);
if (Core::IsRunning(Core::System::GetInstance()))
{
m_active_extension = GetWiimote()->GetActiveExtensionNumber();
m_is_motion_plus_attached = GetWiimote()->IsMotionPlusAttached();
}
else
{
Common::IniFile ini;
ini.Load(File::GetUserPath(D_CONFIG_IDX) + "WiimoteNew.ini");
const std::string section_name = "Wiimote" + std::to_string(num + 1);
std::string extension;
ini.GetIfExists(section_name, "Extension", &extension);
if (extension == "Nunchuk")
m_active_extension = WiimoteEmu::ExtensionNumber::NUNCHUK;
else if (extension == "Classic")
m_active_extension = WiimoteEmu::ExtensionNumber::CLASSIC;
else
m_active_extension = WiimoteEmu::ExtensionNumber::NONE;
m_is_motion_plus_attached = true;
ini.GetIfExists(section_name, "Extension/Attach MotionPlus", &m_is_motion_plus_attached);
}
UpdateExt();
}
WiimoteEmu::Wiimote* WiiTASInputWindow::GetWiimote()
@ -392,7 +366,60 @@ WiimoteEmu::Extension* WiiTASInputWindow::GetExtension()
GetAttachments()->GetAttachmentList()[m_active_extension].get());
}
void WiiTASInputWindow::UpdateExt()
void WiiTASInputWindow::UpdateExtension(const int extension)
{
const auto new_extension = static_cast<WiimoteEmu::ExtensionNumber>(extension);
if (new_extension == m_active_extension)
return;
m_active_extension = new_extension;
UpdateControlVisibility();
UpdateInputOverrideFunction();
}
void WiiTASInputWindow::UpdateMotionPlus(const bool attached)
{
if (attached == m_is_motion_plus_attached)
return;
m_is_motion_plus_attached = attached;
UpdateControlVisibility();
}
void WiiTASInputWindow::LoadExtensionAndMotionPlus()
{
if (Core::IsRunning(Core::System::GetInstance()))
{
m_active_extension = GetWiimote()->GetActiveExtensionNumber();
m_is_motion_plus_attached = GetWiimote()->IsMotionPlusAttached();
}
else
{
Common::IniFile ini;
ini.Load(File::GetUserPath(D_CONFIG_IDX) + "WiimoteNew.ini");
const std::string section_name = "Wiimote" + std::to_string(m_num + 1);
std::string extension;
ini.GetIfExists(section_name, "Extension", &extension);
if (extension == "Nunchuk")
m_active_extension = WiimoteEmu::ExtensionNumber::NUNCHUK;
else if (extension == "Classic")
m_active_extension = WiimoteEmu::ExtensionNumber::CLASSIC;
else
m_active_extension = WiimoteEmu::ExtensionNumber::NONE;
m_is_motion_plus_attached = true;
ini.GetIfExists(section_name, "Extension/Attach MotionPlus", &m_is_motion_plus_attached);
}
UpdateControlVisibility();
UpdateInputOverrideFunction();
}
void WiiTASInputWindow::UpdateControlVisibility()
{
if (m_active_extension == WiimoteEmu::ExtensionNumber::NUNCHUK)
{
@ -451,17 +478,30 @@ void WiiTASInputWindow::UpdateExt()
m_nunchuk_buttons_box->hide();
m_classic_buttons_box->hide();
}
// Without this, switching between attachments can leave the Stick/IR widgets excessively large
adjustSize();
resize(sizeHint());
}
void WiiTASInputWindow::hideEvent(QHideEvent* event)
void WiiTASInputWindow::hideEvent(QHideEvent* const event)
{
GetWiimote()->ClearInputOverrideFunction();
GetExtension()->ClearInputOverrideFunction();
TASInputWindow::hideEvent(event);
}
void WiiTASInputWindow::showEvent(QShowEvent* event)
void WiiTASInputWindow::showEvent(QShowEvent* const event)
{
WiimoteEmu::Wiimote* wiimote = GetWiimote();
LoadExtensionAndMotionPlus();
TASInputWindow::showEvent(event);
}
void WiiTASInputWindow::UpdateInputOverrideFunction()
{
WiimoteEmu::Wiimote* const wiimote = GetWiimote();
if (m_active_extension != WiimoteEmu::ExtensionNumber::CLASSIC)
wiimote->SetInputOverrideFunction(m_wiimote_overrider.GetInputOverrideFunction());

View File

@ -34,12 +34,17 @@ public:
void hideEvent(QHideEvent* event) override;
void showEvent(QShowEvent* event) override;
void UpdateExtension(int extension);
void UpdateMotionPlus(bool attached);
private:
WiimoteEmu::Wiimote* GetWiimote();
ControllerEmu::Attachments* GetAttachments();
WiimoteEmu::Extension* GetExtension();
void UpdateExt();
void LoadExtensionAndMotionPlus();
void UpdateControlVisibility();
void UpdateInputOverrideFunction();
WiimoteEmu::ExtensionNumber m_active_extension;
bool m_is_motion_plus_attached;

View File

@ -129,7 +129,8 @@ BuildExpression(const std::vector<ciface::Core::DeviceContainer::InputDetection>
// Remove duplicates
std::ranges::sort(alternations);
alternations.erase(std::unique(alternations.begin(), alternations.end()), alternations.end());
const auto unique_result = std::ranges::unique(alternations);
alternations.erase(unique_result.begin(), unique_result.end());
return fmt::to_string(fmt::join(alternations, "|"));
}