diff --git a/CMakeLists.txt b/CMakeLists.txt index 66d85a147..4b8c90106 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -160,10 +160,10 @@ endif() if(WINDOWS_STORE) set(USE_OPENGL OFF) set(USE_VULKAN OFF) - target_compile_features(${PROJECT_NAME} PRIVATE c_std_11 cxx_std_17) -else() - target_compile_features(${PROJECT_NAME} PRIVATE c_std_11 cxx_std_11) endif() + +target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17) + set_target_properties(${PROJECT_NAME} PROPERTIES CXX_EXTENSIONS OFF LINK_FLAGS_RELEASE -s) @@ -1175,6 +1175,11 @@ if(USE_VULKAN) add_subdirectory(core/deps/Vulkan-Headers) target_link_libraries(${PROJECT_NAME} PRIVATE Vulkan::Headers) + if (APPLE) + # Only available on macOS 10.12+ + target_compile_definitions(${PROJECT_NAME} PRIVATE VMA_USE_STL_SHARED_MUTEX=0) + endif() + add_library(VulkanMemoryAllocator INTERFACE) target_include_directories(VulkanMemoryAllocator INTERFACE core/deps/VulkanMemoryAllocator/include) target_link_libraries(${PROJECT_NAME} PRIVATE VulkanMemoryAllocator) diff --git a/core/cfg/ini.cpp b/core/cfg/ini.cpp index 5ef06a17e..c5879572c 100644 --- a/core/cfg/ini.cpp +++ b/core/cfg/ini.cpp @@ -260,18 +260,13 @@ void ConfigFile::parse(FILE* file) void ConfigFile::save(FILE* file) { - for (const auto& section_it : this->sections) + for (const auto& [section_name, section] : this->sections) { - const std::string& section_name = section_it.first; - const ConfigSection& section = section_it.second; - if (!section_name.empty()) std::fprintf(file, "[%s]\n", section_name.c_str()); - for (const auto& entry_it : section.entries) + for (const auto& [entry_name, entry] : section.entries) { - const std::string& entry_name = entry_it.first; - const ConfigEntry& entry = entry_it.second; std::fprintf(file, "%s = %s\n", entry_name.c_str(), entry.get_string().c_str()); } if (!section_name.empty()) diff --git a/core/cfg/option.h b/core/cfg/option.h index a47549f61..519c9f8b5 100644 --- a/core/cfg/option.h +++ b/core/cfg/option.h @@ -21,6 +21,7 @@ #include #include #include +#include #include "cfg.h" #include "hw/maple/maple_cfg.h" #ifdef LIBRETRO @@ -100,10 +101,6 @@ private: friend class Option; }; -// Missing in C++11 -template -using enable_if_t = typename std::enable_if::type; - template class Option : public BaseOption { public: @@ -173,36 +170,36 @@ public: protected: template - enable_if_t::value, T> + std::enable_if_t, T> doLoad(const std::string& section, const std::string& name) const { return cfgLoadBool(section, name, value); } template - enable_if_t::value, T> + std::enable_if_t::value, T> doLoad(const std::string& section, const std::string& name) const { return cfgLoadInt64(section, name, value); } template - enable_if_t<(std::is_integral::value || std::is_enum::value) - && !std::is_same::value && !std::is_same::value, T> + std::enable_if_t<(std::is_integral_v || std::is_enum_v) + && !std::is_same_v && !std::is_same_v, T> doLoad(const std::string& section, const std::string& name) const { return (T)cfgLoadInt(section, name, (int)value); } template - enable_if_t::value, T> + std::enable_if_t, T> doLoad(const std::string& section, const std::string& name) const { return cfgLoadStr(section, name, value); } template - enable_if_t::value, T> + std::enable_if_t, T> doLoad(const std::string& section, const std::string& name) const { std::string strValue = cfgLoadStr(section, name, ""); @@ -213,7 +210,7 @@ protected: } template - enable_if_t, U>::value, T> + std::enable_if_t, U>, T> doLoad(const std::string& section, const std::string& name) const { std::string paths = cfgLoadStr(section, name, ""); @@ -272,36 +269,36 @@ protected: } template - enable_if_t::value> + std::enable_if_t> doSave(const std::string& section, const std::string& name) const { cfgSaveBool(section, name, value); } template - enable_if_t::value> + std::enable_if_t::value> doSave(const std::string& section, const std::string& name) const { cfgSaveInt64(section, name, value); } template - enable_if_t<(std::is_integral::value || std::is_enum::value) - && !std::is_same::value && !std::is_same::value> + std::enable_if_t<(std::is_integral_v || std::is_enum_v) + && !std::is_same_v && !std::is_same_v> doSave(const std::string& section, const std::string& name) const { cfgSaveInt(section, name, (int)value); } template - enable_if_t::value> + std::enable_if_t> doSave(const std::string& section, const std::string& name) const { cfgSaveStr(section, name, value); } template - enable_if_t::value> + std::enable_if_t> doSave(const std::string& section, const std::string& name) const { char buf[64]; @@ -310,7 +307,7 @@ protected: } template - enable_if_t, U>::value> + std::enable_if_t, U>> doSave(const std::string& section, const std::string& name) const { std::string s; diff --git a/core/cheats.cpp b/core/cheats.cpp index b998cbeae..7951f34b9 100644 --- a/core/cheats.cpp +++ b/core/cheats.cpp @@ -473,7 +473,7 @@ void CheatManager::reset(const std::string& gameId) } } if (widescreen_cheat != nullptr) - for (size_t i = 0; i < ARRAY_SIZE(widescreen_cheat->addresses) && widescreen_cheat->addresses[i] != 0; i++) + for (size_t i = 0; i < std::size(widescreen_cheat->addresses) && widescreen_cheat->addresses[i] != 0; i++) verify(widescreen_cheat->addresses[i] < RAM_SIZE); } setActive(active); @@ -514,7 +514,7 @@ void CheatManager::apply() { if (widescreen_cheat != nullptr) { - for (size_t i = 0; i < ARRAY_SIZE(widescreen_cheat->addresses) && widescreen_cheat->addresses[i] != 0; i++) + for (size_t i = 0; i < std::size(widescreen_cheat->addresses) && widescreen_cheat->addresses[i] != 0; i++) { u32 address = widescreen_cheat->addresses[i]; u32 curVal = readRam(address, 32); diff --git a/core/hw/aica/aica.cpp b/core/hw/aica/aica.cpp index d7e11f249..259cccd3b 100644 --- a/core/hw/aica/aica.cpp +++ b/core/hw/aica/aica.cpp @@ -105,7 +105,7 @@ static int AicaUpdate(int tag, int c, int j) void timeStep() { - for (int i=0;i<3;i++) + for (std::size_t i = 0; i < std::size(timers); i++) timers[i].StepTimer(1); SCIPD->SAMPLE_DONE = 1; @@ -290,7 +290,7 @@ void reset(bool hard) sgc::init(); sh4_sched_request(aica_schid, AICA_TICK); } - for (u32 i = 0; i < 3; i++) + for (std::size_t i = 0; i < std::size(timers); i++) timers[i].Init(aica_reg, i); resetRtc(hard); arm::reset(); diff --git a/core/hw/aica/aica_mem.cpp b/core/hw/aica/aica_mem.cpp index f73c64723..907ef7b64 100644 --- a/core/hw/aica/aica_mem.cpp +++ b/core/hw/aica/aica_mem.cpp @@ -14,7 +14,7 @@ static void (*midiReceiver)(u8 data); //Aica read/write (both sh4 & arm) -//00000000~007FFFFF @DRAM_AREA* +//00000000~007FFFFF @DRAM_AREA* //00800000~008027FF @CHANNEL_DATA //00802800~00802FFF @COMMON_DATA //00803000~00807FFF @DSP_DATA @@ -54,7 +54,7 @@ T readRegInternal(u32 addr) else v &= 0xf; } - if (sizeof(T) == 1) + if constexpr (sizeof(T) == 1) { if (addr & 1) v >>= 8; @@ -110,7 +110,7 @@ void writeRegInternal(u32 addr, T data) if (addr < 0x2818) { writeCommonReg8(addr, data & 0xFF); - if (sz == 2) + if constexpr (sz == 2) writeCommonReg8(addr + 1, data >> 8); return; } @@ -130,7 +130,7 @@ void writeRegInternal(u32 addr, T data) s32 &v = addr < 0x4400 ? dsp::state.TEMP[(addr - 0x4000) / 8] : dsp::state.MEMS[(addr - 0x4400) / 8]; if (addr & 4) { - if (sz == 1) + if constexpr (sz == 1) { if (addr & 1) v = (v & 0x0000ffff) | (((s32)data << 24) >> 8); @@ -181,7 +181,7 @@ void writeRegInternal(u32 addr, T data) WriteMemArr(aica_reg, addr, data); dsp::writeProg(addr); - if (sz == 2) + if constexpr (sz == 2) dsp::writeProg(addr + 1); return; } diff --git a/core/hw/aica/sgc_if.cpp b/core/hw/aica/sgc_if.cpp index 97f64cc27..1847246c0 100755 --- a/core/hw/aica/sgc_if.cpp +++ b/core/hw/aica/sgc_if.cpp @@ -159,16 +159,6 @@ static void VolumePan(SampleType value, u32 vol, u32 pan, SampleType& outl, Samp } } -template -static void clip(T& v, T min, T max) { - v = std::min(max, std::max(min, v)); -} - -template -static void clip16(T& v) { - clip(v, -32768, 32767); -} - const DSP_OUT_VOL_REG *dsp_out_vol = (DSP_OUT_VOL_REG *)&aica_reg[0x2000]; static int beepOn; static int beepPeriod; @@ -505,7 +495,7 @@ struct ChannelEx f = std::max(1, f); sample = f * sample + (0x2000 - f + FEG.q) * FEG.prev1 - FEG.q * FEG.prev2; sample >>= 13; - clip16(sample); + sample = std::clamp(sample, -32768, 32767); FEG.prev2 = FEG.prev1; FEG.prev1 = sample; } @@ -678,10 +668,7 @@ struct ChannelEx u32 EG_EffRate(s32 base_rate, u32 rate) { s32 rv = base_rate + rate * 2; - - clip(rv, 0, 0x3f); - - return rv; + return std::clamp(rv, 0, 0x3f); } //D2R,D1R,AR,DL,RR,KRS, [OCT,FNS] for now @@ -898,10 +885,9 @@ static SampleType DecodeADPCM(u32 sample,s32 prev,s32& quant) rv = sign * rv + prev; quant = (quant * adpcm_qs[data])>>8; + quant = std::clamp(quant, 127, 24576); - clip(quant,127,24576); - clip16(rv); - return rv; + return std::clamp(rv, -32768, 32767); } template @@ -1295,7 +1281,7 @@ void init() { staticinitialise(); - for (int i = 0; i < 16; i++) + for (std::size_t i = 0; i < std::size(volume_lut); i++) { volume_lut[i]=(s32)((1<<15)/pow(2.0,(15-i)/2.0)); if (i==0) @@ -1316,7 +1302,7 @@ void init() FEG_SPS[i] = CalcEgSteps(AEG_DSR_Time[i]); //FEG_SPS[i] = CalcEgSteps(FEG_Time[i]); } - for (int i=0;i<64;i++) + for (std::size_t i = 0; i < std::size(Chans); i++) Chans[i].Init(i,aica_reg); for (int s = 0; s < 8; s++) @@ -1519,8 +1505,8 @@ void AICA_Sample() printf("Clipped mixl %d mixr %d\n", mixl, mixr); #endif - clip16(mixl); - clip16(mixr); + mixl = std::clamp(mixl, -32768, 32767); + mixr = std::clamp(mixr, -32768, 32767); WriteSample(mixr,mixl); } diff --git a/core/hw/arm7/arm7.cpp b/core/hw/arm7/arm7.cpp index 640924709..8c874d29e 100644 --- a/core/hw/arm7/arm7.cpp +++ b/core/hw/arm7/arm7.cpp @@ -99,7 +99,7 @@ void init() #endif reset(); - for (int i = 0; i < 256; i++) + for (std::size_t i = 0; i < std::size(cpuBitsSet); i++) { int count = 0; for (int j = 0; j < 8; j++) diff --git a/core/hw/arm7/arm7_rec.cpp b/core/hw/arm7/arm7_rec.cpp index 28196e116..9793f66cb 100644 --- a/core/hw/arm7/arm7_rec.cpp +++ b/core/hw/arm7/arm7_rec.cpp @@ -668,7 +668,7 @@ void flush() icPtr = ICache; arm7backend_flush(); verify(arm_compilecode != nullptr); - for (u32 i = 0; i < ARRAY_SIZE(EntryPoints); i++) + for (u32 i = 0; i < std::size(EntryPoints); i++) EntryPoints[i] = arm_compilecode; } @@ -681,7 +681,7 @@ void init() #endif verify(rc); - for (int i = 0; i < 256; i++) + for (std::size_t i = 0; i < std::size(cpuBitsSet); i++) { int count = 0; for (int j = 0; j < 8; j++) diff --git a/core/hw/arm7/arm7_rec_arm32.cpp b/core/hw/arm7/arm7_rec_arm32.cpp index c43920f17..79ecb4fda 100644 --- a/core/hw/arm7/arm7_rec_arm32.cpp +++ b/core/hw/arm7/arm7_rec_arm32.cpp @@ -66,9 +66,9 @@ const std::array alloc_regs{ r5, r6, r7, r9, r10, r11 }; -class Arm32ArmRegAlloc : public ArmRegAlloc +class Arm32ArmRegAlloc : public ArmRegAlloc { - using super = ArmRegAlloc; + using super = ArmRegAlloc; void LoadReg(int host_reg, Arm7Reg armreg, ArmOp::Condition cc = ArmOp::AL) { diff --git a/core/hw/arm7/arm7_rec_arm64.cpp b/core/hw/arm7/arm7_rec_arm64.cpp index 7ce10f95b..e65dfd734 100644 --- a/core/hw/arm7/arm7_rec_arm64.cpp +++ b/core/hw/arm7/arm7_rec_arm64.cpp @@ -65,8 +65,8 @@ class AArch64ArmRegAlloc : public ArmRegAlloc static const WRegister regs[] = { w19, w20, w21, w22, w23, w24, w25, w27 }; - static_assert(MAX_REGS == ARRAY_SIZE(regs), "MAX_REGS == ARRAY_SIZE(regs)"); - verify(i >= 0 && (u32)i < ARRAY_SIZE(regs)); + static_assert(MAX_REGS == std::size(regs), "MAX_REGS == std::size(regs)"); + verify(i >= 0 && (u32)i < std::size(regs)); return regs[i]; } diff --git a/core/hw/arm7/arm7_rec_x64.cpp b/core/hw/arm7/arm7_rec_x64.cpp index ad2413dd9..4064ab2b4 100644 --- a/core/hw/arm7/arm7_rec_x64.cpp +++ b/core/hw/arm7/arm7_rec_x64.cpp @@ -56,9 +56,9 @@ static const std::array alloc_regs { }; #endif -class X64ArmRegAlloc : public ArmRegAlloc +class X64ArmRegAlloc : public ArmRegAlloc { - using super = ArmRegAlloc; + using super = ArmRegAlloc; Arm7Compiler& assembler; void LoadReg(int host_reg, Arm7Reg armreg); diff --git a/core/hw/holly/sb_mem.cpp b/core/hw/holly/sb_mem.cpp index a537e9ed9..fc2a52f44 100644 --- a/core/hw/holly/sb_mem.cpp +++ b/core/hw/holly/sb_mem.cpp @@ -52,7 +52,7 @@ T DYNACALL ReadMem_area0(u32 paddr) // System/Boot ROM if (addr < (System == DC_PLATFORM_ATOMISWAVE ? 0x20000 : 0x200000)) { - if (Mirror) + if constexpr (Mirror) { INFO_LOG(MEMORY, "Read from area0 BIOS mirror [Unassigned], addr=%x", addr); return 0; @@ -64,7 +64,7 @@ T DYNACALL ReadMem_area0(u32 paddr) // Flash memory if (addr < 0x00200000 + settings.platform.flash_size) { - if (Mirror) + if constexpr (Mirror) { INFO_LOG(MEMORY, "Read from area0 Flash mirror [Unassigned], addr=%x", addr); return 0; @@ -87,7 +87,7 @@ T DYNACALL ReadMem_area0(u32 paddr) // TA / PVR core registers if (addr >= 0x005F8000 && addr <= 0x005F9FFF) { - if (sz != 4) + if constexpr (sz != 4) // House of the Dead 2 return 0; return (T)pvr_ReadReg(paddr); @@ -149,7 +149,7 @@ void DYNACALL WriteMem_area0(u32 paddr, T data) { case 0: // System/Boot ROM - if (!Mirror) + if constexpr (!Mirror) { if (System == DC_PLATFORM_ATOMISWAVE) { diff --git a/core/hw/maple/maple_cfg.cpp b/core/hw/maple/maple_cfg.cpp index 5abef857d..f8de993e2 100644 --- a/core/hw/maple/maple_cfg.cpp +++ b/core/hw/maple/maple_cfg.cpp @@ -86,7 +86,7 @@ void MapleConfigMap::GetInput(PlainJoystickState* pjs) #else const u32* mapping = settings.input.JammaSetup == JVS::LightGun ? awavelg_button_mapping : awave_button_mapping; pjs->kcode = ~0; - for (u32 i = 0; i < ARRAY_SIZE(awave_button_mapping); i++) + for (u32 i = 0; i < std::size(awave_button_mapping); i++) { if ((inputState.kcode & (1 << i)) == 0) pjs->kcode &= ~mapping[i]; diff --git a/core/hw/maple/maple_devs.cpp b/core/hw/maple/maple_devs.cpp index 391d51c30..42dea1583 100755 --- a/core/hw/maple/maple_devs.cpp +++ b/core/hw/maple/maple_devs.cpp @@ -1104,7 +1104,7 @@ struct maple_keyboard : maple_base //int8 led ; leds currently lit //1 w8(0); //int8 key[6] ; normal keys pressed //6 - for (int i = 0; i < 6; i++) + for (std::size_t i = 0; i < std::size(keys); i++) w8(keys[i]); } return MDRS_DataTransfer; diff --git a/core/hw/maple/maple_jvs.cpp b/core/hw/maple/maple_jvs.cpp index b9250444a..73da76dd8 100644 --- a/core/hw/maple/maple_jvs.cpp +++ b/core/hw/maple/maple_jvs.cpp @@ -70,13 +70,13 @@ const char *GetCurrentGameButtonName(DreamcastKey key) u32 arcade_key; if (settings.platform.isNaomi()) { - if (pos >= ARRAY_SIZE(naomi_button_mapping)) + if (pos >= std::size(naomi_button_mapping)) return nullptr; arcade_key = naomi_button_mapping[pos]; } else { - if (pos >= ARRAY_SIZE(awave_button_mapping)) + if (pos >= std::size(awave_button_mapping)) return nullptr; const u32* mapping = settings.input.JammaSetup == JVS::LightGun ? awavelg_button_mapping : awave_button_mapping; arcade_key = mapping[pos]; @@ -651,7 +651,7 @@ protected: u16 read_analog_axis(int player_num, int player_axis, bool inverted) override { if (init_in_progress) return 0; - const MapleInputState& inputState = mapleInputState[std::min(player_num, (int)ARRAY_SIZE(mapleInputState) - 1)]; + const MapleInputState& inputState = mapleInputState[std::min(player_num, (int)std::size(mapleInputState) - 1)]; if (inputState.absPos.x < 0 || inputState.absPos.x > 639 || inputState.absPos.y < 0 || inputState.absPos.y > 479) return 0; else @@ -828,70 +828,70 @@ maple_naomi_jamma::maple_naomi_jamma() { case JVS::Default: default: - io_boards.push_back(std::unique_ptr(new jvs_837_13551(1, this))); + io_boards.push_back(std::make_unique(1, this)); break; case JVS::FourPlayers: - io_boards.push_back(std::unique_ptr(new jvs_837_13551_4P(1, this))); + io_boards.push_back(std::make_unique(1, this)); break; case JVS::RotaryEncoders: - io_boards.push_back(std::unique_ptr(new jvs_837_13938(1, this))); - io_boards.push_back(std::unique_ptr(new jvs_837_13551(2, this))); + io_boards.push_back(std::make_unique(1, this)); + io_boards.push_back(std::make_unique(2, this)); break; case JVS::OutTrigger: - io_boards.push_back(std::unique_ptr(new jvs_837_13938(1, this))); - io_boards.push_back(std::unique_ptr(new jvs_837_13551_noanalog(2, this))); + io_boards.push_back(std::make_unique(1, this)); + io_boards.push_back(std::make_unique(2, this)); break; case JVS::SegaMarineFishing: - io_boards.push_back(std::unique_ptr(new jvs_837_13844(1, this))); + io_boards.push_back(std::make_unique(1, this)); break; case JVS::DualIOBoards4P: if (settings.content.gameId == "VIRTUA ATHLETE") { // reverse the board order so that P1 is P1 - io_boards.push_back(std::unique_ptr(new jvs_837_13551(1, this, 2))); - io_boards.push_back(std::unique_ptr(new jvs_837_13551(2, this, 0))); + io_boards.push_back(std::make_unique(1, this, 2)); + io_boards.push_back(std::make_unique(2, this, 0)); } else { - io_boards.push_back(std::unique_ptr(new jvs_837_13551(1, this))); - io_boards.push_back(std::unique_ptr(new jvs_837_13551(2, this, 2))); + io_boards.push_back(std::make_unique(1, this)); + io_boards.push_back(std::make_unique(2, this, 2)); } break; case JVS::LightGun: - io_boards.push_back(std::unique_ptr(new jvs_namco_jyu(1, this))); + io_boards.push_back(std::make_unique(1, this)); break; case JVS::LightGunAsAnalog: // Regular board sending lightgun coords as axis 0/1 - io_boards.push_back(std::unique_ptr(new jvs_837_13551(1, this))); + io_boards.push_back(std::make_unique(1, this)); io_boards.back()->lightgun_as_analog = true; break; case JVS::Mazan: - io_boards.push_back(std::unique_ptr(new jvs_namco_fcb(1, this))); - io_boards.push_back(std::unique_ptr(new jvs_namco_fcb(2, this))); + io_boards.push_back(std::make_unique(1, this)); + io_boards.push_back(std::make_unique(2, this)); break; case JVS::GunSurvivor: - io_boards.push_back(std::unique_ptr(new jvs_namco_fca(1, this))); + io_boards.push_back(std::make_unique(1, this)); break; case JVS::DogWalking: - io_boards.push_back(std::unique_ptr(new jvs_837_13844_encoders(1, this))); + io_boards.push_back(std::make_unique(1, this)); break; case JVS::TouchDeUno: - io_boards.push_back(std::unique_ptr(new jvs_837_13844_touch(1, this))); + io_boards.push_back(std::make_unique(1, this)); break; case JVS::WorldKicks: - io_boards.push_back(std::unique_ptr(new jvs_namco_v226(1, this))); + io_boards.push_back(std::make_unique(1, this)); break; case JVS::WorldKicksPCB: - io_boards.push_back(std::unique_ptr(new jvs_namco_v226_pcb(1, this))); + io_boards.push_back(std::make_unique(1, this)); break; case JVS::WaveRunnerGP: - io_boards.push_back(std::unique_ptr(new jvs_837_13844_wrungp(1, this))); + io_boards.push_back(std::make_unique(1, this)); break; case JVS::_18Wheeler: - io_boards.push_back(std::unique_ptr(new jvs_837_13844_18wheeler(1, this))); + io_boards.push_back(std::make_unique(1, this)); break; case JVS::F355: - io_boards.push_back(std::unique_ptr(new jvs_837_13844_racing(1, this))); + io_boards.push_back(std::make_unique(1, this)); break; } } @@ -1144,7 +1144,7 @@ void maple_naomi_jamma::handle_86_subcommand() case 0x35: // Receive then transmit with repeat (15 then 27) receive_jvs_messages(channel); - // FALLTHROUGH + [[fallthrough]]; case 0x27: // Transmit with repeat { @@ -1626,7 +1626,7 @@ u32 jvs_io_board::handle_jvs_message(u8 *buffer_in, u32 length_in, u8 *buffer_ou for (int p = 0; p < 4; p++) buttons[p] = ~mapleInputState[p].kcode; #else - for (u32 i = 0; i < ARRAY_SIZE(naomi_button_mapping); i++) + for (u32 i = 0; i < std::size(naomi_button_mapping); i++) for (int p = 0; p < 4; p++) if ((mapleInputState[p].kcode & (1 << i)) == 0) buttons[p] |= naomi_button_mapping[i]; @@ -1702,7 +1702,7 @@ u32 jvs_io_board::handle_jvs_message(u8 *buffer_in, u32 length_in, u8 *buffer_ou for (; axis / 2 < player_count && axis < buffer_in[cmdi + 1]; axis += 2) { int playerNum = first_player + axis / 2; - const MapleInputState& inputState = mapleInputState[std::min(playerNum, (int)ARRAY_SIZE(mapleInputState) - 1)]; + const MapleInputState& inputState = mapleInputState[std::min(playerNum, (int)std::size(mapleInputState) - 1)]; u16 x; u16 y; if (inputState.absPos.x < 0 || inputState.absPos.x > 639 @@ -1732,7 +1732,7 @@ u32 jvs_io_board::handle_jvs_message(u8 *buffer_in, u32 length_in, u8 *buffer_ou u16 axis_value; if (NaomiGameInputs != NULL) { - if (player_axis >= ARRAY_SIZE(NaomiGameInputs->axes) + if (player_axis >= std::size(NaomiGameInputs->axes) || NaomiGameInputs->axes[player_axis].name == NULL) { // Next player @@ -1857,7 +1857,7 @@ u32 jvs_io_board::handle_jvs_message(u8 *buffer_in, u32 length_in, u8 *buffer_ou break; case 0x30: // substract coin - if (buffer_in[cmdi + 1] > 0 && first_player + buffer_in[cmdi + 1] - 1 < (int)ARRAY_SIZE(coin_count)) + if (buffer_in[cmdi + 1] > 0 && first_player + buffer_in[cmdi + 1] - 1 < (int)std::size(coin_count)) coin_count[first_player + buffer_in[cmdi + 1] - 1] -= (buffer_in[cmdi + 2] << 8) + buffer_in[cmdi + 3]; JVS_STATUS1(); // report byte cmdi += 4; diff --git a/core/hw/mem/addrspace.cpp b/core/hw/mem/addrspace.cpp index 21aaecfe1..65a0e67ac 100644 --- a/core/hw/mem/addrspace.cpp +++ b/core/hw/mem/addrspace.cpp @@ -446,7 +446,7 @@ void initMappings() // This is outside of the 512MB addr space. We map 8MB in all cases to help some games read past the end of aica ram {0x20000000, 0x20800000, MAP_ARAM_START_OFFSET, ARAM_SIZE, true}, // writable aica ram }; - virtmem::create_mappings(&mem_mappings[0], ARRAY_SIZE(mem_mappings)); + virtmem::create_mappings(&mem_mappings[0], std::size(mem_mappings)); // Point buffers to actual data pointers aica::aica_ram.setRegion(&ram_base[0x20000000], ARAM_SIZE); // Points to the writable AICA addrspace diff --git a/core/hw/naomi/gdcartridge.cpp b/core/hw/naomi/gdcartridge.cpp index 6019e8960..cbef5c21e 100644 --- a/core/hw/naomi/gdcartridge.cpp +++ b/core/hw/naomi/gdcartridge.cpp @@ -325,7 +325,7 @@ u64 GDCartridge::des_encrypt_decrypt(u64 src, const u32 *des_subkeys) permutate(l, r, 0x55555555, 1); int subkey; - if(decrypt) + if constexpr (decrypt) subkey = 30; else subkey = 0; @@ -346,7 +346,7 @@ u64 GDCartridge::des_encrypt_decrypt(u64 src, const u32 *des_subkeys) l ^= DES_SBOX3[ (temp>>16) & 0x3f ]; l ^= DES_SBOX1[ (temp>>24) & 0x3f ]; subkey++; - if(decrypt) + if constexpr (decrypt) subkey -= 4; temp = ((l<<1) | (l>>31)) ^ des_subkeys[subkey]; @@ -362,7 +362,7 @@ u64 GDCartridge::des_encrypt_decrypt(u64 src, const u32 *des_subkeys) r ^= DES_SBOX3[ (temp>>16) & 0x3f ]; r ^= DES_SBOX1[ (temp>>24) & 0x3f ]; subkey++; - if(decrypt) + if constexpr (decrypt) subkey -= 4; } diff --git a/core/hw/naomi/multiboard.cpp b/core/hw/naomi/multiboard.cpp index 8a16aee36..b9868573b 100644 --- a/core/hw/naomi/multiboard.cpp +++ b/core/hw/naomi/multiboard.cpp @@ -150,7 +150,7 @@ void Multiboard::startSlave() "-config", top.c_str(), CurrentCartridge->game->bios == nullptr ? "naomi" : CurrentCartridge->game->bios }; - os_RunInstance(ARRAY_SIZE(args), args); + os_RunInstance(std::size(args), args); } slaveStarted = true; } diff --git a/core/hw/naomi/naomi.cpp b/core/hw/naomi/naomi.cpp index 8ad1bd936..1b59ddafa 100644 --- a/core/hw/naomi/naomi.cpp +++ b/core/hw/naomi/naomi.cpp @@ -751,7 +751,7 @@ static void forceFeedbackMidiReceiver(u8 data) if (midiTxBuf[0] != 0xfd) networkOutput.output("midiffb", (midiTxBuf[0] << 16) | (midiTxBuf[1]) << 8 | midiTxBuf[2]); } - midiTxBufIndex = (midiTxBufIndex + 1) % ARRAY_SIZE(midiTxBuf); + midiTxBufIndex = (midiTxBufIndex + 1) % std::size(midiTxBuf); } void initMidiForceFeedback() diff --git a/core/hw/naomi/naomi_m3comm.cpp b/core/hw/naomi/naomi_m3comm.cpp index 00b8e68e6..5f22ba09f 100644 --- a/core/hw/naomi/naomi_m3comm.cpp +++ b/core/hw/naomi/naomi_m3comm.cpp @@ -86,7 +86,7 @@ bool NaomiM3Comm::receiveNetwork() const u32 slot_size = swap16(*(u16*)&m68k_ram[0x204]); const u32 packet_size = slot_size * slot_count; - std::unique_ptr buf(new u8[packet_size]); + std::unique_ptr buf = std::make_unique(packet_size); u16 packetNumber; if (!naomiNetwork.receive(buf.get(), packet_size, &packetNumber)) diff --git a/core/hw/pvr/elan.cpp b/core/hw/pvr/elan.cpp index 4028dad1c..935b76589 100644 --- a/core/hw/pvr/elan.cpp +++ b/core/hw/pvr/elan.cpp @@ -859,7 +859,7 @@ private: v.u1 = v1.u1 * a1 + v2.u1 * a2; v.v1 = v1.v1 * a1 + v2.v1 * a2; - for (size_t i = 0; i < ARRAY_SIZE(v1.col); i++) + for (size_t i = 0; i < std::size(v1.col); i++) { v.col[i] = (u8)std::round(v1.col[i] * a1 + v2.col[i] * a2); v.spc[i] = (u8)std::round(v1.spc[i] * a1 + v2.spc[i] * a2); diff --git a/core/hw/pvr/pvr_mem.cpp b/core/hw/pvr/pvr_mem.cpp index e98036385..8e23f32a7 100644 --- a/core/hw/pvr/pvr_mem.cpp +++ b/core/hw/pvr/pvr_mem.cpp @@ -213,7 +213,7 @@ template float pvr_read32p(u32 addr); template void DYNACALL pvr_write32p(u32 addr, T data) { - if (sizeof(T) == 1) + if constexpr (sizeof(T) == 1) { INFO_LOG(MEMORY, "%08x: 8-bit VRAM writes are not possible", addr); return; diff --git a/core/hw/pvr/ta_vtx.cpp b/core/hw/pvr/ta_vtx.cpp index b4c584dc3..f321ca3a2 100644 --- a/core/hw/pvr/ta_vtx.cpp +++ b/core/hw/pvr/ta_vtx.cpp @@ -159,7 +159,7 @@ public: static std::vector *CurrentPPlist; static PolyParam* CurrentPP; static TaListFP* TaCmd; - static bool fetchTextures; + inline static bool fetchTextures = true; }; const u32 *BaseTAParser::ta_type_lut = TaTypeLut::instance().table; @@ -176,7 +176,6 @@ PolyParam* BaseTAParser::CurrentPP; std::vector* BaseTAParser::CurrentPPlist; BaseTAParser::TaListFP *BaseTAParser::TaCmd; BaseTAParser::TaListFP *BaseTAParser::VertexDataFP; -bool BaseTAParser::fetchTextures = true; template class TAParserTempl : public BaseTAParser @@ -189,7 +188,7 @@ class TAParserTempl : public BaseTAParser TA_VertexParam* vp=(TA_VertexParam*)data; u32 rv=0; - if (part==2) + if constexpr (part == 2) { TaCmd=ta_main; } @@ -218,18 +217,18 @@ break; #define ver_64B_def(num) \ case num : {\ /*process first half*/\ - if (part!=2)\ + if constexpr (part != 2)\ {\ rv+=SZ32;\ AppendPolyVertex##num##A(&vp->vtx##num##A);\ }\ /*process second half*/\ - if (part==0)\ + if constexpr (part == 0)\ {\ AppendPolyVertex##num##B(&vp->vtx##num##B);\ rv+=SZ32;\ }\ - else if (part==2)\ + else if constexpr (part == 2)\ {\ AppendPolyVertex##num##B((TA_Vertex##num##B*)data);\ rv+=SZ32;\ @@ -369,7 +368,7 @@ strip_end: template static Ta_Dma* TACALL ta_poly_B_32(Ta_Dma* data,Ta_Dma* data_end) { - if (t==2) + if constexpr (t == 2) AppendPolyParam2B((TA_PolyParam2B*)data); else AppendPolyParam4B((TA_PolyParam4B*)data); @@ -1549,7 +1548,7 @@ static void vtxdec_init() 0x3b80 ~ 0x3f80 -> actual useful range. Rest is clamping to 0 or 255 ~ */ - for (u32 i = 0; i < ARRAY_SIZE(f32_su8_tbl); i++) + for (u32 i = 0; i < std::size(f32_su8_tbl); i++) { u32 fr = i << 16; diff --git a/core/hw/sh4/dyna/blockmanager.cpp b/core/hw/sh4/dyna/blockmanager.cpp index 3d5c01862..22ffd95ab 100644 --- a/core/hw/sh4/dyna/blockmanager.cpp +++ b/core/hw/sh4/dyna/blockmanager.cpp @@ -501,7 +501,7 @@ void RuntimeBlockInfo::AddRef(const RuntimeBlockInfoPtr& other) void RuntimeBlockInfo::RemRef(const RuntimeBlockInfoPtr& other) { - bm_List::iterator it = std::find(pre_refs.begin(), pre_refs.end(), other); + auto it = std::find(pre_refs.begin(), pre_refs.end(), other); if (it != pre_refs.end()) pre_refs.erase(it); } diff --git a/core/hw/sh4/modules/dmac.cpp b/core/hw/sh4/modules/dmac.cpp index a7ad1b3e6..6cc5f875d 100644 --- a/core/hw/sh4/modules/dmac.cpp +++ b/core/hw/sh4/modules/dmac.cpp @@ -111,7 +111,7 @@ static const InterruptID dmac_itr[] = { sh4_DMAC_DMTE0, sh4_DMAC_DMTE1, sh4_DMAC template static void WriteCHCR(u32 addr, u32 data) { - if (ch == 0 || ch == 1) + if constexpr (ch == 0 || ch == 1) DMAC_CHCR(ch).full = data & 0xff0ffff7; else // no AL or RL on channels 2 and 3 diff --git a/core/hw/sh4/modules/fastmmu.cpp b/core/hw/sh4/modules/fastmmu.cpp index 7d1c1048d..aeb400316 100644 --- a/core/hw/sh4/modules/fastmmu.cpp +++ b/core/hw/sh4/modules/fastmmu.cpp @@ -56,7 +56,7 @@ static void cache_entry(const TLB_Entry &entry) { if (entry.Data.SZ0 == 0 && entry.Data.SZ1 == 0) return; - verify(full_table_size < ARRAY_SIZE(full_table)); + verify(full_table_size < std::size(full_table)); full_table[full_table_size].entry = entry; @@ -132,7 +132,7 @@ int main(int argc, char *argv[]) perror(argv[1]); return 1; } - full_table_size = fread(full_table, sizeof(full_table[0]), ARRAY_SIZE(full_table), f); + full_table_size = fread(full_table, sizeof(full_table[0]), std::size(full_table), f); fclose(f); printf("Loaded %d entries\n", full_table_size); std::vector addrs; diff --git a/core/hw/sh4/modules/mmu.cpp b/core/hw/sh4/modules/mmu.cpp index 7d2a1b556..2cd6707de 100644 --- a/core/hw/sh4/modules/mmu.cpp +++ b/core/hw/sh4/modules/mmu.cpp @@ -468,7 +468,7 @@ void MMU_init() { u32 match_key = ((~ITLB_LRU_AND[e]) & 0x3F); u32 match_mask = match_key | ITLB_LRU_OR[e]; - for (u32 i = 0; i<64; i++) + for (u32 i = 0; i < std::size(ITLB_LRU_USE); i++) { if ((i & match_mask) == match_key) { @@ -480,7 +480,7 @@ void MMU_init() mmu_set_state(); #ifdef FAST_MMU // pre-fill kernel memory - for (u32 vpn = ARRAY_SIZE(mmuAddressLUT) / 2; vpn < ARRAY_SIZE(mmuAddressLUT); vpn++) + for (u32 vpn = std::size(mmuAddressLUT) / 2; vpn < std::size(mmuAddressLUT); vpn++) mmuAddressLUT[vpn] = vpn << 12; #endif } diff --git a/core/hw/sh4/modules/tmu.cpp b/core/hw/sh4/modules/tmu.cpp index 4f8968d02..c8e467bce 100644 --- a/core/hw/sh4/modules/tmu.cpp +++ b/core/hw/sh4/modules/tmu.cpp @@ -293,7 +293,7 @@ void TMURegisters::init() //TMU TCPR2 0xFFD8002C 0x1FD8002C 32 Held Held Held Held Pclk setHandlers(TMU_TCPR2_read, TMU_TCPR2_write); - for (int i = 0; i < 3; i++) + for (std::size_t i = 0; i < std::size(tmu_sched); i++) tmu_sched[i] = sh4_sched_register(i, &sched_tmu_cb); reset(); diff --git a/core/hw/sh4/modules/wince.h b/core/hw/sh4/modules/wince.h index 21b360d81..aecfbb50b 100644 --- a/core/hw/sh4/modules/wince.h +++ b/core/hw/sh4/modules/wince.h @@ -289,7 +289,7 @@ static bool print_wince_syscall(u32 address) const char *api; char api_buf[128]; - if (api_id < ARRAY_SIZE(wince_apis)) + if (api_id < std::size(wince_apis)) api = wince_apis[api_id]; else { @@ -305,7 +305,7 @@ static bool print_wince_syscall(u32 address) const char *method = NULL; char method_buf[128]; - if (api_id < ARRAY_SIZE(wince_methods) && meth_id < ARRAY_SIZE(wince_methods[api_id])) + if (api_id < std::size(wince_methods) && meth_id < std::size(wince_methods[api_id])) method = wince_methods[api_id][meth_id]; if (method == NULL) { diff --git a/core/hw/sh4/sh4_mmr.cpp b/core/hw/sh4/sh4_mmr.cpp index 23adb3f40..0a3d37452 100644 --- a/core/hw/sh4/sh4_mmr.cpp +++ b/core/hw/sh4/sh4_mmr.cpp @@ -196,14 +196,14 @@ T DYNACALL ReadMem_P4(u32 addr) case 0xF0: DEBUG_LOG(SH4, "IC Address read %08x", addr); - if (sz == 4) + if constexpr (sz == 4) return icache.ReadAddressArray(addr); else return 0; case 0xF1: DEBUG_LOG(SH4, "IC Data read %08x", addr); - if (sz == 4) + if constexpr (sz == 4) return icache.ReadDataArray(addr); else return 0; @@ -222,14 +222,14 @@ T DYNACALL ReadMem_P4(u32 addr) case 0xF4: DEBUG_LOG(SH4, "OC Address read %08x", addr); - if (sz == 4) + if constexpr (sz == 4) return ocache.ReadAddressArray(addr); else return 0; case 0xF5: DEBUG_LOG(SH4, "OC Data read %08x", addr); - if (sz == 4) + if constexpr (sz == 4) return ocache.ReadDataArray(addr); else return 0; @@ -278,13 +278,13 @@ void DYNACALL WriteMem_P4(u32 addr,T data) case 0xF0: DEBUG_LOG(SH4, "IC Address write %08x = %x", addr, data); - if (sz == 4) + if constexpr (sz == 4) icache.WriteAddressArray(addr, data); return; case 0xF1: DEBUG_LOG(SH4, "IC Data write %08x = %x", addr, data); - if (sz == 4) + if constexpr (sz == 4) icache.WriteDataArray(addr, data); return; @@ -310,13 +310,13 @@ void DYNACALL WriteMem_P4(u32 addr,T data) case 0xF4: // DEBUG_LOG(SH4, "OC Address write %08x = %x", addr, data); - if (sz == 4) + if constexpr (sz == 4) ocache.WriteAddressArray(addr, data); return; case 0xF5: DEBUG_LOG(SH4, "OC Data write %08x = %x", addr, data); - if (sz == 4) + if constexpr (sz == 4) ocache.WriteDataArray(addr, data); return; @@ -328,7 +328,7 @@ void DYNACALL WriteMem_P4(u32 addr,T data) u32 va = t.VPN << 10; - for (int i = 0; i < 64; i++) + for (std::size_t i = 0; i < std::size(UTLB); i++) { if (mmu_match(va, UTLB[i].Address, UTLB[i].Data)) { @@ -338,7 +338,7 @@ void DYNACALL WriteMem_P4(u32 addr,T data) } } - for (int i = 0; i < 4; i++) + for (std::size_t i = 0; i < std::size(ITLB); i++) { if (mmu_match(va, ITLB[i].Address, ITLB[i].Data)) { diff --git a/core/input/gamepad_device.cpp b/core/input/gamepad_device.cpp index dcca87cdc..65fc747f6 100644 --- a/core/input/gamepad_device.cpp +++ b/core/input/gamepad_device.cpp @@ -135,7 +135,7 @@ bool GamepadDevice::gamepad_btn_input(u32 code, bool pressed) _input_detected = nullptr; return true; } - if (!input_mapper || _maple_port > (int)ARRAY_SIZE(kcode)) + if (!input_mapper || _maple_port > (int)std::size(kcode)) return false; bool rc = false; diff --git a/core/input/keyboard_device.h b/core/input/keyboard_device.h index 55d700ca2..456633d6c 100644 --- a/core/input/keyboard_device.h +++ b/core/input/keyboard_device.h @@ -431,17 +431,17 @@ void KeyboardDeviceTemplate::keyboard_input(Keycode keycode, bool press break; } const int port = maple_port(); - if (port >= 0 && port < (int)ARRAY_SIZE(kb_shift)) + if (port >= 0 && port < (int)std::size(kb_shift)) kb_shift[port] = _modifier_keys; if (dc_keycode != 0 && dc_keycode < 0xE0) { gui_keyboard_key(dc_keycode, pressed, _modifier_keys); - if (port >= 0 && port < (int)ARRAY_SIZE(kb_key)) + if (port >= 0 && port < (int)std::size(kb_key)) { if (pressed) { - if (_kb_used < ARRAY_SIZE(kb_key[port])) + if (_kb_used < std::size(kb_key[port])) { bool found = false; for (u32 i = 0; !found && i < _kb_used; i++) @@ -460,9 +460,9 @@ void KeyboardDeviceTemplate::keyboard_input(Keycode keycode, bool press if (kb_key[port][i] == dc_keycode) { _kb_used--; - for (u32 j = i; j < ARRAY_SIZE(kb_key[port]) - 1; j++) + for (u32 j = i; j < std::size(kb_key[port]) - 1; j++) kb_key[port][j] = kb_key[port][j + 1]; - kb_key[port][ARRAY_SIZE(kb_key[port]) - 1] = 0; + kb_key[port][std::size(kb_key[port]) - 1] = 0; break; } } @@ -480,7 +480,7 @@ void KeyboardDeviceTemplate::keyboard_input(Keycode keycode, bool press // Do not map keyboard keys to gamepad buttons unless the GUI is open // or the corresponding maple device (if any) isn't a keyboard else if (gui_is_open() - || port == (int)ARRAY_SIZE(kb_key) + || port == (int)std::size(kb_key) || (settings.platform.isConsole() && config::MapleMainDevices[port] != MDT_Keyboard) || (settings.platform.isNaomi() && settings.input.JammaSetup != JVS::Keyboard) || settings.platform.isAtomiswave()) diff --git a/core/input/mapping.cpp b/core/input/mapping.cpp index e310e6261..44216566a 100644 --- a/core/input/mapping.cpp +++ b/core/input/mapping.cpp @@ -164,10 +164,10 @@ using namespace emucfg; static DreamcastKey getKeyId(const std::string& name) { - for (u32 i = 0; i < ARRAY_SIZE(button_list); i++) + for (u32 i = 0; i < std::size(button_list); i++) if (name == button_list[i].option) return button_list[i].id; - for (u32 i = 0; i < ARRAY_SIZE(axis_list); i++) + for (u32 i = 0; i < std::size(axis_list); i++) if (name == axis_list[i].option) return axis_list[i].id; @@ -258,7 +258,7 @@ void InputMapping::loadv1(ConfigFile& mf) { for (int port = 0; port < 4; port++) { - for (u32 i = 0; i < ARRAY_SIZE(button_list); i++) + for (u32 i = 0; i < std::size(button_list); i++) { std::string option; if (port == 0) @@ -278,7 +278,7 @@ void InputMapping::loadv1(ConfigFile& mf) } } - for (u32 i = 0; i < ARRAY_SIZE(axis_list); i++) + for (u32 i = 0; i < std::size(axis_list); i++) { std::string option; if (port == 0) @@ -385,10 +385,10 @@ void InputMapping::set_dirty() static const char *getKeyName(DreamcastKey key) { - for (u32 i = 0; i < ARRAY_SIZE(button_list); i++) + for (u32 i = 0; i < std::size(button_list); i++) if (key == button_list[i].id) return button_list[i].option.c_str(); - for (u32 i = 0; i < ARRAY_SIZE(axis_list); i++) + for (u32 i = 0; i < std::size(axis_list); i++) if (key == axis_list[i].id) return axis_list[i].option.c_str(); ERROR_LOG(INPUT, "Invalid key %x", key); diff --git a/core/input/mouse.cpp b/core/input/mouse.cpp index 97d528286..6e171e512 100644 --- a/core/input/mouse.cpp +++ b/core/input/mouse.cpp @@ -53,13 +53,13 @@ void Mouse::setRelPos(float deltax, float deltay) { void Mouse::setWheel(int delta) { std::lock_guard lock(relPosMutex); - if (maple_port() >= 0 && maple_port() < (int)ARRAY_SIZE(mo_wheel_delta)) + if (maple_port() >= 0 && maple_port() < (int)std::size(mo_wheel_delta)) mo_wheel_delta[maple_port()] += delta; } void Mouse::setButton(Button button, bool pressed) { - if (maple_port() >= 0 && maple_port() < (int)ARRAY_SIZE(mo_buttons)) + if (maple_port() >= 0 && maple_port() < (int)std::size(mo_buttons)) { if (pressed) mo_buttons[maple_port()] &= ~(1 << (int)button); @@ -116,7 +116,7 @@ static void screenToNative(int& x, int& y, int width, int height) void SetMousePosition(int x, int y, int width, int height, u32 mouseId) { - if (mouseId >= ARRAY_SIZE(mo_x_abs)) + if (mouseId >= std::size(mo_x_abs)) return; mo_width = width; mo_height = height; @@ -144,7 +144,7 @@ void SetMousePosition(int x, int y, int width, int height, u32 mouseId) void SetRelativeMousePosition(float xrel, float yrel, u32 mouseId) { - if (mouseId >= ARRAY_SIZE(mo_x_delta)) + if (mouseId >= std::size(mo_x_delta)) return; int width = mo_width; int height = mo_height; diff --git a/core/network/picoppp.cpp b/core/network/picoppp.cpp index d15378b29..4f6cefa80 100644 --- a/core/network/picoppp.cpp +++ b/core/network/picoppp.cpp @@ -404,9 +404,7 @@ static void tcp_callback(uint16_t ev, pico_socket *s) { set_tcp_nodelay(sockfd); - tcp_sockets.emplace(std::piecewise_construct, - std::forward_as_tuple(sock_a), - std::forward_as_tuple(sock_a, sockfd)); + tcp_sockets.try_emplace(sock_a, sock_a, sockfd); } } } @@ -564,10 +562,7 @@ static void read_native_sockets() set_non_blocking(sockfd); set_tcp_nodelay(sockfd); - tcp_sockets.emplace(std::piecewise_construct, - std::forward_as_tuple(ps), - std::forward_as_tuple(ps, sockfd)); - + tcp_sockets.try_emplace(ps, ps, sockfd); } // Check connecting outbound TCP sockets @@ -616,9 +611,7 @@ static void read_native_sockets() { set_tcp_nodelay(it->second); - tcp_sockets.emplace(std::piecewise_construct, - std::forward_as_tuple(it->first), - std::forward_as_tuple(it->first, it->second)); + tcp_sockets.try_emplace(it->first, it->first, it->second); read_from_dc_socket(it->first, it->second); } @@ -841,10 +834,10 @@ static void *pico_thread_func(void *) // Find the network ports for the current game const GamePortList *ports = nullptr; - for (u32 i = 0; i < ARRAY_SIZE(GamesPorts) && ports == nullptr; i++) + for (u32 i = 0; i < std::size(GamesPorts) && ports == nullptr; i++) { const auto& game = GamesPorts[i]; - for (u32 j = 0; j < ARRAY_SIZE(game.gameId) && game.gameId[j] != nullptr; j++) + for (u32 j = 0; j < std::size(game.gameId) && game.gameId[j] != nullptr; j++) { if (settings.content.gameId == game.gameId[j]) { @@ -870,10 +863,10 @@ static void *pico_thread_func(void *) WARN_LOG(MODEM, "UPNP Init failed"); else { - for (u32 i = 0; i < ARRAY_SIZE(ports->udpPorts) && ports->udpPorts[i] != 0; i++) + for (u32 i = 0; i < std::size(ports->udpPorts) && ports->udpPorts[i] != 0; i++) if (!upnp.AddPortMapping(ports->udpPorts[i], false)) WARN_LOG(MODEM, "UPNP AddPortMapping UDP %d failed", ports->udpPorts[i]); - for (u32 i = 0; i < ARRAY_SIZE(ports->tcpPorts) && ports->tcpPorts[i] != 0; i++) + for (u32 i = 0; i < std::size(ports->tcpPorts) && ports->tcpPorts[i] != 0; i++) if (!upnp.AddPortMapping(ports->tcpPorts[i], true)) WARN_LOG(MODEM, "UPNP AddPortMapping TCP %d failed", ports->tcpPorts[i]); } @@ -991,7 +984,7 @@ static void *pico_thread_func(void *) saddr.sin_addr.s_addr = INADDR_ANY; if (ports != nullptr) { - for (u32 i = 0; i < ARRAY_SIZE(ports->udpPorts) && ports->udpPorts[i] != 0; i++) + for (u32 i = 0; i < std::size(ports->udpPorts) && ports->udpPorts[i] != 0; i++) { uint16_t port = short_be(ports->udpPorts[i]); sock_t sockfd = find_udp_socket(port); @@ -1008,7 +1001,7 @@ static void *pico_thread_func(void *) } } - for (u32 i = 0; i < ARRAY_SIZE(ports->tcpPorts) && ports->tcpPorts[i] != 0; i++) + for (u32 i = 0; i < std::size(ports->tcpPorts) && ports->tcpPorts[i] != 0; i++) { uint16_t port = short_be(ports->tcpPorts[i]); saddr.sin_port = port; diff --git a/core/oslib/audiobackend_coreaudio.cpp b/core/oslib/audiobackend_coreaudio.cpp index 424eda3f5..10a3d0dc8 100644 --- a/core/oslib/audiobackend_coreaudio.cpp +++ b/core/oslib/audiobackend_coreaudio.cpp @@ -257,7 +257,7 @@ public: } AudioQueueBufferRef buffers[2]; - for (UInt32 i = 0; i < ARRAY_SIZE(buffers) && err == noErr; i++) + for (UInt32 i = 0; i < std::size(buffers) && err == noErr; i++) { err = AudioQueueAllocateBuffer(recordQueue, 480, &buffers[i]); if (err == noErr) diff --git a/core/rec-ARM64/rec_arm64.cpp b/core/rec-ARM64/rec_arm64.cpp index 083392a75..eb8c21f3d 100644 --- a/core/rec-ARM64/rec_arm64.cpp +++ b/core/rec-ARM64/rec_arm64.cpp @@ -2336,7 +2336,7 @@ bool ngen_Rewrite(host_context_t &context, void *faultAddress) u32 size = 0; bool found = false; u32 masked = armv8_op & STR_LDR_MASK; - for (u32 i = 0; i < ARRAY_SIZE(armv8_mem_ops); i++) + for (u32 i = 0; i < std::size(armv8_mem_ops); i++) { if (masked == armv8_mem_ops[i]) { diff --git a/core/reios/gdrom_hle.cpp b/core/reios/gdrom_hle.cpp index cd68da83b..0da858036 100644 --- a/core/reios/gdrom_hle.cpp +++ b/core/reios/gdrom_hle.cpp @@ -28,11 +28,7 @@ gdrom_hle_state_t gd_hle_state; static void GDROM_HLE_ReadSES() { - u32 s = gd_hle_state.params[0]; - u32 b = gd_hle_state.params[1]; - u32 ba = gd_hle_state.params[2]; - u32 bb = gd_hle_state.params[3]; - + auto [s, b, ba, bb] = gd_hle_state.params; INFO_LOG(REIOS, "GDROM_HLE_ReadSES: doing nothing w/ %d, %d, %d, %d", s, b, ba, bb); } @@ -53,7 +49,7 @@ static void GDROM_HLE_ReadTOC() libGDR_GetToc(toc, (DiskArea)area); // Swap results to LE - for (int i = 0; i < 102; i++) { + for (std::size_t i = 0; i < std::size(toc); i++) { toc[i] = SWAP32(toc[i]); } if (!mmu_enabled()) @@ -65,7 +61,7 @@ static void GDROM_HLE_ReadTOC() return; } } - for (int i = 0; i < 102; i++, dest += 4) + for (std::size_t i = 0; i < std::size(toc); i++, dest += 4) WriteMem32(dest, toc[i]); } @@ -97,7 +93,7 @@ static void read_sectors_to(u32 addr, u32 sector, u32 count) { libGDR_ReadSector((u8 *)temp, sector, 1, sizeof(temp)); - for (std::size_t i = 0; i < ARRAY_SIZE(temp); i++) + for (std::size_t i = 0; i < std::size(temp); i++) { if (virtual_addr) WriteMem32(addr, temp[i]); @@ -203,7 +199,7 @@ static void multi_xfer() int remaining = 2048 - gd_hle_state.multi_read_offset; if (size >= 4 && remaining >= 4 && (dest & 3) == 0) { - if (dma) + if constexpr (dma) WriteMem32_nommu(dest, *(u32*)&buf[gd_hle_state.multi_read_offset]); else WriteMem32(dest, *(u32*)&buf[gd_hle_state.multi_read_offset]); @@ -214,7 +210,7 @@ static void multi_xfer() } else if (size >= 2 && remaining >= 2 && (dest & 1) == 0) { - if (dma) + if constexpr (dma) WriteMem16_nommu(dest, *(u16*)&buf[gd_hle_state.multi_read_offset]); else WriteMem16(dest, *(u16*)&buf[gd_hle_state.multi_read_offset]); @@ -225,7 +221,7 @@ static void multi_xfer() } else { - if (dma) + if constexpr (dma) WriteMem8_nommu(dest, buf[gd_hle_state.multi_read_offset]); else WriteMem8(dest, buf[gd_hle_state.multi_read_offset]); @@ -410,10 +406,7 @@ static void GD_HLE_Command(gd_command cc) case GDCC_SET_MODE: { - u32 speed = gd_hle_state.params[0]; - u32 standby = gd_hle_state.params[1]; - u32 read_flags = gd_hle_state.params[2]; - u32 read_retry = gd_hle_state.params[3]; + auto [speed, standby, read_flags, read_retry] = gd_hle_state.params; debugf("GDROM: SET_MODE speed %x standby %x read_flags %x read_retry %x", speed, standby, read_flags, read_retry); @@ -745,7 +738,7 @@ void gdrom_hle_op() // // Returns: GDC_OK, GDC_ERR DEBUG_LOG(REIOS, "GDROM: HLE CHANGE_DATA_TYPE PTR_r4:%X",r[4]); - for(int i=0; i<4; i++) { + for(std::size_t i = 0; i < std::size(SecMode); i++) { SecMode[i] = ReadMem32(r[4]+(i<<2)); DEBUG_LOG(REIOS, "%08X", SecMode[i]); } diff --git a/core/rend/TexCache.cpp b/core/rend/TexCache.cpp index fa5e6f647..e25d3ccbe 100644 --- a/core/rend/TexCache.cpp +++ b/core/rend/TexCache.cpp @@ -158,9 +158,9 @@ void palette_update() break; } } - for (int i = 0; i < 64; i++) + for (std::size_t i = 0; i < std::size(pal_hash_16); i++) pal_hash_16[i] = XXH32(&PALETTE_RAM[i << 4], 16 * 4, 7); - for (int i = 0; i < 4; i++) + for (std::size_t i = 0; i < std::size(pal_hash_256); i++) pal_hash_256[i] = XXH32(&PALETTE_RAM[i << 8], 256 * 4, 7); } diff --git a/core/rend/TexCache.h b/core/rend/TexCache.h index 91f64d293..9e5d1f504 100644 --- a/core/rend/TexCache.h +++ b/core/rend/TexCache.h @@ -127,8 +127,6 @@ public: } }; -#define clamp(minv, maxv, x) ((x) < (minv) ? (minv) : (x) > (maxv) ? (maxv) : (x)) - // OpenGL struct RGBAPacker { static u32 pack(u8 r, u8 g, u8 b, u8 a) { @@ -152,7 +150,7 @@ inline static u32 YUV422(s32 Y, s32 Yu, s32 Yv) s32 G = Y - (Yu * 11 + Yv * 22) / 32; // Y - (Yu-128) * (11/8) * 0.25 - (Yv-128) * (11/8) * 0.5 ? s32 B = Y + Yu * 110 / 64; // Y + (Yu-128) * (11/8) * 1.25 ? - return Packer::pack(clamp(0, 255, R), clamp(0, 255, G), clamp(0, 255, B), 0xFF); + return Packer::pack(std::clamp(0, 255, R), std::clamp(0, 255, G), std::clamp(0, 255, B), 0xFF); } #define twop(x,y,bcx,bcy) (detwiddle[0][bcy][x]+detwiddle[1][bcx][y]) @@ -705,7 +703,6 @@ public: template class BaseTextureCache { - using TexCacheIter = typename std::unordered_map::iterator; public: Texture *getTextureCacheData(TSP tsp, TCW tcw) { @@ -725,7 +722,7 @@ public: else key |= (u64)(tcw.full & TCWTextureCacheMask.full) << 32; - TexCacheIter it = cache.find(key); + auto it = cache.find(key); Texture* texture; if (it != cache.end()) @@ -772,10 +769,10 @@ public: u32 TargetFrame = std::max((u32)120, FrameCount) - 120; - for (const auto& pair : cache) + for (const auto& [id, texture] : cache) { - if (pair.second.dirty && pair.second.dirty < TargetFrame) - list.push_back(pair.first); + if (texture.dirty && texture.dirty < TargetFrame) + list.push_back(id); if (list.size() > 5) break; @@ -791,8 +788,8 @@ public: void Clear() { custom_texture.Terminate(); - for (auto& pair : cache) - pair.second.Delete(); + for (auto& [id, texture] : cache) + texture.Delete(); cache.clear(); KillTex = false; @@ -835,4 +832,3 @@ static inline void MakeFogTexture(u8 *tex_data) void dump_screenshot(u8 *buffer, u32 width, u32 height, bool alpha = false, u32 rowPitch = 0, bool invertY = true); extern const std::array D_Adjust_LoD_Bias; -#undef clamp diff --git a/core/rend/dx11/dx11_overlay.cpp b/core/rend/dx11/dx11_overlay.cpp index 4c05b54d7..7f171656e 100644 --- a/core/rend/dx11/dx11_overlay.cpp +++ b/core/rend/dx11/dx11_overlay.cpp @@ -167,8 +167,7 @@ void DX11Overlay::draw(u32 width, u32 height, bool vmu, bool crosshair) && config::MapleMainDevices[i] != MDT_LightGun) continue; - float x, y; - std::tie(x, y) = getCrosshairPosition(i); + auto [x, y] = getCrosshairPosition(i); #ifdef LIBRETRO float halfWidth = LIGHTGUN_CROSSHAIR_SIZE / 2.f / config::ScreenStretching * 100.f; float halfHeight = LIGHTGUN_CROSSHAIR_SIZE / 2.f; diff --git a/core/rend/dx11/dx11_quad.h b/core/rend/dx11/dx11_quad.h index e27cf60a7..311884c11 100644 --- a/core/rend/dx11/dx11_quad.h +++ b/core/rend/dx11/dx11_quad.h @@ -40,7 +40,7 @@ public: { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 2 * sizeof(float), D3D11_INPUT_PER_VERTEX_DATA, 0 }, }; ComPtr blob = shaders->getQuadVertexShaderBlob(); - if (FAILED(device->CreateInputLayout(layout, ARRAY_SIZE(layout), blob->GetBufferPointer(), blob->GetBufferSize(), &inputLayout.get()))) + if (FAILED(device->CreateInputLayout(layout, std::size(layout), blob->GetBufferPointer(), blob->GetBufferSize(), &inputLayout.get()))) WARN_LOG(RENDERER, "Input layout creation failed"); // Rasterizer state diff --git a/core/rend/dx11/dx11_renderer.cpp b/core/rend/dx11/dx11_renderer.cpp index da23a9bc5..014f438f2 100644 --- a/core/rend/dx11/dx11_renderer.cpp +++ b/core/rend/dx11/dx11_renderer.cpp @@ -24,6 +24,8 @@ #include "rend/tileclip.h" #include "rend/sorter.h" +#include + const D3D11_INPUT_ELEMENT_DESC MainLayout[] { { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, (UINT)offsetof(Vertex, x), D3D11_INPUT_PER_VERTEX_DATA, 0 }, @@ -52,9 +54,9 @@ bool DX11Renderer::Init() samplers = &theDX11Context.getSamplers(); bool success = (bool)shaders->getVertexShader(true, true); ComPtr blob = shaders->getVertexShaderBlob(); - success = success && SUCCEEDED(device->CreateInputLayout(MainLayout, ARRAY_SIZE(MainLayout), blob->GetBufferPointer(), blob->GetBufferSize(), &mainInputLayout.get())); + success = success && SUCCEEDED(device->CreateInputLayout(MainLayout, std::size(MainLayout), blob->GetBufferPointer(), blob->GetBufferSize(), &mainInputLayout.get())); blob = shaders->getMVVertexShaderBlob(); - success = success && SUCCEEDED(device->CreateInputLayout(ModVolLayout, ARRAY_SIZE(ModVolLayout), blob->GetBufferPointer(), blob->GetBufferSize(), &modVolInputLayout.get())); + success = success && SUCCEEDED(device->CreateInputLayout(ModVolLayout, std::size(ModVolLayout), blob->GetBufferPointer(), blob->GetBufferSize(), &modVolInputLayout.get())); // Constants buffers { @@ -151,7 +153,7 @@ bool DX11Renderer::Init() deviceContext->UpdateSubresource(whiteTexture, 0, nullptr, texData, 8 * sizeof(u32), 8 * sizeof(u32) * 8); } - quad = std::unique_ptr(new Quad()); + quad = std::make_unique(); quad->init(device, deviceContext, shaders); n2Helper.init(device, deviceContext); @@ -414,7 +416,7 @@ void DX11Renderer::setupPixelShaderConstants() memcpy(mappedSubres.pData, &pixelConstants, sizeof(pixelConstants)); deviceContext->Unmap(pxlConstants, 0); ID3D11Buffer *buffers[] { pxlConstants, pxlPolyConstants }; - deviceContext->PSSetConstantBuffers(0, ARRAY_SIZE(buffers), buffers); + deviceContext->PSSetConstantBuffers(0, std::size(buffers), buffers); } bool DX11Renderer::Render() diff --git a/core/rend/dx11/dx11_shaders.cpp b/core/rend/dx11/dx11_shaders.cpp index 830edd8ab..3d555b2f5 100644 --- a/core/rend/dx11/dx11_shaders.cpp +++ b/core/rend/dx11/dx11_shaders.cpp @@ -459,8 +459,8 @@ const ComPtr& DX11Shaders::getShader(bool pp_Texture, bool pp auto& shader = shaders[hash]; if (shader == nullptr) { - verify(pp_ShadInstr < ARRAY_SIZE(MacroValues)); - verify(pp_FogCtrl < ARRAY_SIZE(MacroValues)); + verify(pp_ShadInstr < std::size(MacroValues)); + verify(pp_FogCtrl < std::size(MacroValues)); PixelMacros[MacroGouraud].Definition = MacroValues[gouraud]; PixelMacros[MacroTexture].Definition = MacroValues[pp_Texture]; PixelMacros[MacroUseAlpha].Definition = MacroValues[pp_UseAlpha]; @@ -698,7 +698,7 @@ void CachedDX11Shaders::loadCache(const std::string& filename) break; if (std::fread(&size, sizeof(size), 1, fp) != 1) break; - std::unique_ptr blob = std::unique_ptr(new u8[size]); + std::unique_ptr blob = std::make_unique(size); if (std::fread(&blob[0], 1, size, fp) != size) break; shaderCache[hash] = { size, std::move(blob) }; @@ -728,7 +728,7 @@ void CachedDX11Shaders::cacheShader(u64 hash, const ComPtr& blob) if (!enabled) return; u32 size = (u32)blob->GetBufferSize(); - std::unique_ptr data = std::unique_ptr(new u8[size]); + std::unique_ptr data = std::make_unique(size); memcpy(&data[0], blob->GetBufferPointer(), size); shaderCache[hash] = { size, std::move(data) }; } diff --git a/core/rend/dx11/dx11context.cpp b/core/rend/dx11/dx11context.cpp index 710ce57d2..451563a5c 100644 --- a/core/rend/dx11/dx11context.cpp +++ b/core/rend/dx11/dx11context.cpp @@ -57,9 +57,9 @@ bool DX11Context::init(bool keepCurrentWindow) D3D_FEATURE_LEVEL featureLevels[] = { - D3D_FEATURE_LEVEL_11_1, - D3D_FEATURE_LEVEL_11_0, - D3D_FEATURE_LEVEL_10_1, + D3D_FEATURE_LEVEL_11_1, + D3D_FEATURE_LEVEL_11_0, + D3D_FEATURE_LEVEL_10_1, D3D_FEATURE_LEVEL_10_0, }; HRESULT hr; @@ -336,7 +336,7 @@ bool DX11Context::checkTextureSupport() const char * const fmtNames[] = { "B5G5R5A1", "B4G4R4A4", "B5G6R5", "B8G8R8A8", "A8" }; const TextureType dcTexTypes[] = { TextureType::_5551, TextureType::_4444, TextureType::_565, TextureType::_8888, TextureType::_8 }; UINT support; - for (size_t i = 0; i < ARRAY_SIZE(formats); i++) + for (std::size_t i = 0; i < std::size(formats); i++) { supportedTexFormats[(int)dcTexTypes[i]] = false; pDevice->CheckFormatSupport(formats[i], &support); diff --git a/core/rend/dx11/oit/dx11_oitbuffers.h b/core/rend/dx11/oit/dx11_oitbuffers.h index 0866eda9e..c8a63be44 100644 --- a/core/rend/dx11/oit/dx11_oitbuffers.h +++ b/core/rend/dx11/oit/dx11_oitbuffers.h @@ -100,7 +100,7 @@ public: { ID3D11UnorderedAccessView *uavs[] { pixelsBufferView, abufferPointersView }; UINT initialCounts[] { 0, (UINT)-1 }; - deviceContext->OMSetRenderTargetsAndUnorderedAccessViews(D3D11_KEEP_RENDER_TARGETS_AND_DEPTH_STENCIL, nullptr, nullptr, 1, ARRAY_SIZE(uavs), uavs, initialCounts); + deviceContext->OMSetRenderTargetsAndUnorderedAccessViews(D3D11_KEEP_RENDER_TARGETS_AND_DEPTH_STENCIL, nullptr, nullptr, 1, std::size(uavs), uavs, initialCounts); } void term() diff --git a/core/rend/dx11/oit/dx11_oitrenderer.cpp b/core/rend/dx11/oit/dx11_oitrenderer.cpp index 16a48cec8..278fc1c99 100644 --- a/core/rend/dx11/oit/dx11_oitrenderer.cpp +++ b/core/rend/dx11/oit/dx11_oitrenderer.cpp @@ -81,7 +81,7 @@ struct DX11OITRenderer : public DX11Renderer pixelBufferSize = config::PixelBufferSize; ComPtr blob = shaders.getVertexShaderBlob(); mainInputLayout.reset(); - success = SUCCEEDED(device->CreateInputLayout(MainLayout, ARRAY_SIZE(MainLayout), blob->GetBufferPointer(), blob->GetBufferSize(), &mainInputLayout.get())) && success; + success = SUCCEEDED(device->CreateInputLayout(MainLayout, std::size(MainLayout), blob->GetBufferPointer(), blob->GetBufferSize(), &mainInputLayout.get())) && success; blob = shaders.getFinalVertexShaderBlob(); success = SUCCEEDED(device->CreateInputLayout(MainLayout, 0, blob->GetBufferPointer(), blob->GetBufferSize(), &finalInputLayout.get())) && success; diff --git a/core/rend/dx11/oit/dx11_oitshaders.cpp b/core/rend/dx11/oit/dx11_oitshaders.cpp index 82bcbc2e8..2b1ad7059 100644 --- a/core/rend/dx11/oit/dx11_oitshaders.cpp +++ b/core/rend/dx11/oit/dx11_oitshaders.cpp @@ -934,9 +934,9 @@ const ComPtr& DX11OITShaders::getShader(bool pp_Texture, bool auto& shader = shaders[hash]; if (shader == nullptr) { - verify(pp_ShadInstr < ARRAY_SIZE(MacroValues)); - verify(pp_FogCtrl < ARRAY_SIZE(MacroValues)); - verify(pass < (int)ARRAY_SIZE(MacroValues)); + verify(pp_ShadInstr < std::size(MacroValues)); + verify(pp_FogCtrl < std::size(MacroValues)); + verify(pass < (int)std::size(MacroValues)); PixelMacros[MacroGouraud].Definition = MacroValues[gouraud]; PixelMacros[MacroTexture].Definition = MacroValues[pp_Texture]; PixelMacros[MacroUseAlpha].Definition = MacroValues[pp_UseAlpha]; diff --git a/core/rend/dx9/d3d_overlay.cpp b/core/rend/dx9/d3d_overlay.cpp index 68445ec4e..a8bf76493 100644 --- a/core/rend/dx9/d3d_overlay.cpp +++ b/core/rend/dx9/d3d_overlay.cpp @@ -116,8 +116,7 @@ void D3DOverlay::draw(u32 width, u32 height, bool vmu, bool crosshair) && config::MapleMainDevices[i] != MDT_LightGun) continue; - float x, y; - std::tie(x, y) = getCrosshairPosition(i); + auto [x, y] = getCrosshairPosition(i); float halfWidth = XHAIR_WIDTH * settings.display.uiScale / 2.f; RECT rect { (long) (x - halfWidth), (long) (y - halfWidth), (long) (x + halfWidth), (long) (y + halfWidth) }; D3DCOLOR color = (config::CrosshairColor[i] & 0xFF00FF00) diff --git a/core/rend/dx9/d3d_shaders.cpp b/core/rend/dx9/d3d_shaders.cpp index 12e7690e2..331f23ddd 100644 --- a/core/rend/dx9/d3d_shaders.cpp +++ b/core/rend/dx9/d3d_shaders.cpp @@ -313,8 +313,8 @@ const ComPtr& D3DShaders::getShader(bool pp_Texture, bool auto it = shaders.find(hash); if (it == shaders.end()) { - verify(pp_ShadInstr < ARRAY_SIZE(MacroValues)); - verify(pp_FogCtrl < ARRAY_SIZE(MacroValues)); + verify(pp_ShadInstr < std::size(MacroValues)); + verify(pp_FogCtrl < std::size(MacroValues)); PixelMacros[MacroTexture].Definition = MacroValues[pp_Texture]; PixelMacros[MacroUseAlpha].Definition = MacroValues[pp_UseAlpha]; PixelMacros[MacroIgnoreTexA].Definition = MacroValues[pp_IgnoreTexA]; diff --git a/core/rend/gl4/abuffer.cpp b/core/rend/gl4/abuffer.cpp index 01b15ccb0..e9a4b8d9a 100644 --- a/core/rend/gl4/abuffer.cpp +++ b/core/rend/gl4/abuffer.cpp @@ -19,6 +19,8 @@ #include "gl4.h" #include "rend/gles/glcache.h" +#include + static GLuint pixels_buffer; static GLuint pixels_pointers; static GLuint atomic_buffer; @@ -360,7 +362,7 @@ void initABuffer() } if (g_quadBuffer == nullptr) { - g_quadBuffer = std::unique_ptr(new GlBuffer(GL_ARRAY_BUFFER, GL_STATIC_DRAW)); + g_quadBuffer = std::make_unique(GL_ARRAY_BUFFER, GL_STATIC_DRAW); static const float vertices[] = { -1, 1, 1, -1, -1, 1, @@ -371,7 +373,7 @@ void initABuffer() } if (g_quadIndexBuffer == nullptr) { - g_quadIndexBuffer = std::unique_ptr(new GlBuffer(GL_ELEMENT_ARRAY_BUFFER, GL_STATIC_DRAW)); + g_quadIndexBuffer = std::make_unique(GL_ELEMENT_ARRAY_BUFFER, GL_STATIC_DRAW); static const GLushort indices[] = { 0, 1, 2, 1, 3 }; g_quadIndexBuffer->update(indices, sizeof(indices)); } diff --git a/core/rend/gl4/gl4.h b/core/rend/gl4/gl4.h index 351ee2478..c10003eab 100755 --- a/core/rend/gl4/gl4.h +++ b/core/rend/gl4/gl4.h @@ -153,7 +153,7 @@ struct gl4_ctx return modvol_vao[bufferIndex]; } void nextBuffer() { - bufferIndex = (bufferIndex + 1) % ARRAY_SIZE(geometry); + bufferIndex = (bufferIndex + 1) % std::size(geometry); } } vbo; }; diff --git a/core/rend/gl4/gldraw.cpp b/core/rend/gl4/gldraw.cpp index 0c6a8e57c..3d4980745 100644 --- a/core/rend/gl4/gldraw.cpp +++ b/core/rend/gl4/gldraw.cpp @@ -22,6 +22,8 @@ #include "rend/tileclip.h" #include "rend/osd.h" +#include + static gl4PipelineShader* CurrentShader; extern u32 gcflip; GLuint geom_fbo; @@ -736,10 +738,10 @@ static std::unique_ptr osdIndex; static void setupOsdVao() { if (osdVerts == nullptr) - osdVerts = std::unique_ptr(new GlBuffer(GL_ARRAY_BUFFER)); + osdVerts = std::make_unique(GL_ARRAY_BUFFER); if (osdIndex == nullptr) { - osdIndex = std::unique_ptr(new GlBuffer(GL_ELEMENT_ARRAY_BUFFER)); + osdIndex = std::make_unique(GL_ELEMENT_ARRAY_BUFFER); GLushort indices[] = { 0, 1, 2, 1, 3 }; osdIndex->update(indices, sizeof(indices)); } diff --git a/core/rend/gl4/gles.cpp b/core/rend/gl4/gles.cpp index 8b2488a91..f58a2a15b 100644 --- a/core/rend/gl4/gles.cpp +++ b/core/rend/gl4/gles.cpp @@ -28,6 +28,8 @@ #include "rend/gles/postprocess.h" #endif +#include + //Fragment and vertex shaders code const char* ShaderHeader = R"( @@ -610,8 +612,8 @@ static void gl4_term() for (auto& buffer : gl4.vbo.tr_poly_params) buffer.reset(); gl4_delete_shaders(); - glDeleteVertexArrays(ARRAY_SIZE(gl4.vbo.main_vao), gl4.vbo.main_vao); - glDeleteVertexArrays(ARRAY_SIZE(gl4.vbo.modvol_vao), gl4.vbo.modvol_vao); + glDeleteVertexArrays(std::size(gl4.vbo.main_vao), gl4.vbo.main_vao); + glDeleteVertexArrays(std::size(gl4.vbo.modvol_vao), gl4.vbo.modvol_vao); #ifdef LIBRETRO gl4TermVmuLightgun(); #endif @@ -649,13 +651,13 @@ static void gl_create_resources() glGenVertexArrays(2, &gl4.vbo.modvol_vao[0]); //create vbos - for (u32 i = 0; i < ARRAY_SIZE(gl4.vbo.geometry); i++) + for (u32 i = 0; i < std::size(gl4.vbo.geometry); i++) { - gl4.vbo.geometry[i] = std::unique_ptr(new GlBuffer(GL_ARRAY_BUFFER)); - gl4.vbo.modvols[i] = std::unique_ptr(new GlBuffer(GL_ARRAY_BUFFER)); - gl4.vbo.idxs[i] = std::unique_ptr(new GlBuffer(GL_ELEMENT_ARRAY_BUFFER)); + gl4.vbo.geometry[i] = std::make_unique(GL_ARRAY_BUFFER); + gl4.vbo.modvols[i] = std::make_unique(GL_ARRAY_BUFFER); + gl4.vbo.idxs[i] = std::make_unique(GL_ELEMENT_ARRAY_BUFFER); // Create the buffer for Translucent poly params - gl4.vbo.tr_poly_params[i] = std::unique_ptr(new GlBuffer(GL_SHADER_STORAGE_BUFFER)); + gl4.vbo.tr_poly_params[i] = std::make_unique(GL_SHADER_STORAGE_BUFFER); gl4.vbo.bufferIndex = i; gl4SetupMainVBO(); gl4SetupModvolVBO(); diff --git a/core/rend/gles/glcache.h b/core/rend/gles/glcache.h index de188da90..0996b3c7b 100644 --- a/core/rend/gles/glcache.h +++ b/core/rend/gles/glcache.h @@ -167,7 +167,7 @@ public: return; GLsizei shader_count; GLuint shaders[2]; - glGetAttachedShaders(program, ARRAY_SIZE(shaders), &shader_count, shaders); + glGetAttachedShaders(program, std::size(shaders), &shader_count, shaders); for (int i = 0; i < shader_count; i++) glDeleteShader(shaders[i]); diff --git a/core/rend/gles/gldraw.cpp b/core/rend/gles/gldraw.cpp index 3f5fcfe07..b91cdbbb7 100644 --- a/core/rend/gles/gldraw.cpp +++ b/core/rend/gles/gldraw.cpp @@ -5,6 +5,8 @@ #include "naomi2.h" #include "rend/transform_matrix.h" +#include + /* Drawing and related state management @@ -645,7 +647,7 @@ void OpenGLRenderer::RenderFramebuffer(const FramebufferInfo& info) gl.ofbo2.framebuffer.reset(); if (gl.ofbo2.framebuffer == nullptr) - gl.ofbo2.framebuffer = std::unique_ptr(new GlFramebuffer(gl.dcfb.width, gl.dcfb.height, false, true)); + gl.ofbo2.framebuffer = std::make_unique(gl.dcfb.width, gl.dcfb.height, false, true); else gl.ofbo2.framebuffer->bind(); glCheck(); @@ -696,7 +698,7 @@ void writeFramebufferToVRAM() && (gl.fbscaling.framebuffer->getWidth() != (int)scaledW || gl.fbscaling.framebuffer->getHeight() != (int)scaledH)) gl.fbscaling.framebuffer.reset(); if (gl.fbscaling.framebuffer == nullptr) - gl.fbscaling.framebuffer = std::unique_ptr(new GlFramebuffer(scaledW, scaledH)); + gl.fbscaling.framebuffer = std::make_unique(scaledW, scaledH); if (gl.gl_major < 3) { @@ -807,10 +809,10 @@ static std::unique_ptr osdIndex; static void setupOsdVao() { if (osdVerts == nullptr) - osdVerts = std::unique_ptr(new GlBuffer(GL_ARRAY_BUFFER)); + osdVerts = std::make_unique(GL_ARRAY_BUFFER); if (osdIndex == nullptr) { - osdIndex = std::unique_ptr(new GlBuffer(GL_ELEMENT_ARRAY_BUFFER)); + osdIndex = std::make_unique(GL_ELEMENT_ARRAY_BUFFER); GLushort indices[] = { 0, 1, 2, 1, 3 }; osdIndex->update(indices, sizeof(indices)); } @@ -1018,9 +1020,9 @@ void DrawGunCrosshair(u8 port) void termVmuLightgun() { - glcache.DeleteTextures(ARRAY_SIZE(vmuTextureId), vmuTextureId); + glcache.DeleteTextures(std::size(vmuTextureId), vmuTextureId); memset(vmuTextureId, 0, sizeof(vmuTextureId)); - glcache.DeleteTextures(ARRAY_SIZE(lightgunTextureId), lightgunTextureId); + glcache.DeleteTextures(std::size(lightgunTextureId), lightgunTextureId); memset(lightgunTextureId, 0, sizeof(lightgunTextureId)); osdVerts.reset(); osdIndex.reset(); diff --git a/core/rend/gles/gles.cpp b/core/rend/gles/gles.cpp index 3e7c24c7e..2b2dd3269 100644 --- a/core/rend/gles/gles.cpp +++ b/core/rend/gles/gles.cpp @@ -19,6 +19,7 @@ #endif #include +#include #ifdef GLES #ifndef GL_RED @@ -933,9 +934,9 @@ static void gl_create_resources() verify(glGenVertexArrays != nullptr); //create vbos - gl.vbo.geometry = std::unique_ptr(new GlBuffer(GL_ARRAY_BUFFER)); - gl.vbo.modvols = std::unique_ptr(new GlBuffer(GL_ARRAY_BUFFER)); - gl.vbo.idxs = std::unique_ptr(new GlBuffer(GL_ELEMENT_ARRAY_BUFFER)); + gl.vbo.geometry = std::make_unique(GL_ARRAY_BUFFER); + gl.vbo.modvols = std::make_unique(GL_ARRAY_BUFFER); + gl.vbo.idxs = std::make_unique(GL_ELEMENT_ARRAY_BUFFER); initQuad(); } diff --git a/core/rend/gles/gltex.cpp b/core/rend/gles/gltex.cpp index 8026bf664..0fcef97d5 100644 --- a/core/rend/gles/gltex.cpp +++ b/core/rend/gles/gltex.cpp @@ -191,7 +191,7 @@ GLuint BindRTT(bool withDepthBuffer) glcache.BindTexture(GL_TEXTURE_2D, texture); glTexImage2D(GL_TEXTURE_2D, 0, channels, fbw2, fbh2, 0, channels, format, 0); - gl.rtt.framebuffer = std::unique_ptr(new GlFramebuffer((int)fbw2, (int)fbh2, withDepthBuffer, texture)); + gl.rtt.framebuffer = std::make_unique((int)fbw2, (int)fbh2, withDepthBuffer, texture); glViewport(0, 0, fbw, fbh); @@ -405,7 +405,7 @@ GLuint init_output_framebuffer(int width, int height) glcache.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glcache.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); } - gl.ofbo.framebuffer = std::unique_ptr(new GlFramebuffer(width, height, true, texture)); + gl.ofbo.framebuffer = std::make_unique(width, height, true, texture); glcache.Disable(GL_SCISSOR_TEST); glcache.ClearColor(0.f, 0.f, 0.f, 0.f); diff --git a/core/rend/gles/naomi2.h b/core/rend/gles/naomi2.h index 52e3a257c..fe46f8651 100644 --- a/core/rend/gles/naomi2.h +++ b/core/rend/gles/naomi2.h @@ -61,7 +61,7 @@ void initN2Uniforms(ShaderType *shader) shader->useBaseOver = glGetUniformLocation(shader->program, "useBaseOver"); shader->bumpId0 = glGetUniformLocation(shader->program, "bumpId0"); shader->bumpId1 = glGetUniformLocation(shader->program, "bumpId1"); - for (u32 i = 0; i < ARRAY_SIZE(shader->lights); i++) + for (u32 i = 0; i < std::size(shader->lights); i++) { char str[128]; sprintf(str, "lights[%d].color", i); diff --git a/core/rend/gles/opengl_driver.cpp b/core/rend/gles/opengl_driver.cpp index aed2911ff..2f250abbe 100644 --- a/core/rend/gles/opengl_driver.cpp +++ b/core/rend/gles/opengl_driver.cpp @@ -60,7 +60,7 @@ OpenGLDriver::~OpenGLDriver() EventManager::unlisten(Event::Terminate, emuEventCallback, this); std::vector texIds; - texIds.reserve(ARRAY_SIZE(vmu_lcd_tex_ids) + 1 + textures.size()); + texIds.reserve(std::size(vmu_lcd_tex_ids) + 1 + textures.size()); for (ImTextureID texId : vmu_lcd_tex_ids) if (texId != ImTextureID()) texIds.push_back((GLuint)(uintptr_t)texId); diff --git a/core/rend/gles/postprocess.cpp b/core/rend/gles/postprocess.cpp index ee41b1b86..a87254227 100644 --- a/core/rend/gles/postprocess.cpp +++ b/core/rend/gles/postprocess.cpp @@ -219,7 +219,7 @@ std::array PostProcessShader::shaders; void PostProcessor::init(int width, int height) { - framebuffer = std::unique_ptr(new GlFramebuffer(width, height)); + framebuffer = std::make_unique(width, height); float vertices[] = { -1, 1, 1, diff --git a/core/rend/gui.cpp b/core/rend/gui.cpp index 60d8672fe..e3202298d 100644 --- a/core/rend/gui.cpp +++ b/core/rend/gui.cpp @@ -405,7 +405,7 @@ static void gui_newFrame() static void delayedKeysUp() { ImGuiIO& io = ImGui::GetIO(); - for (u32 i = 0; i < ARRAY_SIZE(keysUpNextFrame); i++) + for (u32 i = 0; i < std::size(keysUpNextFrame); i++) if (keysUpNextFrame[i]) io.KeysDown[i] = false; memset(keysUpNextFrame, 0, sizeof(keysUpNextFrame)); @@ -1238,7 +1238,7 @@ static inline void gui_debug_tab() static const char *levels[] = { "Notice", "Error", "Warning", "Info", "Debug" }; if (ImGui::BeginCombo("Log Verbosity", levels[logManager->GetLogLevel() - 1], ImGuiComboFlags_None)) { - for (size_t i = 0; i < ARRAY_SIZE(levels); i++) + for (std::size_t i = 0; i < std::size(levels); i++) { bool is_selected = logManager->GetLogLevel() - 1 == (int)i; if (ImGui::Selectable(levels[i], &is_selected)) { @@ -1334,15 +1334,15 @@ static void gui_display_settings() { ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, normal_padding); const char *languages[] = { "Japanese", "English", "German", "French", "Spanish", "Italian", "Default" }; - OptionComboBox("Language", config::Language, languages, ARRAY_SIZE(languages), + OptionComboBox("Language", config::Language, languages, std::size(languages), "The language as configured in the Dreamcast BIOS"); const char *broadcast[] = { "NTSC", "PAL", "PAL/M", "PAL/N", "Default" }; - OptionComboBox("Broadcast", config::Broadcast, broadcast, ARRAY_SIZE(broadcast), + OptionComboBox("Broadcast", config::Broadcast, broadcast, std::size(broadcast), "TV broadcasting standard for non-VGA modes"); const char *region[] = { "Japan", "USA", "Europe", "Default" }; - OptionComboBox("Region", config::Region, region, ARRAY_SIZE(region), + OptionComboBox("Region", config::Region, region, std::size(region), "BIOS region"); const char *cable[] = { "VGA", "RGB Component", "TV Composite" }; @@ -1495,7 +1495,7 @@ static void gui_display_settings() ImGui::PushID(port_name); if (ImGui::BeginCombo(port_name, maple_ports[gamepad->maple_port() + 1])) { - for (int j = -1; j < (int)ARRAY_SIZE(maple_ports) - 1; j++) + for (int j = -1; j < (int)std::size(maple_ports) - 1; j++) { bool is_selected = gamepad->maple_port() == j; if (ImGui::Selectable(maple_ports[j + 1], &is_selected)) @@ -2977,7 +2977,7 @@ void gui_refresh_files() static void reset_vmus() { - for (u32 i = 0; i < ARRAY_SIZE(vmu_lcd_status); i++) + for (u32 i = 0; i < std::size(vmu_lcd_status); i++) vmu_lcd_status[i] = false; } diff --git a/core/rend/osd.cpp b/core/rend/osd.cpp index 03afdba39..3419ba33c 100644 --- a/core/rend/osd.cpp +++ b/core/rend/osd.cpp @@ -98,7 +98,7 @@ static void DrawButton2(const float xy[8], bool state) const std::vector& GetOSDVertices() { - osdVertices.reserve(ARRAY_SIZE(vjoy_pos) * 4); + osdVertices.reserve(std::size(vjoy_pos) * 4); osdVertices.clear(); DrawButton2(vjoy_pos[0], kcode[0] & DC_DPAD_LEFT); DrawButton2(vjoy_pos[1], kcode[0] & DC_DPAD_UP); @@ -177,10 +177,10 @@ bool vmu_lcd_changed[8]; void push_vmu_screen(int bus_id, int bus_port, u8* buffer) { int vmu_id = bus_id * 2 + bus_port; - if (vmu_id < 0 || vmu_id >= (int)ARRAY_SIZE(vmu_lcd_data)) + if (vmu_id < 0 || vmu_id >= (int)std::size(vmu_lcd_data)) return; u32 *p = &vmu_lcd_data[vmu_id][0]; - for (int i = 0; i < (int)ARRAY_SIZE(vmu_lcd_data[vmu_id]); i++, buffer++) + for (int i = 0; i < (int)std::size(vmu_lcd_data[vmu_id]); i++, buffer++) #ifdef LIBRETRO *p++ = (*buffer != 0 ? vmu_screen_params[bus_id].vmu_pixel_on_R | (vmu_screen_params[bus_id].vmu_pixel_on_G << 8) | (vmu_screen_params[bus_id].vmu_pixel_on_B << 16) diff --git a/core/rend/vulkan/drawer.cpp b/core/rend/vulkan/drawer.cpp index d6c0bb867..d38937bec 100644 --- a/core/rend/vulkan/drawer.cpp +++ b/core/rend/vulkan/drawer.cpp @@ -409,7 +409,7 @@ bool Drawer::Draw(const Texture *fogTexture, const Texture *paletteTexture) void TextureDrawer::Init(SamplerManager *samplerManager, ShaderManager *shaderManager, TextureCache *textureCache) { if (!rttPipelineManager) - rttPipelineManager = std::unique_ptr(new RttPipelineManager()); + rttPipelineManager = std::make_unique(); rttPipelineManager->Init(shaderManager); Drawer::Init(samplerManager, rttPipelineManager.get()); @@ -442,7 +442,7 @@ vk::CommandBuffer TextureDrawer::BeginRenderPass() if (!depthAttachment || widthPow2 > depthAttachment->getExtent().width || heightPow2 > depthAttachment->getExtent().height) { if (!depthAttachment) - depthAttachment = std::unique_ptr(new FramebufferAttachment(context->GetPhysicalDevice(), device)); + depthAttachment = std::make_unique(context->GetPhysicalDevice(), device); else GetContext()->WaitIdle(); depthAttachment->Init(widthPow2, heightPow2, GetContext()->GetDepthFormat(), @@ -483,7 +483,7 @@ vk::CommandBuffer TextureDrawer::BeginRenderPass() if (!colorAttachment || widthPow2 > colorAttachment->getExtent().width || heightPow2 > colorAttachment->getExtent().height) { if (!colorAttachment) - colorAttachment = std::unique_ptr(new FramebufferAttachment(context->GetPhysicalDevice(), device)); + colorAttachment = std::make_unique(context->GetPhysicalDevice(), device); else GetContext()->WaitIdle(); colorAttachment->Init(widthPow2, heightPow2, vk::Format::eR8G8B8A8Unorm, @@ -589,8 +589,8 @@ void ScreenDrawer::Init(SamplerManager *samplerManager, ShaderManager *shaderMan this->viewport = viewport; if (!depthAttachment) { - depthAttachment = std::unique_ptr( - new FramebufferAttachment(GetContext()->GetPhysicalDevice(), GetContext()->GetDevice())); + depthAttachment = std::make_unique( + GetContext()->GetPhysicalDevice(), GetContext()->GetDevice()); depthAttachment->Init(viewport.width, viewport.height, GetContext()->GetDepthFormat(), vk::ImageUsageFlagBits::eDepthStencilAttachment | vk::ImageUsageFlagBits::eTransientAttachment); } @@ -649,8 +649,8 @@ void ScreenDrawer::Init(SamplerManager *samplerManager, ShaderManager *shaderMan }; while (colorAttachments.size() < size) { - colorAttachments.push_back(std::unique_ptr( - new FramebufferAttachment(GetContext()->GetPhysicalDevice(), GetContext()->GetDevice()))); + colorAttachments.push_back(std::make_unique( + GetContext()->GetPhysicalDevice(), GetContext()->GetDevice())); vk::ImageUsageFlags usage = vk::ImageUsageFlagBits::eColorAttachment; if (config::EmulateFramebuffer) usage |= vk::ImageUsageFlagBits::eTransferSrc; @@ -668,7 +668,7 @@ void ScreenDrawer::Init(SamplerManager *samplerManager, ShaderManager *shaderMan frameRendered = false; if (!screenPipelineManager) - screenPipelineManager = std::unique_ptr(new PipelineManager()); + screenPipelineManager = std::make_unique(); screenPipelineManager->Init(shaderManager, *renderPassLoad); Drawer::Init(samplerManager, screenPipelineManager.get()); } diff --git a/core/rend/vulkan/drawer.h b/core/rend/vulkan/drawer.h index f1689fea2..17c385f16 100644 --- a/core/rend/vulkan/drawer.h +++ b/core/rend/vulkan/drawer.h @@ -214,8 +214,8 @@ protected: u32 bufferIndex = imageIndex + renderPass * GetSwapChainSize(); while (mainBuffers.size() <= bufferIndex) { - mainBuffers.push_back(std::unique_ptr(new BufferData(std::max(512 * 1024u, size), - vk::BufferUsageFlagBits::eVertexBuffer | vk::BufferUsageFlagBits::eIndexBuffer | vk::BufferUsageFlagBits::eUniformBuffer))); + mainBuffers.push_back(std::make_unique(std::max(512 * 1024u, size), + vk::BufferUsageFlagBits::eVertexBuffer | vk::BufferUsageFlagBits::eIndexBuffer | vk::BufferUsageFlagBits::eUniformBuffer)); } if (mainBuffers[bufferIndex]->bufferSize < size) { @@ -223,8 +223,8 @@ protected: while (newSize < size) newSize *= 2; INFO_LOG(RENDERER, "Increasing main buffer size %d -> %d", (u32)mainBuffers[bufferIndex]->bufferSize, newSize); - mainBuffers[bufferIndex] = std::unique_ptr(new BufferData(newSize, - vk::BufferUsageFlagBits::eVertexBuffer | vk::BufferUsageFlagBits::eIndexBuffer | vk::BufferUsageFlagBits::eUniformBuffer)); + mainBuffers[bufferIndex] = std::make_unique(newSize, + vk::BufferUsageFlagBits::eVertexBuffer | vk::BufferUsageFlagBits::eIndexBuffer | vk::BufferUsageFlagBits::eUniformBuffer); } return mainBuffers[bufferIndex].get(); } diff --git a/core/rend/vulkan/oit/oit_buffer.h b/core/rend/vulkan/oit/oit_buffer.h index cc5944625..58e129235 100644 --- a/core/rend/vulkan/oit/oit_buffer.h +++ b/core/rend/vulkan/oit/oit_buffer.h @@ -39,22 +39,22 @@ public: if (!pixelBuffer) { pixelBufferSize = config::PixelBufferSize; - pixelBuffer = std::unique_ptr(new BufferData(std::min(pixelBufferSize, context->GetMaxMemoryAllocationSize()), - vk::BufferUsageFlagBits::eStorageBuffer, vk::MemoryPropertyFlagBits::eDeviceLocal)); + pixelBuffer = std::make_unique(std::min(pixelBufferSize, context->GetMaxMemoryAllocationSize()), + vk::BufferUsageFlagBits::eStorageBuffer, vk::MemoryPropertyFlagBits::eDeviceLocal); } if (!pixelCounter) { - pixelCounter = std::unique_ptr(new BufferData(4, - vk::BufferUsageFlagBits::eStorageBuffer | vk::BufferUsageFlagBits::eTransferDst, vk::MemoryPropertyFlagBits::eDeviceLocal)); - pixelCounterReset = std::unique_ptr(new BufferData(4, vk::BufferUsageFlagBits::eTransferSrc)); + pixelCounter = std::make_unique(4, + vk::BufferUsageFlagBits::eStorageBuffer | vk::BufferUsageFlagBits::eTransferDst, vk::MemoryPropertyFlagBits::eDeviceLocal); + pixelCounterReset = std::make_unique(4, vk::BufferUsageFlagBits::eTransferSrc); const int zero = 0; pixelCounterReset->upload(sizeof(zero), &zero); } // We need to wait until this buffer is not used before deleting it context->WaitIdle(); abufferPointer.reset(); - abufferPointer = std::unique_ptr(new BufferData(maxWidth * maxHeight * sizeof(int), - vk::BufferUsageFlagBits::eStorageBuffer, vk::MemoryPropertyFlagBits::eDeviceLocal)); + abufferPointer = std::make_unique(maxWidth * maxHeight * sizeof(int), + vk::BufferUsageFlagBits::eStorageBuffer, vk::MemoryPropertyFlagBits::eDeviceLocal); firstFrameAfterInit = true; } @@ -77,8 +77,8 @@ public: if (pixelBufferSize != config::PixelBufferSize) { pixelBufferSize = config::PixelBufferSize; - pixelBuffer = std::unique_ptr(new BufferData(std::min(pixelBufferSize, VulkanContext::Instance()->GetMaxMemoryAllocationSize()), - vk::BufferUsageFlagBits::eStorageBuffer, vk::MemoryPropertyFlagBits::eDeviceLocal)); + pixelBuffer = std::make_unique(std::min(pixelBufferSize, VulkanContext::Instance()->GetMaxMemoryAllocationSize()), + vk::BufferUsageFlagBits::eStorageBuffer, vk::MemoryPropertyFlagBits::eDeviceLocal); } } diff --git a/core/rend/vulkan/oit/oit_drawer.cpp b/core/rend/vulkan/oit/oit_drawer.cpp index 7f0d3da6c..f4bf1a7c3 100644 --- a/core/rend/vulkan/oit/oit_drawer.cpp +++ b/core/rend/vulkan/oit/oit_drawer.cpp @@ -23,6 +23,7 @@ #include "rend/sorter.h" #include +#include void OITDrawer::DrawPoly(const vk::CommandBuffer& cmdBuffer, u32 listType, bool autosort, Pass pass, const PolyParam& poly, u32 first, u32 count) @@ -441,8 +442,8 @@ void OITDrawer::MakeBuffers(int width, int height) for (auto& attachment : colorAttachments) { attachment.reset(); - attachment = std::unique_ptr( - new FramebufferAttachment(GetContext()->GetPhysicalDevice(), GetContext()->GetDevice())); + attachment = std::make_unique( + GetContext()->GetPhysicalDevice(), GetContext()->GetDevice()); attachment->Init(maxWidth, maxHeight, vk::Format::eR8G8B8A8Unorm, vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eInputAttachment); } @@ -450,8 +451,8 @@ void OITDrawer::MakeBuffers(int width, int height) for (auto& attachment : depthAttachments) { attachment.reset(); - attachment = std::unique_ptr( - new FramebufferAttachment(GetContext()->GetPhysicalDevice(), GetContext()->GetDevice())); + attachment = std::make_unique( + GetContext()->GetPhysicalDevice(), GetContext()->GetDevice()); attachment->Init(maxWidth, maxHeight, GetContext()->GetDepthFormat(), vk::ImageUsageFlagBits::eDepthStencilAttachment | vk::ImageUsageFlagBits::eInputAttachment); } @@ -490,8 +491,8 @@ void OITScreenDrawer::MakeFramebuffers(const vk::Extent2D& viewport) usage |= vk::ImageUsageFlagBits::eSampled; while (finalColorAttachments.size() < GetSwapChainSize()) { - finalColorAttachments.push_back(std::unique_ptr( - new FramebufferAttachment(GetContext()->GetPhysicalDevice(), GetContext()->GetDevice()))); + finalColorAttachments.push_back(std::make_unique( + GetContext()->GetPhysicalDevice(), GetContext()->GetDevice())); finalColorAttachments.back()->Init(viewport.width, viewport.height, vk::Format::eR8G8B8A8Unorm, usage); std::array attachments = { @@ -568,7 +569,7 @@ vk::CommandBuffer OITTextureDrawer::NewFrame() if (!colorAttachment || widthPow2 > colorAttachment->getExtent().width || heightPow2 > colorAttachment->getExtent().height) { if (!colorAttachment) - colorAttachment = std::unique_ptr(new FramebufferAttachment(context->GetPhysicalDevice(), device)); + colorAttachment = std::make_unique(context->GetPhysicalDevice(), device); else GetContext()->WaitIdle(); colorAttachment->Init(widthPow2, heightPow2, vk::Format::eR8G8B8A8Unorm, diff --git a/core/rend/vulkan/oit/oit_drawer.h b/core/rend/vulkan/oit/oit_drawer.h index fa6837280..3b2d92d4b 100644 --- a/core/rend/vulkan/oit/oit_drawer.h +++ b/core/rend/vulkan/oit/oit_drawer.h @@ -50,7 +50,7 @@ protected: this->pipelineManager = pipelineManager; this->samplerManager = samplerManager; if (!quadBuffer) - quadBuffer = std::unique_ptr(new QuadBuffer()); + quadBuffer = std::make_unique(); this->oitBuffers = oitBuffers; descriptorSets.init(samplerManager, pipelineManager->GetPipelineLayout(), @@ -87,9 +87,9 @@ protected: u32 bufferIndex = imageIndex + renderPass * GetSwapChainSize(); while (mainBuffers.size() <= bufferIndex) { - mainBuffers.push_back(std::unique_ptr(new BufferData(std::max(512 * 1024u, size), + mainBuffers.push_back(std::make_unique(std::max(512 * 1024u, size), vk::BufferUsageFlagBits::eVertexBuffer | vk::BufferUsageFlagBits::eIndexBuffer | vk::BufferUsageFlagBits::eUniformBuffer - | vk::BufferUsageFlagBits::eStorageBuffer))); + | vk::BufferUsageFlagBits::eStorageBuffer)); } if (mainBuffers[bufferIndex]->bufferSize < size) { @@ -97,9 +97,9 @@ protected: while (newSize < size) newSize *= 2; INFO_LOG(RENDERER, "Increasing main buffer size %d -> %d", (u32)mainBuffers[bufferIndex]->bufferSize, newSize); - mainBuffers[bufferIndex] = std::unique_ptr(new BufferData(newSize, + mainBuffers[bufferIndex] = std::make_unique(newSize, vk::BufferUsageFlagBits::eVertexBuffer | vk::BufferUsageFlagBits::eIndexBuffer | vk::BufferUsageFlagBits::eUniformBuffer - | vk::BufferUsageFlagBits::eStorageBuffer)); + | vk::BufferUsageFlagBits::eStorageBuffer); } return mainBuffers[bufferIndex].get(); } @@ -161,7 +161,7 @@ public: const vk::Extent2D& viewport) { if (!screenPipelineManager) - screenPipelineManager = std::unique_ptr(new OITPipelineManager()); + screenPipelineManager = std::make_unique(); screenPipelineManager->Init(shaderManager, oitBuffers); OITDrawer::Init(samplerManager, screenPipelineManager.get(), oitBuffers); @@ -230,7 +230,7 @@ public: TextureCache *textureCache, OITBuffers *oitBuffers) { if (!rttPipelineManager) - rttPipelineManager = std::unique_ptr(new RttOITPipelineManager()); + rttPipelineManager = std::make_unique(); rttPipelineManager->Init(shaderManager, oitBuffers); OITDrawer::Init(samplerManager, rttPipelineManager.get(), oitBuffers); diff --git a/core/rend/vulkan/oit/oit_pipeline.h b/core/rend/vulkan/oit/oit_pipeline.h index 686ee0f70..ed0ab4080 100644 --- a/core/rend/vulkan/oit/oit_pipeline.h +++ b/core/rend/vulkan/oit/oit_pipeline.h @@ -432,9 +432,9 @@ private: }; return vk::PipelineVertexInputStateCreateInfo( vk::PipelineVertexInputStateCreateFlags(), - ARRAY_SIZE(vertexBindingDescriptions), + std::size(vertexBindingDescriptions), vertexBindingDescriptions, - full ? ARRAY_SIZE(vertexInputAttributeDescriptions) : ARRAY_SIZE(vertexInputLightAttributeDescriptions), + full ? std::size(vertexInputAttributeDescriptions) : std::size(vertexInputLightAttributeDescriptions), full ? vertexInputAttributeDescriptions : vertexInputLightAttributeDescriptions); } diff --git a/core/rend/vulkan/overlay.cpp b/core/rend/vulkan/overlay.cpp index f8d465929..babdacf36 100644 --- a/core/rend/vulkan/overlay.cpp +++ b/core/rend/vulkan/overlay.cpp @@ -27,6 +27,8 @@ #include "vmu_xhair.h" #endif +#include + VulkanOverlay::~VulkanOverlay() = default; void VulkanOverlay::Init(QuadPipeline *pipeline) @@ -34,10 +36,10 @@ void VulkanOverlay::Init(QuadPipeline *pipeline) this->pipeline = pipeline; for (auto& drawer : drawers) { - drawer = std::unique_ptr(new QuadDrawer()); + drawer = std::make_unique(); drawer->Init(pipeline); } - xhairDrawer = std::unique_ptr(new QuadDrawer()); + xhairDrawer = std::make_unique(); xhairDrawer->Init(pipeline); } @@ -54,7 +56,7 @@ void VulkanOverlay::Term() std::unique_ptr VulkanOverlay::createTexture(vk::CommandBuffer commandBuffer, int width, int height, const u8 *data) { - auto texture = std::unique_ptr(new Texture()); + auto texture = std::make_unique(); texture->tex_type = TextureType::_8888; texture->SetCommandBuffer(commandBuffer); texture->UploadToGPU(width, height, data, false); @@ -205,8 +207,7 @@ void VulkanOverlay::Draw(vk::CommandBuffer commandBuffer, vk::Extent2D viewport, if (settings.platform.isConsole() && config::MapleMainDevices[i] != MDT_LightGun) continue; - float x, y; - std::tie(x, y) = getCrosshairPosition(i); + auto [x, y] = getCrosshairPosition(i); #ifdef LIBRETRO float w = LIGHTGUN_CROSSHAIR_SIZE * scaling / config::ScreenStretching * 100.f; diff --git a/core/rend/vulkan/pipeline.h b/core/rend/vulkan/pipeline.h index 6aa338720..bdeeba822 100644 --- a/core/rend/vulkan/pipeline.h +++ b/core/rend/vulkan/pipeline.h @@ -305,9 +305,9 @@ private: }; return vk::PipelineVertexInputStateCreateInfo( vk::PipelineVertexInputStateCreateFlags(), - ARRAY_SIZE(vertexBindingDescriptions), + std::size(vertexBindingDescriptions), vertexBindingDescriptions, - full ? ARRAY_SIZE(vertexInputAttributeDescriptions) : ARRAY_SIZE(vertexInputLightAttributeDescriptions), + full ? std::size(vertexInputAttributeDescriptions) : std::size(vertexInputLightAttributeDescriptions), full ? vertexInputAttributeDescriptions : vertexInputLightAttributeDescriptions); } @@ -360,7 +360,7 @@ public: }; rttRenderPass = GetContext()->GetDevice().createRenderPassUnique(vk::RenderPassCreateInfo(vk::RenderPassCreateFlags(), 2, attachmentDescriptions, - 1, &subpass, renderToTextureBuffer ? ARRAY_SIZE(vramWriteDeps) : ARRAY_SIZE(dependencies), renderToTextureBuffer ? vramWriteDeps : dependencies)); + 1, &subpass, renderToTextureBuffer ? std::size(vramWriteDeps) : std::size(dependencies), renderToTextureBuffer ? vramWriteDeps : dependencies)); PipelineManager::Init(shaderManager, *rttRenderPass); } diff --git a/core/rend/vulkan/quad.cpp b/core/rend/vulkan/quad.cpp index fa11f29e9..8d88efb5b 100644 --- a/core/rend/vulkan/quad.cpp +++ b/core/rend/vulkan/quad.cpp @@ -21,6 +21,8 @@ #include "quad.h" #include "vulkan_context.h" +#include + static VulkanContext *GetContext() { return VulkanContext::Instance(); @@ -40,9 +42,9 @@ vk::PipelineVertexInputStateCreateInfo GetQuadInputStateCreateInfo(bool uv) }; return vk::PipelineVertexInputStateCreateInfo( vk::PipelineVertexInputStateCreateFlags(), - ARRAY_SIZE(vertexBindingDescriptions), + std::size(vertexBindingDescriptions), vertexBindingDescriptions, - ARRAY_SIZE(vertexInputAttributeDescriptions) - (uv ? 0 : 1), + std::size(vertexInputAttributeDescriptions) - (uv ? 0 : 1), vertexInputAttributeDescriptions); } @@ -161,7 +163,7 @@ void QuadPipeline::Init(ShaderManager *shaderManager, vk::RenderPass renderPass, void QuadDrawer::Init(QuadPipeline *pipeline) { this->pipeline = pipeline; - buffer = std::unique_ptr(new QuadBuffer()); + buffer = std::make_unique(); descriptorSets.resize(VulkanContext::Instance()->GetSwapChainSize()); for (auto& descSet : descriptorSets) descSet.reset(); diff --git a/core/rend/vulkan/quad.h b/core/rend/vulkan/quad.h index a74572c93..c6b653f79 100644 --- a/core/rend/vulkan/quad.h +++ b/core/rend/vulkan/quad.h @@ -38,7 +38,7 @@ class QuadBuffer public: QuadBuffer() { - buffer = std::unique_ptr(new BufferData(sizeof(QuadVertex) * 4, vk::BufferUsageFlagBits::eVertexBuffer)); + buffer = std::make_unique(sizeof(QuadVertex) * 4, vk::BufferUsageFlagBits::eVertexBuffer); } void Bind(vk::CommandBuffer commandBuffer) diff --git a/core/rend/vulkan/texture.cpp b/core/rend/vulkan/texture.cpp index 55e4df40e..a958675cd 100644 --- a/core/rend/vulkan/texture.cpp +++ b/core/rend/vulkan/texture.cpp @@ -214,7 +214,7 @@ void Texture::Init(u32 width, u32 height, vk::Format format, u32 dataSize, bool vk::ImageUsageFlags usageFlags = vk::ImageUsageFlagBits::eSampled; if (needsStaging) { - stagingBufferData = std::unique_ptr(new BufferData(dataSize, vk::BufferUsageFlagBits::eTransferSrc)); + stagingBufferData = std::make_unique(dataSize, vk::BufferUsageFlagBits::eTransferSrc); usageFlags |= vk::ImageUsageFlagBits::eTransferDst; initialLayout = vk::ImageLayout::eUndefined; } @@ -260,7 +260,7 @@ void Texture::SetImage(u32 srcSize, const void *srcData, bool isNew, bool genMip { if (!stagingBufferData) // This can happen if a texture is first created for RTT, then later updated - stagingBufferData = std::unique_ptr(new BufferData(srcSize, vk::BufferUsageFlagBits::eTransferSrc)); + stagingBufferData = std::make_unique(srcSize, vk::BufferUsageFlagBits::eTransferSrc); data = stagingBufferData->MapMemory(); } else @@ -404,9 +404,9 @@ void FramebufferAttachment::Init(u32 width, u32 height, vk::Format format, const if (usage & vk::ImageUsageFlagBits::eTransferSrc) { - stagingBufferData = std::unique_ptr(new BufferData(width * height * 4, + stagingBufferData = std::make_unique(width * height * 4, vk::BufferUsageFlagBits::eTransferSrc | vk::BufferUsageFlagBits::eTransferDst, - vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCached | vk::MemoryPropertyFlagBits::eHostCoherent)); + vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCached | vk::MemoryPropertyFlagBits::eHostCoherent); } vk::ImageCreateInfo imageCreateInfo(vk::ImageCreateFlags(), vk::ImageType::e2D, format, vk::Extent3D(extent, 1), 1, 1, vk::SampleCountFlagBits::e1, vk::ImageTiling::eOptimal, usage, @@ -439,10 +439,10 @@ void TextureCache::Cleanup() u32 TargetFrame = std::max((u32)120, FrameCount) - 120; - for (const auto& pair : cache) + for (const auto& [id, texture] : cache) { - if (pair.second.dirty && pair.second.dirty < TargetFrame) - list.push_back(pair.first); + if (texture.dirty && texture.dirty < TargetFrame) + list.push_back(id); if (list.size() > 5) break; diff --git a/core/rend/vulkan/vulkan_context.cpp b/core/rend/vulkan/vulkan_context.cpp index ac9c6d02f..0563668d2 100644 --- a/core/rend/vulkan/vulkan_context.cpp +++ b/core/rend/vulkan/vulkan_context.cpp @@ -38,6 +38,8 @@ VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE #endif +#include + void ReInitOSD(); VulkanContext *VulkanContext::contextInstance; @@ -494,12 +496,12 @@ bool VulkanContext::InitDevice() } allocator.Init(physicalDevice, *device, *instance); - shaderManager = std::unique_ptr(new ShaderManager()); - quadPipeline = std::unique_ptr(new QuadPipeline(true, false)); - quadPipelineWithAlpha = std::unique_ptr(new QuadPipeline(false, false)); - quadDrawer = std::unique_ptr(new QuadDrawer()); - quadRotatePipeline = std::unique_ptr(new QuadPipeline(true, true)); - quadRotateDrawer = std::unique_ptr(new QuadDrawer()); + shaderManager = std::make_unique(); + quadPipeline = std::make_unique(true, false); + quadPipelineWithAlpha = std::make_unique(false, false); + quadDrawer = std::make_unique(); + quadRotatePipeline = std::make_unique(true, true); + quadRotateDrawer = std::make_unique(); vk::PhysicalDeviceProperties props; physicalDevice.getProperties(&props); @@ -786,8 +788,8 @@ bool VulkanContext::init() #else #error "Unknown Vulkan platform" #endif - overlay = std::unique_ptr(new VulkanOverlay()); - textureCache = std::unique_ptr(new TextureCache()); + overlay = std::make_unique(); + textureCache = std::make_unique(); return InitDevice(); } diff --git a/core/rend/vulkan/vulkan_context.h b/core/rend/vulkan/vulkan_context.h index 620632f08..b1af59857 100644 --- a/core/rend/vulkan/vulkan_context.h +++ b/core/rend/vulkan/vulkan_context.h @@ -235,7 +235,7 @@ static inline vk::Format findDepthFormat(vk::PhysicalDevice physicalDevice) const vk::Format depthFormats[] = { vk::Format::eD32SfloatS8Uint, vk::Format::eD24UnormS8Uint, vk::Format::eD16UnormS8Uint }; vk::ImageTiling tiling; vk::Format depthFormat = vk::Format::eUndefined; - for (size_t i = 0; i < ARRAY_SIZE(depthFormats); i++) + for (size_t i = 0; i < std::size(depthFormats); i++) { vk::FormatProperties formatProperties = physicalDevice.getFormatProperties(depthFormats[i]); @@ -249,7 +249,7 @@ static inline vk::Format findDepthFormat(vk::PhysicalDevice physicalDevice) if (depthFormat == vk::Format::eUndefined) { // Try to find a linear format - for (size_t i = 0; i < ARRAY_SIZE(depthFormats); i++) + for (size_t i = 0; i < std::size(depthFormats); i++) { vk::FormatProperties formatProperties = physicalDevice.getFormatProperties(depthFormats[i]); diff --git a/core/rend/vulkan/vulkan_driver.h b/core/rend/vulkan/vulkan_driver.h index 6cedeeff8..e659863ae 100644 --- a/core/rend/vulkan/vulkan_driver.h +++ b/core/rend/vulkan/vulkan_driver.h @@ -81,7 +81,7 @@ public: ImTextureID updateTexture(const std::string& name, const u8 *data, int width, int height) override { - VkTexture vkTex(std::unique_ptr(new Texture())); + VkTexture vkTex(std::make_unique()); vkTex.texture->tex_type = TextureType::_8888; vkTex.texture->SetCommandBuffer(getCommandBuffer()); vkTex.texture->UploadToGPU(width, height, data, false); diff --git a/core/rend/vulkan/vulkan_renderer.h b/core/rend/vulkan/vulkan_renderer.h index b13f94073..cbdc78a05 100644 --- a/core/rend/vulkan/vulkan_renderer.h +++ b/core/rend/vulkan/vulkan_renderer.h @@ -46,7 +46,7 @@ protected: int w, h; u8 *image_data = loadOSDButtons(w, h); texCommandPool.BeginFrame(); - vjoyTexture = std::unique_ptr(new Texture()); + vjoyTexture = std::make_unique(); vjoyTexture->tex_type = TextureType::_8888; vk::CommandBuffer cmdBuffer = texCommandPool.Allocate(); cmdBuffer.begin(vk::CommandBufferBeginInfo(vk::CommandBufferUsageFlagBits::eOneTimeSubmit)); @@ -60,16 +60,16 @@ protected: } if (!osdBuffer) { - osdBuffer = std::unique_ptr(new BufferData(sizeof(OSDVertex) * VJOY_VISIBLE * 4, - vk::BufferUsageFlagBits::eVertexBuffer)); + osdBuffer = std::make_unique(sizeof(OSDVertex) * VJOY_VISIBLE * 4, + vk::BufferUsageFlagBits::eVertexBuffer); } #endif - quadPipeline = std::unique_ptr(new QuadPipeline(false, false)); + quadPipeline = std::make_unique(false, false); quadPipeline->Init(&shaderManager, renderPass, subpass); - framebufferDrawer = std::unique_ptr(new QuadDrawer()); + framebufferDrawer = std::make_unique(); framebufferDrawer->Init(quadPipeline.get()); #ifdef LIBRETRO - overlay = std::unique_ptr(new VulkanOverlay()); + overlay = std::make_unique(); overlay->Init(quadPipeline.get()); #endif return true; @@ -211,7 +211,7 @@ public: std::unique_ptr& curTexture = framebufferTextures[framebufferTexIndex]; if (!curTexture) { - curTexture = std::unique_ptr(new Texture()); + curTexture = std::make_unique(); curTexture->tex_type = TextureType::_8888; } @@ -257,7 +257,7 @@ protected: { if (!fogTexture) { - fogTexture = std::unique_ptr(new Texture()); + fogTexture = std::make_unique(); fogTexture->tex_type = TextureType::_8; fog_needs_update = true; } @@ -277,7 +277,7 @@ protected: { if (!paletteTexture) { - paletteTexture = std::unique_ptr(new Texture()); + paletteTexture = std::make_unique(); paletteTexture->tex_type = TextureType::_8888; forcePaletteUpdate(); } diff --git a/core/sdl/sdl_gamepad.h b/core/sdl/sdl_gamepad.h index 45658f2d5..d89c30a8a 100644 --- a/core/sdl/sdl_gamepad.h +++ b/core/sdl/sdl_gamepad.h @@ -86,9 +86,9 @@ public: return true; }; - if (Arcade) + if constexpr (Arcade) { - if (Gamepad) + if constexpr (Gamepad) { // 1 2 3 4 5 6 // A B X Y R L diff --git a/core/types.h b/core/types.h index ec4de47a5..8f3006f33 100644 --- a/core/types.h +++ b/core/types.h @@ -326,10 +326,6 @@ struct OnLoad OnLoad(OnLoadFP* fp) { fp(); } }; -#ifndef ARRAY_SIZE -#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) -#endif - class FlycastException : public std::runtime_error { public: diff --git a/core/windows/rawinput.cpp b/core/windows/rawinput.cpp index ce85a1c9e..a39ed4a64 100644 --- a/core/windows/rawinput.cpp +++ b/core/windows/rawinput.cpp @@ -278,7 +278,7 @@ static LRESULT CALLBACK rawWindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM u8 keycode = 0xff; if ((ri.data.keyboard.Flags & RI_KEY_E0) != 0) { - for (u32 i = 0; i < ARRAY_SIZE(Ps2toUsbE0); i++) + for (u32 i = 0; i < std::size(Ps2toUsbE0); i++) if (Ps2toUsbE0[i][0] == scancode) { keycode = Ps2toUsbE0[i][1]; diff --git a/core/windows/winmain.cpp b/core/windows/winmain.cpp index 1fd62b93f..9a463cab1 100644 --- a/core/windows/winmain.cpp +++ b/core/windows/winmain.cpp @@ -237,7 +237,7 @@ static void setupPath() { #ifndef TARGET_UWP wchar_t fname[512]; - GetModuleFileNameW(0, fname, ARRAY_SIZE(fname)); + GetModuleFileNameW(0, fname, std::size(fname)); std::string fn; nowide::stackstring path; @@ -736,7 +736,7 @@ static bool dumpCallback(const wchar_t* dump_path, if (succeeded) { wchar_t s[MAX_PATH + 32]; - _snwprintf(s, ARRAY_SIZE(s), L"Minidump saved to '%s\\%s.dmp'", dump_path, minidump_id); + _snwprintf(s, std::size(s), L"Minidump saved to '%s\\%s.dmp'", dump_path, minidump_id); ::OutputDebugStringW(s); nowide::stackstring path; @@ -887,7 +887,7 @@ int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi google_breakpad::CustomInfoEntry(L"prod", L"Flycast"), google_breakpad::CustomInfoEntry(L"ver", L"" GIT_VERSION), }; - google_breakpad::CustomClientInfo custom_info = { custom_entries, ARRAY_SIZE(custom_entries) }; + google_breakpad::CustomClientInfo custom_info = { custom_entries, std::size(custom_entries) }; google_breakpad::ExceptionHandler handler(tempDir, nullptr, diff --git a/shell/android-studio/flycast/src/main/jni/src/Android.cpp b/shell/android-studio/flycast/src/main/jni/src/Android.cpp index a11a47f29..367073389 100644 --- a/shell/android-studio/flycast/src/main/jni/src/Android.cpp +++ b/shell/android-studio/flycast/src/main/jni/src/Android.cpp @@ -408,7 +408,7 @@ extern "C" JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_rendinitNa extern "C" JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_vjoy(JNIEnv * env, jobject obj,int id,float x, float y, float w, float h) { - if (id < ARRAY_SIZE(vjoy_pos)) + if (id < std::size(vjoy_pos)) { vjoy_pos[id][0] = x; vjoy_pos[id][1] = y; diff --git a/shell/android-studio/flycast/src/main/jni/src/android_keyboard.h b/shell/android-studio/flycast/src/main/jni/src/android_keyboard.h index fbdf87b84..50a870e30 100644 --- a/shell/android-studio/flycast/src/main/jni/src/android_keyboard.h +++ b/shell/android-studio/flycast/src/main/jni/src/android_keyboard.h @@ -573,7 +573,7 @@ public: protected: u8 convert_keycode(int keycode) override { - if (keycode < 0 || keycode >= ARRAY_SIZE(AndroidKeycodes)) + if (keycode < 0 || keycode >= std::size(AndroidKeycodes)) return 0; else return AndroidKeycodes[keycode]; diff --git a/shell/libretro/libretro.cpp b/shell/libretro/libretro.cpp index 84b3e1e14..cdc30a0dc 100644 --- a/shell/libretro/libretro.cpp +++ b/shell/libretro/libretro.cpp @@ -1298,11 +1298,11 @@ static uint32_t map_gamepad_button(unsigned device, unsigned id) { case RETRO_DEVICE_JOYPAD: joymap = dc_joymap; - joymap_size = ARRAY_SIZE(dc_joymap); + joymap_size = std::size(dc_joymap); break; case RETRO_DEVICE_LIGHTGUN: joymap = dc_lg_joymap; - joymap_size = ARRAY_SIZE(dc_lg_joymap); + joymap_size = std::size(dc_lg_joymap); break; default: return 0; @@ -1315,11 +1315,11 @@ static uint32_t map_gamepad_button(unsigned device, unsigned id) { case RETRO_DEVICE_JOYPAD: joymap = nao_joymap; - joymap_size = ARRAY_SIZE(nao_joymap); + joymap_size = std::size(nao_joymap); break; case RETRO_DEVICE_LIGHTGUN: joymap = nao_lg_joymap; - joymap_size = ARRAY_SIZE(nao_lg_joymap); + joymap_size = std::size(nao_lg_joymap); break; default: return 0; @@ -1331,11 +1331,11 @@ static uint32_t map_gamepad_button(unsigned device, unsigned id) { case RETRO_DEVICE_JOYPAD: joymap = aw_joymap; - joymap_size = ARRAY_SIZE(aw_joymap); + joymap_size = std::size(aw_joymap); break; case RETRO_DEVICE_LIGHTGUN: joymap = aw_lg_joymap; - joymap_size = ARRAY_SIZE(aw_lg_joymap); + joymap_size = std::size(aw_lg_joymap); break; default: return 0; diff --git a/tests/src/AicaArmTest.cpp b/tests/src/AicaArmTest.cpp index e5a23507a..ea6ec9050 100644 --- a/tests/src/AicaArmTest.cpp +++ b/tests/src/AicaArmTest.cpp @@ -1035,7 +1035,7 @@ TEST_F(AicaArmTest, RegAllocTest) 0xe0855006, // add r5, r5, r6 0xe0866000, // add r6, r6, r0 }; - PrepareOps(ARRAY_SIZE(ops), ops); + PrepareOps(std::size(ops), ops); for (int i = 0; i < 15; i++) arm_Reg[i].I = 0; @@ -1056,7 +1056,7 @@ TEST_F(AicaArmTest, ConditionRegAllocTest) 0x03a0004d, // moveq r0, #77 0xe1a01000 // mov r1, r0 }; - PrepareOps(ARRAY_SIZE(ops1), ops1); + PrepareOps(std::size(ops1), ops1); arm_Reg[0].I = 22; arm_Reg[1].I = 22; ResetNZCV(); @@ -1070,7 +1070,7 @@ TEST_F(AicaArmTest, ConditionRegAllocTest) 0x01a01000, // moveq r1, r0 0xe1a02000 // mov r2, r0 }; - PrepareOps(ARRAY_SIZE(ops2), ops2); + PrepareOps(std::size(ops2), ops2); arm_Reg[0].I = 22; arm_Reg[1].I = 0; arm_Reg[2].I = 0;