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