Implemented COW into NzMatrix4; Optimized NzString COW

This commit is contained in:
Lynix
2012-05-07 13:02:07 +02:00
parent 8c420b48c3
commit 45f3fc4e28
7 changed files with 509 additions and 219 deletions

View File

@@ -24,10 +24,11 @@ template<typename T> class NzMatrix4
T r31, T r32, T r33, T r34,
T r41, T r42, T r43, T r44);
NzMatrix4(T matrix[16]);
//NzMatrix4(const NzMatrix3<T>& mat);
template<typename U> explicit NzMatrix4(const NzMatrix4<U>& mat);
NzMatrix4(const NzMatrix4& mat) = default;
~NzMatrix4() = default;
//NzMatrix4(const NzMatrix3<T>& matrix);
template<typename U> explicit NzMatrix4(const NzMatrix4<U>& matrix);
NzMatrix4(const NzMatrix4& matrix);
NzMatrix4(NzMatrix4&& matrix);
~NzMatrix4();
T GetDeterminant() const;
NzMatrix4 GetInverse() const;
@@ -44,9 +45,10 @@ template<typename T> class NzMatrix4
T r31, T r32, T r33, T r34,
T r41, T r42, T r43, T r44);
void Set(T matrix[16]);
//NzMatrix4(const NzMatrix3<T>& mat);
void Set(const NzMatrix4& mat);
template<typename U> void Set(const NzMatrix4<U>& mat);
//NzMatrix4(const NzMatrix3<T>& matrix);
void Set(const NzMatrix4& matrix);
void Set(NzMatrix4&& matrix);
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 SetPerspective(T angle, T ratio, T zNear, T zFar);
@@ -69,13 +71,16 @@ template<typename T> class NzMatrix4
T& operator()(unsigned int x, unsigned int y);
const T& operator()(unsigned int x, unsigned int y) const;
NzMatrix4 operator*(const NzMatrix4& mat) const;
NzMatrix4& operator=(const NzMatrix4& matrix);
NzMatrix4& operator=(NzMatrix4&& matrix);
NzMatrix4 operator*(const NzMatrix4& matrix) const;
NzVector2<T> operator*(const NzVector2<T>& vector) const;
NzVector3<T> operator*(const NzVector3<T>& vector) const;
NzVector4<T> operator*(const NzVector4<T>& vector) const;
NzMatrix4 operator*(T scalar) const;
NzMatrix4& operator*=(const NzMatrix4& mat);
NzMatrix4& operator*=(const NzMatrix4& matrix);
NzMatrix4& operator*=(T scalar);
static NzMatrix4 LookAt(const NzVector3<T>& eye, const NzVector3<T>& center, const NzVector3<T>& up);
@@ -84,13 +89,31 @@ template<typename T> class NzMatrix4
static NzMatrix4 Scale(const NzVector3<T>& scale);
static NzMatrix4 Translate(const NzVector3<T>& translation);
T m11, m12, m13, m14,
m21, m22, m23, m24,
m31, m32, m33, m34,
m41, m42, m43, m44;
struct SharedMatrix
{
SharedMatrix() : // Vivement GCC 4.7 sur Windows
refCount(1)
{
}
T m11, m12, m13, m14,
m21, m22, m23, m24,
m31, m32, m33, m34,
m41, m42, m43, m44;
unsigned int refCount;
NazaraMutex(mutex)
};
private:
void EnsureOwnership();
void ReleaseMatrix();
SharedMatrix* m_sharedMatrix;
};
template<typename T> std::ostream& operator<<(std::ostream& out, const NzMatrix4<T>& mat);
template<typename T> std::ostream& operator<<(std::ostream& out, const NzMatrix4<T>& matrix);
typedef NzMatrix4<double> NzMatrix4d;
typedef NzMatrix4<float> NzMatrix4f;