-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathAssetCreatorCollection.cpp
More file actions
93 lines (76 loc) · 4.02 KB
/
Copy pathAssetCreatorCollection.cpp
File metadata and controls
93 lines (76 loc) · 4.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include "AssetCreatorCollection.h"
#include <cassert>
AssetCreatorCollection::AssetCreatorCollection(const Zone& zone)
{
m_asset_creators_by_type.resize(zone.m_pools->GetAssetTypeCount());
m_asset_post_processors_by_type.resize(zone.m_pools->GetAssetTypeCount());
m_default_asset_creators_by_type.resize(zone.m_pools->GetAssetTypeCount());
}
void AssetCreatorCollection::AddAssetCreator(std::unique_ptr<IAssetCreator> creator)
{
const auto maybeHandlingAssetType = creator->GetHandlingAssetType();
assert(!maybeHandlingAssetType || static_cast<unsigned>(*maybeHandlingAssetType) < m_asset_creators_by_type.size());
if (maybeHandlingAssetType && static_cast<unsigned>(*maybeHandlingAssetType) < m_asset_creators_by_type.size())
m_asset_creators_by_type[static_cast<unsigned>(*maybeHandlingAssetType)].emplace_back(creator.get());
m_asset_creators.emplace_back(std::move(creator));
}
void AssetCreatorCollection::AddAssetPostProcessor(std::unique_ptr<IAssetPostProcessor> postProcessor)
{
const auto handlingAssetType = postProcessor->GetHandlingAssetType();
assert(static_cast<unsigned>(handlingAssetType) < m_asset_post_processors_by_type.size());
if (static_cast<unsigned>(handlingAssetType) < m_asset_post_processors_by_type.size())
m_asset_post_processors_by_type[static_cast<unsigned>(handlingAssetType)].emplace_back(postProcessor.get());
m_asset_post_processors.emplace_back(std::move(postProcessor));
}
void AssetCreatorCollection::AddDefaultAssetCreator(std::unique_ptr<IDefaultAssetCreator> defaultAssetCreator)
{
const auto handlingAssetType = defaultAssetCreator->GetHandlingAssetType();
assert(static_cast<unsigned>(handlingAssetType) < m_default_asset_creators_by_type.size());
assert(!m_default_asset_creators_by_type[handlingAssetType]);
if (static_cast<unsigned>(handlingAssetType) < m_default_asset_creators_by_type.size())
m_default_asset_creators_by_type[handlingAssetType] = std::move(defaultAssetCreator);
}
AssetCreationResult AssetCreatorCollection::CreateAsset(const asset_type_t assetType, const std::string& assetName, AssetCreationContext& context) const
{
assert(assetType >= 0 && static_cast<unsigned>(assetType) < m_asset_creators_by_type.size());
if (assetType >= 0 && static_cast<unsigned>(assetType) < m_asset_creators_by_type.size())
{
for (const auto& creator : m_asset_creators_by_type[assetType])
{
const auto result = creator->CreateAsset(assetName, context);
if (result.HasTakenAction())
{
// Post process asset if creation was successful
if (result.HasBeenSuccessful())
{
assert(static_cast<unsigned>(assetType) < m_asset_post_processors_by_type.size());
for (auto* postProcessor : m_asset_post_processors_by_type[assetType])
postProcessor->PostProcessAsset(*result.GetAssetInfo(), context);
}
// Return result that was either successful or failed
return result;
}
}
}
return AssetCreationResult::NoAction();
}
AssetCreationResult AssetCreatorCollection::CreateDefaultAsset(const asset_type_t assetType, const std::string& assetName, AssetCreationContext& context) const
{
assert(assetType >= 0 && static_cast<unsigned>(assetType) < m_default_asset_creators_by_type.size());
if (assetType >= 0 && static_cast<unsigned>(assetType) < m_default_asset_creators_by_type.size() && m_default_asset_creators_by_type[assetType])
{
return m_default_asset_creators_by_type[assetType]->CreateDefaultAsset(assetName, context);
}
return AssetCreationResult::NoAction();
}
bool AssetCreatorCollection::FinalizeZone(AssetCreationContext& context) const
{
for (const auto& creator : m_asset_creators)
{
if (!creator->FinalizeZone(context))
return false;
}
for (const auto& postProcessor : m_asset_post_processors)
postProcessor->FinalizeZone(context);
return true;
}