Plasma Engine  2.0
Loading...
Searching...
No Matches
BlackboardComponent.h
1#pragma once
2
3#include <Core/Messages/EventMessage.h>
4#include <Core/ResourceManager/ResourceHandle.h>
5#include <Core/Utils/Blackboard.h>
6#include <GameEngine/GameEngineDLL.h>
7
10
12
14{
15 plHashedString m_sName;
16 plVariant m_InitialValue;
18
19 plResult Serialize(plStreamWriter& inout_stream) const;
20 plResult Deserialize(plStreamReader& inout_stream);
21};
22
23PL_DECLARE_REFLECTABLE_TYPE(PL_GAMEENGINE_DLL, plBlackboardEntry);
24
26
27struct PL_GAMEENGINE_DLL plMsgBlackboardEntryChanged : public plEventMessage
28{
29 PL_DECLARE_MESSAGE_TYPE(plMsgBlackboardEntryChanged, plEventMessage);
30
31 plHashedString m_sName;
32 plVariant m_OldValue;
33 plVariant m_NewValue;
34
35private:
36 const char* GetName() const { return m_sName; }
37 void SetName(const char* szName) { m_sName.Assign(szName); }
38};
39
41
45class PL_GAMEENGINE_DLL plBlackboardComponent : public plComponent
46{
47 PL_DECLARE_ABSTRACT_COMPONENT_TYPE(plBlackboardComponent, plComponent);
48
50 // plComponent
51
52public:
53 virtual void SerializeComponent(plWorldWriter& inout_stream) const override;
54 virtual void DeserializeComponent(plWorldReader& inout_stream) override;
55
56protected:
57 virtual void OnActivated() override;
58 virtual void OnDeactivated() override;
59
61 // plBlackboardComponent
62
63public:
66
73 static plSharedPtr<plBlackboard> FindBlackboard(plGameObject* pSearchObject, plStringView sBlackboardName = plStringView());
74
76 const plSharedPtr<plBlackboard>& GetBoard();
77 plSharedPtr<const plBlackboard> GetBoard() const;
78
79 void SetShowDebugInfo(bool bShow); // [ property ]
80 bool GetShowDebugInfo() const; // [ property ]
81
82 void SetTemplateFile(const char* szName); // [ property ]
83 const char* GetTemplateFile() const; // [ property ]
84
85 void SetEntryValue(const char* szName, const plVariant& value); // [ scriptable ]
86 plVariant GetEntryValue(const char* szName) const; // [ scriptable ]
87
88protected:
89 static plBlackboard* Reflection_FindBlackboard(plGameObject* pSearchObject, plStringView sBlackboardName);
90
91 void OnUpdateLocalBounds(plMsgUpdateLocalBounds& msg) const;
92 void OnExtractRenderData(plMsgExtractRenderData& msg) const;
93
95
97};
98
100
102
104class PL_GAMEENGINE_DLL plLocalBlackboardComponent : public plBlackboardComponent
105{
107
109 // plComponent
110
111public:
112 virtual void SerializeComponent(plWorldWriter& inout_stream) const override;
113 virtual void DeserializeComponent(plWorldReader& inout_stream) override;
114
115protected:
116 virtual void Initialize() override;
117 virtual void OnActivated() override;
118 virtual void OnDeactivated() override;
119 virtual void OnSimulationStarted() override;
120
122 // plBlackboardComponent
123
124public:
128
130
131 void SetSendEntryChangedMessage(bool bSend); // [ property ]
132 bool GetSendEntryChangedMessage() const; // [ property ]
133
134 void SetBlackboardName(const char* szName); // [ property ]
135 const char* GetBlackboardName() const; // [ property ]
136
137private:
138 plUInt32 Entries_GetCount() const;
139 const plBlackboardEntry& Entries_GetValue(plUInt32 uiIndex) const;
140 void Entries_SetValue(plUInt32 uiIndex, const plBlackboardEntry& entry);
141 void Entries_Insert(plUInt32 uiIndex, const plBlackboardEntry& entry);
142 void Entries_Remove(plUInt32 uiIndex);
143
144 void OnEntryChanged(const plBlackboard::EntryEvent& e);
145 void InitializeFromTemplate();
146
147 // this array is not held during runtime, it is only needed during editor time until the component is serialized out
148 plDynamicArray<plBlackboardEntry> m_InitialEntries;
149
150 plEventMessageSender<plMsgBlackboardEntryChanged> m_EntryChangedSender; // [ event ]
151};
152
156
158{
159 using StorageType = plUInt8;
160
169};
170
171PL_DECLARE_REFLECTABLE_TYPE(PL_GAMEENGINE_DLL, plGlobalBlackboardInitMode);
172
174
179{
181
183 // plComponent
184
185public:
186 virtual void SerializeComponent(plWorldWriter& inout_stream) const override;
187 virtual void DeserializeComponent(plWorldReader& inout_stream) override;
188
189protected:
190 virtual void Initialize() override;
191 virtual void OnActivated() override;
192 virtual void OnDeactivated() override;
193 virtual void OnSimulationStarted() override;
194
196 // plGlobalBlackboardComponent
197
198public:
202
204
205 void SetBlackboardName(const char* szName); // [ property ]
206 const char* GetBlackboardName() const; // [ property ]
207
208 plEnum<plGlobalBlackboardInitMode> m_InitMode; // [ property ]
209
210private:
211 void InitializeFromTemplate();
212
213 plHashedString m_sName;
214};
This base component represents an plBlackboard, which can be used to share state between multiple com...
Definition BlackboardComponent.h:46
A blackboard is a key/value store that provides OnChange events to be informed when a value changes.
Definition Blackboard.h:66
Base class of all component types.
Definition Component.h:25
Definition ComponentManager.h:88
Definition DynamicArray.h:81
A message sender that sends all messages to the next component derived from plEventMessageHandlerComp...
Definition EventMessage.h:39
This class represents an object inside the world.
Definition GameObject.h:32
This component references a global blackboard by name. If necessary, the blackboard will be created.
Definition BlackboardComponent.h:179
This class is optimized to take nearly no memory (sizeof(void*)) and to allow very fast checks whethe...
Definition HashedString.h:25
void Assign(const char(&string)[N])
Assigning a new string from a string constant is a slow operation, but the hash computation can happe...
This component creates its own plBlackboard, and thus locally holds state.
Definition BlackboardComponent.h:105
A Shared ptr manages a shared object and destroys that object when no one references it anymore....
Definition SharedPtr.h:10
Interface for binary in (read) streams.
Definition Stream.h:22
Interface for binary out (write) streams.
Definition Stream.h:107
plStringView represent a read-only sub-string of a larger string, as it can store a dedicated string ...
Definition StringView.h:34
plVariant is a class that can store different types of variables, which is useful in situations where...
Definition Variant.h:44
Reads a world description from a stream. Allows to instantiate that world multiple times in different...
Definition WorldReader.h:47
Stores an entire plWorld in a stream.
Definition WorldWriter.h:13
The plBitflags class allows you to work with type-safe bitflags.
Definition Bitflags.h:82
Definition Blackboard.h:117
Definition BlackboardComponent.h:14
A custom enum implementation that allows to define the underlying storage type to control its memory ...
Definition Enum.h:37
Base class for all messages that are sent as 'events'.
Definition EventMessage.h:8
Definition BlackboardComponent.h:158
Enum
Definition BlackboardComponent.h:162
@ EnsureEntriesExist
Brief only adds entries to the blackboard, that haven't been added before. Doesn't change the values ...
Definition BlackboardComponent.h:163
@ ResetEntryValues
Overwrites values of existing entries, to reset them to the start value defined in the template.
Definition BlackboardComponent.h:164
@ ClearEntireBlackboard
Removes all entries from the blackboard and only adds the ones from the template. This also gets rid ...
Definition BlackboardComponent.h:165
Definition BlackboardComponent.h:28
Definition RenderData.h:116
Definition UpdateLocalBoundsMessage.h:9
Default enum for returning failure or success, instead of using a bool.
Definition Types.h:54