3 #ifndef GRAIL_ENTITY_STATE_H
4 #define GRAIL_ENTITY_STATE_H
6 #include "BehaviorData.h"
7 #include "Flatbuffers/EntityState_generated.h"
21 std::map<std::string, std::string> privateBlackboardData{};
22 std::vector<std::string> localSharedBlackboardAccess{};
23 std::vector<std::string> globalSharedBlackboardAccess{};
24 std::vector<std::string> entityTags{};
28 inline flatbuffers::Offset<generated::EntityState> Pack(flatbuffers::FlatBufferBuilder& builder,
31 std::vector<flatbuffers::Offset<generated::StringStringMap>> packedPrivateBlackboards{};
32 packedPrivateBlackboards.reserve(entityState.privateBlackboardData.size());
33 std::vector<flatbuffers::Offset<flatbuffers::String>> packedLocalBlackboards{};
34 packedLocalBlackboards.reserve(entityState.localSharedBlackboardAccess.size());
35 std::vector<flatbuffers::Offset<flatbuffers::String>> packedGlobalBlackboards{};
36 packedGlobalBlackboards.reserve(entityState.globalSharedBlackboardAccess.size());
37 std::vector<flatbuffers::Offset<flatbuffers::String>> packedTags{};
38 packedTags.reserve(entityState.entityTags.size());
40 std::for_each(entityState.privateBlackboardData.begin(), entityState.privateBlackboardData.end(),
41 [&packedPrivateBlackboards, &builder](
const auto& blackboardData)
43 packedPrivateBlackboards.push_back(generated::CreateStringStringMap(builder,
44 builder.CreateString(blackboardData.first),
45 builder.CreateString(blackboardData.second)));
47 std::for_each(entityState.localSharedBlackboardAccess.begin(), entityState.localSharedBlackboardAccess.end(),
48 [&packedLocalBlackboards, &builder](
const auto& blackboardName)
50 packedLocalBlackboards.push_back(builder.CreateString(blackboardName));
52 std::for_each(entityState.globalSharedBlackboardAccess.begin(), entityState.globalSharedBlackboardAccess.end(),
53 [&packedGlobalBlackboards, &builder](
const auto& blackboardName)
55 packedGlobalBlackboards.push_back(builder.CreateString(blackboardName));
57 std::for_each(entityState.entityTags.begin(), entityState.entityTags.end(),
58 [&packedTags, &builder](
const auto& entityTag)
60 packedTags.push_back(builder.CreateString(entityTag));
62 return generated::CreateEntityState(builder,
63 builder.CreateString(entityState.name),
65 builder.CreateVector(packedPrivateBlackboards),
66 builder.CreateVector(packedLocalBlackboards),
67 builder.CreateVector(packedGlobalBlackboards),
68 builder.CreateVector(packedTags),
69 Pack(builder, entityState.currentBehaviorData));
72 inline EntityState Unpack(
const generated::EntityState& entityState)
74 EntityState deserializedState{entityState.name()->str(), entityState.id()};
75 for(
const auto& blackboardData : *entityState.privateBlackboardData())
77 deserializedState.privateBlackboardData.insert({blackboardData->key()->str(), blackboardData->value()->str()});
79 deserializedState.localSharedBlackboardAccess.reserve(entityState.localSharedBlackboardAccess()->size());
80 for(
const auto& blackboardName : *entityState.localSharedBlackboardAccess())
82 deserializedState.localSharedBlackboardAccess.emplace_back(blackboardName->str());
84 deserializedState.globalSharedBlackboardAccess.reserve(entityState.globalSharedBlackboardAccess()->size());
85 for(
const auto& blackboardName : *entityState.globalSharedBlackboardAccess())
87 deserializedState.globalSharedBlackboardAccess.emplace_back(blackboardName->str());
89 deserializedState.entityTags.reserve(entityState.entityTags()->size());
90 for(
const auto& entityTag : *entityState.entityTags())
92 deserializedState.entityTags.emplace_back(entityTag->str());
94 deserializedState.currentBehaviorData = Unpack(*entityState.currentBehaviorData());
95 return deserializedState;