ezEngine  Milestone 7
World.h
1 #pragma once
2 
3 #include <Core/World/Implementation/SpatialData.h>
4 #include <Core/World/Implementation/WorldData.h>
5 
18 class EZ_CORE_DLL ezWorld
19 {
20 public:
22  ezWorld(const char* szWorldName);
23  ~ezWorld();
24 
26  const char* GetName() const;
27 
29  ezGameObjectHandle CreateObject(const ezGameObjectDesc& desc);
30 
32  ezGameObjectHandle CreateObject(const ezGameObjectDesc& desc, ezGameObject*& out_pObject);
33 
35  void DeleteObject(const ezGameObjectHandle& object);
36 
38  void DeleteObjectDelayed(const ezGameObjectHandle& object);
39 
41  bool IsValidObject(const ezGameObjectHandle& object) const;
42 
44  bool TryGetObject(const ezGameObjectHandle& object, ezGameObject*& out_pObject) const;
45 
47  // bool TryGetObjectWithName(const char* szName, ezGameObject*& out_pObject) const;
48 
49 
51  ezUInt32 GetObjectCount() const;
52 
54  ezInternal::WorldData::ObjectStorage::Iterator GetObjects();
55 
57  ezInternal::WorldData::ObjectStorage::ConstIterator GetObjects() const;
58 
62 
63  enum TraversalMethod
64  {
65  BreadthFirst,
66  DepthFirst
67  };
68 
70  void Traverse(VisitorFunc visitorFunc, TraversalMethod method = DepthFirst);
71 
72 
74  template <typename ManagerType>
75  ManagerType* CreateComponentManager();
76 
78  template <typename ManagerType>
79  void DeleteComponentManager();
80 
82  template <typename ManagerType>
83  ManagerType* GetComponentManager() const;
84 
86  ezComponentManagerBase* GetComponentManager(const ezRTTI* pRtti) const;
87 
89  bool IsValidComponent(const ezComponentHandle& component) const;
90 
92  template <typename ComponentType>
93  bool TryGetComponent(const ezComponentHandle& component, ComponentType*& out_pComponent) const;
94 
95 
97  void SendMessage(const ezGameObjectHandle& receiverObject, ezMessage& msg,
98  ezObjectMsgRouting::Enum routing = ezObjectMsgRouting::Default);
99 
101  void PostMessage(const ezGameObjectHandle& receiverObject, ezMessage& msg,
102  ezObjectMsgQueueType::Enum queueType, ezObjectMsgRouting::Enum routing = ezObjectMsgRouting::Default);
103 
105  void PostMessage(const ezGameObjectHandle& receiverObject, ezMessage& msg,
106  ezObjectMsgQueueType::Enum queueType, ezTime delay, ezObjectMsgRouting::Enum routing = ezObjectMsgRouting::Default);
107 
108 
111  void Update();
112 
114  ezTask* GetUpdateTask();
115 
116 
118  const ezInternal::SpatialData& GetSpatialData() const;
119 
120 
124  void GetCoordinateSystem(const ezVec3& vGlobalPosition, ezCoordinateSystem& out_CoordinateSystem) const;
125 
127  void SetCoordinateSystemProvider(ezUniquePtr<ezCoordinateSystemProvider>&& pProvider);
128 
130  ezCoordinateSystemProvider* GetCoordinateSystemProvider() const;
131 
132 
134  ezAllocatorBase* GetAllocator();
135 
137  ezInternal::WorldLargeBlockAllocator* GetBlockAllocator();
138 
140  ezInternal::WorldData::ReadMarker& GetReadMarker() const;
141 
143  ezInternal::WorldData::WriteMarker& GetWriteMarker();
144 
145 
147  void SetUserData(void* pUserData);
148 
150  void* GetUserData() const;
151 
152 public:
154  static ezUInt32 GetWorldCount();
155 
157  static ezWorld* GetWorld(ezUInt32 uiIndex);
158 
159 private:
160  friend class ezGameObject;
161  friend class ezComponentManagerBase;
162 
163  void CheckForReadAccess() const;
164  void CheckForWriteAccess() const;
165 
166  ezGameObject* GetObjectUnchecked(ezUInt32 uiIndex) const;
167 
168  void SetParent(ezGameObject* pObject, ezGameObject* pNewParent);
169  void LinkToParent(ezGameObject* pObject);
170  void UnlinkFromParent(ezGameObject* pObject);
171 
172  void ProcessQueuedMessages(ezObjectMsgQueueType::Enum queueType);
173 
175  ezResult RegisterUpdateFunctionWithDependency(const ezComponentManagerBase::UpdateFunctionDesc& desc, bool bInsertAsUnresolved);
177  void DeregisterUpdateFunctions(ezComponentManagerBase* pManager);
178 
179  void UpdateFromThread();
180  void UpdateSynchronous(const ezArrayPtr<ezInternal::WorldData::RegisteredUpdateFunction>& updateFunctions);
181  void UpdateAsynchronous();
182  void DeleteDeadObjects();
183  void DeleteDeadComponents();
184 
185  void PatchHierarchyData(ezGameObject* pObject);
186 
187  ezProfilingId m_UpdateProfilingID;
188  ezDelegateTask<void> m_UpdateTask;
189 
190  ezInternal::WorldData m_Data;
191  typedef ezInternal::WorldData::ObjectStorage::Entry ObjectStorageEntry;
192 
193  typedef ezInternal::WorldData::QueuedMsgMetaData QueuedMsgMetaData;
194 
195  ezInternal::SpatialData m_SpatialData;
196 
197  ezUInt32 m_uiIndex;
198  static ezStaticArray<ezWorld*, 64> s_Worlds;
199 };
200 
201 #include <Core/World/Implementation/World_inl.h>
202