-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathKeyValuePairsCompilerT6.cpp
More file actions
83 lines (68 loc) · 2.91 KB
/
Copy pathKeyValuePairsCompilerT6.cpp
File metadata and controls
83 lines (68 loc) · 2.91 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
#include "KeyValuePairsCompilerT6.h"
#include "Game/T6/CommonT6.h"
#include "Game/T6/T6.h"
#include "KeyValuePairs/KeyValuePairsCreator.h"
#include <cassert>
#include <format>
using namespace T6;
namespace
{
class KeyValuePairsCompiler final : public IAssetCreator
{
public:
KeyValuePairsCompiler(MemoryManager& memory, const Zone& zone, const ZoneDefinition& zoneDefinition, ZoneAssetCreationStateContainer& zoneStates)
: m_memory(memory),
m_zone(zone),
m_zone_definition(zoneDefinition),
m_kvp_creator(zoneStates.GetZoneAssetCreationState<key_value_pairs::Creator>())
{
}
[[nodiscard]] std::optional<asset_type_t> GetHandlingAssetType() const override
{
return std::nullopt;
}
AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override
{
return AssetCreationResult::NoAction();
}
bool FinalizeZone(AssetCreationContext& context) override
{
m_kvp_creator.Finalize(m_zone_definition);
const auto commonKvps = m_kvp_creator.GetFinalKeyValuePairs();
if (commonKvps.empty())
return true;
auto* gameKvps = m_memory.Alloc<KeyValuePairs>();
gameKvps->name = m_memory.Dup(m_zone.m_name.c_str());
gameKvps->numVariables = static_cast<unsigned>(commonKvps.size());
gameKvps->keyValuePairs = m_memory.Alloc<KeyValuePair>(commonKvps.size());
const auto namespaceHash = Common::Com_HashKey(m_zone.m_name.c_str(), 64);
for (auto kvpIndex = 0u; kvpIndex < gameKvps->numVariables; kvpIndex++)
{
const auto& commonKvp = commonKvps[kvpIndex];
auto& gameKvp = gameKvps->keyValuePairs[kvpIndex];
assert(commonKvp.m_key_str || commonKvp.m_key_hash);
if (commonKvp.m_key_str)
gameKvp.keyHash = Common::Com_HashKey(commonKvp.m_key_str->c_str(), 64);
else
gameKvp.keyHash = *commonKvp.m_key_hash;
gameKvp.namespaceHash = namespaceHash;
gameKvp.value = m_memory.Dup(commonKvp.m_value.c_str());
}
context.AddAsset(AssetRegistration<AssetKeyValuePairs>(m_zone.m_name, gameKvps));
return true;
}
private:
MemoryManager& m_memory;
const Zone& m_zone;
const ZoneDefinition& m_zone_definition;
key_value_pairs::Creator& m_kvp_creator;
};
} // namespace
namespace key_value_pairs
{
std::unique_ptr<IAssetCreator>
CreateCompilerT6(MemoryManager& memory, const Zone& zone, const ZoneDefinition& zoneDefinition, ZoneAssetCreationStateContainer& zoneStates)
{
return std::make_unique<KeyValuePairsCompiler>(memory, zone, zoneDefinition, zoneStates);
}
} // namespace key_value_pairs