Browse Source

ode: fix several unprotected debug() prints

This should especially help with trimesh generation performance, which previously formatted a complete description of the trimesh to the debug output even if it was disabled.
rdb 6 years ago
parent
commit
acb0a41049

+ 6 - 2
panda/src/ode/odeGeom.cxx

@@ -33,12 +33,16 @@ TypeHandle OdeGeom::_type_handle;
 OdeGeom::
 OdeGeom(dGeomID id) :
   _id(id) {
-  odegeom_cat.debug() << get_type() << "(" << _id << ")\n";
+  if (odegeom_cat.is_debug()) {
+    odegeom_cat.debug() << get_type() << "(" << _id << ")\n";
+  }
 }
 
 OdeGeom::
 ~OdeGeom() {
-  odegeom_cat.debug() << "~" << get_type() << "(" << _id << ")\n";
+  if (odegeom_cat.is_debug()) {
+    odegeom_cat.debug() << "~" << get_type() << "(" << _id << ")\n";
+  }
   /*
   GeomSurfaceMap::iterator iter = _geom_surface_map.find(this->get_id());
   if (iter != _geom_surface_map.end()) {

+ 8 - 4
panda/src/ode/odeJoint.cxx

@@ -31,15 +31,19 @@ TypeHandle OdeJoint::_type_handle;
 OdeJoint::
 OdeJoint() :
   _id(nullptr) {
-  std::ostream &out = odejoint_cat.debug();
-  out << get_type() << "(" << _id  << ")\n";
+  if (odejoint_cat.is_debug()) {
+    std::ostream &out = odejoint_cat.debug();
+    out << get_type() << "(" << _id  << ")\n";
+  }
 }
 
 OdeJoint::
 OdeJoint(dJointID id) :
   _id(id) {
-  std::ostream &out = odejoint_cat.debug();
-  out << get_type() << "(" << _id  << ")\n";
+  if (odejoint_cat.is_debug()) {
+    std::ostream &out = odejoint_cat.debug();
+    out << get_type() << "(" << _id  << ")\n";
+  }
 }
 
 OdeJoint::

+ 5 - 3
panda/src/ode/odeSpace.cxx

@@ -157,9 +157,11 @@ auto_callback(void *data, dGeomID o1, dGeomID o2) {
   numc = dCollide(o1, o2, OdeSpace::MAX_CONTACTS, &contact[0].geom, sizeof(dContact));
 
   if (numc) {
-    odespace_cat.debug() << "collision between geoms " << o1 << " and " << o2 << "\n";
-    odespace_cat.debug() << "collision between body " << b1 << " and " << b2 << "\n";
-    odespace_cat.debug() << "surface1= "<< surface1 << " surface2=" << surface2 << "\n";
+    if (odespace_cat.is_debug()) {
+      odespace_cat.debug() << "collision between geoms " << o1 << " and " << o2 << "\n";
+      odespace_cat.debug() << "collision between body " << b1 << " and " << b2 << "\n";
+      odespace_cat.debug() << "surface1= "<< surface1 << " surface2=" << surface2 << "\n";
+    }
 
     PT(OdeCollisionEntry) entry;
     if (!_static_auto_collide_space->_collision_event.empty()) {

+ 3 - 1
panda/src/ode/odeTriMeshData.I

@@ -38,7 +38,9 @@ get(int data_id) {
 
 INLINE void OdeTriMeshData::
 build_single(const void* vertices, int vertex_stride, int vertex_count, const void* indices, int index_count, int tri_stride) {
-  odetrimeshdata_cat.debug() << "build_single(" << vertices << ", " << vertex_stride << ", " << vertex_count << ", " << indices << ", " << index_count << ", " << tri_stride << ")\n";
+  if (odetrimeshdata_cat.is_debug()) {
+    odetrimeshdata_cat.debug() << "build_single(" << vertices << ", " << vertex_stride << ", " << vertex_count << ", " << indices << ", " << index_count << ", " << tri_stride << ")\n";
+  }
   dGeomTriMeshDataBuildSingle(_id, vertices, vertex_stride, vertex_count, indices, index_count, tri_stride);
 }
 

+ 44 - 20
panda/src/ode/odeTriMeshData.cxx

@@ -20,7 +20,9 @@ OdeTriMeshData::TriMeshDataMap *OdeTriMeshData::_tri_mesh_data_map = nullptr;
 
 void OdeTriMeshData::
 link_data(dGeomID id, PT(OdeTriMeshData) data) {
-  odetrimeshdata_cat.debug() << get_class_type() << "::link_data(" << id << "->" << data << ")" << "\n";
+  if (odetrimeshdata_cat.is_debug()) {
+    odetrimeshdata_cat.debug() << get_class_type() << "::link_data(" << id << "->" << data << ")" << "\n";
+  }
   get_tri_mesh_data_map()[id] = data;
 }
 
@@ -36,7 +38,9 @@ get_data(dGeomID id) {
 
 void OdeTriMeshData::
 unlink_data(dGeomID id) {
-  odetrimeshdata_cat.debug() << get_class_type() << "::unlink_data(" << id << ")" << "\n";
+  if (odetrimeshdata_cat.is_debug()) {
+    odetrimeshdata_cat.debug() << get_class_type() << "::unlink_data(" << id << ")" << "\n";
+  }
   nassertv(_tri_mesh_data_map != nullptr);
   TriMeshDataMap::iterator iter = _tri_mesh_data_map->find(id);
   if (iter != _tri_mesh_data_map->end()) {
@@ -46,11 +50,13 @@ unlink_data(dGeomID id) {
 
 void OdeTriMeshData::
 print_data(const std::string &marker) {
-  odetrimeshdata_cat.debug() << get_class_type() << "::print_data(" << marker << ")\n";
-  const TriMeshDataMap &data_map = get_tri_mesh_data_map();
-  TriMeshDataMap::const_iterator iter = data_map.begin();
-  for (;iter != data_map.end(); ++iter) {
-    odetrimeshdata_cat.debug() << "\t" << iter->first << " : " << iter->second << "\n";
+  if (odetrimeshdata_cat.is_debug()) {
+    odetrimeshdata_cat.debug() << get_class_type() << "::print_data(" << marker << ")\n";
+    const TriMeshDataMap &data_map = get_tri_mesh_data_map();
+    TriMeshDataMap::const_iterator iter = data_map.begin();
+    for (;iter != data_map.end(); ++iter) {
+      odetrimeshdata_cat.debug() << "\t" << iter->first << " : " << iter->second << "\n";
+    }
   }
 }
 
@@ -95,11 +101,15 @@ OdeTriMeshData(const NodePath& model, bool use_normals) :
   _normals(nullptr),
   _num_vertices(0),
   _num_faces(0) {
-  odetrimeshdata_cat.debug() << get_type() << "(" << _id << ")" << "\n";
+  if (odetrimeshdata_cat.is_debug()) {
+    odetrimeshdata_cat.debug() << get_type() << "(" << _id << ")" << "\n";
+  }
 
   process_model(model, use_normals);
 
-  write_faces(odetrimeshdata_cat.debug());
+  if (odetrimeshdata_cat.is_debug()) {
+    write_faces(odetrimeshdata_cat.debug());
+  }
 
 #ifdef dSINGLE
   if (!use_normals) {
@@ -131,7 +141,9 @@ OdeTriMeshData(const OdeTriMeshData &other) {
 
 OdeTriMeshData::
 ~OdeTriMeshData() {
-  odetrimeshdata_cat.debug() << "~" << get_type() << "(" << _id << ")" << "\n";
+  if (odetrimeshdata_cat.is_debug()) {
+    odetrimeshdata_cat.debug() << "~" << get_type() << "(" << _id << ")" << "\n";
+  }
   destroy();
   if (_vertices != nullptr) {
     PANDA_FREE_ARRAY(_vertices);
@@ -152,7 +164,9 @@ OdeTriMeshData::
 
 void OdeTriMeshData::
 destroy() {
-  odetrimeshdata_cat.debug() << get_type() << "::destroy(" << _id << ")" << "\n";
+  if (odetrimeshdata_cat.is_debug()) {
+    odetrimeshdata_cat.debug() << get_type() << "::destroy(" << _id << ")" << "\n";
+  }
   if (_id != nullptr) {
     dGeomTriMeshDataDestroy(_id);
     remove_data(this);
@@ -185,8 +199,10 @@ process_model(const NodePath& model, bool &use_normals) {
     analyze((GeomNode*)geomNodePaths[i].node());
   }
 
-  odetrimeshdata_cat.debug() << "Found " << _num_vertices << " vertices.\n";
-  odetrimeshdata_cat.debug() << "Found " << _num_faces << " faces.\n";
+  if (odetrimeshdata_cat.is_debug()) {
+    odetrimeshdata_cat.debug() << "Found " << _num_vertices << " vertices.\n";
+    odetrimeshdata_cat.debug() << "Found " << _num_faces << " faces.\n";
+  }
 
   _vertices = (StridedVertex *)PANDA_MALLOC_ARRAY(_num_vertices * sizeof(StridedVertex));
   _faces = (StridedTri *)PANDA_MALLOC_ARRAY(_num_faces * sizeof(StridedTri));
@@ -195,17 +211,23 @@ process_model(const NodePath& model, bool &use_normals) {
 
   for (int i = 0; i < geomNodePaths.get_num_paths(); ++i) {
     process_geom_node((GeomNode*)geomNodePaths[i].node());
-    odetrimeshdata_cat.debug() << "_num_vertices now at " << _num_vertices << "\n";
+    if (odetrimeshdata_cat.is_debug()) {
+      odetrimeshdata_cat.debug() << "_num_vertices now at " << _num_vertices << "\n";
+    }
   }
 
-  odetrimeshdata_cat.debug() << "Filled " << _num_faces << " triangles(" \
-                      << _num_vertices << " vertices)\n";
+  if (odetrimeshdata_cat.is_debug()) {
+    odetrimeshdata_cat.debug()
+      << "Filled " << _num_faces << " triangles(" << _num_vertices << " vertices)\n";
+  }
 }
 
 void OdeTriMeshData::
 process_geom_node(const GeomNode *geomNode) {
-  ostream &out = odetrimeshdata_cat.debug();
-  out.width(2); out << "" << "process_geom_node(" << *geomNode << ")" << "\n";
+  if (odetrimeshdata_cat.is_debug()) {
+    ostream &out = odetrimeshdata_cat.debug();
+    out.width(2); out << "" << "process_geom_node(" << *geomNode << ")" << "\n";
+  }
   for (int i = 0; i < geomNode->get_num_geoms(); ++i) {
     process_geom(geomNode->get_geom(i));
   }
@@ -213,8 +235,10 @@ process_geom_node(const GeomNode *geomNode) {
 
 void OdeTriMeshData::
 process_geom(const Geom *geom) {
-  ostream &out = odetrimeshdata_cat.debug();
-  out.width(4); out << "" << "process_geom(" << *geom << ")" << "\n";
+  if (odetrimeshdata_cat.is_debug()) {
+    ostream &out = odetrimeshdata_cat.debug();
+    out.width(4); out << "" << "process_geom(" << *geom << ")" << "\n";
+  }
   if (geom->get_primitive_type() != Geom::PT_polygons) {
     return;
   }

+ 9 - 3
panda/src/ode/odeWorld.cxx

@@ -20,7 +20,9 @@ TypeHandle OdeWorld::_type_handle;
 OdeWorld::
 OdeWorld() :
   _id(dWorldCreate()) {
-  odeworld_cat.debug() << get_type() << "(" << _id << ")" << "\n";
+  if (odeworld_cat.is_debug()) {
+    odeworld_cat.debug() << get_type() << "(" << _id << ")" << "\n";
+  }
   _num_surfaces = 0;
 
 }
@@ -34,7 +36,9 @@ OdeWorld(const OdeWorld &copy) :
 
 OdeWorld::
 ~OdeWorld() {
-  odeworld_cat.debug() << "~" << get_type() << "(" << _id << ")" << "\n";
+  if (odeworld_cat.is_debug()) {
+    odeworld_cat.debug() << "~" << get_type() << "(" << _id << ")" << "\n";
+  }
 }
 
 void OdeWorld::
@@ -71,7 +75,9 @@ init_surface_table(uint8_t num_surfaces) {
 
 void OdeWorld::
 set_surface(int pos1, int pos2, sSurfaceParams& entry) {
-  odeworld_cat.debug() << " pos1 " << pos1 << " pos2 " << pos2 << " num surfaces " << (int)_num_surfaces << " endline\n";
+  if (odeworld_cat.is_debug()) {
+    odeworld_cat.debug() << " pos1 " << pos1 << " pos2 " << pos2 << " num surfaces " << (int)_num_surfaces << " endline\n";
+  }
   if((_num_surfaces <= pos1) || (_num_surfaces <= pos2)) {
     odeworld_cat.error() << "surface position exceeds size of surface table, set num_surface in initSurfaceTable higher." << "\n";
     return;