Fixed per-class thread safety

This commit is contained in:
Lynix
2012-05-08 08:20:57 +02:00
parent 45f3fc4e28
commit e91cde657b
44 changed files with 90 additions and 145 deletions

View File

@@ -9,6 +9,9 @@
#include <Nazara/Core/String.hpp>
#define NAZARA_CLASS_MATRIX4
#include <Nazara/Math/ThreadSafety.hpp>
template<typename T> class NzEulerAngles;
template<typename T> class NzQuaternion;
template<typename T> class NzVector2;
@@ -51,6 +54,7 @@ template<typename T> class NzMatrix4
template<typename U> void Set(const NzMatrix4<U>& matrix);
void SetIdentity();
void SetLookAt(const NzVector3<T>& eye, const NzVector3<T>& center, const NzVector3<T>& up);
void SetOrtho(T left, T top, T width, T height, T zNear = -1.0, T zFar = 1.0);
void SetPerspective(T angle, T ratio, T zNear, T zFar);
void SetRotation(const NzQuaternion<T>& rotation);
void SetScale(const NzVector3<T>& scale);
@@ -84,6 +88,7 @@ template<typename T> class NzMatrix4
NzMatrix4& operator*=(T scalar);
static NzMatrix4 LookAt(const NzVector3<T>& eye, const NzVector3<T>& center, const NzVector3<T>& up);
static NzMatrix4 Ortho(T left, T top, T width, T height, T zNear = -1.0, T zFar = 1.0);
static NzMatrix4 Perspective(T angle, T ratio, T zNear, T zFar);
static NzMatrix4 Rotate(const NzQuaternion<T>& rotation);
static NzMatrix4 Scale(const NzVector3<T>& scale);
@@ -96,10 +101,10 @@ template<typename T> class NzMatrix4
{
}
T m11, m12, m13, m14,
m21, m22, m23, m24,
m31, m32, m33, m34,
m41, m42, m43, m44;
T m11, m12, m13, m14;
T m21, m22, m23, m24;
T m31, m32, m33, m34;
T m41, m42, m43, m44;
unsigned int refCount;
@@ -118,6 +123,8 @@ template<typename T> std::ostream& operator<<(std::ostream& out, const NzMatrix4
typedef NzMatrix4<double> NzMatrix4d;
typedef NzMatrix4<float> NzMatrix4f;
#undef NAZARA_CLASS_MATRIX4
#include <Nazara/Math/Matrix4.inl>
#endif // NAZARA_MATRIX4_HPP

View File

@@ -14,6 +14,9 @@
#include <cstring>
#include <limits>
#include <stdexcept>
#define NAZARA_CLASS_MATRIX4
#include <Nazara/Math/ThreadSafety.hpp>
#include <Nazara/Core/Debug.hpp>
template<typename T>
@@ -289,6 +292,22 @@ void NzMatrix4<T>::SetIdentity()
0.0, 0.0, 0.0, 1.0);
}
template<typename T>
void NzMatrix4<T>::SetOrtho(T left, T top, T width, T height, T zNear, T zFar)
{
#if NAZARA_MATH_MATRIX_COLUMN_MAJOR
Set(2.0/(width-left), 0.0, 0.0, -(width+left)/(width-left),
0.0, 2.0/(top-height), 0.0, -(top+height)/(top-height),
0.0, 0.0, -2.0/(zFar-zNear), -(zFar+zNear)/(zFar-zNear),
0.0, 0.0, 0.0, 1.0);
#else
Set(2.0/(width-left), 0.0, 0.0, 0.0,
0.0, 2.0/(top-height), 0.0, 0.0,
0.0, 0.0, -2.0/(zFar-zNear), 0.0,
-(width+left)/(width-left), -(top+height)/(top-height), -(zFar+zNear)/(zFar-zNear), 1.0);
#endif
}
template<typename T>
void NzMatrix4<T>::SetLookAt(const NzVector3<T>& eye, const NzVector3<T>& center, const NzVector3<T>& up)
{
@@ -320,7 +339,7 @@ void NzMatrix4<T>::SetPerspective(T angle, T ratio, T zNear, T zFar)
angle = NzDegreeToRadian(angle/2);
#endif
T f = 1 / std::tan(angle);
auto f = 1 / std::tan(angle);
#if NAZARA_MATH_MATRIX_COLUMN_MAJOR
Set(f / ratio, 0.0, 0.0, 0.0,
@@ -713,6 +732,15 @@ NzMatrix4<T> NzMatrix4<T>::LookAt(const NzVector3<T>& eye, const NzVector3<T>& c
return matrix;
}
template<typename T>
NzMatrix4<T> NzMatrix4<T>::Ortho(T left, T top, T width, T height, T zNear, T zFar)
{
NzMatrix4 matrix;
matrix.SetOrtho(left, top, width, height, zNear, zFar);
return matrix;
}
template<typename T>
NzMatrix4<T> NzMatrix4<T>::Perspective(T angle, T ratio, T zNear, T zFar)
{
@@ -789,5 +817,6 @@ void NzMatrix4<T>::ReleaseMatrix()
m_sharedMatrix = nullptr;
}
#undef NAZARA_MATRIX4_INL
#include <Nazara/Core/DebugOff.hpp>

View File

@@ -15,8 +15,8 @@
#undef NazaraNamedLock
#if NAZARA_MATH_THREADSAFE && (\
(NAZARA_THREADSAFETY_MATRIX3 && (defined(NAZARA_MATRIX3) || defined(NAZARA_MATRIX3_CPP))) || \
(NAZARA_THREADSAFETY_MATRIX4 && (defined(NAZARA_MATRIX4) || defined(NAZARA_MATRIX4_CPP))))
(NAZARA_THREADSAFETY_MATRIX3 && (defined(NAZARA_MATRIX3) || defined(NAZARA_MATRIX3_INL))) || \
(NAZARA_THREADSAFETY_MATRIX4 && (defined(NAZARA_MATRIX4) || defined(NAZARA_MATRIX4_INL))))
#include <Nazara/Core/Lock.hpp>
#include <Nazara/Core/Mutex.hpp>