VideoCommon: add a handle to custom asset, this is an id that is only relevant for a particular game session but is slightly faster as a numeric value for lookups than the traditional asset id

This commit is contained in:
iwubcode
2025-03-01 22:16:09 -06:00
parent d7de49ccf6
commit 9ec69b5925
2 changed files with 14 additions and 3 deletions

View File

@ -6,8 +6,8 @@
namespace VideoCommon
{
CustomAsset::CustomAsset(std::shared_ptr<CustomAssetLibrary> library,
const CustomAssetLibrary::AssetID& asset_id)
: m_owning_library(std::move(library)), m_asset_id(asset_id)
const CustomAssetLibrary::AssetID& asset_id, u64 asset_handle)
: m_owning_library(std::move(library)), m_asset_id(asset_id), m_handle(asset_handle)
{
}
@ -34,6 +34,11 @@ const CustomAssetLibrary::TimeType& CustomAsset::GetLastLoadedTime() const
return m_last_loaded_time;
}
std::size_t CustomAsset::GetHandle() const
{
return m_handle;
}
const CustomAssetLibrary::AssetID& CustomAsset::GetAssetId() const
{
return m_asset_id;

View File

@ -18,7 +18,7 @@ class CustomAsset
{
public:
CustomAsset(std::shared_ptr<CustomAssetLibrary> library,
const CustomAssetLibrary::AssetID& asset_id);
const CustomAssetLibrary::AssetID& asset_id, u64 session_id);
virtual ~CustomAsset() = default;
CustomAsset(const CustomAsset&) = delete;
CustomAsset(CustomAsset&&) = delete;
@ -39,6 +39,11 @@ public:
// Returns an id that uniquely identifies this asset
const CustomAssetLibrary::AssetID& GetAssetId() const;
// Returns an id that is unique to this game session
// This is a faster form to hash and can be used
// as an index
std::size_t GetHandle() const;
// A rough estimate of how much space this asset
// will take in memroy
std::size_t GetByteSizeInMemory() const;
@ -49,6 +54,7 @@ protected:
private:
virtual CustomAssetLibrary::LoadInfo LoadImpl(const CustomAssetLibrary::AssetID& asset_id) = 0;
CustomAssetLibrary::AssetID m_asset_id;
std::size_t m_handle;
mutable std::mutex m_info_lock;
std::size_t m_bytes_loaded = 0;