3 #ifndef GRAIL_STATE_SNAPSHOT_H
4 #define GRAIL_STATE_SNAPSHOT_H
6 #include "BlackboardState.h"
7 #include "EntityGroupData.h"
8 #include "EntityState.h"
9 #include "Flatbuffers/GrailStateSnapshot_generated.h"
20 float absoluteTime = 0.0f;
21 float relativeTime = 0.0f;
22 std::vector<std::string> tags{};
23 std::vector<BlackboardState> sharedBlackboards{};
24 std::vector<EntityGroupData> entityGroups{};
25 std::vector<EntityState> entityData{};
28 inline flatbuffers::Offset<generated::GrailStateSnapshot> Pack(flatbuffers::FlatBufferBuilder& builder,
31 std::vector<flatbuffers::Offset<generated::BlackboardState>> packedSharedBlackboards{};
32 packedSharedBlackboards.reserve(snapshot.sharedBlackboards.size());
33 std::vector<flatbuffers::Offset<generated::EntityGroupData>> packedEntityGroups{};
34 packedEntityGroups.reserve(snapshot.entityGroups.size());
35 std::vector<flatbuffers::Offset<generated::EntityState>> packedEntityData{};
36 packedEntityData.reserve(snapshot.entityData.size());
37 std::vector<flatbuffers::Offset<flatbuffers::String>> packedTags{};
38 packedTags.reserve(snapshot.tags.size());
39 std::for_each(snapshot.tags.begin(), snapshot.tags.end(),
40 [&packedTags, &builder](
const auto& tag)
42 packedTags.push_back(builder.CreateString(tag));
44 std::for_each(snapshot.sharedBlackboards.begin(), snapshot.sharedBlackboards.end(),
45 [&packedSharedBlackboards, &builder](
const auto& blackboard)
47 packedSharedBlackboards.push_back(Pack(builder, blackboard));
49 std::for_each(snapshot.entityGroups.begin(), snapshot.entityGroups.end(),
50 [&packedEntityGroups, &builder](
const auto& entityGroup)
52 packedEntityGroups.push_back(Pack(builder, entityGroup));
54 std::for_each(snapshot.entityData.begin(), snapshot.entityData.end(),
55 [&packedEntityData, &builder](
const auto& entityData)
57 packedEntityData.push_back(Pack(builder, entityData));
59 return generated::CreateGrailStateSnapshot(builder,
60 snapshot.absoluteTime,
61 snapshot.relativeTime,
62 builder.CreateVector(packedTags),
63 builder.CreateVector(packedSharedBlackboards),
64 builder.CreateVector(packedEntityGroups),
65 builder.CreateVector(packedEntityData));
68 inline GrailStateSnapshot Unpack(
const generated::GrailStateSnapshot& snapshot)
70 GrailStateSnapshot deserializedData{};
71 deserializedData.absoluteTime = snapshot.absoluteTime();
72 deserializedData.relativeTime = snapshot.relativeTime();
74 deserializedData.tags.reserve(snapshot.tags()->size());
75 for(
const auto& tag : *snapshot.tags())
77 deserializedData.tags.emplace_back(tag->str());
79 deserializedData.sharedBlackboards.reserve(snapshot.sharedBlackboards()->size());
80 for(
const auto& blackboardState : *snapshot.sharedBlackboards())
82 deserializedData.sharedBlackboards.emplace_back(Unpack(*blackboardState));
84 deserializedData.entityGroups.reserve(snapshot.entityGroups()->size());
85 for(
const auto& entityGroup : *snapshot.entityGroups())
87 deserializedData.entityGroups.emplace_back(Unpack(*entityGroup));
89 deserializedData.entityData.reserve(snapshot.entityData()->size());
90 for(
const auto& entityData : *snapshot.entityData())
92 deserializedData.entityData.emplace_back(Unpack(*entityData));
94 return deserializedData;