ezEngine  Milestone 7
WorldData_inl.h
1 
2 namespace ezInternal
3 {
4 
5  // static
6  template <typename VISITOR>
7  EZ_FORCE_INLINE bool WorldData::TraverseHierarchyLevel(Hierarchy::DataBlockArray& blocks, void* pUserData /* = nullptr*/)
8  {
9  for (ezUInt32 uiBlockIndex = 0; uiBlockIndex < blocks.GetCount(); ++uiBlockIndex)
10  {
11  WorldData::Hierarchy::DataBlock& block = blocks[uiBlockIndex];
12  ezGameObject::TransformationData* pCurrentData = block.m_pData;
13  ezGameObject::TransformationData* pEndData = block.m_pData + block.m_uiCount;
14 
15  while (pCurrentData < pEndData)
16  {
17  if (!VISITOR::Visit(pCurrentData, pUserData))
18  return false;
19 
20  ++pCurrentData;
21  }
22  }
23 
24  return true;
25  }
26 
27  // static
28  EZ_FORCE_INLINE void WorldData::UpdateGlobalTransform(ezGameObject::TransformationData* pData, float fInvDeltaSeconds)
29  {
30  const ezVec3 vOldWorldPos = pData->m_globalTransform.m_vPosition;
31  pData->UpdateGlobalTransform();
32  pData->UpdateGlobalBounds();
33  pData->m_velocity = ((pData->m_globalTransform.m_vPosition - vOldWorldPos) * fInvDeltaSeconds).GetAsDirectionVec4();
34  }
35 
36  // static
37  EZ_FORCE_INLINE void WorldData::UpdateGlobalTransformWithParent(ezGameObject::TransformationData* pData, float fInvDeltaSeconds)
38  {
39  const ezVec3 vOldWorldPos = pData->m_globalTransform.m_vPosition;
40  pData->UpdateGlobalTransformWithParent();
41  pData->UpdateGlobalBounds();
42  pData->m_velocity = ((pData->m_globalTransform.m_vPosition - vOldWorldPos) * fInvDeltaSeconds).GetAsDirectionVec4();
43  }
44 
46 
47  EZ_FORCE_INLINE WorldData::ReadMarker::ReadMarker(const WorldData& data) : m_Data(data)
48  {
49  }
50 
51  EZ_FORCE_INLINE void WorldData::ReadMarker::Acquire()
52  {
53  EZ_ASSERT_DEV(m_Data.m_WriteThreadID == (ezThreadID)0 || m_Data.m_WriteThreadID == ezThreadUtils::GetCurrentThreadID(),
54  "World '%s' cannot be marked for reading because it is already marked for writing by another thread.", m_Data.m_sName.GetData());
55  m_Data.m_iReadCounter.Increment();
56  }
57 
58  EZ_FORCE_INLINE void WorldData::ReadMarker::Release()
59  {
60  m_Data.m_iReadCounter.Decrement();
61  }
62 
64 
65  EZ_FORCE_INLINE WorldData::WriteMarker::WriteMarker(WorldData& data) : m_Data(data)
66  {
67  }
68 
69  EZ_FORCE_INLINE void WorldData::WriteMarker::Acquire()
70  {
71  // already locked by this thread?
72  if (m_Data.m_WriteThreadID != ezThreadUtils::GetCurrentThreadID())
73  {
74  EZ_ASSERT_DEV(m_Data.m_iReadCounter == 0, "World '%s' cannot be marked for writing because it is already marked for reading.", m_Data.m_sName.GetData());
75  EZ_ASSERT_DEV(m_Data.m_WriteThreadID == (ezThreadID)0, "World '%s' cannot be marked for writing because it is already marked for writing by another thread.", m_Data.m_sName.GetData());
76 
77  m_Data.m_WriteThreadID = ezThreadUtils::GetCurrentThreadID();
78  m_Data.m_iReadCounter.Increment(); // allow reading as well
79  }
80 
81  m_Data.m_iWriteCounter++;
82  }
83 
84  EZ_FORCE_INLINE void WorldData::WriteMarker::Release()
85  {
86  m_Data.m_iWriteCounter--;
87 
88  if (m_Data.m_iWriteCounter == 0)
89  {
90  m_Data.m_iReadCounter.Decrement();
91  m_Data.m_WriteThreadID = (ezThreadID)0;
92  }
93  }
94 
95 }