Merge pull request #5514 from JosJuice/updaterunninggamemetadata-optional

Use std::optional for UpdateRunningGameMetadata
This commit is contained in:
Leo Lam 2017-06-03 17:14:39 +02:00 committed by GitHub
commit 0ff8e2b36f
4 changed files with 25 additions and 42 deletions

View File

@ -5,6 +5,7 @@
#include <algorithm>
#include <cinttypes>
#include <memory>
#include <optional>
#include <string>
#include "AudioCommon/AudioCommon.h"
@ -506,7 +507,7 @@ void SetLidOpen()
GenerateDIInterrupt(INT_CVRINT);
}
bool UpdateRunningGameMetadata(u64 title_id)
bool UpdateRunningGameMetadata(std::optional<u64> title_id)
{
if (!DVDThread::HasDisc())
return false;
@ -518,18 +519,6 @@ bool UpdateRunningGameMetadata(u64 title_id)
return DVDThread::UpdateRunningGameMetadata(partition, title_id);
}
bool UpdateRunningGameMetadata()
{
if (!DVDThread::HasDisc())
return false;
const DiscIO::Partition& partition = DVDThread::GetDiscType() == DiscIO::Platform::WII_DISC ?
s_current_partition :
DiscIO::PARTITION_NONE;
return DVDThread::UpdateRunningGameMetadata(partition);
}
void ChangePartition(const DiscIO::Partition& partition)
{
s_current_partition = partition;

View File

@ -4,6 +4,7 @@
#pragma once
#include <optional>
#include <string>
#include <vector>
@ -114,12 +115,11 @@ bool IsDiscInside();
void ChangeDiscAsHost(const std::string& new_path); // Can only be called by the host thread
void ChangeDiscAsCPU(const std::string& new_path); // Can only be called by the CPU thread
// If a disc is inserted and its title ID is equal to the title_id argument, returns true and
// calls SConfig::SetRunningGameMetadata(IVolume&, Partition&). Otherwise, returns false.
bool UpdateRunningGameMetadata(u64 title_id);
// If a disc is inserted, returns true and calls
// SConfig::SetRunningGameMetadata(IVolume&, Partition&). Otherwise, returns false.
bool UpdateRunningGameMetadata();
// This function returns true and calls SConfig::SetRunningGameMetadata(IVolume&, Partition&)
// if both of the following conditions are true:
// - A disc is inserted
// - The title_id argument doesn't contain a value, or its value matches the disc's title ID
bool UpdateRunningGameMetadata(std::optional<u64> title_id = {});
// Direct access to DI for IOS HLE (simpler to implement than how real IOS accesses DI,
// and lets us skip encrypting/decrypting in some cases)

View File

@ -6,6 +6,7 @@
#include <map>
#include <memory>
#include <mutex>
#include <optional>
#include <thread>
#include <utility>
#include <vector>
@ -209,30 +210,22 @@ IOS::ES::TicketReader GetTicket(const DiscIO::Partition& partition)
return s_disc->GetTicket(partition);
}
bool UpdateRunningGameMetadata(const DiscIO::Partition& partition, u64 title_id)
bool UpdateRunningGameMetadata(const DiscIO::Partition& partition, std::optional<u64> title_id)
{
if (!s_disc)
return false;
WaitUntilIdle();
u64 volume_title_id;
if (!s_disc->GetTitleID(&volume_title_id, partition))
return false;
if (title_id)
{
u64 volume_title_id;
if (!s_disc->GetTitleID(&volume_title_id, partition))
return false;
if (volume_title_id != title_id)
return false;
SConfig::GetInstance().SetRunningGameMetadata(*s_disc, partition);
return true;
}
bool UpdateRunningGameMetadata(const DiscIO::Partition& partition)
{
if (!s_disc)
return false;
DVDThread::WaitUntilIdle();
if (volume_title_id != *title_id)
return false;
}
SConfig::GetInstance().SetRunningGameMetadata(*s_disc, partition);
return true;

View File

@ -5,6 +5,7 @@
#pragma once
#include <memory>
#include <optional>
#include <vector>
#include "Common/CommonTypes.h"
@ -44,12 +45,12 @@ bool HasDisc();
DiscIO::Platform GetDiscType();
IOS::ES::TMDReader GetTMD(const DiscIO::Partition& partition);
IOS::ES::TicketReader GetTicket(const DiscIO::Partition& partition);
// If a disc is inserted and its title ID is equal to the title_id argument, returns true and
// calls SConfig::SetRunningGameMetadata(IVolume&, Partition&). Otherwise, returns false.
bool UpdateRunningGameMetadata(const DiscIO::Partition& partition, u64 title_id);
// If a disc is inserted, returns true and calls
// SConfig::SetRunningGameMetadata(IVolume&, Partition&). Otherwise, returns false.
bool UpdateRunningGameMetadata(const DiscIO::Partition& partition);
// This function returns true and calls SConfig::SetRunningGameMetadata(IVolume&, Partition&)
// if both of the following conditions are true:
// - A disc is inserted
// - The title_id argument doesn't contain a value, or its value matches the disc's title ID
bool UpdateRunningGameMetadata(const DiscIO::Partition& partition,
std::optional<u64> title_id = {});
void StartRead(u64 dvd_offset, u32 length, const DiscIO::Partition& partition,
DVDInterface::ReplyType reply_type, s64 ticks_until_completion);