Added full support for runtime editing of material properties #215
|
@ -143,6 +143,16 @@ namespace SHADE
|
|||
return result;
|
||||
}
|
||||
|
||||
std::optional<SHADE::SHAsset> SHAssetManager::GetAsset(AssetID id) noexcept
|
||||
{
|
||||
if (assetCollection.contains(id))
|
||||
{
|
||||
return assetCollection[id];
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* \brief Create record for new asset. CAN ONLY CREATE FOR CUSTOM
|
||||
* ASSETS CREATED BY THE ENGINE.
|
||||
|
|
|
@ -50,6 +50,7 @@ namespace SHADE
|
|||
* \return const& to unordered_map<AssetName, AssetID>
|
||||
****************************************************************************/
|
||||
static std::vector<SHAsset> GetAllAssets() noexcept;
|
||||
static std::optional<SHAsset> GetAsset(AssetID id) noexcept;
|
||||
|
||||
/****************************************************************************
|
||||
* \brief Create record for new resource. CAN ONLY CREATE FOR CUSTOM
|
||||
|
|
|
@ -103,4 +103,17 @@ namespace SHADE
|
|||
|
||||
return {};
|
||||
}
|
||||
|
||||
std::optional<std::string> SHResourceManager::GetAssetName(Handle<void> handle)
|
||||
{
|
||||
const Handle GENERIC_HANDLE = Handle(handle);
|
||||
auto assetId = GetAssetID(GENERIC_HANDLE);
|
||||
if (assetId.has_value())
|
||||
{
|
||||
const auto ASSET_INFO = SHAssetManager::GetAsset(assetId.value());
|
||||
if (ASSET_INFO.has_value())
|
||||
return ASSET_INFO.value().name;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,9 +64,7 @@ namespace SHADE
|
|||
/// Note that for specific types, the retrieved Handle may not be valid until after
|
||||
/// FinaliseChanges() is called.
|
||||
/// </summary>
|
||||
/// <typeparam name="ResourceType">
|
||||
/// Type of resource to load.
|
||||
/// </typeparam>
|
||||
/// <typeparam name="ResourceType">Type of resource to load.</typeparam>
|
||||
/// <param name="assetId">Asset ID of the resource to load.</param>
|
||||
/// <returns>Handle to a loaded runtime asset.</returns>
|
||||
template<typename ResourceType>
|
||||
|
@ -74,6 +72,17 @@ namespace SHADE
|
|||
template<>
|
||||
static inline Handle<SHMaterial> LoadOrGet<SHMaterial>(AssetID assetId);
|
||||
/// <summary>
|
||||
/// Retrieves an existing loaded object of the specified type if it has already been
|
||||
/// loaded prior.
|
||||
/// </summary>
|
||||
/// <typeparam name="ResourceType">Type of resource to load.</typeparam>
|
||||
/// <param name="assetId">Asset ID of the resource to retrieve.</param>
|
||||
/// <returns>
|
||||
/// Handle to a loaded runtime asset. Null handle if not loaded before.
|
||||
/// </returns>
|
||||
template<typename ResourceType>
|
||||
static Handle<ResourceType> Get(AssetID assetId);
|
||||
/// <summary>
|
||||
/// Unloads an existing loaded asset. Attempting to unload an invalid Handle will
|
||||
/// simply do nothing except emit a warning.
|
||||
/// Faster than the untemplated version.
|
||||
|
@ -121,6 +130,31 @@ namespace SHADE
|
|||
/// value.
|
||||
/// </return>
|
||||
static std::optional<AssetID> GetAssetID(Handle<void> handle);
|
||||
/// <summary>
|
||||
/// Retrieves the name associated with the AssetID that is associated with the
|
||||
/// specified Handle.
|
||||
/// Faster than the untemplated version.
|
||||
/// </summary>
|
||||
/// <typeparam name="ResourceType">Type of resource to get the name of.</typeparam>
|
||||
/// <param name="handle">Handle to get the name of.</param>
|
||||
/// <return>
|
||||
/// Name for the specified Handle. If the Handle is invalid, there will be no
|
||||
/// value.
|
||||
/// </return>
|
||||
template<typename T>
|
||||
static std::optional<std::string> GetAssetName(Handle<T> handle);
|
||||
/// <summary>
|
||||
/// Retrieves the name associated with the AssetID that is associated with the
|
||||
/// specified Handle.
|
||||
/// Compared to the templated version, this function is slower as it requires
|
||||
/// searching through the storage of all resource types.
|
||||
/// </summary>
|
||||
/// <param name="handle">Handle to get the name of.</param>
|
||||
/// <return>
|
||||
/// Name for the specified Handle. If the Handle is invalid, there will be no
|
||||
/// value.
|
||||
/// </return>
|
||||
static std::optional<std::string> GetAssetName(Handle<void> handle);
|
||||
|
||||
private:
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
|
|
@ -93,6 +93,16 @@ namespace SHADE
|
|||
return handle;
|
||||
}
|
||||
|
||||
template<typename ResourceType>
|
||||
Handle<ResourceType> SHResourceManager::Get(AssetID assetId)
|
||||
{
|
||||
auto [typedHandleMap, typedAssetIdMap] = getAssetHandleMap<ResourceType>();
|
||||
if (typedHandleMap.get().contains(assetId))
|
||||
return Handle<ResourceType>(typedHandleMap.get()[assetId]);
|
||||
else
|
||||
return Handle<ResourceType>();
|
||||
}
|
||||
|
||||
template<typename ResourceType>
|
||||
void SHResourceManager::Unload(Handle<ResourceType> asset)
|
||||
{
|
||||
|
@ -139,6 +149,18 @@ namespace SHADE
|
|||
|
||||
return {};
|
||||
}
|
||||
template<typename T>
|
||||
std::optional<std::string> SHADE::SHResourceManager::GetAssetName(Handle<T> handle)
|
||||
{
|
||||
auto assetId = GetAssetID<T>(handle);
|
||||
if (assetId.has_value())
|
||||
{
|
||||
const auto ASSET_INFO = SHAssetManager::GetAsset(assetId.value());
|
||||
if (ASSET_INFO.has_value())
|
||||
return ASSET_INFO.value().name;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Helper Functions */
|
||||
|
|
Loading…
Reference in New Issue