From 326da1943127eccdaffa36078dfdace49924d723 Mon Sep 17 00:00:00 2001 From: David Rose Date: Sun, 23 May 2010 00:21:07 +0000 Subject: [PATCH] limit cost of test_vref_integrity() --- panda/src/egg/config_egg.cxx | 6 ++++ panda/src/egg/config_egg.h | 1 + panda/src/egg/eggPrimitive.cxx | 63 ++++++++++++++++++---------------- 3 files changed, 40 insertions(+), 30 deletions(-) diff --git a/panda/src/egg/config_egg.cxx b/panda/src/egg/config_egg.cxx index abd0e08ebd..ee8e505719 100644 --- a/panda/src/egg/config_egg.cxx +++ b/panda/src/egg/config_egg.cxx @@ -144,6 +144,12 @@ ConfigVariableDouble egg_coplanar_threshold PRC_DESC("The numerical threshold below which polygons are considered " "to be coplanar. Determined empirically.")); +ConfigVariableInt egg_test_vref_integrity +("egg-test-vref-integrity", 20, + PRC_DESC("The maximum number of vertices a primitive may have before " + "its vertices will no longer be checked for internal integrity. " + "This is meaningful in non-production builds only.")); + //////////////////////////////////////////////////////////////////// // Function: init_libegg // Description: Initializes the library. This must be called at diff --git a/panda/src/egg/config_egg.h b/panda/src/egg/config_egg.h index 65119c7662..339079fa76 100644 --- a/panda/src/egg/config_egg.h +++ b/panda/src/egg/config_egg.h @@ -39,6 +39,7 @@ extern EXPCL_PANDAEGG ConfigVariableBool egg_consider_fans; extern EXPCL_PANDAEGG ConfigVariableDouble egg_max_tfan_angle; extern EXPCL_PANDAEGG ConfigVariableInt egg_min_tfan_tris; extern EXPCL_PANDAEGG ConfigVariableDouble egg_coplanar_threshold; +extern EXPCL_PANDAEGG ConfigVariableInt egg_test_vref_integrity; extern EXPCL_PANDAEGG void init_libegg(); diff --git a/panda/src/egg/eggPrimitive.cxx b/panda/src/egg/eggPrimitive.cxx index 6ee75c0d73..139e30d579 100644 --- a/panda/src/egg/eggPrimitive.cxx +++ b/panda/src/egg/eggPrimitive.cxx @@ -17,6 +17,7 @@ #include "eggMiscFuncs.h" #include "eggTextureCollection.h" #include "lexerDefs.h" +#include "config_egg.h" #include "indent.h" #include "vector_int.h" @@ -813,37 +814,39 @@ copy_vertices(const EggPrimitive &other) { void EggPrimitive:: test_vref_integrity() const { test_ref_count_integrity(); - - // First, we need to know how many times each vertex appears. - // Usually, this will be only one, but it's possible for a vertex to - // appear more than once. - typedef pmap VertexCount; - VertexCount _count; - - // Now count up the vertices. - iterator vi; - for (vi = begin(); vi != end(); ++vi) { - const EggVertex *vert = *vi; - vert->test_ref_count_integrity(); - - VertexCount::iterator vci = _count.find(vert); - if (vci == _count.end()) { - _count[vert] = 1; - } else { - (*vci).second++; + + if ((int)size() <= egg_test_vref_integrity) { + // First, we need to know how many times each vertex appears. + // Usually, this will be only one, but it's possible for a vertex to + // appear more than once. + typedef pmap VertexCount; + VertexCount _count; + + // Now count up the vertices. + iterator vi; + for (vi = begin(); vi != end(); ++vi) { + const EggVertex *vert = *vi; + vert->test_ref_count_integrity(); + + VertexCount::iterator vci = _count.find(vert); + if (vci == _count.end()) { + _count[vert] = 1; + } else { + (*vci).second++; + } + } + + // Ok, now walk through the vertices found and make sure the vertex + // has the proper number of entries of this primitive in its pref. + VertexCount::iterator vci; + for (vci = _count.begin(); vci != _count.end(); ++vci) { + const EggVertex *vert = (*vci).first; + + int count = (*vci).second; + int vert_count = vert->has_pref(this); + + nassertv(count == vert_count); } - } - - // Ok, now walk through the vertices found and make sure the vertex - // has the proper number of entries of this primitive in its pref. - VertexCount::iterator vci; - for (vci = _count.begin(); vci != _count.end(); ++vci) { - const EggVertex *vert = (*vci).first; - - int count = (*vci).second; - int vert_count = vert->has_pref(this); - - nassertv(count == vert_count); } }