Plasma Engine  2.0
Loading...
Searching...
No Matches
PathComponent.h
1#pragma once
2
3#include <Core/Messages/EventMessage.h>
4#include <Core/World/Component.h>
5#include <Core/World/ComponentManager.h>
6#include <Foundation/Types/Bitflags.h>
7#include <GameEngine/GameEngineDLL.h>
8#include <RendererCore/RendererCoreDLL.h>
9
12
14
15PL_DECLARE_FLAGS(plUInt32, plPathComponentFlags, VisualizePath, VisualizeUpDir);
16PL_DECLARE_REFLECTABLE_TYPE(PL_GAMEENGINE_DLL, plPathComponentFlags);
17
19
20struct PL_GAMEENGINE_DLL plMsgPathChanged : public plEventMessage
21{
22 PL_DECLARE_MESSAGE_TYPE(plMsgPathChanged, plEventMessage);
23};
24
26
27class plPathComponentManager : public plComponentManager<class plPathComponent, plBlockStorageType::FreeList>
28{
29public:
31
32 void SetEnableUpdate(plPathComponent* pThis, bool bEnable);
33
34protected:
35 void Initialize() override;
36 void Update(const plWorldModule::UpdateContext& context);
37
39};
40
54class PL_GAMEENGINE_DLL plPathComponent : public plComponent
55{
56 PL_DECLARE_COMPONENT_TYPE(plPathComponent, plComponent, plPathComponentManager);
57
59 // plComponent
60
61public:
62 virtual void SerializeComponent(plWorldWriter& ref_stream) const override;
63 virtual void DeserializeComponent(plWorldReader& ref_stream) override;
64
65protected:
66 virtual void OnActivated() override;
67 virtual void OnDeactivated() override;
68
70 // plPathComponent
71
72public:
75
77 void OnMsgPathChanged(plMsgPathChanged& ref_msg); // [ message handler ]
78
80 void SetClosed(bool bClosed); // [ property ]
81 bool GetClosed() const { return m_bClosed; } // [ property ]
82
83 void SetPathFlags(plBitflags<plPathComponentFlags> flags); // [ property ]
84 plBitflags<plPathComponentFlags> GetPathFlags() const { return m_PathFlags; } // [ property ]
85
86
89 {
90 plVec3 m_vPosition = plVec3::MakeZero();
91 plVec3 m_vTangentIn = plVec3::MakeZero();
92 plVec3 m_vTangentOut = plVec3::MakeZero();
93 plAngle m_Roll;
94
95 plResult Serialize(plStreamWriter& ref_writer) const;
96 plResult Deserialize(plStreamReader& ref_reader);
97 };
98
100 void EnsureControlPointRepresentationIsUpToDate();
101
103 const plArrayPtr<const plPathComponent::ControlPoint> GetControlPointRepresentation() const { return m_ControlPointRepresentation; }
104
105
108 {
109 plVec3 m_vPosition = plVec3::MakeZero();
110 plVec3 m_vUpDirection = plVec3::MakeAxisZ();
111 };
112
114 void EnsureLinearizedRepresentationIsUpToDate();
115
118
120 float GetLinearizedRepresentationLength() const { return m_fLinearizedLength; }
121
123 void SetDisableControlPointUpdates(bool bDisable) { m_bDisableControlPointUpdates = bDisable; }
124
130 {
132 void SetToStart();
133
134 private:
135 friend class plPathComponent;
136
137 float m_fSegmentFraction = 0.0f;
138 plUInt32 m_uiSegmentNode = 0;
139 };
140
145 void SetLinearSamplerTo(LinearSampler& ref_sampler, float fDistance) const;
146
150 bool AdvanceLinearSamplerBy(LinearSampler& ref_sampler, float& inout_fAddDistance) const;
151
153 plPathComponent::LinearizedElement SampleLinearizedRepresentation(const LinearSampler& sampler) const;
154
162 void SetLinearizationError(float fError); // [ property ]
163 float GetLinearizationError() const { return m_fLinearizationError; } // [ property ]
164
165protected:
166 plUInt32 Nodes_GetCount() const { return m_Nodes.GetCount(); } // [ property ]
167 const plString& Nodes_GetNode(plUInt32 i) const { return m_Nodes[i]; } // [ property ]
168 void Nodes_SetNode(plUInt32 i, const plString& node); // [ property ]
169 void Nodes_Insert(plUInt32 uiIndex, const plString& node); // [ property ]
170 void Nodes_Remove(plUInt32 uiIndex); // [ property ]
171
172 void FindControlPoints(plDynamicArray<ControlPoint>& out_ControlPoints) const;
173 void CreateLinearizedPathRepresentation(const plDynamicArray<ControlPoint>& points);
174
175 void DrawDebugVisualizations();
176
177 plBitflags<plPathComponentFlags> m_PathFlags; // [ property ]
178 float m_fLinearizationError = 0.05f; // [ property ]
179 float m_fLinearizedLength = 0.0f; //
180 bool m_bDisableControlPointUpdates = false; //
181 bool m_bControlPointsChanged = true; //
182 bool m_bLinearizedRepresentationChanged = true; //
183 bool m_bClosed = false; // [ property ]
184 plDynamicArray<plString> m_Nodes; // [ property ]
185 plDynamicArray<LinearizedElement> m_LinearizedRepresentation; //
186 plDynamicArray<ControlPoint> m_ControlPointRepresentation; //
187};
188
190
192
195{
196 using StorageType = plUInt8;
197
198 enum Enum
199 {
202
203 Default = Auto
204 };
205};
206
207PL_DECLARE_REFLECTABLE_TYPE(PL_GAMEENGINE_DLL, plPathNodeTangentMode);
208
209
216class PL_GAMEENGINE_DLL plPathNodeComponent : public plComponent
217{
219
221 // plPathNodeComponent
222
223public:
226
228 void SetRoll(plAngle roll); // [ property ]
229 plAngle GetRoll() const { return m_Roll; } // [ property ]
230 //
231 void SetTangentMode1(plEnum<plPathNodeTangentMode> mode); // [ property ]
232 plEnum<plPathNodeTangentMode> GetTangentMode1() const { return m_TangentMode1; } // [ property ]
233 //
234 void SetTangentMode2(plEnum<plPathNodeTangentMode> mode); // [ property ]
235 plEnum<plPathNodeTangentMode> GetTangentMode2() const { return m_TangentMode2; } // [ property ]
236
237protected:
238 void OnMsgTransformChanged(plMsgTransformChanged& msg);
239 void OnMsgParentChanged(plMsgParentChanged& msg);
240
241 virtual void OnActivated() override;
242 virtual void OnDeactivated() override;
243
244 void PathChanged();
245
246 plAngle m_Roll;
247 plEnum<plPathNodeTangentMode> m_TangentMode1;
248 plEnum<plPathNodeTangentMode> m_TangentMode2;
249};
Float wrapper struct for a safe usage and conversions of angles.
Definition Angle.h:10
This class encapsulates an array and it's size. It is recommended to use this class instead of plain ...
Definition ArrayPtr.h:37
Base class of all component types.
Definition Component.h:25
Definition ComponentManager.h:88
Definition DynamicArray.h:81
A hybrid array uses in-place storage to handle the first few elements without any allocation....
Definition HybridArray.h:12
Describes a path shape.
Definition PathComponent.h:55
float GetLinearizedRepresentationLength() const
Returns the total length of the linearized path representation.
Definition PathComponent.h:120
const plArrayPtr< const plPathComponent::LinearizedElement > GetLinearizedRepresentation() const
Grants access to the linearized representation that define the path's shape.
Definition PathComponent.h:117
void SetDisableControlPointUpdates(bool bDisable)
Forces that the current control point state is never updated in the future. Used as a work-around dur...
Definition PathComponent.h:123
const plArrayPtr< const plPathComponent::ControlPoint > GetControlPointRepresentation() const
Grants access to the control points that define the path's shape.
Definition PathComponent.h:103
Definition PathComponent.h:28
void Initialize() override
This method is called after the constructor. A derived type can override this method to do initializa...
Definition PathComponent.cpp:845
Attach this to child object of an plPathComponent to turn them into viable path nodes.
Definition PathComponent.h:217
Interface for binary in (read) streams.
Definition Stream.h:22
Interface for binary out (write) streams.
Definition Stream.h:107
static plVec3Template< float > MakeZero()
Definition Vec3.h:38
static plVec3Template< float > MakeAxisZ()
Definition Vec3.h:47
A world encapsulates a scene graph of game objects and various component managers and their component...
Definition World.h:22
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
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 HierarchyChangedMessages.h:7
Definition PathComponent.h:21
Definition TransformChangedMessage.h:7
The 'raw' data for a single path control point.
Definition PathComponent.h:89
An object that keeps track of where one is sampling the path component.
Definition PathComponent.h:130
If the path is linearized, this represents a single sample point.
Definition PathComponent.h:108
The different modes that tangents may use in a path node.
Definition PathComponent.h:195
Enum
Definition PathComponent.h:199
@ Auto
The curvature through the node is automatically computed to be smooth.
Definition PathComponent.h:200
@ Linear
There is no curvature through this node/tangent. Creates sharp corners.
Definition PathComponent.h:201
Default enum for returning failure or success, instead of using a bool.
Definition Types.h:54
Definition WorldModule.h:33