Merge branch 'main' into PlayerController

This commit is contained in:
Glence 2023-03-10 17:22:05 +08:00
commit b9cfcdb11d
4 changed files with 37 additions and 18 deletions

View File

@ -31,6 +31,6 @@ namespace SHADE
struct SH_API SHAnimClipContainerAsset final : SHAssetData struct SH_API SHAnimClipContainerAsset final : SHAssetData
{ {
AssetID animRawDataAssetId; AssetID animRawDataAssetId;
std::vector<SHAnimClipAsset> clips{}; std::vector<SHAnimClipAsset*> clips{};
}; };
} }

View File

@ -66,19 +66,19 @@ namespace SHADE
for (auto const& clip : anim.clips) for (auto const& clip : anim.clips)
{ {
uint32_t charCount {static_cast<uint32_t>(clip.name.size())}; uint32_t charCount {static_cast<uint32_t>(clip->name.size())};
file.write( file.write(
reinterpret_cast<char const*>(&charCount), reinterpret_cast<char const*>(&charCount),
sizeof(uint32_t) sizeof(uint32_t)
); );
file.write( file.write(
clip.name.data(), clip->name.data(),
charCount charCount
); );
file.write( file.write(
reinterpret_cast<char const*>(&clip.firstIndex), reinterpret_cast<char const*>(&clip->firstIndex),
sizeof(uint32_t) * 2 sizeof(uint32_t) * 2
); );
} }
@ -99,28 +99,29 @@ namespace SHADE
reinterpret_cast<char*>(&size), reinterpret_cast<char*>(&size),
sizeof(uint32_t) sizeof(uint32_t)
); );
data->clips.resize(size);
for (auto i{0}; i < size; ++i) for (auto& clip : data->clips)
{ {
auto& clip {data->clips.emplace_back()}; clip = new SHAnimClipAsset;
uint32_t charCount; uint32_t charCount;
file.read( file.read(
reinterpret_cast<char*>(&charCount), reinterpret_cast<char*>(&charCount),
sizeof(uint32_t) sizeof(uint32_t)
); );
clip.name.resize(charCount); clip->name.resize(charCount);
file.read( file.read(
clip.name.data(), clip->name.data(),
charCount charCount
); );
file.read( file.read(
reinterpret_cast<char*>(&clip.firstIndex), reinterpret_cast<char*>(&clip->firstIndex),
sizeof(uint32_t) * 2 sizeof(uint32_t) * 2
); );
clip.animRawDataAssetId = data->animRawDataAssetId; clip->animRawDataAssetId = data->animRawDataAssetId;
} }
result = data; result = data;

View File

@ -314,10 +314,10 @@ namespace SHADE
.parent = parent .parent = parent
}; };
auto& newClip {animContainer->clips.emplace_back()}; auto& newClip {animContainer->clips.emplace_back()};
newClip.name = name; newClip->name = name;
assetCollection.emplace(id, asset); assetCollection.emplace(id, asset);
assetCollection[parent].subAssets.push_back(&assetCollection[id]); assetCollection[parent].subAssets.push_back(&assetCollection[id]);
assetData.emplace(id, &newClip); assetData.emplace(id, newClip);
return id; return id;
} }
@ -639,6 +639,25 @@ namespace SHADE
assetData.emplace(asset.id, data); assetData.emplace(asset.id, data);
} }
switch (asset.type)
{
case AssetType::ANIM_CONTAINER:
{
auto container = reinterpret_cast<SHAnimClipContainerAsset*>(data);
for (auto i{0}; i < asset.subAssets.size(); ++i)
{
assetData.emplace(
asset.subAssets[i]->id,
container->clips[i]
);
}
}
break;
default:
break;
}
return data; return data;
} }
@ -646,7 +665,6 @@ namespace SHADE
{ {
auto const& parent = assetCollection[asset.parent]; auto const& parent = assetCollection[asset.parent];
auto parentData = loaders[static_cast<size_t>(parent.type)]->Load(parent.path); auto parentData = loaders[static_cast<size_t>(parent.type)]->Load(parent.path);
if (parentData == nullptr) if (parentData == nullptr)
{ {
SHLOG_ERROR("[Asset Manager] Unable to load asset into memory: {}\n", parent.path.string()); SHLOG_ERROR("[Asset Manager] Unable to load asset into memory: {}\n", parent.path.string());
@ -676,7 +694,7 @@ namespace SHADE
{ {
assetData.emplace( assetData.emplace(
parent.subAssets[i]->id, parent.subAssets[i]->id,
&parentContainer->clips[i] parentContainer->clips[i]
); );
} }
} }
@ -859,7 +877,7 @@ namespace SHADE
for(auto& clip : data->clips) for(auto& clip : data->clips)
{ {
SHAsset subAsset{ SHAsset subAsset{
.name = clip.name, .name = clip->name,
.id = GenerateAssetID(AssetType::ANIM_CLIP), .id = GenerateAssetID(AssetType::ANIM_CLIP),
.type = AssetType::ANIM_CLIP, .type = AssetType::ANIM_CLIP,
.isSubAsset = true, .isSubAsset = true,
@ -869,7 +887,7 @@ namespace SHADE
assetCollection.emplace(subAsset.id, subAsset); assetCollection.emplace(subAsset.id, subAsset);
assetCollection[newAsset.id].subAssets.push_back(&assetCollection[subAsset.id]); assetCollection[newAsset.id].subAssets.push_back(&assetCollection[subAsset.id]);
assetData.emplace(subAsset.id, &clip); assetData.emplace(subAsset.id, clip);
} }
SHAssetMetaHandler::WriteMetaData(assetCollection[newAsset.id]); SHAssetMetaHandler::WriteMetaData(assetCollection[newAsset.id]);

View File

@ -194,10 +194,10 @@ namespace SHADE
auto assetId = SHResourceManager::GetAssetID(animClip); auto assetId = SHResourceManager::GetAssetID(animClip);
if (assetId.has_value()) if (assetId.has_value())
{ {
auto animAsset = SHAssetManager::GetData<SHAnimClipAsset>(assetId.value()); auto const animAsset = SHAssetManager::GetData<SHAnimClipAsset>(assetId.value());
animAsset->firstIndex = firstIndex; animAsset->firstIndex = firstIndex;
animAsset->lastIndex = endIndex; animAsset->lastIndex = endIndex;
SHAssetManager::SaveAsset(assetId.value()); SHAssetManager::SaveAsset(containerAsset->id);
} }
} }