Reload of recompiled data

This commit is contained in:
Xiao Qi 2023-02-23 13:49:21 +08:00
parent a391d9373e
commit 5d3e755b9b
2 changed files with 23 additions and 11 deletions

View File

@ -41,7 +41,7 @@ namespace SHADE
std::vector<SHAssetLoader*> SHAssetManager::loaders(TYPE_COUNT); std::vector<SHAssetLoader*> SHAssetManager::loaders(TYPE_COUNT);
std::unordered_map<AssetID, SHAsset> SHAssetManager::assetCollection; std::unordered_map<AssetID, SHAsset> SHAssetManager::assetCollection;
std::unordered_map<AssetID, SHAssetData * const> SHAssetManager::assetData; std::unordered_map<AssetID, SHAssetData *> SHAssetManager::assetData;
/**************************************************************************** /****************************************************************************
@ -460,6 +460,22 @@ namespace SHADE
else else
{ {
target = GetAssetIDFromPath(path); target = GetAssetIDFromPath(path);
//Reload data
auto result = GetAsset(target);
if (result.has_value())
{
auto const& asset{ result.value() };
auto newData = loaders[static_cast<size_t>(asset.type)]->Load(asset.path);
delete assetData[target];
assetData[target] = newData;
}
else
{
SHLOG_ERROR("[Asset Manager] Critical: reload of existing compiled data failed");
}
}
// send compile asset event // send compile asset event
SHCompileAssetEvent compileShaderEvent SHCompileAssetEvent compileShaderEvent
{ {
@ -470,10 +486,6 @@ namespace SHADE
SHEventManager::BroadcastEvent<SHCompileAssetEvent>(compileShaderEvent, SH_ASSET_COMPILE_EVENT); SHEventManager::BroadcastEvent<SHCompileAssetEvent>(compileShaderEvent, SH_ASSET_COMPILE_EVENT);
} }
//TODO SEND EVENT HERE
}
FolderPointer SHAssetManager::GetRootFolder() noexcept FolderPointer SHAssetManager::GetRootFolder() noexcept
{ {
return folderRoot; return folderRoot;

View File

@ -123,7 +123,7 @@ namespace SHADE
// For all resources // For all resources
static std::unordered_map<AssetID, SHAsset> assetCollection; static std::unordered_map<AssetID, SHAsset> assetCollection;
static std::unordered_map<AssetID, SHAssetData * const> assetData; static std::unordered_map<AssetID, SHAssetData *> assetData;
}; };
} }