Plasma Engine  2.0
Loading...
Searching...
No Matches
WorldModule.h
1#pragma once
2
3#include <Core/World/Declarations.h>
4#include <Foundation/Configuration/Startup.h>
5#include <Foundation/Strings/HashedString.h>
6
7class plWorld;
8
9class PL_CORE_DLL plWorldModule : public plReflectedClass
10{
11 PL_ADD_DYNAMIC_REFLECTION(plWorldModule, plReflectedClass);
12
13protected:
14 plWorldModule(plWorld* pWorld);
15 virtual ~plWorldModule();
16
17public:
19 plWorld* GetWorld();
20
22 const plWorld* GetWorld() const;
23
25 plUInt32 GetWorldIndex() const;
26
27protected:
28 friend class plWorld;
29 friend class plInternal::WorldData;
30 friend class plMemoryUtils;
31
33 {
34 plUInt32 m_uiFirstComponentIndex = 0;
35 plUInt32 m_uiComponentCount = 0;
36 };
37
40
43 {
44 struct Phase
45 {
46 using StorageType = plUInt8;
47
48 enum Enum
49 {
50 PreAsync,
51 Async,
52 PostAsync,
53 PostTransform,
54 COUNT,
55
56 Default = PreAsync
57 };
58 };
59
60 UpdateFunctionDesc(const UpdateFunction& function, plStringView sFunctionName)
61 : m_Function(function)
62 {
63 m_sFunctionName.Assign(sFunctionName);
64 }
65
73 bool m_bOnlyUpdateWhenSimulating = false;
74 plUInt16 m_uiGranularity = 0;
76 float m_fPriority = 0.0f;
77 };
78
80 void RegisterUpdateFunction(const UpdateFunctionDesc& desc);
81
84 void DeregisterUpdateFunction(const UpdateFunctionDesc& desc);
85
87 plAllocator* GetAllocator();
88
90 plInternal::WorldLargeBlockAllocator* GetBlockAllocator();
91
93 bool GetWorldSimulationEnabled() const;
94
95protected:
98 virtual void Initialize() {}
99
101 virtual void Deinitialize() {}
102
105 virtual void OnSimulationStarted() {}
106
108 virtual void WorldClear() {}
109
110 plWorld* m_pWorld;
111};
112
114
116class PL_CORE_DLL plWorldModuleFactory
117{
118public:
119 static plWorldModuleFactory* GetInstance();
120
121 template <typename ModuleType, typename RTTIType>
122 plWorldModuleTypeId RegisterWorldModule();
123
125 plWorldModuleTypeId GetTypeId(const plRTTI* pRtti);
126
128 plWorldModule* CreateWorldModule(plUInt16 uiTypeId, plWorld* pWorld);
129
134 void RegisterInterfaceImplementation(plStringView sInterfaceName, plStringView sImplementationName);
135
136private:
137 PL_MAKE_SUBSYSTEM_STARTUP_FRIEND(Core, WorldModuleFactory);
138
139 using CreatorFunc = plWorldModule* (*)(plAllocator*, plWorld*);
140
142 plWorldModuleTypeId RegisterWorldModule(const plRTTI* pRtti, CreatorFunc creatorFunc);
143
144 static void PluginEventHandler(const plPluginEvent& EventData);
145 void FillBaseTypeIds();
146 void ClearUnloadedTypeToIDs();
147 void AdjustBaseTypeId(const plRTTI* pParentRtti, const plRTTI* pRtti, plUInt16 uiParentTypeId);
148
150
151 struct CreatorFuncContext
152 {
153 PL_DECLARE_POD_TYPE();
154
155 CreatorFunc m_Func;
156 const plRTTI* m_pRtti;
157 };
158
160
161 plHashTable<plString, plString> m_InterfaceImplementations;
162};
163
165#define PL_DECLARE_WORLD_MODULE() \
166public: \
167 static PL_ALWAYS_INLINE plWorldModuleTypeId TypeId() { return s_TypeId; } \
168 \
169private: \
170 static plWorldModuleTypeId s_TypeId;
171
173#define PL_IMPLEMENT_WORLD_MODULE(moduleType) \
174 plWorldModuleTypeId moduleType::s_TypeId = plWorldModuleFactory::GetInstance()->RegisterWorldModule<moduleType, moduleType>();
175
177#define PL_CREATE_MODULE_UPDATE_FUNCTION_DESC(func, instance) plWorldModule::UpdateFunctionDesc(plWorldModule::UpdateFunction(&func, instance), #func)
178
179#include <Core/World/Implementation/WorldModule_inl.h>
Base class for all memory allocators.
Definition Allocator.h:23
Definition DynamicArray.h:81
Definition HashTable.h:333
This class is optimized to take nearly no memory (sizeof(void*)) and to allow very fast checks whethe...
Definition HashedString.h:25
A hybrid array uses in-place storage to handle the first few elements without any allocation....
Definition HybridArray.h:12
Definition WorldData.h:18
This class provides functions to work on raw memory.
Definition MemoryUtils.h:26
This class holds information about reflected types. Each instance represents one type that is known t...
Definition RTTI.h:30
All classes that should be dynamically reflectable, need to be derived from this base class.
Definition DynamicRTTI.h:86
plStringView represent a read-only sub-string of a larger string, as it can store a dedicated string ...
Definition StringView.h:34
A world encapsulates a scene graph of game objects and various component managers and their component...
Definition World.h:22
Helper class to get component type ids and create new instances of world modules from rtti.
Definition WorldModule.h:117
Definition WorldModule.h:10
virtual void OnSimulationStarted()
This method is called at the start of the next world update when the world is simulated....
Definition WorldModule.h:105
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
virtual void WorldClear()
Called by plWorld::Clear(). Can be used to clear cached data when a world is completely cleared of ob...
Definition WorldModule.h:108
A custom enum implementation that allows to define the underlying storage type to control its memory ...
Definition Enum.h:37
The data that is broadcast whenever a plugin is (un-) loaded.
Definition Plugin.h:11
Definition WorldModule.h:33
Definition WorldModule.h:45
Description of an update function that can be registered at the world.
Definition WorldModule.h:43
plHybridArray< plHashedString, 4 > m_DependsOn
Definition WorldModule.h:69
plHashedString m_sFunctionName
Definition WorldModule.h:67
UpdateFunction m_Function
Delegate to the actual update function.
Definition WorldModule.h:66
plEnum< Phase > m_Phase
Definition WorldModule.h:71