diff --git a/Eule/Matrix4x4.cpp b/Eule/Matrix4x4.cpp index c8bb58a..1dbb1e4 100644 --- a/Eule/Matrix4x4.cpp +++ b/Eule/Matrix4x4.cpp @@ -2,7 +2,7 @@ #include "Vector3.h" #include "Math.h" -//#define _EULE_NO_INTRINSICS_ +#define _EULE_NO_INTRINSICS_ #ifndef _EULE_NO_INTRINSICS_ #include #endif diff --git a/Eule/Quaternion.cpp b/Eule/Quaternion.cpp index 56dda36..55e3504 100644 --- a/Eule/Quaternion.cpp +++ b/Eule/Quaternion.cpp @@ -1,7 +1,7 @@ #include "Quaternion.h" #include "Constants.h" -//#define _EULE_NO_INTRINSICS_ +#define _EULE_NO_INTRINSICS_ #ifndef _EULE_NO_INTRINSICS_ #include #endif @@ -174,6 +174,8 @@ bool Quaternion::operator!= (const Quaternion& q) const Quaternion Quaternion::Inverse() const { + const std::lock_guard lock(lock_inverseCache); + if (!isCacheUpToDate_inverse) { cache_inverse = (Conjugate() * (1.0 / v.SqrMagnitude())).v; @@ -214,6 +216,8 @@ Vector3d Quaternion::RotateVector(const Vector3d& vec) const Vector3d Quaternion::ToEulerAngles() const { + const std::lock_guard lock(lock_eulerCache); + if (!isCacheUpToDate_euler) { Vector3d euler; @@ -245,6 +249,8 @@ Vector3d Quaternion::ToEulerAngles() const Matrix4x4 Quaternion::ToRotationMatrix() const { + const std::lock_guard lock(lock_matrixCache); + if (!isCacheUpToDate_matrix) { Matrix4x4 m; @@ -328,7 +334,7 @@ namespace Eule return os; } - std::wostream& operator<<(std::wostream& os, const Quaternion& q) + std::wostream& operator<< (std::wostream& os, const Quaternion& q) { os << L"[" << q.v << L"]"; return os; diff --git a/Eule/Quaternion.h b/Eule/Quaternion.h index 8af70c2..e36fe57 100644 --- a/Eule/Quaternion.h +++ b/Eule/Quaternion.h @@ -2,6 +2,7 @@ #include "Vector3.h" #include "Vector4.h" #include "Matrix4x4.h" +#include namespace Eule { @@ -95,5 +96,9 @@ namespace Eule mutable bool isCacheUpToDate_inverse = false; mutable Vector4d cache_inverse; + // Mutexes for thread-safe caching + mutable std::mutex lock_eulerCache; + mutable std::mutex lock_matrixCache; + mutable std::mutex lock_inverseCache; }; } diff --git a/Eule/Vector2.cpp b/Eule/Vector2.cpp index dcfb857..7b844ab 100644 --- a/Eule/Vector2.cpp +++ b/Eule/Vector2.cpp @@ -2,7 +2,7 @@ #include "Math.h" #include -//#define _EULE_NO_INTRINSICS_ +#define _EULE_NO_INTRINSICS_ #ifndef _EULE_NO_INTRINSICS_ #include #endif diff --git a/Eule/Vector3.cpp b/Eule/Vector3.cpp index 1cb9e62..360deb6 100644 --- a/Eule/Vector3.cpp +++ b/Eule/Vector3.cpp @@ -2,7 +2,7 @@ #include "Math.h" #include -//#define _EULE_NO_INTRINSICS_ +#define _EULE_NO_INTRINSICS_ #ifndef _EULE_NO_INTRINSICS_ #include #endif diff --git a/Eule/Vector4.cpp b/Eule/Vector4.cpp index 850c3bb..941d68f 100644 --- a/Eule/Vector4.cpp +++ b/Eule/Vector4.cpp @@ -2,7 +2,7 @@ #include "Math.h" #include -//#define _EULE_NO_INTRINSICS_ +#define _EULE_NO_INTRINSICS_ #ifndef _EULE_NO_INTRINSICS_ #include #endif