From cf725075fe0b773b08cee06d3e5df2b08ad3875e Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Thu, 19 Aug 2004 01:47:58 +0000 Subject: [PATCH] split out DrawMesh cleanup --- stepmania/src/Model.cpp | 83 ++++++++++++++++------------------------- stepmania/src/Model.h | 15 +++++++- 2 files changed, 46 insertions(+), 52 deletions(-) diff --git a/stepmania/src/Model.cpp b/stepmania/src/Model.cpp index 137779d875..9de02a9b5b 100644 --- a/stepmania/src/Model.cpp +++ b/stepmania/src/Model.cpp @@ -438,25 +438,15 @@ void Model::DrawPrimitives() { DISPLAY->SetTextureModeModulate(); - for (int i = 0; i < (int)m_pGeometry->m_Meshes.size(); i++) + for( unsigned i = 0; i < m_pGeometry->m_Meshes.size(); ++i ) { - msMesh *pMesh = &m_pGeometry->m_Meshes[i]; - const RageCompiledGeometry* TempGeometry = m_pTempGeometry ? m_pTempGeometry : m_pGeometry->m_pGeometry; + const msMesh *pMesh = &m_pGeometry->m_Meshes[i]; - // apply mesh-specific bone (if any) - if( pMesh->nBoneIndex != -1 ) - { - DISPLAY->PushMatrix(); - - RageMatrix &mat = m_vpBones[pMesh->nBoneIndex].mFinal; - DISPLAY->PreMultMatrix( mat ); - } - DISPLAY->TexturePushMatrix(); if( pMesh->nMaterialIndex != -1 ) // has a material { - // apply material + // apply material msMaterial& mat = m_Materials[ pMesh->nMaterialIndex ]; RageColor Emissive = mat.Emissive; @@ -469,15 +459,13 @@ void Model::DrawPrimitives() DISPLAY->SetMaterial( Emissive, Ambient, Diffuse, mat.Specular, mat.fShininess ); - float fScrollX = 0; - float fScrollY = 0; if( mat.diffuse.m_fTexVelocityX != 0 || mat.diffuse.m_fTexVelocityY != 0 ) { - fScrollX = mat.diffuse.m_fTexVelocityX * mat.diffuse.GetSecondsIntoAnimation() / mat.diffuse.GetAnimationLengthSeconds(); - fScrollY = mat.diffuse.m_fTexVelocityY * mat.diffuse.GetSecondsIntoAnimation() / mat.diffuse.GetAnimationLengthSeconds(); + float fScrollX = mat.diffuse.m_fTexVelocityX * mat.diffuse.GetSecondsIntoAnimation() / mat.diffuse.GetAnimationLengthSeconds(); + float fScrollY = mat.diffuse.m_fTexVelocityY * mat.diffuse.GetSecondsIntoAnimation() / mat.diffuse.GetAnimationLengthSeconds(); DISPLAY->SetTextureWrapping( true ); + DISPLAY->TextureTranslate( fScrollX, fScrollY, 0 ); } - DISPLAY->TextureTranslate( fScrollX, fScrollY, 0 ); // render the first pass with texture 1 DISPLAY->SetTexture( 0, mat.diffuse.GetCurrentTexture() ); @@ -505,16 +493,10 @@ void Model::DrawPrimitives() DISPLAY->SetSphereEnironmentMapping( false ); } - // Draw it - DISPLAY->DrawCompiledGeometry( TempGeometry, i, m_pGeometry->m_Meshes ); + DrawMesh( i ); + DISPLAY->SetSphereEnironmentMapping( false ); - DISPLAY->TexturePopMatrix(); - - if( pMesh->nBoneIndex != -1 ) - { - DISPLAY->PopMatrix(); - } } } @@ -525,10 +507,9 @@ void Model::DrawPrimitives() { DISPLAY->SetTextureModeGlow(); - for (int i = 0; i < (int)m_pGeometry->m_Meshes.size(); i++) + for( unsigned i = 0; i < m_pGeometry->m_Meshes.size(); ++i ) { - msMesh *pMesh = &m_pGeometry->m_Meshes[i]; - const RageCompiledGeometry* TempGeometry = m_pTempGeometry ? m_pTempGeometry : m_pGeometry->m_pGeometry; + const msMesh *pMesh = &m_pGeometry->m_Meshes[i]; // apply material RageColor emissive = RageColor(0,0,0,0); @@ -537,12 +518,7 @@ void Model::DrawPrimitives() RageColor specular = RageColor(0,0,0,0); float shininess = 1; - DISPLAY->SetMaterial( - emissive, - ambient, - diffuse, - specular, - shininess ); + DISPLAY->SetMaterial( emissive, ambient, diffuse, specular, shininess ); DISPLAY->ClearAllTextures(); if( pMesh->nMaterialIndex != -1 ) @@ -554,25 +530,32 @@ void Model::DrawPrimitives() { } - // apply mesh-specific bone (if any) - if( pMesh->nBoneIndex != -1 ) - { - DISPLAY->PushMatrix(); - - RageMatrix &mat = m_vpBones[pMesh->nBoneIndex].mFinal; - DISPLAY->PreMultMatrix( mat ); - } - - DISPLAY->DrawCompiledGeometry( TempGeometry, i, m_pGeometry->m_Meshes ); - - if( pMesh->nBoneIndex != -1 ) - { - DISPLAY->PopMatrix(); - } + DrawMesh( i ); } } } +void Model::DrawMesh( int i ) const +{ + const msMesh *pMesh = &m_pGeometry->m_Meshes[i]; + + // apply mesh-specific bone (if any) + if( pMesh->nBoneIndex != -1 ) + { + DISPLAY->PushMatrix(); + + const RageMatrix &mat = m_vpBones[pMesh->nBoneIndex].mFinal; + DISPLAY->PreMultMatrix( mat ); + } + + // Draw it + const RageCompiledGeometry* TempGeometry = m_pTempGeometry ? m_pTempGeometry : m_pGeometry->m_pGeometry; + DISPLAY->DrawCompiledGeometry( TempGeometry, i, m_pGeometry->m_Meshes ); + + if( pMesh->nBoneIndex != -1 ) + DISPLAY->PopMatrix(); +} + void Model::SetDefaultAnimation( CString sAnimation, float fPlayRate ) { m_sDefaultAnimation = sAnimation; diff --git a/stepmania/src/Model.h b/stepmania/src/Model.h index c0f948b2f0..0a4bc35b2c 100644 --- a/stepmania/src/Model.h +++ b/stepmania/src/Model.h @@ -10,8 +10,18 @@ #include #include "RageModelGeometry.h" -struct msModel; +/* This is a static class that holds and renders model data; it can be shared among + * multiple Models. (Note that geometry data is stored and refcounted separately; + * that can */ +/* XXX: dumb name */ +/* class ModelHolder : public Actor +{ +public: +private: + RageModelGeometry *m_pGeometry; + +} */ class Model : public Actor { @@ -19,7 +29,6 @@ public: Model (); virtual ~Model (); -public: void Clear (); void Load( CString sFile ); @@ -63,6 +72,8 @@ private: vector m_vTempMeshes; RageCompiledGeometry* m_pTempGeometry; + void DrawMesh( int i ) const; + float m_fCurFrame; CString m_sDefaultAnimation; float m_fDefaultAnimationRate;