From: <axl...@us...> - 2010-05-19 22:05:58
|
Revision: 742 http://hgengine.svn.sourceforge.net/hgengine/?rev=742&view=rev Author: axlecrusher Date: 2010-05-19 22:05:52 +0000 (Wed, 19 May 2010) Log Message: ----------- Clean setting and using matrix pointers. This causes a large speedup of all matrix math operations. I suspect this is much friendlier to the CPU cache. Modified Paths: -------------- Mercury2/src/Camera.cpp Mercury2/src/Light.cpp Mercury2/src/Mercury2.cpp Mercury2/src/MercuryNode.cpp Mercury2/src/MercuryNode.h Mercury2/src/RenderGraph.cpp Mercury2/src/TransformNode.cpp Mercury2/src/TransformNode.h Modified: Mercury2/src/Camera.cpp =================================================================== --- Mercury2/src/Camera.cpp 2010-05-19 16:42:33 UTC (rev 741) +++ Mercury2/src/Camera.cpp 2010-05-19 22:05:52 UTC (rev 742) @@ -45,7 +45,7 @@ { m_tainted = false; - MercuryMatrix local, parent(GetParentMatrix()); + MercuryMatrix local, parent(*m_pGlobalMatrix); MQuaternion r( GetRotation() ); Modified: Mercury2/src/Light.cpp =================================================================== --- Mercury2/src/Light.cpp 2010-05-19 16:42:33 UTC (rev 741) +++ Mercury2/src/Light.cpp 2010-05-19 22:05:52 UTC (rev 742) @@ -30,8 +30,8 @@ void Light::Render(const MercuryMatrix& matrix) { - m_worldPosition = FindModelViewMatrix(); - m_worldPosition2 = FindGlobalMatrix(); + m_worldPosition = GetModelViewMatrix(); + m_worldPosition2 = GetGlobalMatrix(); CURRENTRENDERGRAPH->AddDifferedLight( this ); // m_boundingVolume->Render(); // m_parent = node; Modified: Mercury2/src/Mercury2.cpp =================================================================== --- Mercury2/src/Mercury2.cpp 2010-05-19 16:42:33 UTC (rev 741) +++ Mercury2/src/Mercury2.cpp 2010-05-19 22:05:52 UTC (rev 742) @@ -35,7 +35,7 @@ bool SHOWBOUNDINGVOLUME = false; bool SHOWAXISES = false; bool DOOCCLUSIONCULL = false; - +/* MSemaphore UpdateLoopGo; void* UpdateThread(void* node) { @@ -46,7 +46,7 @@ } return NULL; } - +*/ int SignalHandler( int signal ) { char buffer[2048]; @@ -144,9 +144,12 @@ do { timer.Touch(); + + root->RecursiveUpdate( timer.Age(), MercuryMatrix::IdentityMatrix ); //comment to use threads + + //seems to work better after update. is this the correct place? MESSAGEMAN.PumpMessages( timer.MicrosecondsSinceInit() ); - root->RecursiveUpdate( timer.Age() ); //comment to use threads CURRENTRENDERGRAPH = &renderGraph; if ( MercuryNode::NeedsRebuild() ) Modified: Mercury2/src/MercuryNode.cpp =================================================================== --- Mercury2/src/MercuryNode.cpp 2010-05-19 16:42:33 UTC (rev 741) +++ Mercury2/src/MercuryNode.cpp 2010-05-19 22:05:52 UTC (rev 742) @@ -20,8 +20,8 @@ m_nextSibling(NULL), m_flags(SAVECHILDREN & ENABLESAVE), m_iPasses( DEFAULT_PASSES ), m_iForcePasses( 0 ) { - m_pGlobalMatrix = &MercuryMatrix::Identity(); - m_pModelViewMatrix = &MercuryMatrix::Identity(); + m_pGlobalMatrix = &MercuryMatrix::IdentityMatrix; + m_pModelViewMatrix = &MercuryMatrix::IdentityMatrix; } MercuryNode::~MercuryNode() @@ -192,12 +192,15 @@ return 0; } -void MercuryNode::RecursiveUpdate(float dTime) +void MercuryNode::RecursiveUpdate(float dTime, const MercuryMatrix& globalMatrix) { + m_pGlobalMatrix = &globalMatrix; + if (m_parent) m_pModelViewMatrix = m_parent->m_pModelViewMatrix; + Update(dTime); - + for (MercuryNode* child = FirstChild(); child != NULL; child = NextChild(child)) - child->RecursiveUpdate(dTime); + child->RecursiveUpdate(dTime, *m_pGlobalMatrix); } void MercuryNode::RecursivePreRender() @@ -421,40 +424,11 @@ (*i)->Asset().PostRender(this); } -const MercuryMatrix& MercuryNode::FindGlobalMatrix() const -{ - const MercuryNode* n = NULL; - const TransformNode* tn; - for (n = this; n; n = n->Parent()) - { - tn = TransformNode::Cast(n); - if ( tn ) - return tn->GetGlobalMatrix(); - } - - return MercuryMatrix::Identity(); -} - -const MercuryMatrix& MercuryNode::FindModelViewMatrix() const -{ - const MercuryNode* n = NULL; - const TransformNode* tn; - for (n = this; n; n = n->Parent()) - { - tn = TransformNode::Cast(n); - if ( tn ) - return tn->GetModelViewMatrix(); - } - - return MercuryMatrix::Identity(); -} - MercuryMatrix MercuryNode::ManipulateMatrix(const MercuryMatrix& matrix) { return VIEWMATRIX * matrix; } - NodeFactory& NodeFactory::GetInstance() { static NodeFactory* instance = NULL; Modified: Mercury2/src/MercuryNode.h =================================================================== --- Mercury2/src/MercuryNode.h 2010-05-19 16:42:33 UTC (rev 741) +++ Mercury2/src/MercuryNode.h 2010-05-19 22:05:52 UTC (rev 742) @@ -71,7 +71,7 @@ MercuryNode * TraversalNextNode( MercuryNode * stopnode, int & iDepthDelta ); virtual void Update(float dTime) {}; - virtual void RecursiveUpdate(float dTime); + virtual void RecursiveUpdate(float dTime, const MercuryMatrix& globalMatrix); void ThreadedUpdate(float dTime); @@ -170,10 +170,6 @@ // std::list< MercuryAsset* > m_render; // std::list< MercuryAsset* > m_postrender; - ///This will get the world space matrix - const MercuryMatrix& FindGlobalMatrix() const; - const MercuryMatrix& FindModelViewMatrix() const; - const MercuryMatrix * m_pGlobalMatrix; const MercuryMatrix * m_pModelViewMatrix; Modified: Mercury2/src/RenderGraph.cpp =================================================================== --- Mercury2/src/RenderGraph.cpp 2010-05-19 16:42:33 UTC (rev 741) +++ Mercury2/src/RenderGraph.cpp 2010-05-19 22:05:52 UTC (rev 742) @@ -58,14 +58,10 @@ RenderGraphEntry* lastEntry = &entry; // MercuryNode* rn = MercuryNode::Cast(node); - //Update the Matrices - node->m_pGlobalMatrix = &node->FindGlobalMatrix(); - node->m_pModelViewMatrix = &node->FindModelViewMatrix(); - if ( node ) { //found a new renderable - entry.m_children.push_back( RenderGraphEntry(&(node->FindGlobalMatrix()), node) ); + entry.m_children.push_back( RenderGraphEntry(&(node->GetGlobalMatrix()), node) ); lastEntry = &(entry.m_children.back()); } Modified: Mercury2/src/TransformNode.cpp =================================================================== --- Mercury2/src/TransformNode.cpp 2010-05-19 16:42:33 UTC (rev 741) +++ Mercury2/src/TransformNode.cpp 2010-05-19 22:05:52 UTC (rev 742) @@ -14,6 +14,8 @@ void TransformNode::Update(float dTime) { if (m_tainted) ComputeMatrix(); + m_pGlobalMatrix = &m_globalMatrix; + m_pModelViewMatrix = &m_modelView; } void TransformNode::RecursivePreRender() @@ -89,23 +91,9 @@ // m_scale[0], m_scale[1], m_scale[2] ); // local = t * local; - m_globalMatrix = GetParentMatrix() * local; + m_globalMatrix = *m_pGlobalMatrix * local; } -const MercuryMatrix& TransformNode::GetParentMatrix() const -{ - const MercuryNode* n = m_parent; - const TransformNode* tn; - while (n) - { - tn = TransformNode::Cast( n ); - if ( tn ) return tn->GetGlobalMatrix(); - n = n->Parent(); - } - - return MercuryMatrix::Identity(); -} - void TransformNode::RippleTaintDown(MercuryNode* node) { TransformNode* tn; @@ -200,11 +188,6 @@ } } -const MercuryMatrix& TransformNode::GetGlobalMatrix() const -{ - return m_globalMatrix; -} - void RotatorNode::Update(float dTime) { MQuaternion r = GetRotation(); Modified: Mercury2/src/TransformNode.h =================================================================== --- Mercury2/src/TransformNode.h 2010-05-19 16:42:33 UTC (rev 741) +++ Mercury2/src/TransformNode.h 2010-05-19 22:05:52 UTC (rev 742) @@ -23,11 +23,6 @@ inline const MercuryVertex& GetPosition() const { return m_position; } inline const MQuaternion& GetRotation() const { return m_rotation; } -// inline const MercuryMatrix& GetGlobalMatrix() const { return m_globalMatrix; } - virtual const MercuryMatrix& GetGlobalMatrix() const; - inline const MercuryMatrix& GetModelViewMatrix() const { return m_modelView; } - const MercuryMatrix& GetParentMatrix() const; - void SetTaint(bool taint); virtual void ComputeMatrix(); @@ -55,6 +50,7 @@ // MercuryMatrix m_localMatrix; protected: + //these are the matrices that should be pointed to MercuryMatrix m_modelView; MercuryMatrix m_globalMatrix; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |