(C++)  1.1.0
A multi-platform, modular, universal engine for embedding advanced AI in games.
DebugInfoGenerator.h
1 #pragma once
2 
3 #include "IDebugSnapshotReceiver.h"
4 #include "ITimestampProvider.h"
5 #include "../../GrailData/DebugInfo/GrailDebugInfo.h"
6 
7 #include <cmath>
8 #include <memory>
9 
10 namespace grail
11 {
13  {
14  public:
15  DebugInfoGenerator(const std::shared_ptr<ITimestampProvider>& timestampProvider);
16  ~DebugInfoGenerator() override;
17 
18  const GrailDebugInfo& GetDebugInfo() const;
19  void ResetDebugInfo();
20  void ProcessSnapshot(GrailStateSnapshot& snapshot) override;
21  void ProcessSnapshot(UtilityReasonerSnapshot& snapshot) override;
22  void ProcessSnapshot(PlannerReasonerSnapshot& snapshot) override;
23  void ProcessSnapshot(SimulatedGameReasonerSnapshot& snapshot) override;
24 
25  private:
26  template<typename SnapshotType>
27  void ProcessNewSnapshot(SnapshotType& snapshot,
28  std::vector<SnapshotType>& snapshotList)
29  {
30  debugInfo.endTime = std::fmax(snapshot.absoluteTime, debugInfo.endTime);
31  snapshot.relativeTime = timestampProvider->GetTimestamp() - debugInfo.startTime;
32  snapshotList.push_back(snapshot);
33  }
34 
35  template<typename SnapshotType>
36  void ProcessReasonerSnapshot(SnapshotType& reasonerSnapshot,
37  std::map<size_t, std::vector<SnapshotType>>& listsPerEntity,
38  size_t entityId)
39  {
40  auto iter = listsPerEntity.find(entityId);
41  if (iter == listsPerEntity.end())
42  {
43  std::vector<SnapshotType> snapshots;
44  ProcessNewSnapshot(reasonerSnapshot, snapshots);
45  listsPerEntity[entityId] = std::move(snapshots);
46  }
47  else
48  {
49  ProcessNewSnapshot(reasonerSnapshot, iter->second);
50  }
51  }
52 
53 
54  std::shared_ptr<ITimestampProvider> timestampProvider = nullptr;
55  GrailDebugInfo debugInfo{};
56  };
57 }
Definition: DebugInfoGenerator.h:13
Definition: IDebugSnapshotReceiver.h:7
Definition: GrailDebugInfo.h:15
Definition: GrailStateSnapshot.h:14
Definition: PlannerSnapshots.h:70
Definition: SimulatedGamesSnapshots.h:95
Definition: UtilityReasonerSnapshot.h:11