Grail (C++)  1.4.0
A multi-platform, modular, universal engine for embedding advanced AI in games.
LiveDebuggerServerBinary.h
1 #ifndef GRAIL_LIVE_DEBUGGER_SERVER_BINARY_H
2 #define GRAIL_LIVE_DEBUGGER_SERVER_BINARY_H
3 
4 #include "LiveDebuggerServer.h"
5 #include "DataType.h"
6 #include "flatbuffers/flatbuffer_builder.h"
7 
8 namespace grail
9 {
10 namespace live
11 {
13  {
14  enum class DataDecorator : uint8_t
15  {
16  STATE = 1,
17  UTILITY = 2,
18  PLANNER = 3,
19  SIMGAMES = 4,
20  };
21 
22  public:
23  LiveDebuggerServerBinary(const std::string& serverName);
24 
25  virtual void ProcessSnapshot(data::GrailStateSnapshot& stateSnapshot) override;
26  virtual void ProcessSnapshot(data::UtilityReasonerSnapshot& utilitySnapshot) override;
27  virtual void ProcessSnapshot(data::PlannerReasonerSnapshot& plannerSnapshot) override;
28  virtual void ProcessSnapshot(data::SimulatedGameReasonerSnapshot& simulatedGamesSnapshot) override;
29 
30  private:
31  template <typename SnapshotType>
32  void SendSnapshots(SnapshotType snapshot, DataDecorator dataDecorator)
33  {
34  if(tcpServer.IsAnyConnected())
35  {
36  builder.Clear();
37  auto serializedSnapshot = grail::data::Pack(builder, snapshot);
38  builder.Finish(serializedSnapshot);
39  auto decoratedBufferSize = builder.GetSize() + 1;
40  uint8_t* decoratedBuffer = new uint8_t[decoratedBufferSize];
41  decoratedBuffer[0] = static_cast<uint8_t>(dataDecorator);
42  memcpy(decoratedBuffer + 1, builder.GetBufferPointer(), builder.GetSize() * sizeof(uint8_t));
43  tcpServer.SendToAll(decoratedBuffer, decoratedBufferSize, DataType::BINARY);
44  delete[] decoratedBuffer;
45  }
46  }
47 
48  flatbuffers::FlatBufferBuilder builder{};
49  };
50 }
51 }
52 
53 #endif // GRAIL_LIVE_DEBUGGER_SERVER_BINARY_H
grail::data::UtilityReasonerSnapshot
Definition: UtilityReasonerSnapshot.h:15
grail::data::SimulatedGameReasonerSnapshot
Definition: SimulatedGamesSnapshots.h:129
grail::data::PlannerReasonerSnapshot
Definition: PlannerSnapshots.h:92
grail::live::LiveDebuggerServerBinary
Definition: LiveDebuggerServerBinary.h:12
grail::data::GrailStateSnapshot
Definition: GrailStateSnapshot.h:18
grail::live::LiveDebuggerServer
Definition: LiveDebuggerServer.h:16