From 648c21947c6c115209e5529de6e747e474fd64e2 Mon Sep 17 00:00:00 2001 From: Kester Maddock Date: Tue, 4 May 2004 13:17:46 +0000 Subject: Use a better compare function for RAS_IPolygonMaterial Fix sharing verticies - must test pos, normal, uv & colour before sharing (not just index) --- .../gameengine/Rasterizer/RAS_IPolygonMaterial.cpp | 49 +++++++++++++++++----- source/gameengine/Rasterizer/RAS_MeshObject.cpp | 25 +++++------ source/gameengine/Rasterizer/RAS_MeshObject.h | 8 ++-- 3 files changed, 54 insertions(+), 28 deletions(-) diff --git a/source/gameengine/Rasterizer/RAS_IPolygonMaterial.cpp b/source/gameengine/Rasterizer/RAS_IPolygonMaterial.cpp index 33cdc43afd8..6a202780652 100644 --- a/source/gameengine/Rasterizer/RAS_IPolygonMaterial.cpp +++ b/source/gameengine/Rasterizer/RAS_IPolygonMaterial.cpp @@ -81,17 +81,44 @@ bool RAS_IPolyMaterial::Equals(const RAS_IPolyMaterial& lhs) const bool RAS_IPolyMaterial::Less(const RAS_IPolyMaterial& rhs) const { - return ( - this->m_materialname < rhs.m_materialname || - this->m_texturename < rhs.m_texturename || - this->m_lightlayer < rhs.m_lightlayer || - this->m_tile < rhs.m_tile || - this->m_tilexrep < rhs.m_tilexrep || - this->m_tileyrep < rhs.m_tileyrep || - this->m_transparant < rhs.m_transparant || - this->m_drawingmode < rhs.m_drawingmode || - this->m_bIsTriangle < rhs.m_bIsTriangle - ); + /** + * @warning STL requires lhs.Less(rhs) == rhs.Less(lhs) implies lhs.Equals(rhs). + * This function *must* return different values for lhs.Less(rhs) and rhs.Less(lhs) if + * !lhs.Equals(rhs) !! + */ + if (m_materialname.hash() < rhs.m_materialname.hash()) + return true; + + if (m_materialname.hash() > rhs.m_materialname.hash() || + m_texturename.hash() > rhs.m_texturename.hash()) + return false; + + if (m_texturename.hash() < rhs.m_texturename.hash() || + m_lightlayer < rhs.m_lightlayer) + return true; + + if (m_lightlayer > rhs.m_lightlayer || + m_bIsTriangle > rhs.m_bIsTriangle) + return false; + + if (m_bIsTriangle < rhs.m_bIsTriangle || + m_drawingmode < rhs.m_drawingmode) + return true; + + if (m_drawingmode > rhs.m_drawingmode || + m_transparant > !rhs.m_transparant) + return false; + + if (m_transparant < rhs.m_transparant || + m_tileyrep < rhs.m_tileyrep) + return true; + + if (m_tileyrep > rhs.m_tileyrep || + m_tilexrep > rhs.m_tilexrep) + return false; + + return (m_tilexrep < rhs.m_tilexrep || + m_tile < rhs.m_tile); } int RAS_IPolyMaterial::GetLightLayer() diff --git a/source/gameengine/Rasterizer/RAS_MeshObject.cpp b/source/gameengine/Rasterizer/RAS_MeshObject.cpp index 4f5833df50b..7ff43b53a65 100644 --- a/source/gameengine/Rasterizer/RAS_MeshObject.cpp +++ b/source/gameengine/Rasterizer/RAS_MeshObject.cpp @@ -132,14 +132,14 @@ RAS_Polygon* RAS_MeshObject::GetPolygon(int num) -set::iterator RAS_MeshObject::GetFirstMaterial() +RAS_MaterialBucket::Set::iterator RAS_MeshObject::GetFirstMaterial() { return m_materials.begin(); } -set::iterator RAS_MeshObject::GetLastMaterial() +RAS_MaterialBucket::Set::iterator RAS_MeshObject::GetLastMaterial() { return m_materials.end(); } @@ -260,36 +260,33 @@ int RAS_MeshObject::FindOrAddVertex(int vtxarray, KX_ArrayOptimizer* ao = GetArrayOptimizer(mat);//*(m_matVertexArrays[*mat]); int numverts = ao->m_VertexArrayCache1[vtxarray]->size();//m_VertexArrayCount[vtxarray]; - + RAS_TexVert newvert(xyz,uv,rgbacolor,newnormal, 0); #define KX_FIND_SHARED_VERTICES #ifdef KX_FIND_SHARED_VERTICES - std::vector::iterator it = m_xyz_index_to_vertex_index_mapping[orgindex].begin(); - int index=-1; - while (index < 0 && !(it == m_xyz_index_to_vertex_index_mapping[orgindex].end())) + for (std::vector::iterator it = m_xyz_index_to_vertex_index_mapping[orgindex].begin(); + it != m_xyz_index_to_vertex_index_mapping[orgindex].end(); + it++) { if ((*it).m_arrayindex1 == ao->m_index1 && - ((*it).m_array == vtxarray) && - (*(RAS_IPolyMaterial*) (*it).m_matid) == *mat + (*it).m_array == vtxarray && + *(*it).m_matid == *mat && + (*ao->m_VertexArrayCache1[vtxarray])[(*it).m_index].closeTo(&newvert) ) { return (*it).m_index; } - it++; } - - if (index >= 0) - return index; #endif // KX_FIND_SHARED_VERTICES // no vertex found, add one - ao->m_VertexArrayCache1[vtxarray]->push_back(RAS_TexVert (xyz,uv,rgbacolor,newnormal, 0)); + ao->m_VertexArrayCache1[vtxarray]->push_back(newvert); // printf("(%f,%f,%f) ",xyz[0],xyz[1],xyz[2]); RAS_MatArrayIndex idx; idx.m_arrayindex1 = ao->m_index1; idx.m_array = vtxarray; idx.m_index = numverts; - idx.m_matid = (int) mat; + idx.m_matid = mat; m_xyz_index_to_vertex_index_mapping[orgindex].push_back(idx); return numverts; diff --git a/source/gameengine/Rasterizer/RAS_MeshObject.h b/source/gameengine/Rasterizer/RAS_MeshObject.h index 78e142fda8a..5e823621588 100644 --- a/source/gameengine/Rasterizer/RAS_MeshObject.h +++ b/source/gameengine/Rasterizer/RAS_MeshObject.h @@ -89,10 +89,11 @@ class RAS_MatArrayIndex public: int m_arrayindex1; - int m_matid; + RAS_IPolyMaterial* m_matid; int m_array; int m_index; +/* inline bool Less(const RAS_MatArrayIndex& lhs) const { bool result = ( (m_matid < lhs.m_matid) || @@ -104,13 +105,14 @@ public: return result; } - +*/ }; +/* inline bool operator <( const RAS_MatArrayIndex& rhs,const RAS_MatArrayIndex& lhs) { return ( rhs.Less(lhs)); -} +}*/ /** * RAS_MeshObject stores mesh data for the renderer. -- cgit v1.2.3