Plasma Engine  2.0
Loading...
Searching...
No Matches
ProcPlacementComponent.h
1#pragma once
2
3#include <Core/World/World.h>
4#include <Foundation/Types/SharedPtr.h>
5#include <Foundation/Types/UniquePtr.h>
6#include <ProcGenPlugin/Resources/ProcGenGraphResource.h>
7
11
13
14class PL_PROCGENPLUGIN_DLL plProcPlacementComponentManager : public plComponentManager<plProcPlacementComponent, plBlockStorageType::Compact>
15{
16public:
19
20 virtual void Initialize() override;
21 virtual void Deinitialize() override;
22
23private:
24 friend class plProcPlacementComponent;
25
26 void FindTiles(const plWorldModule::UpdateContext& context);
27 void PreparePlace(const plWorldModule::UpdateContext& context);
28 void PlaceObjects(const plWorldModule::UpdateContext& context);
29
30 void DebugDrawTile(const plProcGenInternal::PlacementTileDesc& desc, const plColor& color, plUInt32 uiQueueIndex = plInvalidIndex);
31
32 void AddComponent(plProcPlacementComponent* pComponent);
33 void RemoveComponent(plProcPlacementComponent* pComponent);
34
36 void DeallocateTile(plUInt32 uiTileIndex);
37
38 plUInt32 AllocateProcessingTask(plUInt32 uiTileIndex);
39 void DeallocateProcessingTask(plUInt32 uiTaskIndex);
40 plUInt32 GetNumAllocatedProcessingTasks() const;
41
42 void RemoveTilesForComponent(plProcPlacementComponent* pComponent, bool* out_bAnyObjectsRemoved = nullptr);
43 void OnResourceEvent(const plResourceEvent& resourceEvent);
44
45 void AddVisibleComponent(const plComponentHandle& hComponent, const plVec3& cameraPosition, const plVec3& cameraDirection) const;
46 void ClearVisibleComponents();
47
48 struct VisibleComponent
49 {
50 plComponentHandle m_hComponent;
51 plVec3 m_vCameraPosition;
52 plVec3 m_vCameraDirection;
53 };
54
55 mutable plMutex m_VisibleComponentsMutex;
56 mutable plDynamicArray<VisibleComponent> m_VisibleComponents;
57
58 plDynamicArray<plComponentHandle> m_ComponentsToUpdate;
59
61 plDynamicArray<plUInt32> m_FreeTiles;
62
63 struct ProcessingTask
64 {
65 PL_ALWAYS_INLINE bool IsValid() const { return m_uiTileIndex != plInvalidIndex; }
66 PL_ALWAYS_INLINE bool IsScheduled() const { return m_PlacementTaskGroupID.IsValid(); }
67 PL_ALWAYS_INLINE void Invalidate()
68 {
69 m_uiScheduledFrame = -1;
70 m_PlacementTaskGroupID.Invalidate();
71 m_uiTileIndex = plInvalidIndex;
72 }
73
74 plUInt64 m_uiScheduledFrame;
78 plTaskGroupID m_PlacementTaskGroupID;
79 plUInt32 m_uiTileIndex;
80 };
81
82 plDynamicArray<ProcessingTask> m_ProcessingTasks;
83 plDynamicArray<plUInt32> m_FreeProcessingTasks;
84
85 struct SortedProcessingTask
86 {
87 plUInt64 m_uiScheduledFrame = 0;
88 plUInt32 m_uiTaskIndex = 0;
89 };
90
91 plDynamicArray<SortedProcessingTask> m_SortedProcessingTasks;
92
94 plTaskGroupID m_UpdateTilesTaskGroupID;
95};
96
98
100{
101 plVec3 m_vOffset = plVec3::MakeZero();
102 plQuat m_Rotation = plQuat::MakeIdentity();
103 plVec3 m_vExtents = plVec3(10);
104
105 plResult Serialize(plStreamWriter& inout_stream) const;
106 plResult Deserialize(plStreamReader& inout_stream);
107};
108
109PL_DECLARE_REFLECTABLE_TYPE(PL_PROCGENPLUGIN_DLL, plProcGenBoxExtents);
110
111class PL_PROCGENPLUGIN_DLL plProcPlacementComponent : public plComponent
112{
114
115public:
118
120
121 virtual void OnActivated() override;
122 virtual void OnDeactivated() override;
123
124 void SetResourceFile(const char* szFile);
125 const char* GetResourceFile() const;
126
127 void SetResource(const plProcGenGraphResourceHandle& hResource);
128 const plProcGenGraphResourceHandle& GetResource() const { return m_hResource; }
129
130 void OnUpdateLocalBounds(plMsgUpdateLocalBounds& ref_msg);
131 void OnMsgExtractRenderData(plMsgExtractRenderData& ref_msg) const;
132
133 virtual void SerializeComponent(plWorldWriter& inout_stream) const override;
134 virtual void DeserializeComponent(plWorldReader& inout_stream) override;
135
136private:
137 plUInt32 BoxExtents_GetCount() const;
138 const plProcGenBoxExtents& BoxExtents_GetValue(plUInt32 uiIndex) const;
139 void BoxExtents_SetValue(plUInt32 uiIndex, const plProcGenBoxExtents& value);
140 void BoxExtents_Insert(plUInt32 uiIndex, const plProcGenBoxExtents& value);
141 void BoxExtents_Remove(plUInt32 uiIndex);
142
143 void UpdateBoundsAndTiles();
144
146
148
149 // runtime data
151
152 struct Bounds
153 {
154 PL_DECLARE_POD_TYPE();
155
156 plSimdBBox m_GlobalBoundingBox;
157 plSimdMat4f m_GlobalToLocalBoxTransform;
158 };
159
161
162 struct OutputContext
163 {
165
167 {
168 PL_DECLARE_POD_TYPE();
169
170 plUInt32 m_uiIndex;
171 plUInt64 m_uiLastSeenFrame;
172 };
173
175
177 };
178
179 plDynamicArray<OutputContext> m_OutputContexts;
180};
plColor represents an RGBA color in linear color space. Values are stored as float,...
Definition Color.h:44
Base class of all component types.
Definition Component.h:25
Definition ComponentManager.h:88
Definition DynamicArray.h:81
Definition HashTable.h:333
Provides a simple mechanism for mutual exclusion to prevent multiple threads from accessing a shared ...
Definition Mutex.h:13
Definition FindPlacementTilesTask.h:17
Definition ProcPlacementComponent.h:112
Definition ProcPlacementComponent.h:15
static const plQuatTemplate< float > MakeIdentity()
Definition Quat_inl.h:29
A Shared ptr manages a shared object and destroys that object when no one references it anymore....
Definition SharedPtr.h:10
Definition SimdBBox.h:6
A 4x4 matrix class.
Definition SimdMat4f.h:7
Interface for binary in (read) streams.
Definition Stream.h:22
Interface for binary out (write) streams.
Definition Stream.h:107
Given out by plTaskSystem::CreateTaskGroup to identify a task group.
Definition TaskSystemDeclarations.h:103
A Unique ptr manages an object and destroys that object when it goes out of scope....
Definition UniquePtr.h:10
static plVec3Template< float > MakeZero()
Definition Vec3.h:38
A world encapsulates a scene graph of game objects and various component managers and their component...
Definition World.h:22
virtual void Initialize()
This method is called after the constructor. A derived type can override this method to do initializa...
Definition WorldModule.h:98
virtual void Deinitialize()
This method is called before the destructor. A derived type can override this method to do deinitiali...
Definition WorldModule.h:101
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
A handle to a component.
Definition Declarations.h:138
Definition RenderData.h:116
Definition UpdateLocalBoundsMessage.h:9
Definition ProcPlacementComponent.h:100
Definition Declarations.h:280
Definition ProcPlacementComponent.h:167
These events may be sent by a specific plResource or by the plResourceManager.
Definition Declarations.h:22
Default enum for returning failure or success, instead of using a bool.
Definition Types.h:54
Definition WorldModule.h:33