limit cost of test_vref_integrity()

This commit is contained in:
David Rose 2010-05-23 00:21:07 +00:00
parent 66b5af633b
commit 326da19431
3 changed files with 40 additions and 30 deletions

View File

@ -144,6 +144,12 @@ ConfigVariableDouble egg_coplanar_threshold
PRC_DESC("The numerical threshold below which polygons are considered " PRC_DESC("The numerical threshold below which polygons are considered "
"to be coplanar. Determined empirically.")); "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 // Function: init_libegg
// Description: Initializes the library. This must be called at // Description: Initializes the library. This must be called at

View File

@ -39,6 +39,7 @@ extern EXPCL_PANDAEGG ConfigVariableBool egg_consider_fans;
extern EXPCL_PANDAEGG ConfigVariableDouble egg_max_tfan_angle; extern EXPCL_PANDAEGG ConfigVariableDouble egg_max_tfan_angle;
extern EXPCL_PANDAEGG ConfigVariableInt egg_min_tfan_tris; extern EXPCL_PANDAEGG ConfigVariableInt egg_min_tfan_tris;
extern EXPCL_PANDAEGG ConfigVariableDouble egg_coplanar_threshold; extern EXPCL_PANDAEGG ConfigVariableDouble egg_coplanar_threshold;
extern EXPCL_PANDAEGG ConfigVariableInt egg_test_vref_integrity;
extern EXPCL_PANDAEGG void init_libegg(); extern EXPCL_PANDAEGG void init_libegg();

View File

@ -17,6 +17,7 @@
#include "eggMiscFuncs.h" #include "eggMiscFuncs.h"
#include "eggTextureCollection.h" #include "eggTextureCollection.h"
#include "lexerDefs.h" #include "lexerDefs.h"
#include "config_egg.h"
#include "indent.h" #include "indent.h"
#include "vector_int.h" #include "vector_int.h"
@ -814,36 +815,38 @@ void EggPrimitive::
test_vref_integrity() const { test_vref_integrity() const {
test_ref_count_integrity(); test_ref_count_integrity();
// First, we need to know how many times each vertex appears. if ((int)size() <= egg_test_vref_integrity) {
// Usually, this will be only one, but it's possible for a vertex to // First, we need to know how many times each vertex appears.
// appear more than once. // Usually, this will be only one, but it's possible for a vertex to
typedef pmap<const EggVertex *, int> VertexCount; // appear more than once.
VertexCount _count; typedef pmap<const EggVertex *, int> VertexCount;
VertexCount _count;
// Now count up the vertices. // Now count up the vertices.
iterator vi; iterator vi;
for (vi = begin(); vi != end(); ++vi) { for (vi = begin(); vi != end(); ++vi) {
const EggVertex *vert = *vi; const EggVertex *vert = *vi;
vert->test_ref_count_integrity(); vert->test_ref_count_integrity();
VertexCount::iterator vci = _count.find(vert); VertexCount::iterator vci = _count.find(vert);
if (vci == _count.end()) { if (vci == _count.end()) {
_count[vert] = 1; _count[vert] = 1;
} else { } else {
(*vci).second++; (*vci).second++;
}
} }
}
// Ok, now walk through the vertices found and make sure the vertex // Ok, now walk through the vertices found and make sure the vertex
// has the proper number of entries of this primitive in its pref. // has the proper number of entries of this primitive in its pref.
VertexCount::iterator vci; VertexCount::iterator vci;
for (vci = _count.begin(); vci != _count.end(); ++vci) { for (vci = _count.begin(); vci != _count.end(); ++vci) {
const EggVertex *vert = (*vci).first; const EggVertex *vert = (*vci).first;
int count = (*vci).second; int count = (*vci).second;
int vert_count = vert->has_pref(this); int vert_count = vert->has_pref(this);
nassertv(count == vert_count); nassertv(count == vert_count);
}
} }
} }