mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2025-01-17 22:25:37 +00:00
System: Update running game when media changes from save state
This commit is contained in:
parent
f2d5ce74df
commit
0a5f7fcd75
|
@ -120,8 +120,6 @@ bool CDROM::DoState(StateWrapper& sw)
|
|||
sw.Do(&m_sector_buffer);
|
||||
|
||||
u32 media_lba = m_media ? m_media->GetPositionOnDisc() : 0;
|
||||
std::string media_filename = m_media ? m_media->GetFileName() : std::string();
|
||||
sw.Do(&media_filename);
|
||||
sw.Do(&media_lba);
|
||||
|
||||
if (sw.IsReading())
|
||||
|
@ -132,21 +130,24 @@ bool CDROM::DoState(StateWrapper& sw)
|
|||
m_system->SetDowncount(m_drive_remaining_ticks);
|
||||
|
||||
// load up media if we had something in there before
|
||||
m_media.reset();
|
||||
if (!media_filename.empty())
|
||||
if (m_media && !m_media->Seek(media_lba))
|
||||
{
|
||||
m_media = CDImage::Open(media_filename.c_str());
|
||||
if (!m_media || !m_media->Seek(media_lba))
|
||||
{
|
||||
Log_ErrorPrintf("Failed to re-insert CD media from save state: '%s'. Ejecting.", media_filename.c_str());
|
||||
Log_ErrorPrint("Failed to seek CD media from save state. Ejecting.");
|
||||
RemoveMedia();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return !sw.HasError();
|
||||
}
|
||||
|
||||
std::string CDROM::GetMediaFileName() const
|
||||
{
|
||||
if (!m_media)
|
||||
return std::string();
|
||||
|
||||
return m_media->GetFileName();
|
||||
}
|
||||
|
||||
void CDROM::InsertMedia(std::unique_ptr<CDImage> media)
|
||||
{
|
||||
if (HasMedia())
|
||||
|
|
|
@ -27,6 +27,7 @@ public:
|
|||
bool DoState(StateWrapper& sw);
|
||||
|
||||
bool HasMedia() const { return static_cast<bool>(m_media); }
|
||||
std::string GetMediaFileName() const;
|
||||
void InsertMedia(std::unique_ptr<CDImage> media);
|
||||
void RemoveMedia();
|
||||
|
||||
|
|
|
@ -497,7 +497,7 @@ void HostInterface::ResetPerformanceCounters()
|
|||
|
||||
void HostInterface::UpdateRunningGame(const char* path, CDImage* image)
|
||||
{
|
||||
if (!path)
|
||||
if (!path || std::strlen(path) == 0)
|
||||
{
|
||||
OnRunningGameChanged("", "", "");
|
||||
return;
|
||||
|
|
|
@ -238,6 +238,26 @@ bool System::DoState(StateWrapper& sw)
|
|||
sw.Do(&m_internal_frame_number);
|
||||
sw.Do(&m_global_tick_counter);
|
||||
|
||||
std::string media_filename = m_cdrom->GetMediaFileName();
|
||||
sw.Do(&media_filename);
|
||||
|
||||
if (sw.IsReading())
|
||||
{
|
||||
std::unique_ptr<CDImage> media;
|
||||
if (!media_filename.empty())
|
||||
{
|
||||
media = CDImage::Open(media_filename.c_str());
|
||||
if (!media)
|
||||
Log_ErrorPrintf("Failed to open CD image from save state: '%s'", media_filename.c_str());
|
||||
}
|
||||
|
||||
m_host_interface->UpdateRunningGame(media_filename.c_str(), media.get());
|
||||
if (media)
|
||||
m_cdrom->InsertMedia(std::move(media));
|
||||
else
|
||||
m_cdrom->RemoveMedia();
|
||||
}
|
||||
|
||||
if (!sw.DoMarker("CPU") || !m_cpu->DoState(sw))
|
||||
return false;
|
||||
|
||||
|
|
Loading…
Reference in a new issue