Grail (C++)  1.3.0
A multi-platform, modular, universal engine for embedding advanced AI in games.
GrailDebugger.h
1 // Copyright QED Software 2023.
2 
3 #ifndef GRAIL_DEBUGGER_H
4 #define GRAIL_DEBUGGER_H
5 
6 #include "GrailStateSnapshotGenerator.h"
7 #include "IDebugSnapshotReceiver.h"
8 #include "ISnapshotGenerator.h"
9 #include "ITimestampProvider.h"
10 #include "../AIEntity.hh"
11 #include "../AIManager.hh"
12 
13 #include <map>
14 #include <memory>
15 #include <unordered_set>
16 #include <vector>
17 
18 namespace grail
19 {
21  {
22  public:
23  struct DebuggerData
24  {
25  std::unique_ptr<GrailDebugger> debugger;
26  std::unique_ptr<class DebugInfoGenerator> debugInfoGenerator;
27  };
28 
29  GrailDebugger(const std::shared_ptr<ITimestampProvider>& timestampProvider);
30  virtual ~GrailDebugger() override = default;
31 
36  static DebuggerData CreateDefaultFor(const AIManager& aiManager,
37  const std::shared_ptr<ITimestampProvider>& timestampProvider);
43  void AttachToManager(AIManager* manager, bool attachToAllEntities = true);
44 
48  void DetachFromManager(AIManager* manager);
49 
54  void AttachToEntity(AIEntity& entity);
55 
60  void DetachFromEntity(AIEntity& entity);
61 
65  void AddDebugSnapshotReceiver(const AIManager* manager, IDebugSnapshotReceiver* receiver);
66 
70  void RemoveDebugSnapshotReceiver(const AIManager* manager, IDebugSnapshotReceiver* receiver);
71 
75  void Update() const;
76 
77  // IReasonerChangeObserver interface
78  virtual void OnReasonerSet(AIEntity& entity, Reasoner* newReasoner) override;
79 
80  // IEntityChangeObserver interface
81  virtual void OnEntityAdded(const AIManager& manager, AIEntity& entity) override;
82  virtual void OnEntityRemoved(const AIManager& manager, size_t entityId) override;
83 
84  private:
85  void AttachToEntity(AIEntity& entity, bool verifyEntityRegistered);
86  bool AttachToReasoner(AIEntity& entity, bool verifyEntityRegistered);
87 
88  std::shared_ptr<ITimestampProvider> timestampProvider = nullptr;
89  std::map<const AIManager*, std::vector<IDebugSnapshotReceiver*>> debugSnapshotReceivers{};
90 
91  std::map<size_t, std::pair<std::unique_ptr<ISnapshotGenerator>, std::unordered_set<const AIManager*>>>
92  reasonerSnapshotGenerators{};
93  std::map<const AIManager*, std::unique_ptr<GrailStateSnapshotGenerator>> grailStateSnapshotGenerators{};
94  };
95 }
96 
97 #endif
grail::GrailDebugger::AddDebugSnapshotReceiver
void AddDebugSnapshotReceiver(const AIManager *manager, IDebugSnapshotReceiver *receiver)
AddDebugSnapshotReceiver - registers a debug snapshot receiver that can react to newly produced debug...
Definition: GrailDebugger.cpp:111
grail::AIEntity
The AIEntity class - Defines a basic object which can execute behaviors.
Definition: AIEntity.hh:50
grail::AIManager
The AIManager class - Manages registered entities and shared blackboards.
Definition: AIManager.hh:32
grail::Reasoner
The Reasoner class - Entity's "brain", assigns them behaviors chosen by user-defined algorithms.
Definition: Reasoner.hh:21
grail::GrailDebugger::DetachFromEntity
void DetachFromEntity(AIEntity &entity)
DetachFromEntity - stops the production of debug data for an entity's reasoner.
Definition: GrailDebugger.cpp:100
grail::GrailDebugger::AttachToManager
void AttachToManager(AIManager *manager, bool attachToAllEntities=true)
AttachToManager - attaches the debugger instance to an AIManager.
Definition: GrailDebugger.cpp:24
grail::IReasonerChangeObserver
Definition: AIEntity.hh:38
grail::GrailDebugger::AttachToEntity
void AttachToEntity(AIEntity &entity)
AttachToEntity - starts producing debug data for an entity's reasoner.
Definition: GrailDebugger.cpp:95
grail::IEntityChangeObserver
Definition: AIManager.hh:15
grail::GrailDebugger
Definition: GrailDebugger.h:20
grail::IDebugSnapshotReceiver
Definition: IDebugSnapshotReceiver.h:16
grail::GrailDebugger::CreateDefaultFor
static DebuggerData CreateDefaultFor(const AIManager &aiManager, const std::shared_ptr< ITimestampProvider > &timestampProvider)
Creates a new GrailDebugger for a specific AIManager.
Definition: GrailDebugger.cpp:15
grail::GrailDebugger::Update
void Update() const
Creates debug data for entities and managers that the debugger is attached to, notifies registered sn...
Definition: GrailDebugger.cpp:159
grail::GrailDebugger::DetachFromManager
void DetachFromManager(AIManager *manager)
DetachFromCurrentlyObservedManager - detaches the debugger from the currently selected AI Manager and...
Definition: GrailDebugger.cpp:63
grail::GrailDebugger::DebuggerData
Definition: GrailDebugger.h:23
grail::GrailDebugger::RemoveDebugSnapshotReceiver
void RemoveDebugSnapshotReceiver(const AIManager *manager, IDebugSnapshotReceiver *receiver)
AddDebugSnapshotReceiver - removes a debug snapshot receiver.
Definition: GrailDebugger.cpp:132