ezEngine  Milestone 7
WorldData.h
1 #pragma once
2 
3 #include <Foundation/Communication/MessageQueue.h>
4 #include <Foundation/Containers/HashTable.h>
5 #include <Foundation/Containers/IdTable.h>
6 
7 #include <Foundation/Memory/BlockStorage.h>
9 
10 #include <Foundation/Threading/DelegateTask.h>
11 
12 #include <Foundation/Types/UniquePtr.h>
13 
14 #include <Core/World/CoordinateSystem.h>
15 #include <Core/World/GameObject.h>
16 
17 namespace ezInternal
18 {
19  class EZ_CORE_DLL WorldData
20  {
21  friend class ::ezWorld;
22  friend class ::ezComponentManagerBase;
23 
24  WorldData(const char* szWorldName);
25  ~WorldData();
26 
27  ezHashedString m_sName;
28  ezProxyAllocator m_Allocator;
29  ezLocalAllocatorWrapper m_AllocatorWrapper;
30  ezInternal::WorldLargeBlockAllocator m_BlockAllocator;
31 
32  enum
33  {
36  };
37 
38  // object storage
41  ObjectStorage m_ObjectStorage;
42 
44 
45  // hierarchy structures
46  struct Hierarchy
47  {
50 
52  };
53 
55  {
56  enum Enum
57  {
58  Static,
59  Dynamic,
60  COUNT
61  };
62  };
63 
64  Hierarchy m_Hierarchies[HierarchyType::COUNT];
65 
66  ezUInt32 CreateTransformationData(const ezBitflags<ezObjectFlags>& objectFlags, ezUInt32 uiHierarchyLevel,
67  ezGameObject::TransformationData*& out_pData);
68 
69  void DeleteTransformationData(const ezBitflags<ezObjectFlags>& objectFlags, ezUInt32 uiHierarchyLevel,
70  ezUInt32 uiIndex);
71 
72  template <typename VISITOR>
73  static bool TraverseHierarchyLevel(Hierarchy::DataBlockArray& blocks, void* pUserData = nullptr);
74 
76  void TraverseBreadthFirst(VisitorFunc& func);
77  void TraverseDepthFirst(VisitorFunc& func);
78  static bool TraverseObjectDepthFirst(ezGameObject* pObject, VisitorFunc& func);
79 
80  static void UpdateGlobalTransform(ezGameObject::TransformationData* pData, float fInvDeltaSeconds);
81  static void UpdateGlobalTransformWithParent(ezGameObject::TransformationData* pData, float fInvDeltaSeconds);
82 
83  void UpdateGlobalTransforms();
84 
85  // game object lookups
87  //ezHashTable<ezUInt64, ezGameObjectId, ezHashHelper<ezUInt64>, ezLocalAllocatorWrapper> m_PersistentToInternalTable;
88 
89  // component manager
91 
93 
96  {
98 
99  UpdateFunction m_Function;
100  const char* m_szFunctionName;
101  ezUInt32 m_uiGranularity;
102  };
103 
104  struct UpdateTask : public ezTask
105  {
106  virtual void Execute() override;
107 
108  UpdateFunction m_Function;
109  ezUInt32 m_uiStartIndex;
110  ezUInt32 m_uiCount;
111  };
112 
113  ezDynamicArray<RegisteredUpdateFunction, ezLocalAllocatorWrapper> m_UpdateFunctions[ezComponentManagerBase::UpdateFunctionDesc::PHASE_COUNT];
115 
117 
118  ezUniquePtr<ezCoordinateSystemProvider> m_pCoordinateSystemProvider;
119 
121  {
122  ezGameObjectHandle m_ReceiverObject;
123  ezObjectMsgRouting::Enum m_Routing;
124  ezTime m_Due;
125  };
126 
128  MessageQueue m_MessageQueues[ezObjectMsgQueueType::COUNT];
129  MessageQueue m_TimedMessageQueues[ezObjectMsgQueueType::COUNT];
130 
131  ezThreadID m_WriteThreadID;
132  ezInt32 m_iWriteCounter;
133  mutable ezAtomicInteger32 m_iReadCounter;
134 
135  public:
137  {
138  public:
139  void Acquire();
140  void Release();
141 
142  private:
143  friend class ::ezInternal::WorldData;
144 
145  ReadMarker(const WorldData& data);
146  const WorldData& m_Data;
147  };
148 
150  {
151  public:
152  void Acquire();
153  void Release();
154 
155  private:
156  friend class ::ezInternal::WorldData;
157 
158  WriteMarker(WorldData& data);
159  WorldData& m_Data;
160  };
161 
162  private:
163  mutable ReadMarker m_ReadMarker;
164  WriteMarker m_WriteMarker;
165 
166  void* m_pUserData;
167  };
168 }
169 
170 #include <Core/World/Implementation/WorldData_inl.h>
171