Grail (C++)  1.4.0
A multi-platform, modular, universal engine for embedding advanced AI in games.
UtilityReasonerSnapshot.h
1 // Copyright QED Software 2023.
2 
3 #ifndef GRAIL_UTILITY_REASONER_SNAPSHOT_H
4 #define GRAIL_UTILITY_REASONER_SNAPSHOT_H
5 
6 #include "UtilityEvaluatorSnapshot.h"
7 #include "Flatbuffers/UtilityReasonerSnapshot_generated.h"
8 
9 #include <vector>
10 
11 namespace grail
12 {
13 namespace data
14 {
16  {
17  size_t entityId = 0;
18  float absoluteTime = 0.0f;
19  float relativeTime = 0.0f;
20  std::vector<UtilityEvaluatorSnapshot> evaluatorSnapshots{};
21  };
22 
23  inline flatbuffers::Offset<generated::UtilityReasonerSnapshot> Pack(flatbuffers::FlatBufferBuilder& builder,
24  const UtilityReasonerSnapshot& snapshot)
25  {
26  std::vector<flatbuffers::Offset<generated::UtilityEvaluatorSnapshot>> packedEvaluatorSnapshots{};
27  packedEvaluatorSnapshots.reserve(snapshot.evaluatorSnapshots.size());
28  std::for_each(snapshot.evaluatorSnapshots.begin(), snapshot.evaluatorSnapshots.end(),
29  [&packedEvaluatorSnapshots, &builder](const auto& evaluatorSnapshot)
30  {
31  packedEvaluatorSnapshots.push_back(Pack(builder, evaluatorSnapshot));
32  });
33  return generated::CreateUtilityReasonerSnapshot(builder, snapshot.entityId, snapshot.absoluteTime,
34  snapshot.relativeTime,builder.CreateVector(packedEvaluatorSnapshots));
35  }
36 
37  inline UtilityReasonerSnapshot Unpack(const generated::UtilityReasonerSnapshot& snapshot)
38  {
39  UtilityReasonerSnapshot utilityReasonerSnapshot{snapshot.entityId(), snapshot.absoluteTime(), snapshot.relativeTime()};
40  utilityReasonerSnapshot.evaluatorSnapshots.reserve(snapshot.evaluatorSnapshots()->size());
41  for(const auto& evaluation : *snapshot.evaluatorSnapshots())
42  {
43  utilityReasonerSnapshot.evaluatorSnapshots.emplace_back(Unpack(*evaluation));
44  }
45  return utilityReasonerSnapshot;
46  }
47 }
48 }
49 
50 #endif
grail::data::UtilityReasonerSnapshot
Definition: UtilityReasonerSnapshot.h:15