|
From: <axl...@us...> - 2009-04-12 18:09:50
|
Revision: 209
http://hgengine.svn.sourceforge.net/hgengine/?rev=209&view=rev
Author: axlecrusher
Date: 2009-04-12 18:09:46 +0000 (Sun, 12 Apr 2009)
Log Message:
-----------
more updates to improve speed of basic math functions
Modified Paths:
--------------
Mercury2/src/MercuryMath.cpp
Mercury2/src/MercuryMath.h
Mercury2/src/MercuryMatrix.cpp
Mercury2/src/MercuryMatrix.h
Mercury2/src/RenderGraph.h
Mercury2/src/RenderableNode.cpp
Mercury2/src/TransformNode.cpp
Modified: Mercury2/src/MercuryMath.cpp
===================================================================
--- Mercury2/src/MercuryMath.cpp 2009-04-12 16:32:55 UTC (rev 208)
+++ Mercury2/src/MercuryMath.cpp 2009-04-12 18:09:46 UTC (rev 209)
@@ -65,20 +65,17 @@
void Copy4f( void * dest, const void * source )
{
- for (uint8_t i = 0; i < 4; ++i)
- ((float*)dest)[i] = ((float*)source)[i];
+ COPY<float,4>((float*)source, (float*)dest);
}
void Copy8f( void * dest, const void * source )
{
- for (uint8_t i = 0; i < 8; ++i)
- ((float*)dest)[i] = ((float*)source)[i];
+ COPY<float,8>((float*)source, (float*)dest);
}
void Copy16f( void * dest, const void * source )
{
- for (uint8_t i = 0; i < 16; ++i)
- ((float*)dest)[i] = ((float*)source)[i];
+ COPY<float,16>((float*)source, (float*)dest);
}
void MatrixMultiply4f ( const FloatRow* in1a, const FloatRow* in2a, FloatRow* outa)
Modified: Mercury2/src/MercuryMath.h
===================================================================
--- Mercury2/src/MercuryMath.h 2009-04-12 16:32:55 UTC (rev 208)
+++ Mercury2/src/MercuryMath.h 2009-04-12 18:09:46 UTC (rev 209)
@@ -16,6 +16,18 @@
#define RADDEG 57.2957795130823208767f //radian to degree
#define Q_PI 3.14159265358979323846f
+template<typename t, unsigned i>
+inline void COPY(const t* s, t*d)
+{
+ d[i-1] = s[i-1];
+ COPY<t,i-1>(s,d);
+}
+
+template<> inline void COPY<float,0>(const float* s, float* d)
+{
+ d[0] = s[0];
+}
+
#if defined(WIN32)
//In win32, sin works faster than sinf and similar functions
#define SIN( x ) float( sin ( x ) )
Modified: Mercury2/src/MercuryMatrix.cpp
===================================================================
--- Mercury2/src/MercuryMatrix.cpp 2009-04-12 16:32:55 UTC (rev 208)
+++ Mercury2/src/MercuryMatrix.cpp 2009-04-12 18:09:46 UTC (rev 209)
@@ -3,7 +3,7 @@
MercuryMatrix::MercuryMatrix()
{
- Identity();
+ *this = Identity();
}
const MercuryMatrix& MercuryMatrix::operator=(const MercuryMatrix& m)
@@ -26,14 +26,19 @@
ZeroFloatRow( m_matrix[3] );
}
-void MercuryMatrix::Identity()
+const MercuryMatrix& MercuryMatrix::Identity()
{
- const static float Identity[16] = {
- 1.0f, 0.0f, 0.0f, 0.0f,
- 0.0f, 1.0f, 0.0f, 0.0f,
- 0.0f, 0.0f, 1.0f, 0.0f,
- 0.0f, 0.0f, 0.0f, 1.0f };
- Copy16f(&m_matrix[0], Identity );
+ if (IdentityMatrix.m_matrix[0][0] != 1.0f)
+ {
+ float identity[16] = {
+ 1.0f, 0.0f, 0.0f, 0.0f,
+ 0.0f, 1.0f, 0.0f, 0.0f,
+ 0.0f, 0.0f, 1.0f, 0.0f,
+ 0.0f, 0.0f, 0.0f, 1.0f };
+ Copy16f(MercuryMatrix::IdentityMatrix.m_matrix[0], identity );
+ }
+
+ return IdentityMatrix;
}
void MercuryMatrix::Translate(float x, float y, float z)
Modified: Mercury2/src/MercuryMatrix.h
===================================================================
--- Mercury2/src/MercuryMatrix.h 2009-04-12 16:32:55 UTC (rev 208)
+++ Mercury2/src/MercuryMatrix.h 2009-04-12 18:09:46 UTC (rev 209)
@@ -15,6 +15,8 @@
///[row][column] (The internal matrix)
// float m_matrix[4][4];
FloatRow m_matrix[4];
+
+ static MercuryMatrix IdentityMatrix;
public:
MercuryMatrix();
inline MercuryMatrix(const MercuryMatrix& m) { *this = m; }
@@ -41,10 +43,9 @@
inline void Transpose() { TransposeMatrix( m_matrix ); }
void Zero();
- void Identity();
+ static const MercuryMatrix& Identity();
void Print() const;
- static MercuryMatrix IdentityMatrix;
}
#if !defined( WIN32 ) || defined( _MSC_VER )
M_ALIGN(64);
Modified: Mercury2/src/RenderGraph.h
===================================================================
--- Mercury2/src/RenderGraph.h 2009-04-12 16:32:55 UTC (rev 208)
+++ Mercury2/src/RenderGraph.h 2009-04-12 18:09:46 UTC (rev 209)
@@ -8,8 +8,14 @@
{
friend class RenderGraph;
public:
- RenderGraphEntry(const MercuryMatrix* matrix = &MercuryMatrix::IdentityMatrix, RenderableNode* node = NULL)
- :m_node(node), m_matrix(matrix)
+ RenderGraphEntry()
+ {
+ m_node = NULL;
+ m_matrix = &MercuryMatrix::Identity();
+ }
+
+ RenderGraphEntry(const MercuryMatrix* matrix, RenderableNode* node)
+ :m_node(node), m_matrix(matrix)
{}
void AddChild(RenderGraphEntry entry);
Modified: Mercury2/src/RenderableNode.cpp
===================================================================
--- Mercury2/src/RenderableNode.cpp 2009-04-12 16:32:55 UTC (rev 208)
+++ Mercury2/src/RenderableNode.cpp 2009-04-12 18:09:46 UTC (rev 209)
@@ -70,7 +70,7 @@
if ( (tn = TransformNode::Cast(n)) )
return tn->GetGlobalMatrix();
- return MercuryMatrix::IdentityMatrix;
+ return MercuryMatrix::Identity();
}
void RenderableNode::AddPreRender(MercuryAsset* asset)
Modified: Mercury2/src/TransformNode.cpp
===================================================================
--- Mercury2/src/TransformNode.cpp 2009-04-12 16:32:55 UTC (rev 208)
+++ Mercury2/src/TransformNode.cpp 2009-04-12 18:09:46 UTC (rev 209)
@@ -71,7 +71,7 @@
n = n->Parent();
}
- return MercuryMatrix::IdentityMatrix;
+ return MercuryMatrix::Identity();
}
void TransformNode::RippleTaintDown()
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|