2023-06-01 19:57:57 -05:00
|
|
|
// Copyright 2023 Dolphin Emulator Project
|
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
|
|
|
|
|
#include "VideoCommon/Assets/CustomAsset.h"
|
|
|
|
|
|
2025-06-06 20:43:31 -05:00
|
|
|
#include <utility>
|
|
|
|
|
|
2023-06-01 19:57:57 -05:00
|
|
|
namespace VideoCommon
|
|
|
|
|
{
|
|
|
|
|
CustomAsset::CustomAsset(std::shared_ptr<CustomAssetLibrary> library,
|
2025-03-01 22:16:09 -06:00
|
|
|
const CustomAssetLibrary::AssetID& asset_id, u64 asset_handle)
|
|
|
|
|
: m_owning_library(std::move(library)), m_asset_id(asset_id), m_handle(asset_handle)
|
2023-06-01 19:57:57 -05:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-06 20:34:44 -05:00
|
|
|
std::size_t CustomAsset::Load()
|
2023-06-01 19:57:57 -05:00
|
|
|
{
|
2025-06-06 19:55:03 -05:00
|
|
|
std::lock_guard lk(m_info_lock);
|
2025-05-23 23:27:11 -05:00
|
|
|
// 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();
|
|
|
|
|
|
2023-06-01 19:57:57 -05:00
|
|
|
const auto load_information = LoadImpl(m_asset_id);
|
2025-06-06 19:24:12 -05:00
|
|
|
if (load_information.bytes_loaded > 0)
|
2023-06-01 19:57:57 -05:00
|
|
|
{
|
2025-06-06 19:24:12 -05:00
|
|
|
m_bytes_loaded = load_information.bytes_loaded;
|
2025-05-23 23:27:11 -05:00
|
|
|
m_last_loaded_time = load_time;
|
2025-06-06 20:34:44 -05:00
|
|
|
return m_bytes_loaded;
|
2023-06-01 19:57:57 -05:00
|
|
|
}
|
2025-06-06 20:34:44 -05:00
|
|
|
return 0;
|
2023-06-01 19:57:57 -05:00
|
|
|
}
|
|
|
|
|
|
2025-05-04 12:14:18 -05:00
|
|
|
std::size_t CustomAsset::Unload()
|
|
|
|
|
{
|
2025-06-06 19:55:03 -05:00
|
|
|
std::lock_guard lk(m_info_lock);
|
2025-05-04 12:14:18 -05:00
|
|
|
UnloadImpl();
|
2025-06-06 20:43:31 -05:00
|
|
|
return std::exchange(m_bytes_loaded, 0);
|
2025-05-04 12:14:18 -05:00
|
|
|
}
|
|
|
|
|
|
2025-06-06 19:55:03 -05:00
|
|
|
CustomAsset::TimeType CustomAsset::GetLastLoadedTime() const
|
2023-06-01 19:57:57 -05:00
|
|
|
{
|
|
|
|
|
return m_last_loaded_time;
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-01 22:16:09 -06:00
|
|
|
std::size_t CustomAsset::GetHandle() const
|
|
|
|
|
{
|
|
|
|
|
return m_handle;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-01 19:57:57 -05:00
|
|
|
const CustomAssetLibrary::AssetID& CustomAsset::GetAssetId() const
|
|
|
|
|
{
|
|
|
|
|
return m_asset_id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace VideoCommon
|