@@ -36,6 +36,7 @@ namespace wi::scene
3636
3737 XMFLOAT3 TransformComponent::GetPosition () const
3838 {
39+ std::shared_lock lock (_mutex);
3940 return wi::math::GetPosition (world);
4041 }
4142 XMFLOAT4 TransformComponent::GetRotation () const
@@ -52,22 +53,29 @@ namespace wi::scene
5253 }
5354 XMVECTOR TransformComponent::GetPositionV () const
5455 {
56+ std::shared_lock lock (_mutex);
5557 return XMLoadFloat3 ((XMFLOAT3 *)&world._41 );
5658 }
5759 XMVECTOR TransformComponent::GetRotationV () const
5860 {
61+ std::shared_lock lock (_mutex);
5962 XMVECTOR S, R, T;
6063 XMMatrixDecompose (&S, &R, &T, XMLoadFloat4x4 (&world));
6164 return R;
6265 }
6366 XMVECTOR TransformComponent::GetScaleV () const
6467 {
68+ std::shared_lock lock (_mutex);
6569 XMVECTOR S, R, T;
6670 XMMatrixDecompose (&S, &R, &T, XMLoadFloat4x4 (&world));
6771 return S;
6872 }
6973 XMMATRIX TransformComponent::GetLocalMatrix () const
7074 {
75+ std::shared_lock lock (_mutex);
76+ return GetLocalMatrixNoLock ();
77+ }
78+ XMMATRIX TransformComponent::GetLocalMatrixNoLock () const {
7179 XMVECTOR S_local = XMLoadFloat3 (&scale_local);
7280 XMVECTOR R_local = XMLoadFloat4 (&rotation_local);
7381 XMVECTOR T_local = XMLoadFloat3 (&translation_local);
@@ -78,33 +86,40 @@ namespace wi::scene
7886 }
7987 XMFLOAT3 TransformComponent::GetForward () const
8088 {
89+ std::shared_lock lock (_mutex);
8190 return wi::math::GetForward (world);
8291 }
8392 XMFLOAT3 TransformComponent::GetUp () const
8493 {
94+ std::shared_lock lock (_mutex);
8595 return wi::math::GetUp (world);
8696 }
8797 XMFLOAT3 TransformComponent::GetRight () const
8898 {
99+ std::shared_lock lock (_mutex);
89100 return wi::math::GetRight (world);
90101 }
91102 XMVECTOR TransformComponent::GetForwardV () const
92103 {
104+ std::shared_lock lock (_mutex);
93105 XMFLOAT3 v = wi::math::GetForward (world);
94106 return XMLoadFloat3 (&v);
95107 }
96108 XMVECTOR TransformComponent::GetUpV () const
97109 {
110+ std::shared_lock lock (_mutex);
98111 XMFLOAT3 v = wi::math::GetUp (world);
99112 return XMLoadFloat3 (&v);
100113 }
101114 XMVECTOR TransformComponent::GetRightV () const
102115 {
116+ std::shared_lock lock (_mutex);
103117 XMFLOAT3 v = wi::math::GetRight (world);
104118 return XMLoadFloat3 (&v);
105119 }
106120 void TransformComponent::GetPositionRotationScale (XMFLOAT3 & position, XMFLOAT4 & rotation, XMFLOAT3 & scale) const
107121 {
122+ std::shared_lock lock (_mutex);
108123 XMVECTOR S, R, T;
109124 XMMatrixDecompose (&S, &R, &T, XMLoadFloat4x4 (&world));
110125 XMStoreFloat3 (&position, T);
@@ -115,21 +130,24 @@ namespace wi::scene
115130 {
116131 if (IsDirty ())
117132 {
133+ std::unique_lock lock (_mutex);
118134 SetDirty (false );
119135
120- XMStoreFloat4x4 (&world, GetLocalMatrix ());
136+ XMStoreFloat4x4 (&world, GetLocalMatrixNoLock ());
121137 }
122138 }
123139 void TransformComponent::UpdateTransform_Parented (const TransformComponent& parent)
124140 {
125- XMMATRIX W = GetLocalMatrix ();
141+ std::unique_lock lock (_mutex);
142+ XMMATRIX W = GetLocalMatrixNoLock ();
126143 XMMATRIX W_parent = XMLoadFloat4x4 (&parent.world );
127144 W = W * W_parent;
128145
129146 XMStoreFloat4x4 (&world, W);
130147 }
131148 void TransformComponent::ApplyTransform ()
132149 {
150+ std::unique_lock lock (_mutex);
133151 SetDirty ();
134152
135153 XMVECTOR S, R, T;
@@ -140,20 +158,23 @@ namespace wi::scene
140158 }
141159 void TransformComponent::ClearTransform ()
142160 {
161+ std::unique_lock lock (_mutex);
143162 SetDirty ();
144163 scale_local = XMFLOAT3 (1 , 1 , 1 );
145164 rotation_local = XMFLOAT4 (0 , 0 , 0 , 1 );
146165 translation_local = XMFLOAT3 (0 , 0 , 0 );
147166 }
148167 void TransformComponent::Translate (const XMFLOAT3 & value)
149168 {
169+ std::unique_lock lock (_mutex);
150170 SetDirty ();
151171 translation_local.x += value.x ;
152172 translation_local.y += value.y ;
153173 translation_local.z += value.z ;
154174 }
155175 void TransformComponent::Translate (const XMVECTOR & value)
156176 {
177+ std::unique_lock lock (_mutex);
157178 XMFLOAT3 translation;
158179 XMStoreFloat3 (&translation, value);
159180 Translate (translation);
@@ -765,7 +786,7 @@ namespace wi::scene
765786 {
766787 const XMFLOAT3 & pos = vertex_positions[i];
767788 const uint8_t wind = vertex_windweights.empty () ? 0xFF : vertex_windweights[i];
768-
789+
769790 Vertex_POS16 v;
770791 v.FromFULL (aabb, pos, wind);
771792 XMFLOAT3 p = v.GetPOS (aabb);
@@ -1977,7 +1998,7 @@ namespace wi::scene
19771998 }
19781999 size_t MeshComponent::GetMemoryUsageCPU () const
19792000 {
1980- size_t size =
2001+ size_t size =
19812002 vertex_positions.size () * sizeof (XMFLOAT3 ) +
19822003 vertex_normals.size () * sizeof (XMFLOAT3 ) +
19832004 vertex_tangents.size () * sizeof (XMFLOAT4 ) +
0 commit comments