Merge pull request #14776 from tygyh/Core/Use-static-cast

Replace functional cast with `static_cast`
This commit is contained in:
Scott Mansell
2026-08-01 22:17:15 +12:00
committed by GitHub
9 changed files with 37 additions and 35 deletions
+5 -5
View File
@@ -152,8 +152,8 @@ constexpr Seeds genseeds = [] {
for (size_t i = 0; i < array0.size(); ++i) for (size_t i = 0; i < array0.size(); ++i)
{ {
const auto tmp = u8(gentable0[i] - 1); const auto tmp = static_cast<u8>(gentable0[i] - 1);
array0[i] = (u32(0 - (gensubtable[tmp >> 3] & gentable1[tmp & 7])) >> 31); array0[i] = (static_cast<u32>(0 - (gensubtable[tmp >> 3] & gentable1[tmp & 7])) >> 31);
} }
for (int i = 0; i < 0x10; ++i) for (int i = 0; i < 0x10; ++i)
@@ -165,7 +165,7 @@ constexpr Seeds genseeds = [] {
for (u32 j = 0; j < 0x38; j++) for (u32 j = 0; j < 0x38; j++)
{ {
auto tmp = u8(tmp2 + j); auto tmp = static_cast<u8>(tmp2 + j);
if (j > 0x1B) if (j > 0x1B)
{ {
@@ -347,7 +347,7 @@ static bool GetBitString(u32* ctrl, u32* out, u8 len)
static std::optional<GameIDAndRegion> BatchDecrypt(std::span<u32> codes) static std::optional<GameIDAndRegion> BatchDecrypt(std::span<u32> codes)
{ {
const auto size = u32(codes.size()); const auto size = static_cast<u32>(codes.size());
assert((size & 1) == 0); assert((size & 1) == 0);
assert(size != 0); assert(size != 0);
@@ -383,7 +383,7 @@ static std::optional<GameIDAndRegion> BatchDecrypt(std::span<u32> codes)
static u32 GetVal(char chr) static u32 GetVal(char chr)
{ {
const auto ret = u32(strchr(filter, Common::ToUpper(chr)) - filter); const auto ret = static_cast<u32>(strchr(filter, Common::ToUpper(chr)) - filter);
switch (ret) switch (ret)
{ {
case 32: // 'I' case 32: // 'I'
+1 -1
View File
@@ -114,7 +114,7 @@ FreeLookController::FreeLookController(const unsigned int index) : m_index(index
std::string FreeLookController::GetName() const std::string FreeLookController::GetName() const
{ {
return std::string("FreeLook") + char('1' + m_index); return std::string("FreeLook") + static_cast<char>('1' + m_index);
} }
InputConfig* FreeLookController::GetConfig() const InputConfig* FreeLookController::GetConfig() const
+2 -2
View File
@@ -168,7 +168,7 @@ std::optional<std::string> GetStringDescriptor(libusb_device_handle* dev_handle,
if (lang_id_result != 4 || buffer.length < 4 || buffer.descriptor_type != LIBUSB_DT_STRING) if (lang_id_result != 4 || buffer.length < 4 || buffer.descriptor_type != LIBUSB_DT_STRING)
{ {
ERROR_LOG_FMT(IOS_USB, "libusb_get_string_descriptor(desc_index={}, lang_id=0) result:{}", ERROR_LOG_FMT(IOS_USB, "libusb_get_string_descriptor(desc_index={}, lang_id=0) result:{}",
int(desc_index), lang_id_result); static_cast<int>(desc_index), lang_id_result);
return std::nullopt; return std::nullopt;
} }
@@ -180,7 +180,7 @@ std::optional<std::string> GetStringDescriptor(libusb_device_handle* dev_handle,
if (str_result < 2 || buffer.length > str_result || buffer.descriptor_type != LIBUSB_DT_STRING) if (str_result < 2 || buffer.length > str_result || buffer.descriptor_type != LIBUSB_DT_STRING)
{ {
ERROR_LOG_FMT(IOS_USB, "libusb_get_string_descriptor(desc_index={}, lang_id={}) result:{}", ERROR_LOG_FMT(IOS_USB, "libusb_get_string_descriptor(desc_index={}, lang_id={}) result:{}",
int(desc_index), lang_id, str_result); static_cast<int>(desc_index), lang_id, str_result);
return std::nullopt; return std::nullopt;
} }
+3 -3
View File
@@ -1226,8 +1226,8 @@ bool MovieManager::PlayWiimote(int wiimote, DesiredWiimoteState* desired_state)
if (serialized.length > serialized.data.size()) if (serialized.length > serialized.data.size())
{ {
PanicAlertFmtT("Invalid serialized length:{0} in PlayWiimote. byte:{1}", int(serialized.length), PanicAlertFmtT("Invalid serialized length:{0} in PlayWiimote. byte:{1}",
m_current_byte); static_cast<int>(serialized.length), m_current_byte);
EndPlayInput(!m_read_only); EndPlayInput(!m_read_only);
return false; return false;
} }
@@ -1236,7 +1236,7 @@ bool MovieManager::PlayWiimote(int wiimote, DesiredWiimoteState* desired_state)
if (m_current_byte + serialized.length > m_temp_input.size()) if (m_current_byte + serialized.length > m_temp_input.size())
{ {
PanicAlertFmtT("Premature movie end in PlayWiimote. {0} + {1} > {2}", m_current_byte, PanicAlertFmtT("Premature movie end in PlayWiimote. {0} + {1} > {2}", m_current_byte,
int(serialized.length), m_temp_input.size()); static_cast<int>(serialized.length), m_temp_input.size());
EndPlayInput(!m_read_only); EndPlayInput(!m_read_only);
return false; return false;
} }
+2 -1
View File
@@ -1648,7 +1648,8 @@ void NetPlayClient::ThreadFunc()
if (static_cast<int>(netEvent.type) == Common::ENet::SKIPPABLE_EVENT) if (static_cast<int>(netEvent.type) == Common::ENet::SKIPPABLE_EVENT)
INFO_LOG_FMT(NETPLAY, "enet_host_service: skippable packet event"); INFO_LOG_FMT(NETPLAY, "enet_host_service: skippable packet event");
else else
ERROR_LOG_FMT(NETPLAY, "enet_host_service: unknown event type: {}", int(netEvent.type)); ERROR_LOG_FMT(NETPLAY, "enet_host_service: unknown event type: {}",
static_cast<int>(netEvent.type));
break; break;
} }
} }
+7 -6
View File
@@ -326,7 +326,7 @@ void NetPlayServer::ThreadFunc()
if (error != ConnectionError::NoError) if (error != ConnectionError::NoError)
{ {
INFO_LOG_FMT(NETPLAY, "Error {} initializing peer {:x}:{}", u8(error), INFO_LOG_FMT(NETPLAY, "Error {} initializing peer {:x}:{}", static_cast<u8>(error),
netEvent.peer->address.host, netEvent.peer->address.port); netEvent.peer->address.host, netEvent.peer->address.port);
sf::Packet spac; sf::Packet spac;
@@ -391,7 +391,8 @@ void NetPlayServer::ThreadFunc()
if (static_cast<int>(netEvent.type) == Common::ENet::SKIPPABLE_EVENT) if (static_cast<int>(netEvent.type) == Common::ENet::SKIPPABLE_EVENT)
INFO_LOG_FMT(NETPLAY, "enet_host_service: skippable packet event"); INFO_LOG_FMT(NETPLAY, "enet_host_service: skippable packet event");
else else
ERROR_LOG_FMT(NETPLAY, "enet_host_service: unknown event type: {}", int(netEvent.type)); ERROR_LOG_FMT(NETPLAY, "enet_host_service: unknown event type: {}",
static_cast<int>(netEvent.type));
break; break;
} }
} }
@@ -1157,8 +1158,8 @@ unsigned int NetPlayServer::OnData(sf::Packet& packet, Client& player)
SyncSaveDataID sub_id; SyncSaveDataID sub_id;
packet >> sub_id; packet >> sub_id;
INFO_LOG_FMT(NETPLAY, "Got client SyncSaveData message: {:x} from client {}", u8(sub_id), INFO_LOG_FMT(NETPLAY, "Got client SyncSaveData message: {:x} from client {}",
player.pid); static_cast<u8>(sub_id), player.pid);
switch (sub_id) switch (sub_id)
{ {
@@ -1214,8 +1215,8 @@ unsigned int NetPlayServer::OnData(sf::Packet& packet, Client& player)
SyncCodeID sub_id; SyncCodeID sub_id;
packet >> sub_id; packet >> sub_id;
INFO_LOG_FMT(NETPLAY, "Got client SyncCodes message: {:x} from client {}", u8(sub_id), INFO_LOG_FMT(NETPLAY, "Got client SyncCodes message: {:x} from client {}",
player.pid); static_cast<u8>(sub_id), player.pid);
// Check If Code Sync was successful or not // Check If Code Sync was successful or not
switch (sub_id) switch (sub_id)
+12 -12
View File
@@ -263,15 +263,15 @@ namespace
struct SlotWithTimestamp struct SlotWithTimestamp
{ {
// 1-based indexing. // 1-based indexing.
int slot; u32 slot;
double timestamp; double timestamp;
}; };
} // namespace } // namespace
// Returns first slot number (1-based indexing) not in the vector. // Returns first slot number (1-based indexing) not in the vector.
static std::optional<int> GetEmptySlot(std::span<const SlotWithTimestamp> used_slots) static std::optional<u32> GetEmptySlot(std::span<const SlotWithTimestamp> used_slots)
{ {
for (int i = 1; i <= int(NUM_STATES); ++i) for (u32 i = 1; i <= NUM_STATES; ++i)
{ {
if (!Common::Contains(used_slots, i, &SlotWithTimestamp::slot)) if (!Common::Contains(used_slots, i, &SlotWithTimestamp::slot))
return i; return i;
@@ -303,7 +303,7 @@ static std::string SystemTimeAsDoubleToString(double time)
return fmt::format(std::locale{""}, "{:%x %X}", *local_time); return fmt::format(std::locale{""}, "{:%x %X}", *local_time);
} }
static std::string MakeStateFilename(int number) static std::string MakeStateFilename(u32 number)
{ {
return fmt::format("{}{}.s{:02d}", File::GetUserPath(D_STATESAVES_IDX), return fmt::format("{}{}.s{:02d}", File::GetUserPath(D_STATESAVES_IDX),
SConfig::GetInstance().GetGameID(), number); SConfig::GetInstance().GetGameID(), number);
@@ -313,7 +313,7 @@ static std::vector<SlotWithTimestamp> GetUsedSlotsWithTimestamp()
{ {
std::vector<SlotWithTimestamp> result; std::vector<SlotWithTimestamp> result;
StateHeader header; StateHeader header;
for (int i = 1; i <= int(NUM_STATES); ++i) for (u32 i = 1; i <= NUM_STATES; ++i)
{ {
std::string filename = MakeStateFilename(i); std::string filename = MakeStateFilename(i);
if (!File::Exists(filename) || !ReadHeader(filename, header)) if (!File::Exists(filename) || !ReadHeader(filename, header))
@@ -337,7 +337,7 @@ static void CompressBufferToFile(std::span<const u8> raw_buffer, File::IOFile& f
Common::UniqueBuffer<char> compressed_buffer(LZ4_compressBound(bytes_to_compress)); Common::UniqueBuffer<char> compressed_buffer(LZ4_compressBound(bytes_to_compress));
const int compressed_len = LZ4_compress_default( const int compressed_len = LZ4_compress_default(
reinterpret_cast<const char*>(raw_buffer.data()) + total_bytes_compressed, reinterpret_cast<const char*>(raw_buffer.data()) + total_bytes_compressed,
compressed_buffer.get(), bytes_to_compress, int(compressed_buffer.size())); compressed_buffer.get(), bytes_to_compress, static_cast<int>(compressed_buffer.size()));
if (compressed_len == 0) if (compressed_len == 0)
{ {
@@ -474,7 +474,7 @@ static void SaveAsFromCore(Core::System& system, std::string filename)
{ {
// Try with a buffer a bit larger than the previous state. // Try with a buffer a bit larger than the previous state.
// This will often avoid the "Measure" step. // This will often avoid the "Measure" step.
const auto buffer_size_estimate = std::size_t(s_last_state_size) * 110 / 100; const auto buffer_size_estimate = static_cast<std::size_t>(s_last_state_size) * 110 / 100;
Common::UniqueBuffer<u8> buffer{buffer_size_estimate}; Common::UniqueBuffer<u8> buffer{buffer_size_estimate};
if (const auto actual_size = SaveToBuffer(system, buffer)) if (const auto actual_size = SaveToBuffer(system, buffer))
@@ -608,7 +608,7 @@ static bool ReadHeader(const std::string& filename, StateHeader& header)
return ReadStateHeaderFromFile(header, f, get_version_header); return ReadStateHeaderFromFile(header, f, get_version_header);
} }
std::string GetInfoStringOfSlot(int slot, bool translate) std::string GetInfoStringOfSlot(u32 slot, bool translate)
{ {
std::lock_guard lk{s_state_saves_in_progress}; std::lock_guard lk{s_state_saves_in_progress};
@@ -623,7 +623,7 @@ std::string GetInfoStringOfSlot(int slot, bool translate)
return SystemTimeAsDoubleToString(header.legacy_header.time); return SystemTimeAsDoubleToString(header.legacy_header.time);
} }
u64 GetUnixTimeOfSlot(int slot) u64 GetUnixTimeOfSlot(u32 slot)
{ {
std::lock_guard lk{s_state_saves_in_progress}; std::lock_guard lk{s_state_saves_in_progress};
@@ -902,12 +902,12 @@ void Shutdown()
s_flush_unsaved_data_hook.reset(); s_flush_unsaved_data_hook.reset();
} }
void Save(Core::System& system, int slot) void Save(Core::System& system, u32 slot)
{ {
SaveAs(system, MakeStateFilename(slot)); SaveAs(system, MakeStateFilename(slot));
} }
void Load(Core::System& system, int slot) void Load(Core::System& system, u32 slot)
{ {
LoadAs(system, MakeStateFilename(slot)); LoadAs(system, MakeStateFilename(slot));
} }
@@ -922,7 +922,7 @@ void LoadLastSaved(Core::System& system, int i)
s_compress_and_dump_thread.WaitForCompletion(); s_compress_and_dump_thread.WaitForCompletion();
std::vector<SlotWithTimestamp> used_slots = GetUsedSlotsWithTimestamp(); std::vector<SlotWithTimestamp> used_slots = GetUsedSlotsWithTimestamp();
if (std::size_t(i) > used_slots.size()) if (static_cast<std::size_t>(i) > used_slots.size())
{ {
Core::DisplayMessage("State doesn't exist", 2000); Core::DisplayMessage("State doesn't exist", 2000);
return; return;
+4 -4
View File
@@ -84,16 +84,16 @@ void Shutdown();
// Returns a string containing information of the savestate in the given slot // Returns a string containing information of the savestate in the given slot
// which can be presented to the user for identification purposes // which can be presented to the user for identification purposes
std::string GetInfoStringOfSlot(int slot, bool translate = true); std::string GetInfoStringOfSlot(u32 slot, bool translate = true);
// Returns when the savestate in the given slot was created, or 0 if the slot is empty. // Returns when the savestate in the given slot was created, or 0 if the slot is empty.
u64 GetUnixTimeOfSlot(int slot); u64 GetUnixTimeOfSlot(u32 slot);
// These don't happen instantly - they get scheduled as events. // These don't happen instantly - they get scheduled as events.
// ...But only if we're not in the main CPU thread. // ...But only if we're not in the main CPU thread.
// If we're in the main CPU thread then they run immediately instead. // If we're in the main CPU thread then they run immediately instead.
void Save(Core::System& system, int slot); void Save(Core::System& system, u32 slot);
void Load(Core::System& system, int slot); void Load(Core::System& system, u32 slot);
void SaveAs(Core::System& system, std::string filename); void SaveAs(Core::System& system, std::string filename);
void LoadAs(Core::System& system, std::string filename); void LoadAs(Core::System& system, std::string filename);
+1 -1
View File
@@ -329,7 +329,7 @@ std::string SystemUpdater::GetDeviceId()
u32 ios_device_id; u32 ios_device_id;
if (m_ios.GetESCore().GetDeviceId(&ios_device_id) < 0) if (m_ios.GetESCore().GetDeviceId(&ios_device_id) < 0)
return ""; return "";
return std::to_string((u64(1) << 32) | ios_device_id); return std::to_string((1ULL << 32) | ios_device_id);
} }
class OnlineSystemUpdater final : public SystemUpdater class OnlineSystemUpdater final : public SystemUpdater