mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2024-11-25 23:25:41 +00:00
CDImageCHD: Implement precaching
This commit is contained in:
parent
9ab64ecdb3
commit
5d097da160
|
@ -15,6 +15,7 @@
|
||||||
#include <cerrno>
|
#include <cerrno>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <limits>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
Log_SetChannel(CDImageCHD);
|
Log_SetChannel(CDImageCHD);
|
||||||
|
@ -51,6 +52,7 @@ public:
|
||||||
|
|
||||||
bool ReadSubChannelQ(SubChannelQ* subq, const Index& index, LBA lba_in_index) override;
|
bool ReadSubChannelQ(SubChannelQ* subq, const Index& index, LBA lba_in_index) override;
|
||||||
bool HasNonStandardSubchannel() const override;
|
bool HasNonStandardSubchannel() const override;
|
||||||
|
PrecacheResult Precache(ProgressCallback* progress) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool ReadSectorFromIndex(void* buffer, const Index& index, LBA lba_in_index) override;
|
bool ReadSectorFromIndex(void* buffer, const Index& index, LBA lba_in_index) override;
|
||||||
|
@ -299,6 +301,20 @@ bool CDImageCHD::HasNonStandardSubchannel() const
|
||||||
return (m_sbi.GetReplacementSectorCount() > 0);
|
return (m_sbi.GetReplacementSectorCount() > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CDImage::PrecacheResult CDImageCHD::Precache(ProgressCallback* progress)
|
||||||
|
{
|
||||||
|
const std::string_view title(FileSystem::GetFileNameFromPath(m_filename));
|
||||||
|
progress->SetFormattedStatusText("Precaching %.*s...", static_cast<int>(title.size()), title.data());
|
||||||
|
progress->SetProgressRange(100);
|
||||||
|
|
||||||
|
auto callback = [](size_t pos, size_t total, void* param) {
|
||||||
|
const u32 percent = static_cast<u32>((pos * 100) / total);
|
||||||
|
static_cast<ProgressCallback*>(param)->SetProgressValue(std::min<u32>(percent, 100));
|
||||||
|
};
|
||||||
|
return (chd_precache_progress(m_chd, callback, progress) == CHDERR_NONE) ? CDImage::PrecacheResult::Success :
|
||||||
|
CDImage::PrecacheResult::ReadError;
|
||||||
|
}
|
||||||
|
|
||||||
// There's probably a more efficient way of doing this with vectorization...
|
// There's probably a more efficient way of doing this with vectorization...
|
||||||
ALWAYS_INLINE static void CopyAndSwap(void* dst_ptr, const u8* src_ptr, u32 data_size)
|
ALWAYS_INLINE static void CopyAndSwap(void* dst_ptr, const u8* src_ptr, u32 data_size)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue