From acb0a4104900ca0d23fbaa7eb11d363ee70d0782 Mon Sep 17 00:00:00 2001 From: rdb Date: Wed, 14 Aug 2019 13:11:02 +0200 Subject: [PATCH] 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. --- panda/src/ode/odeGeom.cxx | 8 +++- panda/src/ode/odeJoint.cxx | 12 ++++-- panda/src/ode/odeSpace.cxx | 8 ++-- panda/src/ode/odeTriMeshData.I | 4 +- panda/src/ode/odeTriMeshData.cxx | 64 ++++++++++++++++++++++---------- panda/src/ode/odeWorld.cxx | 12 ++++-- 6 files changed, 75 insertions(+), 33 deletions(-) diff --git a/panda/src/ode/odeGeom.cxx b/panda/src/ode/odeGeom.cxx index e25c6c45b6..093d075372 100644 --- a/panda/src/ode/odeGeom.cxx +++ b/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()) { diff --git a/panda/src/ode/odeJoint.cxx b/panda/src/ode/odeJoint.cxx index dd10c57f0a..4ada7fefa5 100644 --- a/panda/src/ode/odeJoint.cxx +++ b/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:: diff --git a/panda/src/ode/odeSpace.cxx b/panda/src/ode/odeSpace.cxx index f2beca8efb..4368a0b437 100644 --- a/panda/src/ode/odeSpace.cxx +++ b/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()) { diff --git a/panda/src/ode/odeTriMeshData.I b/panda/src/ode/odeTriMeshData.I index 2aad3a2404..be5afa0218 100644 --- a/panda/src/ode/odeTriMeshData.I +++ b/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); } diff --git a/panda/src/ode/odeTriMeshData.cxx b/panda/src/ode/odeTriMeshData.cxx index c92602ac34..8e741529f6 100644 --- a/panda/src/ode/odeTriMeshData.cxx +++ b/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; } diff --git a/panda/src/ode/odeWorld.cxx b/panda/src/ode/odeWorld.cxx index f087c46374..66a7233dca 100644 --- a/panda/src/ode/odeWorld.cxx +++ b/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 ©) : 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;