From 0ede5d1537fbe7d433d1d984ca7acfbe3e7300dc Mon Sep 17 00:00:00 2001 From: Filip Gawin Date: Fri, 1 Feb 2019 19:47:07 +0100 Subject: [PATCH] Use range loop (if possible) --- Source/Core/Core/DSP/DSPCore.cpp | 4 +- Source/Core/Core/DSP/DSPCore.h | 4 +- Source/Core/Core/DSP/DSPStacks.cpp | 12 ++-- Source/Core/Core/DSP/Jit/x64/DSPEmitter.cpp | 4 +- Source/Core/Core/DSP/Jit/x64/DSPEmitter.h | 2 +- Source/Core/Core/DSP/Jit/x64/DSPJitUtil.cpp | 28 +++++----- Source/Core/Core/HW/DSPHLE/UCodes/Zelda.cpp | 17 +++--- Source/Core/Core/HW/DSPLLE/DSPLLE.cpp | 6 +- .../Core/HW/GCMemcard/GCMemcardDirectory.cpp | 56 +++++++++---------- Source/Core/Core/NetPlayClient.cpp | 16 +++--- Source/Core/Core/NetPlayServer.cpp | 16 +++--- Source/Core/DolphinQt/RenderWidget.cpp | 5 +- Source/Core/InputCommon/GCAdapter.cpp | 14 ++--- .../Core/VideoBackends/Software/DebugUtil.cpp | 4 +- Source/Core/VideoBackends/Vulkan/Renderer.cpp | 4 +- 15 files changed, 92 insertions(+), 100 deletions(-) diff --git a/Source/Core/Core/DSP/DSPCore.cpp b/Source/Core/Core/DSP/DSPCore.cpp index db798c285c..b8719c3113 100644 --- a/Source/Core/Core/DSP/DSPCore.cpp +++ b/Source/Core/Core/DSP/DSPCore.cpp @@ -145,9 +145,9 @@ bool DSPCore_Init(const DSPInitOptions& opts) memset(&g_dsp.r, 0, sizeof(g_dsp.r)); - std::fill(std::begin(g_dsp.reg_stack_ptr), std::end(g_dsp.reg_stack_ptr), 0); + std::fill(std::begin(g_dsp.reg_stack_ptrs), std::end(g_dsp.reg_stack_ptrs), 0); - for (auto& stack : g_dsp.reg_stack) + for (auto& stack : g_dsp.reg_stacks) std::fill(std::begin(stack), std::end(stack), 0); // Fill IRAM with HALT opcodes. diff --git a/Source/Core/Core/DSP/DSPCore.h b/Source/Core/Core/DSP/DSPCore.h index 36eaf671c4..d6f41daaa6 100644 --- a/Source/Core/Core/DSP/DSPCore.h +++ b/Source/Core/Core/DSP/DSPCore.h @@ -275,7 +275,7 @@ struct SDSP // Bits are defined in a struct in DSP.cpp. u16 cr; - u8 reg_stack_ptr[4]; + u8 reg_stack_ptrs[4]; u8 exceptions; // pending exceptions volatile bool external_interrupt_waiting; bool reset_dspjit_codespace; @@ -286,7 +286,7 @@ struct SDSP // The real DSP has different depths for the different stacks, but it would // be strange if any ucode relied on stack overflows since on the DSP, when // the stack overflows, you're screwed. - u16 reg_stack[4][DSP_STACK_DEPTH]; + u16 reg_stacks[4][DSP_STACK_DEPTH]; // For debugging. u32 iram_crc; diff --git a/Source/Core/Core/DSP/DSPStacks.cpp b/Source/Core/Core/DSP/DSPStacks.cpp index 9883f1d6b4..e7d8afed25 100644 --- a/Source/Core/Core/DSP/DSPStacks.cpp +++ b/Source/Core/Core/DSP/DSPStacks.cpp @@ -15,16 +15,16 @@ namespace DSP { static void dsp_reg_stack_push(size_t stack_reg) { - g_dsp.reg_stack_ptr[stack_reg]++; - g_dsp.reg_stack_ptr[stack_reg] &= DSP_STACK_MASK; - g_dsp.reg_stack[stack_reg][g_dsp.reg_stack_ptr[stack_reg]] = g_dsp.r.st[stack_reg]; + g_dsp.reg_stack_ptrs[stack_reg]++; + g_dsp.reg_stack_ptrs[stack_reg] &= DSP_STACK_MASK; + g_dsp.reg_stacks[stack_reg][g_dsp.reg_stack_ptrs[stack_reg]] = g_dsp.r.st[stack_reg]; } static void dsp_reg_stack_pop(size_t stack_reg) { - g_dsp.r.st[stack_reg] = g_dsp.reg_stack[stack_reg][g_dsp.reg_stack_ptr[stack_reg]]; - g_dsp.reg_stack_ptr[stack_reg]--; - g_dsp.reg_stack_ptr[stack_reg] &= DSP_STACK_MASK; + g_dsp.r.st[stack_reg] = g_dsp.reg_stacks[stack_reg][g_dsp.reg_stack_ptrs[stack_reg]]; + g_dsp.reg_stack_ptrs[stack_reg]--; + g_dsp.reg_stack_ptrs[stack_reg] &= DSP_STACK_MASK; } void dsp_reg_store_stack(StackRegister stack_reg, u16 val) diff --git a/Source/Core/Core/DSP/Jit/x64/DSPEmitter.cpp b/Source/Core/Core/DSP/Jit/x64/DSPEmitter.cpp index 24613fbf22..24a2f2a1c8 100644 --- a/Source/Core/Core/DSP/Jit/x64/DSPEmitter.cpp +++ b/Source/Core/Core/DSP/Jit/x64/DSPEmitter.cpp @@ -478,9 +478,9 @@ Gen::OpArg DSPEmitter::M_SDSP_r_st(size_t index) return MDisp(R15, static_cast(offsetof(SDSP, r.st[index]))); } -Gen::OpArg DSPEmitter::M_SDSP_reg_stack_ptr(size_t index) +Gen::OpArg DSPEmitter::M_SDSP_reg_stack_ptrs(size_t index) { - return MDisp(R15, static_cast(offsetof(SDSP, reg_stack_ptr[index]))); + return MDisp(R15, static_cast(offsetof(SDSP, reg_stack_ptrs[index]))); } } // namespace DSP::JIT::x64 diff --git a/Source/Core/Core/DSP/Jit/x64/DSPEmitter.h b/Source/Core/Core/DSP/Jit/x64/DSPEmitter.h index e4f1f337ac..4c65c9ad4e 100644 --- a/Source/Core/Core/DSP/Jit/x64/DSPEmitter.h +++ b/Source/Core/Core/DSP/Jit/x64/DSPEmitter.h @@ -283,7 +283,7 @@ private: Gen::OpArg M_SDSP_cr(); Gen::OpArg M_SDSP_external_interrupt_waiting(); Gen::OpArg M_SDSP_r_st(size_t index); - Gen::OpArg M_SDSP_reg_stack_ptr(size_t index); + Gen::OpArg M_SDSP_reg_stack_ptrs(size_t index); // Ext command helpers void popExtValueToReg(); diff --git a/Source/Core/Core/DSP/Jit/x64/DSPJitUtil.cpp b/Source/Core/Core/DSP/Jit/x64/DSPJitUtil.cpp index 00bfe715a3..04dba96a86 100644 --- a/Source/Core/Core/DSP/Jit/x64/DSPJitUtil.cpp +++ b/Source/Core/Core/DSP/Jit/x64/DSPJitUtil.cpp @@ -13,53 +13,53 @@ using namespace Gen; namespace DSP::JIT::x64 { // clobbers: -// EAX = (s8)g_dsp.reg_stack_ptr[reg_index] +// EAX = (s8)g_dsp.reg_stack_ptrs[reg_index] // expects: void DSPEmitter::dsp_reg_stack_push(StackRegister stack_reg) { const auto reg_index = static_cast(stack_reg); - // g_dsp.reg_stack_ptr[reg_index]++; - // g_dsp.reg_stack_ptr[reg_index] &= DSP_STACK_MASK; - MOV(8, R(AL), M_SDSP_reg_stack_ptr(reg_index)); + // g_dsp.reg_stack_ptrs[reg_index]++; + // g_dsp.reg_stack_ptrs[reg_index] &= DSP_STACK_MASK; + MOV(8, R(AL), M_SDSP_reg_stack_ptrs(reg_index)); ADD(8, R(AL), Imm8(1)); AND(8, R(AL), Imm8(DSP_STACK_MASK)); - MOV(8, M_SDSP_reg_stack_ptr(reg_index), R(AL)); + MOV(8, M_SDSP_reg_stack_ptrs(reg_index), R(AL)); X64Reg tmp1 = m_gpr.GetFreeXReg(); X64Reg tmp2 = m_gpr.GetFreeXReg(); - // g_dsp.reg_stack[reg_index][g_dsp.reg_stack_ptr[reg_index]] = g_dsp.r[DSP_REG_ST0 + reg_index]; + // g_dsp.reg_stack[reg_index][g_dsp.reg_stack_ptrs[reg_index]] = g_dsp.r[DSP_REG_ST0 + reg_index]; MOV(16, R(tmp1), M_SDSP_r_st(reg_index)); MOVZX(64, 8, RAX, R(AL)); - MOV(64, R(tmp2), ImmPtr(g_dsp.reg_stack[reg_index])); + MOV(64, R(tmp2), ImmPtr(g_dsp.reg_stacks[reg_index])); MOV(16, MComplex(tmp2, EAX, SCALE_2, 0), R(tmp1)); m_gpr.PutXReg(tmp1); m_gpr.PutXReg(tmp2); } // clobbers: -// EAX = (s8)g_dsp.reg_stack_ptr[reg_index] +// EAX = (s8)g_dsp.reg_stack_ptrs[reg_index] // expects: void DSPEmitter::dsp_reg_stack_pop(StackRegister stack_reg) { const auto reg_index = static_cast(stack_reg); - // g_dsp.r[DSP_REG_ST0 + reg_index] = g_dsp.reg_stack[reg_index][g_dsp.reg_stack_ptr[reg_index]]; - MOV(8, R(AL), M_SDSP_reg_stack_ptr(reg_index)); + // g_dsp.r[DSP_REG_ST0 + reg_index] = g_dsp.reg_stack[reg_index][g_dsp.reg_stack_ptrs[reg_index]]; + MOV(8, R(AL), M_SDSP_reg_stack_ptrs(reg_index)); X64Reg tmp1 = m_gpr.GetFreeXReg(); X64Reg tmp2 = m_gpr.GetFreeXReg(); MOVZX(64, 8, RAX, R(AL)); - MOV(64, R(tmp2), ImmPtr(g_dsp.reg_stack[reg_index])); + MOV(64, R(tmp2), ImmPtr(g_dsp.reg_stacks[reg_index])); MOV(16, R(tmp1), MComplex(tmp2, EAX, SCALE_2, 0)); MOV(16, M_SDSP_r_st(reg_index), R(tmp1)); m_gpr.PutXReg(tmp1); m_gpr.PutXReg(tmp2); - // g_dsp.reg_stack_ptr[reg_index]--; - // g_dsp.reg_stack_ptr[reg_index] &= DSP_STACK_MASK; + // g_dsp.reg_stack_ptrs[reg_index]--; + // g_dsp.reg_stack_ptrs[reg_index] &= DSP_STACK_MASK; SUB(8, R(AL), Imm8(1)); AND(8, R(AL), Imm8(DSP_STACK_MASK)); - MOV(8, M_SDSP_reg_stack_ptr(reg_index), R(AL)); + MOV(8, M_SDSP_reg_stack_ptrs(reg_index), R(AL)); } void DSPEmitter::dsp_reg_store_stack(StackRegister stack_reg, Gen::X64Reg host_sreg) diff --git a/Source/Core/Core/HW/DSPHLE/UCodes/Zelda.cpp b/Source/Core/Core/HW/DSPHLE/UCodes/Zelda.cpp index 7657f4e861..14940fe7fd 100644 --- a/Source/Core/Core/HW/DSPHLE/UCodes/Zelda.cpp +++ b/Source/Core/Core/HW/DSPHLE/UCodes/Zelda.cpp @@ -1212,8 +1212,8 @@ void ZeldaAudioRenderer::AddVoice(u16 voice_id) volume_deltas[i] = ((u16)quadrant_volumes[i] * delta) >> shift_factor; // Apply master volume to each quadrant. - for (size_t i = 0; i < 4; ++i) - quadrant_volumes[i] = (quadrant_volumes[i] * vpb.dolby_volume_current) >> shift_factor; + for (s16& quadrant_volume : quadrant_volumes) + quadrant_volume = (quadrant_volume * vpb.dolby_volume_current) >> shift_factor; // Compute reverb volume and ramp deltas. s16 reverb_volumes[4], reverb_volume_deltas[4]; @@ -1400,9 +1400,9 @@ void ZeldaAudioRenderer::LoadInputSamples(MixingBuffer* buffer, VPB* vpb) u32 mask = (1 << shift) - 1; u32 pos = vpb->current_pos_frac << shift; - for (size_t i = 0; i < buffer->size(); ++i) + for (s16& sample : *buffer) { - (*buffer)[i] = ((pos >> 16) & mask) ? 0xC000 : 0x4000; + sample = ((pos >> 16) & mask) ? 0xC000 : 0x4000; pos += vpb->resampling_ratio; } vpb->current_pos_frac = (pos >> shift) & 0xFFFF; @@ -1412,9 +1412,9 @@ void ZeldaAudioRenderer::LoadInputSamples(MixingBuffer* buffer, VPB* vpb) case VPB::SRC_SAW_WAVE: { u32 pos = vpb->current_pos_frac; - for (size_t i = 0; i < buffer->size(); ++i) + for (s16& sample : *buffer) { - (*buffer)[i] = pos & 0xFFFF; + sample = pos & 0xFFFF; pos += (vpb->resampling_ratio) >> 1; } vpb->current_pos_frac = pos & 0xFFFF; @@ -1758,10 +1758,9 @@ void ZeldaAudioRenderer::DecodeAFC(VPB* vpb, s16* dst, size_t block_count) } s32 yn1 = *vpb->AFCYN1(), yn2 = *vpb->AFCYN2(); - for (size_t i = 0; i < 16; ++i) + for (s16 nibble : nibbles) { - s32 sample = - delta * nibbles[i] + yn1 * m_afc_coeffs[idx * 2] + yn2 * m_afc_coeffs[idx * 2 + 1]; + s32 sample = delta * nibble + yn1 * m_afc_coeffs[idx * 2] + yn2 * m_afc_coeffs[idx * 2 + 1]; sample >>= 11; sample = std::clamp(sample, -0x8000, 0x7fff); *dst++ = (s16)sample; diff --git a/Source/Core/Core/HW/DSPLLE/DSPLLE.cpp b/Source/Core/Core/HW/DSPLLE/DSPLLE.cpp index bc266c8a0f..9a4371ffb3 100644 --- a/Source/Core/Core/HW/DSPLLE/DSPLLE.cpp +++ b/Source/Core/Core/HW/DSPLLE/DSPLLE.cpp @@ -61,13 +61,13 @@ void DSPLLE::DoState(PointerWrap& p) p.Do(g_dsp.err_pc); #endif p.Do(g_dsp.cr); - p.Do(g_dsp.reg_stack_ptr); + p.Do(g_dsp.reg_stack_ptrs); p.Do(g_dsp.exceptions); p.Do(g_dsp.external_interrupt_waiting); - for (int i = 0; i < 4; i++) + for (auto& stack : g_dsp.reg_stacks) { - p.Do(g_dsp.reg_stack[i]); + p.Do(stack); } p.Do(g_dsp.step_counter); diff --git a/Source/Core/Core/HW/GCMemcard/GCMemcardDirectory.cpp b/Source/Core/Core/HW/GCMemcard/GCMemcardDirectory.cpp index 7af9e44778..da170ffd30 100644 --- a/Source/Core/Core/HW/GCMemcard/GCMemcardDirectory.cpp +++ b/Source/Core/Core/HW/GCMemcard/GCMemcardDirectory.cpp @@ -593,14 +593,14 @@ void GCMemcardDirectory::FlushToFile() std::unique_lock l(m_write_mutex); int errors = 0; Memcard::DEntry invalid; - for (u16 i = 0; i < m_saves.size(); ++i) + for (Memcard::GCIFile& save : m_saves) { - if (m_saves[i].m_dirty) + if (save.m_dirty) { - if (m_saves[i].m_gci_header.m_gamecode != Memcard::DEntry::UNINITIALIZED_GAMECODE) + if (save.m_gci_header.m_gamecode != Memcard::DEntry::UNINITIALIZED_GAMECODE) { - m_saves[i].m_dirty = false; - if (m_saves[i].m_save_data.empty()) + save.m_dirty = false; + if (save.m_save_data.empty()) { // The save's header has been changed but the actual save blocks haven't been read/written // to @@ -609,9 +609,9 @@ void GCMemcardDirectory::FlushToFile() "GCI header modified without corresponding save data changes"); continue; } - if (m_saves[i].m_filename.empty()) + if (save.m_filename.empty()) { - std::string default_save_name = m_save_directory + m_saves[i].m_gci_header.GCI_FileName(); + std::string default_save_name = m_save_directory + save.m_gci_header.GCI_FileName(); // Check to see if another file is using the same name // This seems unlikely except in the case of file corruption @@ -623,41 +623,38 @@ void GCMemcardDirectory::FlushToFile() if (File::Exists(default_save_name)) PanicAlertT("Failed to find new filename.\n%s\n will be overwritten", default_save_name.c_str()); - m_saves[i].m_filename = default_save_name; + save.m_filename = default_save_name; } - File::IOFile gci(m_saves[i].m_filename, "wb"); + File::IOFile gci(save.m_filename, "wb"); if (gci) { - gci.WriteBytes(&m_saves[i].m_gci_header, Memcard::DENTRY_SIZE); - gci.WriteBytes(m_saves[i].m_save_data.data(), - Memcard::BLOCK_SIZE * m_saves[i].m_save_data.size()); + gci.WriteBytes(&save.m_gci_header, Memcard::DENTRY_SIZE); + gci.WriteBytes(save.m_save_data.data(), Memcard::BLOCK_SIZE * save.m_save_data.size()); if (gci.IsGood()) { - Core::DisplayMessage(fmt::format("Wrote save contents to {}", m_saves[i].m_filename), - 4000); + Core::DisplayMessage(fmt::format("Wrote save contents to {}", save.m_filename), 4000); } else { ++errors; Core::DisplayMessage( - fmt::format("Failed to write save contents to {}", m_saves[i].m_filename), 4000); - ERROR_LOG(EXPANSIONINTERFACE, "Failed to save data to %s", - m_saves[i].m_filename.c_str()); + fmt::format("Failed to write save contents to {}", save.m_filename), 4000); + ERROR_LOG(EXPANSIONINTERFACE, "Failed to save data to %s", save.m_filename.c_str()); } } } - else if (m_saves[i].m_filename.length() != 0) + else if (save.m_filename.length() != 0) { - m_saves[i].m_dirty = false; - std::string& old_name = m_saves[i].m_filename; + save.m_dirty = false; + std::string& old_name = save.m_filename; std::string deleted_name = old_name + ".deleted"; if (File::Exists(deleted_name)) File::Delete(deleted_name); File::Rename(old_name, deleted_name); - m_saves[i].m_filename.clear(); - m_saves[i].m_save_data.clear(); - m_saves[i].m_used_blocks.clear(); + save.m_filename.clear(); + save.m_save_data.clear(); + save.m_used_blocks.clear(); } } @@ -666,12 +663,11 @@ void GCMemcardDirectory::FlushToFile() // simultaneously // this ensures that the save data for all of the current games gci files are stored in the // savestate - const u32 gamecode = Common::swap32(m_saves[i].m_gci_header.m_gamecode.data()); - if (gamecode != m_game_id && gamecode != 0xFFFFFFFF && !m_saves[i].m_save_data.empty()) + const u32 gamecode = Common::swap32(save.m_gci_header.m_gamecode.data()); + if (gamecode != m_game_id && gamecode != 0xFFFFFFFF && !save.m_save_data.empty()) { - INFO_LOG(EXPANSIONINTERFACE, "Flushing savedata to disk for %s", - m_saves[i].m_filename.c_str()); - m_saves[i].m_save_data.clear(); + INFO_LOG(EXPANSIONINTERFACE, "Flushing savedata to disk for %s", save.m_filename.c_str()); + save.m_save_data.clear(); } } #if _WRITE_MC_HEADER @@ -696,9 +692,9 @@ void GCMemcardDirectory::DoState(PointerWrap& p) int num_saves = (int)m_saves.size(); p.Do(num_saves); m_saves.resize(num_saves); - for (auto itr = m_saves.begin(); itr != m_saves.end(); ++itr) + for (Memcard::GCIFile& save : m_saves) { - itr->DoState(p); + save.DoState(p); } } diff --git a/Source/Core/Core/NetPlayClient.cpp b/Source/Core/Core/NetPlayClient.cpp index 556849e533..e6efce1799 100644 --- a/Source/Core/Core/NetPlayClient.cpp +++ b/Source/Core/Core/NetPlayClient.cpp @@ -784,9 +784,9 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet) { const size_t sram_settings_len = sizeof(g_SRAM) - offsetof(Sram, settings); u8 sram[sram_settings_len]; - for (size_t i = 0; i < sram_settings_len; ++i) + for (u8& cell : sram) { - packet >> sram[i]; + packet >> cell; } { @@ -942,8 +942,8 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet) packet >> header.banner_size; packet >> header.permissions; packet >> header.unk1; - for (size_t i = 0; i < header.md5.size(); i++) - packet >> header.md5[i]; + for (u8& byte : header.md5) + packet >> byte; packet >> header.unk2; for (size_t i = 0; i < header.banner_size; i++) packet >> header.banner[i]; @@ -958,11 +958,11 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet) packet >> bk_header.unk1; packet >> bk_header.unk2; packet >> bk_header.total_size; - for (size_t i = 0; i < bk_header.unk3.size(); i++) - packet >> bk_header.unk3[i]; + for (u8& byte : bk_header.unk3) + packet >> byte; packet >> bk_header.tid; - for (size_t i = 0; i < bk_header.mac_address.size(); i++) - packet >> bk_header.mac_address[i]; + for (u8& byte : bk_header.mac_address) + packet >> byte; // Files std::vector files; diff --git a/Source/Core/Core/NetPlayServer.cpp b/Source/Core/Core/NetPlayServer.cpp index 0080cd8a83..e76d362285 100644 --- a/Source/Core/Core/NetPlayServer.cpp +++ b/Source/Core/Core/NetPlayServer.cpp @@ -787,8 +787,8 @@ unsigned int NetPlayServer::OnData(sf::Packet& packet, Client& player) u8 size; packet >> map >> size; std::vector data(size); - for (size_t i = 0; i < data.size(); ++i) - packet >> data[i]; + for (u8& byte : data) + packet >> byte; // If the data is not from the correct player, // then disconnect them. @@ -1568,8 +1568,8 @@ bool NetPlayServer::SyncSaveData() // Header pac << sf::Uint64{header->tid}; pac << header->banner_size << header->permissions << header->unk1; - for (size_t i = 0; i < header->md5.size(); i++) - pac << header->md5[i]; + for (u8 byte : header->md5) + pac << byte; pac << header->unk2; for (size_t i = 0; i < header->banner_size; i++) pac << header->banner[i]; @@ -1578,11 +1578,11 @@ bool NetPlayServer::SyncSaveData() pac << bk_header->size << bk_header->magic << bk_header->ngid << bk_header->number_of_files << bk_header->size_of_files << bk_header->unk1 << bk_header->unk2 << bk_header->total_size; - for (size_t i = 0; i < bk_header->unk3.size(); i++) - pac << bk_header->unk3[i]; + for (u8 byte : bk_header->unk3) + pac << byte; pac << sf::Uint64{bk_header->tid}; - for (size_t i = 0; i < bk_header->mac_address.size(); i++) - pac << bk_header->mac_address[i]; + for (u8 byte : bk_header->mac_address) + pac << byte; // Files for (const WiiSave::Storage::SaveFile& file : *files) diff --git a/Source/Core/DolphinQt/RenderWidget.cpp b/Source/Core/DolphinQt/RenderWidget.cpp index 234eb270cb..c6bc0d414a 100644 --- a/Source/Core/DolphinQt/RenderWidget.cpp +++ b/Source/Core/DolphinQt/RenderWidget.cpp @@ -331,6 +331,7 @@ void RenderWidget::SetImGuiKeyMap() {ImGuiKey_Z, Qt::Key_Z}, }}; auto lock = g_renderer->GetImGuiLock(); - for (auto entry : key_map) - ImGui::GetIO().KeyMap[entry[0]] = entry[1] & 0x1FF; + + for (auto [imgui_key, qt_key] : key_map) + ImGui::GetIO().KeyMap[imgui_key] = (qt_key & 0x1FF); } diff --git a/Source/Core/InputCommon/GCAdapter.cpp b/Source/Core/InputCommon/GCAdapter.cpp index ab9618efdf..dc7c64f6f2 100644 --- a/Source/Core/InputCommon/GCAdapter.cpp +++ b/Source/Core/InputCommon/GCAdapter.cpp @@ -40,10 +40,10 @@ enum // Current adapter status: detected/not detected/in error (holds the error code) static std::atomic s_status = NO_ADAPTER_DETECTED; static libusb_device_handle* s_handle = nullptr; -static u8 s_controller_type[SerialInterface::MAX_SI_CHANNELS] = { +static std::array s_controller_type = { ControllerTypes::CONTROLLER_NONE, ControllerTypes::CONTROLLER_NONE, ControllerTypes::CONTROLLER_NONE, ControllerTypes::CONTROLLER_NONE}; -static u8 s_controller_rumble[4]; +static std::array s_controller_rumble{}; static std::mutex s_mutex; static u8 s_controller_payload[37]; @@ -236,11 +236,8 @@ static void Setup() if (s_status < 0) s_status = NO_ADAPTER_DETECTED; - for (int i = 0; i < SerialInterface::MAX_SI_CHANNELS; i++) - { - s_controller_type[i] = ControllerTypes::CONTROLLER_NONE; - s_controller_rumble[i] = 0; - } + s_controller_type.fill(ControllerTypes::CONTROLLER_NONE); + s_controller_rumble.fill(0); s_libusb_context.GetDeviceList([](libusb_device* device) { if (CheckDeviceAccess(device)) @@ -395,8 +392,7 @@ static void Reset() s_adapter_output_thread.join(); } - for (int i = 0; i < SerialInterface::MAX_SI_CHANNELS; i++) - s_controller_type[i] = ControllerTypes::CONTROLLER_NONE; + s_controller_type.fill(ControllerTypes::CONTROLLER_NONE); s_status = NO_ADAPTER_DETECTED; diff --git a/Source/Core/VideoBackends/Software/DebugUtil.cpp b/Source/Core/VideoBackends/Software/DebugUtil.cpp index ee77e3a5dd..c427160fc7 100644 --- a/Source/Core/VideoBackends/Software/DebugUtil.cpp +++ b/Source/Core/VideoBackends/Software/DebugUtil.cpp @@ -45,9 +45,9 @@ void Init() void Shutdown() { - for (int i = 0; i < NUM_OBJECT_BUFFERS; i++) + for (auto& slot : ObjectBuffer) { - delete[] ObjectBuffer[i]; + delete[] slot; } } diff --git a/Source/Core/VideoBackends/Vulkan/Renderer.cpp b/Source/Core/VideoBackends/Vulkan/Renderer.cpp index 9d096e19e4..e6f1b44b39 100644 --- a/Source/Core/VideoBackends/Vulkan/Renderer.cpp +++ b/Source/Core/VideoBackends/Vulkan/Renderer.cpp @@ -48,8 +48,8 @@ Renderer::Renderer(std::unique_ptr swap_chain, float backbuffer_scale m_swap_chain(std::move(swap_chain)) { UpdateActiveConfig(); - for (size_t i = 0; i < m_sampler_states.size(); i++) - m_sampler_states[i].hex = RenderState::GetPointSamplerState().hex; + for (SamplerState& m_sampler_state : m_sampler_states) + m_sampler_state.hex = RenderState::GetPointSamplerState().hex; } Renderer::~Renderer() = default;