Grail (C++)  1.2.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  GrailDebugger(const std::shared_ptr<ITimestampProvider>& timestampProvider);
24  virtual ~GrailDebugger() override = default;
25 
31  void AttachToManager(AIManager* manager, bool attachToAllEntities = true);
32 
36  void DetachFromManager(AIManager* manager);
37 
42  void AttachToEntity(AIEntity& entity);
43 
48  void DetachFromEntity(AIEntity& entity);
49 
53  void AddDebugSnapshotReceiver(const AIManager* manager, IDebugSnapshotReceiver* receiver);
54 
58  void RemoveDebugSnapshotReceiver(const AIManager* manager, IDebugSnapshotReceiver* receiver);
59 
63  void Update();
64 
65  // IReasonerChangeObserver interface
66  virtual void OnReasonerSet(AIEntity& entity, Reasoner* newReasoner) override;
67 
68  // IEntityChangeObserver interface
69  virtual void OnEntityAdded(const AIManager& manager, AIEntity& entity) override;
70  virtual void OnEntityRemoved(const AIManager& manager, size_t entityId) override;
71 
72  private:
73  bool AttachToReasoner(AIEntity& entity);
74 
75  std::shared_ptr<ITimestampProvider> timestampProvider = nullptr;
76  std::map<const AIManager*, std::vector<IDebugSnapshotReceiver*>> debugSnapshotReceivers{};
77 
78  std::map<size_t, std::pair<std::unique_ptr<ISnapshotGenerator>, std::unordered_set<const AIManager*>>>
79  reasonerSnapshotGenerators{};
80  std::map<const AIManager*, std::unique_ptr<GrailStateSnapshotGenerator>> grailStateSnapshotGenerators{};
81  };
82 }
83 
84 #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:103
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:35
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:92
grail::GrailDebugger::AttachToManager
void AttachToManager(AIManager *manager, bool attachToAllEntities=true)
AttachToManager - attaches the debugger instance to an AIManager.
Definition: GrailDebugger.cpp:13
grail::IReasonerChangeObserver
Definition: AIEntity.hh:38
grail::GrailDebugger::Update
void Update()
Creates debug data for entities and managers that the debugger is attached to, notifies registered sn...
Definition: GrailDebugger.cpp:151
grail::GrailDebugger::AttachToEntity
void AttachToEntity(AIEntity &entity)
AttachToEntity - starts producing debug data for an entity's reasoner.
Definition: GrailDebugger.cpp:84
grail::IEntityChangeObserver
Definition: AIManager.hh:18
grail::GrailDebugger
Definition: GrailDebugger.h:20
grail::IDebugSnapshotReceiver
Definition: IDebugSnapshotReceiver.h:16
grail::GrailDebugger::DetachFromManager
void DetachFromManager(AIManager *manager)
DetachFromCurrentlyObservedManager - detaches the debugger from the currently selected AI Manager and...
Definition: GrailDebugger.cpp:52
grail::GrailDebugger::RemoveDebugSnapshotReceiver
void RemoveDebugSnapshotReceiver(const AIManager *manager, IDebugSnapshotReceiver *receiver)
AddDebugSnapshotReceiver - removes a debug snapshot receiver.
Definition: GrailDebugger.cpp:124