From c7974889cd8a20e712e9535d02f610c9e1affd64 Mon Sep 17 00:00:00 2001 From: libretroadmin Date: Sat, 25 Jun 2022 23:49:01 +0200 Subject: [PATCH] - Remove unnecessary IncrementInternalFrameNumber - Timing_event - remove unnecessary GetPeriod - D3D11 - Remove IsDynamic - LoadState/SaveState - remove second parameter - System - Remove IsRunning/CancelPendingStartup/GetRunningTitle/GetGameCodeForPath/GetRegionForPath/x --- src/core/gpu.cpp | 1 - src/core/host_interface.cpp | 2 +- src/core/system.cpp | 63 +++----------------- src/core/system.h | 10 +--- src/core/timing_event.h | 3 +- src/libretro/libretro_d3d11_host_display.cpp | 1 - src/libretro/libretro_host_interface.cpp | 9 +-- 7 files changed, 14 insertions(+), 75 deletions(-) diff --git a/src/core/gpu.cpp b/src/core/gpu.cpp index d93d6110..89ef1274 100644 --- a/src/core/gpu.cpp +++ b/src/core/gpu.cpp @@ -1062,7 +1062,6 @@ void GPU::WriteGP1(u32 value) { const u32 new_value = param & CRTCState::Regs::DISPLAY_ADDRESS_START_MASK; - System::IncrementInternalFrameNumber(); if (m_crtc_state.regs.display_address_start != new_value) { SynchronizeCRTC(); diff --git a/src/core/host_interface.cpp b/src/core/host_interface.cpp index 78bd4b9f..f293a0c2 100644 --- a/src/core/host_interface.cpp +++ b/src/core/host_interface.cpp @@ -745,7 +745,7 @@ void HostInterface::RecreateSystem() Assert(!System::IsShutdown()); std::unique_ptr stream = ByteStream_CreateGrowableMemoryStream(nullptr, 8 * 1024); - if (!System::SaveState(stream.get(), 0) || !stream->SeekAbsolute(0)) + if (!System::SaveState(stream.get()) || !stream->SeekAbsolute(0)) { ReportError("Failed to save state before system recreation. Shutting down."); DestroySystem(); diff --git a/src/core/system.cpp b/src/core/system.cpp index 16cf76bd..82176583 100644 --- a/src/core/system.cpp +++ b/src/core/system.cpp @@ -97,7 +97,7 @@ static ConsoleRegion s_region = ConsoleRegion::NTSC_U; TickCount g_ticks_per_second = MASTER_CLOCK; static TickCount s_max_slice_ticks = MASTER_CLOCK / 10; static u32 s_frame_number = 1; -static u32 s_internal_frame_number = 1; +static u32 s_internal_frame_number = 0; static std::string s_running_game_path; static std::string s_running_game_code; @@ -142,11 +142,6 @@ void SetState(State new_state) CPU::ForceDispatcherExit(); } -bool IsRunning() -{ - return s_state == State::Running; -} - bool IsPaused() { return s_state == State::Paused; @@ -167,12 +162,6 @@ bool IsStartupCancelled() return s_startup_cancelled.load(); } -void CancelPendingStartup() -{ - if (s_state == State::Starting) - s_startup_cancelled.store(true); -} - ConsoleRegion GetRegion() { return s_region; @@ -210,21 +199,11 @@ void FrameDone() CPU::g_state.downcount = 0; } -void IncrementInternalFrameNumber() -{ - s_internal_frame_number++; -} - const std::string& GetRunningCode() { return s_running_game_code; } -const std::string& GetRunningTitle() -{ - return s_running_game_title; -} - float GetThrottleFrequency() { return s_throttle_frequency; @@ -252,24 +231,16 @@ ConsoleRegion GetConsoleRegionForDiscRegion(DiscRegion region) { case DiscRegion::NTSC_J: return ConsoleRegion::NTSC_J; - + case DiscRegion::PAL: + return ConsoleRegion::PAL; case DiscRegion::NTSC_U: case DiscRegion::Other: default: - return ConsoleRegion::NTSC_U; + break; - case DiscRegion::PAL: - return ConsoleRegion::PAL; } -} -std::string GetGameCodeForPath(const char* image_path, bool fallback_to_hash) -{ - std::unique_ptr cdi = CDImage::Open(image_path, CDImage::OpenFlags::None, nullptr); - if (!cdi) - return {}; - - return GetGameCodeForImage(cdi.get(), fallback_to_hash); + return ConsoleRegion::NTSC_U; } std::string GetGameCodeForImage(CDImage* cdi, bool fallback_to_hash) @@ -324,8 +295,6 @@ std::string GetGameHashCodeForImage(CDImage* cdi) XXH64_update(state, &track_1_length, sizeof(track_1_length)); const u64 hash = XXH64_digest(state); XXH64_freeState(state); - - Log_InfoPrintf("Hash for '%s' - %" PRIX64, exe_name.c_str(), hash); return StringUtil::StdStringFromFormat("HASH-%" PRIX64, hash); } @@ -544,20 +513,6 @@ DiscRegion GetRegionForPsf(const char* path) return psf.GetRegion(); } -std::optional GetRegionForPath(const char* image_path) -{ - if (IsExeFileName(image_path)) - return GetRegionForExe(image_path); - else if (IsPsfFileName(image_path)) - return GetRegionForPsf(image_path); - - std::unique_ptr cdi = CDImage::Open(image_path, CDImage::OpenFlags::None, nullptr); - if (!cdi) - return {}; - - return GetRegionForImage(cdi.get()); -} - bool RecreateGPU(GPURenderer renderer, bool update_display /* = true*/) { ClearMemorySaveStates(); @@ -816,7 +771,6 @@ bool Initialize(bool force_software_renderer) g_ticks_per_second = ScaleTicksToOverclock(MASTER_CLOCK); s_max_slice_ticks = ScaleTicksToOverclock(MASTER_CLOCK / 10); s_frame_number = 1; - s_internal_frame_number = 1; s_throttle_frequency = 60.0f; @@ -1096,18 +1050,17 @@ void Reset() g_mdec.Reset(); g_sio.Reset(); s_frame_number = 1; - s_internal_frame_number = 0; TimingEvents::Reset(); g_gpu->ResetGraphicsAPIState(); } -bool LoadState(ByteStream* state, bool update_display) +bool LoadState(ByteStream* state) { if (IsShutdown()) return false; - return DoLoadState(state, false, update_display); + return DoLoadState(state, false, false); } bool DoLoadState(ByteStream* state, bool force_software_renderer, bool update_display) @@ -1249,7 +1202,7 @@ bool DoLoadState(ByteStream* state, bool force_software_renderer, bool update_di return true; } -bool SaveState(ByteStream* state, u32 screenshot_size /* = 256 */) +bool SaveState(ByteStream* state) { if (IsShutdown()) return false; diff --git a/src/core/system.h b/src/core/system.h index a078c759..8d73d1e5 100644 --- a/src/core/system.h +++ b/src/core/system.h @@ -64,23 +64,19 @@ bool ReadExecutableFromImage(CDImage* cdi, std::string* out_executable_name, std std::string GetGameHashCodeForImage(CDImage* cdi); std::string GetGameCodeForImage(CDImage* cdi, bool fallback_to_hash); -std::string GetGameCodeForPath(const char* image_path, bool fallback_to_hash); DiscRegion GetRegionForCode(std::string_view code); DiscRegion GetRegionFromSystemArea(CDImage* cdi); DiscRegion GetRegionForImage(CDImage* cdi); DiscRegion GetRegionForExe(const char* path); DiscRegion GetRegionForPsf(const char* path); -std::optional GetRegionForPath(const char* image_path); State GetState(); void SetState(State new_state); -bool IsRunning(); bool IsPaused(); bool IsShutdown(); bool IsValid(); bool IsStartupCancelled(); -void CancelPendingStartup(); ConsoleRegion GetRegion(); bool IsPALRegion(); @@ -120,18 +116,16 @@ bool InjectEXEFromBuffer(const void* buffer, u32 buffer_size, bool patch_loader u32 GetFrameNumber(); void FrameDone(); -void IncrementInternalFrameNumber(); const std::string& GetRunningCode(); -const std::string& GetRunningTitle(); float GetThrottleFrequency(); bool Boot(const SystemBootParameters& params); void Reset(); void Shutdown(); -bool LoadState(ByteStream* state, bool update_display = true); -bool SaveState(ByteStream* state, u32 screenshot_size = 256); +bool LoadState(ByteStream* state); +bool SaveState(ByteStream* state); /// Recreates the GPU component, saving/loading the state so it is preserved. Call when the GPU renderer changes. bool RecreateGPU(GPURenderer renderer, bool update_display = true); diff --git a/src/core/timing_event.h b/src/core/timing_event.h index 3988c7fd..eedb0703 100644 --- a/src/core/timing_event.h +++ b/src/core/timing_event.h @@ -22,7 +22,6 @@ public: ALWAYS_INLINE bool IsActive() const { return m_active; } // Returns the number of ticks between each event. - ALWAYS_INLINE TickCount GetPeriod() const { return m_period; } ALWAYS_INLINE TickCount GetInterval() const { return m_interval; } ALWAYS_INLINE TickCount GetDowncount() const { return m_downcount; } @@ -96,4 +95,4 @@ void UpdateCPUDowncount(); TimingEvent** GetHeadEventPtr(); -} // namespace TimingEvents \ No newline at end of file +} // namespace TimingEvents diff --git a/src/libretro/libretro_d3d11_host_display.cpp b/src/libretro/libretro_d3d11_host_display.cpp index c13d7f6d..f3bbb4ad 100644 --- a/src/libretro/libretro_d3d11_host_display.cpp +++ b/src/libretro/libretro_d3d11_host_display.cpp @@ -38,7 +38,6 @@ public: ALWAYS_INLINE ID3D11Texture2D* GetD3DTexture() const { return m_texture.GetD3DTexture(); } ALWAYS_INLINE ID3D11ShaderResourceView* GetD3DSRV() const { return m_texture.GetD3DSRV(); } ALWAYS_INLINE ID3D11ShaderResourceView* const* GetD3DSRVArray() const { return m_texture.GetD3DSRVArray(); } - ALWAYS_INLINE bool IsDynamic() const { return m_dynamic; } private: D3D11::Texture m_texture; diff --git a/src/libretro/libretro_host_interface.cpp b/src/libretro/libretro_host_interface.cpp index 05f7782a..16097061 100644 --- a/src/libretro/libretro_host_interface.cpp +++ b/src/libretro/libretro_host_interface.cpp @@ -576,17 +576,13 @@ size_t LibretroHostInterface::retro_serialize_size() bool LibretroHostInterface::retro_serialize(void* data, size_t size) { std::unique_ptr stream = ByteStream_CreateMemoryStream(data, static_cast(size)); - if (!System::SaveState(stream.get(), 0)) - return false; - return true; + return System::SaveState(stream.get()); } bool LibretroHostInterface::retro_unserialize(const void* data, size_t size) { std::unique_ptr stream = ByteStream_CreateReadOnlyMemoryStream(data, static_cast(size)); - if (!System::LoadState(stream.get(), false)) - return false; - return true; + return System::LoadState(stream.get()); } void* LibretroHostInterface::retro_get_memory_data(unsigned id) @@ -1021,7 +1017,6 @@ void LibretroHostInterface::CheckForSettingsChanges(const Settings& old_settings void LibretroHostInterface::OnRunningGameChanged(const std::string& path, CDImage* image, const std::string& game_code, const std::string& game_title) { - Log_InfoPrintf("Running game changed: %s (%s)", System::GetRunningCode().c_str(), System::GetRunningTitle().c_str()); if (UpdateGameSettings()) UpdateSettings(); }