summaryrefslogtreecommitdiff
path: root/Source/Core/VideoCommon/Assets/CustomAsset.cpp
diff options
context:
space:
mode:
authorJMC47 <JMC4789@gmail.com>2025-06-07 15:51:34 -0400
committerGitHub <noreply@github.com>2025-06-07 15:51:34 -0400
commit52fcdde4852ccab197092da37b00548e33844d85 (patch)
tree02b438f5d1fa1c127f73bdb0a0f12c2678965435 /Source/Core/VideoCommon/Assets/CustomAsset.cpp
parent5eb61024c6e94b949ce21eac81003b43587fc155 (diff)
parentc3d3b8153388866117334cdc719889d1f676a16e (diff)
Merge pull request #13386 from iwubcode/resource_manager_system
VideoCommon: add resource manager, tracks resources to load assets in optimal way and manage memory
Diffstat (limited to 'Source/Core/VideoCommon/Assets/CustomAsset.cpp')
-rw-r--r--Source/Core/VideoCommon/Assets/CustomAsset.cpp42
1 files changed, 25 insertions, 17 deletions
diff --git a/Source/Core/VideoCommon/Assets/CustomAsset.cpp b/Source/Core/VideoCommon/Assets/CustomAsset.cpp
index 1591f93f91..7e2e817d15 100644
--- a/Source/Core/VideoCommon/Assets/CustomAsset.cpp
+++ b/Source/Core/VideoCommon/Assets/CustomAsset.cpp
@@ -3,46 +3,54 @@
#include "VideoCommon/Assets/CustomAsset.h"
+#include <utility>
+
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)
{
}
-bool CustomAsset::Load()
+std::size_t CustomAsset::Load()
{
+ std::lock_guard lk(m_info_lock);
+ // The load time needs to come from before the data is actually read.
+ // Using a time point from after the read marks the asset as more up-to-date than it actually is,
+ // and has potential to race (and not be updated) if a change happens immediately after load.
+ const auto load_time = ClockType::now();
+
const auto load_information = LoadImpl(m_asset_id);
- if (load_information.m_bytes_loaded > 0)
+ if (load_information.bytes_loaded > 0)
{
- std::lock_guard lk(m_info_lock);
- m_bytes_loaded = load_information.m_bytes_loaded;
- m_last_loaded_time = load_information.m_load_time;
+ m_bytes_loaded = load_information.bytes_loaded;
+ m_last_loaded_time = load_time;
+ return m_bytes_loaded;
}
- return load_information.m_bytes_loaded != 0;
+ return 0;
}
-CustomAssetLibrary::TimeType CustomAsset::GetLastWriteTime() const
+std::size_t CustomAsset::Unload()
{
- return m_owning_library->GetLastAssetWriteTime(m_asset_id);
+ std::lock_guard lk(m_info_lock);
+ UnloadImpl();
+ return std::exchange(m_bytes_loaded, 0);
}
-const CustomAssetLibrary::TimeType& CustomAsset::GetLastLoadedTime() const
+CustomAsset::TimeType CustomAsset::GetLastLoadedTime() const
{
- std::lock_guard lk(m_info_lock);
return m_last_loaded_time;
}
-const CustomAssetLibrary::AssetID& CustomAsset::GetAssetId() const
+std::size_t CustomAsset::GetHandle() const
{
- return m_asset_id;
+ return m_handle;
}
-std::size_t CustomAsset::GetByteSizeInMemory() const
+const CustomAssetLibrary::AssetID& CustomAsset::GetAssetId() const
{
- std::lock_guard lk(m_info_lock);
- return m_bytes_loaded;
+ return m_asset_id;
}
} // namespace VideoCommon