From e94472d3adc6e811f723d48cfd6acacf19fe0b9a Mon Sep 17 00:00:00 2001 From: Erin Catto Date: Fri, 10 Apr 2020 23:49:08 -0700 Subject: [PATCH] World dump now writes to a file instead of std out (#596) Dumps to box2d_dump.inl --- include/box2d/b2_body.h | 2 +- include/box2d/b2_joint.h | 2 +- include/box2d/b2_settings.h | 5 +++ src/common/b2_settings.cpp | 29 ++++++++++++ src/dynamics/b2_body.cpp | 40 ++++++++--------- src/dynamics/b2_distance_joint.cpp | 20 ++++----- src/dynamics/b2_fixture.cpp | 70 ++++++++++++++--------------- src/dynamics/b2_friction_joint.cpp | 18 ++++---- src/dynamics/b2_gear_joint.cpp | 16 +++---- src/dynamics/b2_motor_joint.cpp | 20 ++++----- src/dynamics/b2_prismatic_joint.cpp | 30 ++++++------- src/dynamics/b2_pulley_joint.cpp | 24 +++++----- src/dynamics/b2_revolute_joint.cpp | 28 ++++++------ src/dynamics/b2_rope_joint.cpp | 16 +++---- src/dynamics/b2_weld_joint.cpp | 20 ++++----- src/dynamics/b2_wheel_joint.cpp | 26 +++++------ src/dynamics/b2_world.cpp | 29 +++++++----- testbed/test.h | 2 +- 18 files changed, 218 insertions(+), 179 deletions(-) diff --git a/include/box2d/b2_body.h b/include/box2d/b2_body.h index dabc46e6e..dca622338 100644 --- a/include/box2d/b2_body.h +++ b/include/box2d/b2_body.h @@ -388,7 +388,7 @@ class b2Body b2World* GetWorld(); const b2World* GetWorld() const; - /// Dump this body to a log file + /// Dump this body to a file void Dump(); private: diff --git a/include/box2d/b2_joint.h b/include/box2d/b2_joint.h index 89f0bc2a1..58059e76e 100644 --- a/include/box2d/b2_joint.h +++ b/include/box2d/b2_joint.h @@ -149,7 +149,7 @@ class b2Joint bool GetCollideConnected() const; /// Dump this joint to the log file. - virtual void Dump() { b2Log("// Dump is not supported for this joint type.\n"); } + virtual void Dump() { b2Dump("// Dump is not supported for this joint type.\n"); } /// Shift the origin for any points stored in world coordinates. virtual void ShiftOrigin(const b2Vec2& newOrigin) { B2_NOT_USED(newOrigin); } diff --git a/include/box2d/b2_settings.h b/include/box2d/b2_settings.h index 41dd54260..3b17e12fb 100644 --- a/include/box2d/b2_settings.h +++ b/include/box2d/b2_settings.h @@ -142,6 +142,11 @@ void b2Free(void* mem); /// Logging function. void b2Log(const char* string, ...); +/// Dump to a file. Only one dump file allowed at a time. +void b2OpenDump(const char* fileName); +void b2Dump(const char* string, ...); +void b2CloseDump(); + /// Version numbering scheme. /// See http://en.wikipedia.org/wiki/Software_versioning struct b2Version diff --git a/src/common/b2_settings.cpp b/src/common/b2_settings.cpp index 2190504c9..11436f7de 100644 --- a/src/common/b2_settings.cpp +++ b/src/common/b2_settings.cpp @@ -20,6 +20,8 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. +#define _CRT_SECURE_NO_WARNINGS + #include "box2d/b2_settings.h" #include #include @@ -46,3 +48,30 @@ void b2Log(const char* string, ...) vprintf(string, args); va_end(args); } + +FILE* b2_dumpFile = nullptr; + +void b2OpenDump(const char* fileName) +{ + b2Assert(b2_dumpFile == nullptr); + b2_dumpFile = fopen(fileName, "w"); +} + +void b2Dump(const char* string, ...) +{ + if (b2_dumpFile == nullptr) + { + return; + } + + va_list args; + va_start(args, string); + vfprintf(b2_dumpFile, string, args); + va_end(args); +} + +void b2CloseDump() +{ + fclose(b2_dumpFile); + b2_dumpFile = nullptr; +} diff --git a/src/dynamics/b2_body.cpp b/src/dynamics/b2_body.cpp index fddbc81e5..74308a3d2 100644 --- a/src/dynamics/b2_body.cpp +++ b/src/dynamics/b2_body.cpp @@ -531,28 +531,28 @@ void b2Body::Dump() { int32 bodyIndex = m_islandIndex; - b2Log("{\n"); - b2Log(" b2BodyDef bd;\n"); - b2Log(" bd.type = b2BodyType(%d);\n", m_type); - b2Log(" bd.position.Set(%.15lef, %.15lef);\n", m_xf.p.x, m_xf.p.y); - b2Log(" bd.angle = %.15lef;\n", m_sweep.a); - b2Log(" bd.linearVelocity.Set(%.15lef, %.15lef);\n", m_linearVelocity.x, m_linearVelocity.y); - b2Log(" bd.angularVelocity = %.15lef;\n", m_angularVelocity); - b2Log(" bd.linearDamping = %.15lef;\n", m_linearDamping); - b2Log(" bd.angularDamping = %.15lef;\n", m_angularDamping); - b2Log(" bd.allowSleep = bool(%d);\n", m_flags & e_autoSleepFlag); - b2Log(" bd.awake = bool(%d);\n", m_flags & e_awakeFlag); - b2Log(" bd.fixedRotation = bool(%d);\n", m_flags & e_fixedRotationFlag); - b2Log(" bd.bullet = bool(%d);\n", m_flags & e_bulletFlag); - b2Log(" bd.enabled = bool(%d);\n", m_flags & e_enabledFlag); - b2Log(" bd.gravityScale = %.15lef;\n", m_gravityScale); - b2Log(" bodies[%d] = m_world->CreateBody(&bd);\n", m_islandIndex); - b2Log("\n"); + b2Dump("{\n"); + b2Dump(" b2BodyDef bd;\n"); + b2Dump(" bd.type = b2BodyType(%d);\n", m_type); + b2Dump(" bd.position.Set(%.15lef, %.15lef);\n", m_xf.p.x, m_xf.p.y); + b2Dump(" bd.angle = %.15lef;\n", m_sweep.a); + b2Dump(" bd.linearVelocity.Set(%.15lef, %.15lef);\n", m_linearVelocity.x, m_linearVelocity.y); + b2Dump(" bd.angularVelocity = %.15lef;\n", m_angularVelocity); + b2Dump(" bd.linearDamping = %.15lef;\n", m_linearDamping); + b2Dump(" bd.angularDamping = %.15lef;\n", m_angularDamping); + b2Dump(" bd.allowSleep = bool(%d);\n", m_flags & e_autoSleepFlag); + b2Dump(" bd.awake = bool(%d);\n", m_flags & e_awakeFlag); + b2Dump(" bd.fixedRotation = bool(%d);\n", m_flags & e_fixedRotationFlag); + b2Dump(" bd.bullet = bool(%d);\n", m_flags & e_bulletFlag); + b2Dump(" bd.enabled = bool(%d);\n", m_flags & e_enabledFlag); + b2Dump(" bd.gravityScale = %.15lef;\n", m_gravityScale); + b2Dump(" bodies[%d] = m_world->CreateBody(&bd);\n", m_islandIndex); + b2Dump("\n"); for (b2Fixture* f = m_fixtureList; f; f = f->m_next) { - b2Log(" {\n"); + b2Dump(" {\n"); f->Dump(bodyIndex); - b2Log(" }\n"); + b2Dump(" }\n"); } - b2Log("}\n"); + b2Dump("}\n"); } diff --git a/src/dynamics/b2_distance_joint.cpp b/src/dynamics/b2_distance_joint.cpp index 5642103a8..d9461114b 100644 --- a/src/dynamics/b2_distance_joint.cpp +++ b/src/dynamics/b2_distance_joint.cpp @@ -253,14 +253,14 @@ void b2DistanceJoint::Dump() int32 indexA = m_bodyA->m_islandIndex; int32 indexB = m_bodyB->m_islandIndex; - b2Log(" b2DistanceJointDef jd;\n"); - b2Log(" jd.bodyA = bodies[%d];\n", indexA); - b2Log(" jd.bodyB = bodies[%d];\n", indexB); - b2Log(" jd.collideConnected = bool(%d);\n", m_collideConnected); - b2Log(" jd.localAnchorA.Set(%.15lef, %.15lef);\n", m_localAnchorA.x, m_localAnchorA.y); - b2Log(" jd.localAnchorB.Set(%.15lef, %.15lef);\n", m_localAnchorB.x, m_localAnchorB.y); - b2Log(" jd.length = %.15lef;\n", m_length); - b2Log(" jd.frequencyHz = %.15lef;\n", m_frequencyHz); - b2Log(" jd.dampingRatio = %.15lef;\n", m_dampingRatio); - b2Log(" joints[%d] = m_world->CreateJoint(&jd);\n", m_index); + b2Dump(" b2DistanceJointDef jd;\n"); + b2Dump(" jd.bodyA = bodies[%d];\n", indexA); + b2Dump(" jd.bodyB = bodies[%d];\n", indexB); + b2Dump(" jd.collideConnected = bool(%d);\n", m_collideConnected); + b2Dump(" jd.localAnchorA.Set(%.15lef, %.15lef);\n", m_localAnchorA.x, m_localAnchorA.y); + b2Dump(" jd.localAnchorB.Set(%.15lef, %.15lef);\n", m_localAnchorB.x, m_localAnchorB.y); + b2Dump(" jd.length = %.15lef;\n", m_length); + b2Dump(" jd.frequencyHz = %.15lef;\n", m_frequencyHz); + b2Dump(" jd.dampingRatio = %.15lef;\n", m_dampingRatio); + b2Dump(" joints[%d] = m_world->CreateJoint(&jd);\n", m_index); } diff --git a/src/dynamics/b2_fixture.cpp b/src/dynamics/b2_fixture.cpp index d0c1579eb..35a4efbfd 100644 --- a/src/dynamics/b2_fixture.cpp +++ b/src/dynamics/b2_fixture.cpp @@ -232,67 +232,67 @@ void b2Fixture::SetSensor(bool sensor) void b2Fixture::Dump(int32 bodyIndex) { - b2Log(" b2FixtureDef fd;\n"); - b2Log(" fd.friction = %.15lef;\n", m_friction); - b2Log(" fd.restitution = %.15lef;\n", m_restitution); - b2Log(" fd.density = %.15lef;\n", m_density); - b2Log(" fd.isSensor = bool(%d);\n", m_isSensor); - b2Log(" fd.filter.categoryBits = uint16(%d);\n", m_filter.categoryBits); - b2Log(" fd.filter.maskBits = uint16(%d);\n", m_filter.maskBits); - b2Log(" fd.filter.groupIndex = int16(%d);\n", m_filter.groupIndex); + b2Dump(" b2FixtureDef fd;\n"); + b2Dump(" fd.friction = %.15lef;\n", m_friction); + b2Dump(" fd.restitution = %.15lef;\n", m_restitution); + b2Dump(" fd.density = %.15lef;\n", m_density); + b2Dump(" fd.isSensor = bool(%d);\n", m_isSensor); + b2Dump(" fd.filter.categoryBits = uint16(%d);\n", m_filter.categoryBits); + b2Dump(" fd.filter.maskBits = uint16(%d);\n", m_filter.maskBits); + b2Dump(" fd.filter.groupIndex = int16(%d);\n", m_filter.groupIndex); switch (m_shape->m_type) { case b2Shape::e_circle: { b2CircleShape* s = (b2CircleShape*)m_shape; - b2Log(" b2CircleShape shape;\n"); - b2Log(" shape.m_radius = %.15lef;\n", s->m_radius); - b2Log(" shape.m_p.Set(%.15lef, %.15lef);\n", s->m_p.x, s->m_p.y); + b2Dump(" b2CircleShape shape;\n"); + b2Dump(" shape.m_radius = %.15lef;\n", s->m_radius); + b2Dump(" shape.m_p.Set(%.15lef, %.15lef);\n", s->m_p.x, s->m_p.y); } break; case b2Shape::e_edge: { b2EdgeShape* s = (b2EdgeShape*)m_shape; - b2Log(" b2EdgeShape shape;\n"); - b2Log(" shape.m_radius = %.15lef;\n", s->m_radius); - b2Log(" shape.m_vertex0.Set(%.15lef, %.15lef);\n", s->m_vertex0.x, s->m_vertex0.y); - b2Log(" shape.m_vertex1.Set(%.15lef, %.15lef);\n", s->m_vertex1.x, s->m_vertex1.y); - b2Log(" shape.m_vertex2.Set(%.15lef, %.15lef);\n", s->m_vertex2.x, s->m_vertex2.y); - b2Log(" shape.m_vertex3.Set(%.15lef, %.15lef);\n", s->m_vertex3.x, s->m_vertex3.y); - b2Log(" shape.m_hasVertex0 = bool(%d);\n", s->m_hasVertex0); - b2Log(" shape.m_hasVertex3 = bool(%d);\n", s->m_hasVertex3); + b2Dump(" b2EdgeShape shape;\n"); + b2Dump(" shape.m_radius = %.15lef;\n", s->m_radius); + b2Dump(" shape.m_vertex0.Set(%.15lef, %.15lef);\n", s->m_vertex0.x, s->m_vertex0.y); + b2Dump(" shape.m_vertex1.Set(%.15lef, %.15lef);\n", s->m_vertex1.x, s->m_vertex1.y); + b2Dump(" shape.m_vertex2.Set(%.15lef, %.15lef);\n", s->m_vertex2.x, s->m_vertex2.y); + b2Dump(" shape.m_vertex3.Set(%.15lef, %.15lef);\n", s->m_vertex3.x, s->m_vertex3.y); + b2Dump(" shape.m_hasVertex0 = bool(%d);\n", s->m_hasVertex0); + b2Dump(" shape.m_hasVertex3 = bool(%d);\n", s->m_hasVertex3); } break; case b2Shape::e_polygon: { b2PolygonShape* s = (b2PolygonShape*)m_shape; - b2Log(" b2PolygonShape shape;\n"); - b2Log(" b2Vec2 vs[%d];\n", b2_maxPolygonVertices); + b2Dump(" b2PolygonShape shape;\n"); + b2Dump(" b2Vec2 vs[%d];\n", b2_maxPolygonVertices); for (int32 i = 0; i < s->m_count; ++i) { - b2Log(" vs[%d].Set(%.15lef, %.15lef);\n", i, s->m_vertices[i].x, s->m_vertices[i].y); + b2Dump(" vs[%d].Set(%.15lef, %.15lef);\n", i, s->m_vertices[i].x, s->m_vertices[i].y); } - b2Log(" shape.Set(vs, %d);\n", s->m_count); + b2Dump(" shape.Set(vs, %d);\n", s->m_count); } break; case b2Shape::e_chain: { b2ChainShape* s = (b2ChainShape*)m_shape; - b2Log(" b2ChainShape shape;\n"); - b2Log(" b2Vec2 vs[%d];\n", s->m_count); + b2Dump(" b2ChainShape shape;\n"); + b2Dump(" b2Vec2 vs[%d];\n", s->m_count); for (int32 i = 0; i < s->m_count; ++i) { - b2Log(" vs[%d].Set(%.15lef, %.15lef);\n", i, s->m_vertices[i].x, s->m_vertices[i].y); + b2Dump(" vs[%d].Set(%.15lef, %.15lef);\n", i, s->m_vertices[i].x, s->m_vertices[i].y); } - b2Log(" shape.CreateChain(vs, %d);\n", s->m_count); - b2Log(" shape.m_prevVertex.Set(%.15lef, %.15lef);\n", s->m_prevVertex.x, s->m_prevVertex.y); - b2Log(" shape.m_nextVertex.Set(%.15lef, %.15lef);\n", s->m_nextVertex.x, s->m_nextVertex.y); - b2Log(" shape.m_hasPrevVertex = bool(%d);\n", s->m_hasPrevVertex); - b2Log(" shape.m_hasNextVertex = bool(%d);\n", s->m_hasNextVertex); + b2Dump(" shape.CreateChain(vs, %d);\n", s->m_count); + b2Dump(" shape.m_prevVertex.Set(%.15lef, %.15lef);\n", s->m_prevVertex.x, s->m_prevVertex.y); + b2Dump(" shape.m_nextVertex.Set(%.15lef, %.15lef);\n", s->m_nextVertex.x, s->m_nextVertex.y); + b2Dump(" shape.m_hasPrevVertex = bool(%d);\n", s->m_hasPrevVertex); + b2Dump(" shape.m_hasNextVertex = bool(%d);\n", s->m_hasNextVertex); } break; @@ -300,8 +300,8 @@ void b2Fixture::Dump(int32 bodyIndex) return; } - b2Log("\n"); - b2Log(" fd.shape = &shape;\n"); - b2Log("\n"); - b2Log(" bodies[%d]->CreateFixture(&fd);\n", bodyIndex); + b2Dump("\n"); + b2Dump(" fd.shape = &shape;\n"); + b2Dump("\n"); + b2Dump(" bodies[%d]->CreateFixture(&fd);\n", bodyIndex); } diff --git a/src/dynamics/b2_friction_joint.cpp b/src/dynamics/b2_friction_joint.cpp index c461828db..f4a721341 100644 --- a/src/dynamics/b2_friction_joint.cpp +++ b/src/dynamics/b2_friction_joint.cpp @@ -243,13 +243,13 @@ void b2FrictionJoint::Dump() int32 indexA = m_bodyA->m_islandIndex; int32 indexB = m_bodyB->m_islandIndex; - b2Log(" b2FrictionJointDef jd;\n"); - b2Log(" jd.bodyA = bodies[%d];\n", indexA); - b2Log(" jd.bodyB = bodies[%d];\n", indexB); - b2Log(" jd.collideConnected = bool(%d);\n", m_collideConnected); - b2Log(" jd.localAnchorA.Set(%.15lef, %.15lef);\n", m_localAnchorA.x, m_localAnchorA.y); - b2Log(" jd.localAnchorB.Set(%.15lef, %.15lef);\n", m_localAnchorB.x, m_localAnchorB.y); - b2Log(" jd.maxForce = %.15lef;\n", m_maxForce); - b2Log(" jd.maxTorque = %.15lef;\n", m_maxTorque); - b2Log(" joints[%d] = m_world->CreateJoint(&jd);\n", m_index); + b2Dump(" b2FrictionJointDef jd;\n"); + b2Dump(" jd.bodyA = bodies[%d];\n", indexA); + b2Dump(" jd.bodyB = bodies[%d];\n", indexB); + b2Dump(" jd.collideConnected = bool(%d);\n", m_collideConnected); + b2Dump(" jd.localAnchorA.Set(%.15lef, %.15lef);\n", m_localAnchorA.x, m_localAnchorA.y); + b2Dump(" jd.localAnchorB.Set(%.15lef, %.15lef);\n", m_localAnchorB.x, m_localAnchorB.y); + b2Dump(" jd.maxForce = %.15lef;\n", m_maxForce); + b2Dump(" jd.maxTorque = %.15lef;\n", m_maxTorque); + b2Dump(" joints[%d] = m_world->CreateJoint(&jd);\n", m_index); } diff --git a/src/dynamics/b2_gear_joint.cpp b/src/dynamics/b2_gear_joint.cpp index 51ebda95e..c4473ffd3 100644 --- a/src/dynamics/b2_gear_joint.cpp +++ b/src/dynamics/b2_gear_joint.cpp @@ -412,12 +412,12 @@ void b2GearJoint::Dump() int32 index1 = m_joint1->m_index; int32 index2 = m_joint2->m_index; - b2Log(" b2GearJointDef jd;\n"); - b2Log(" jd.bodyA = bodies[%d];\n", indexA); - b2Log(" jd.bodyB = bodies[%d];\n", indexB); - b2Log(" jd.collideConnected = bool(%d);\n", m_collideConnected); - b2Log(" jd.joint1 = joints[%d];\n", index1); - b2Log(" jd.joint2 = joints[%d];\n", index2); - b2Log(" jd.ratio = %.15lef;\n", m_ratio); - b2Log(" joints[%d] = m_world->CreateJoint(&jd);\n", m_index); + b2Dump(" b2GearJointDef jd;\n"); + b2Dump(" jd.bodyA = bodies[%d];\n", indexA); + b2Dump(" jd.bodyB = bodies[%d];\n", indexB); + b2Dump(" jd.collideConnected = bool(%d);\n", m_collideConnected); + b2Dump(" jd.joint1 = joints[%d];\n", index1); + b2Dump(" jd.joint2 = joints[%d];\n", index2); + b2Dump(" jd.ratio = %.15lef;\n", m_ratio); + b2Dump(" joints[%d] = m_world->CreateJoint(&jd);\n", m_index); } diff --git a/src/dynamics/b2_motor_joint.cpp b/src/dynamics/b2_motor_joint.cpp index f5c0c72c7..71a880f6c 100644 --- a/src/dynamics/b2_motor_joint.cpp +++ b/src/dynamics/b2_motor_joint.cpp @@ -298,14 +298,14 @@ void b2MotorJoint::Dump() int32 indexA = m_bodyA->m_islandIndex; int32 indexB = m_bodyB->m_islandIndex; - b2Log(" b2MotorJointDef jd;\n"); - b2Log(" jd.bodyA = bodies[%d];\n", indexA); - b2Log(" jd.bodyB = bodies[%d];\n", indexB); - b2Log(" jd.collideConnected = bool(%d);\n", m_collideConnected); - b2Log(" jd.linearOffset.Set(%.15lef, %.15lef);\n", m_linearOffset.x, m_linearOffset.y); - b2Log(" jd.angularOffset = %.15lef;\n", m_angularOffset); - b2Log(" jd.maxForce = %.15lef;\n", m_maxForce); - b2Log(" jd.maxTorque = %.15lef;\n", m_maxTorque); - b2Log(" jd.correctionFactor = %.15lef;\n", m_correctionFactor); - b2Log(" joints[%d] = m_world->CreateJoint(&jd);\n", m_index); + b2Dump(" b2MotorJointDef jd;\n"); + b2Dump(" jd.bodyA = bodies[%d];\n", indexA); + b2Dump(" jd.bodyB = bodies[%d];\n", indexB); + b2Dump(" jd.collideConnected = bool(%d);\n", m_collideConnected); + b2Dump(" jd.linearOffset.Set(%.15lef, %.15lef);\n", m_linearOffset.x, m_linearOffset.y); + b2Dump(" jd.angularOffset = %.15lef;\n", m_angularOffset); + b2Dump(" jd.maxForce = %.15lef;\n", m_maxForce); + b2Dump(" jd.maxTorque = %.15lef;\n", m_maxTorque); + b2Dump(" jd.correctionFactor = %.15lef;\n", m_correctionFactor); + b2Dump(" joints[%d] = m_world->CreateJoint(&jd);\n", m_index); } diff --git a/src/dynamics/b2_prismatic_joint.cpp b/src/dynamics/b2_prismatic_joint.cpp index 404196df4..3ab7c0267 100644 --- a/src/dynamics/b2_prismatic_joint.cpp +++ b/src/dynamics/b2_prismatic_joint.cpp @@ -589,21 +589,21 @@ void b2PrismaticJoint::Dump() int32 indexA = m_bodyA->m_islandIndex; int32 indexB = m_bodyB->m_islandIndex; - b2Log(" b2PrismaticJointDef jd;\n"); - b2Log(" jd.bodyA = bodies[%d];\n", indexA); - b2Log(" jd.bodyB = bodies[%d];\n", indexB); - b2Log(" jd.collideConnected = bool(%d);\n", m_collideConnected); - b2Log(" jd.localAnchorA.Set(%.9g, %.9g);\n", m_localAnchorA.x, m_localAnchorA.y); - b2Log(" jd.localAnchorB.Set(%.9g, %.9g);\n", m_localAnchorB.x, m_localAnchorB.y); - b2Log(" jd.localAxisA.Set(%.9g, %.9g);\n", m_localXAxisA.x, m_localXAxisA.y); - b2Log(" jd.referenceAngle = %.9g;\n", m_referenceAngle); - b2Log(" jd.enableLimit = bool(%d);\n", m_enableLimit); - b2Log(" jd.lowerTranslation = %.9g;\n", m_lowerTranslation); - b2Log(" jd.upperTranslation = %.9g;\n", m_upperTranslation); - b2Log(" jd.enableMotor = bool(%d);\n", m_enableMotor); - b2Log(" jd.motorSpeed = %.9g;\n", m_motorSpeed); - b2Log(" jd.maxMotorForce = %.9g;\n", m_maxMotorForce); - b2Log(" joints[%d] = m_world->CreateJoint(&jd);\n", m_index); + b2Dump(" b2PrismaticJointDef jd;\n"); + b2Dump(" jd.bodyA = bodies[%d];\n", indexA); + b2Dump(" jd.bodyB = bodies[%d];\n", indexB); + b2Dump(" jd.collideConnected = bool(%d);\n", m_collideConnected); + b2Dump(" jd.localAnchorA.Set(%.9g, %.9g);\n", m_localAnchorA.x, m_localAnchorA.y); + b2Dump(" jd.localAnchorB.Set(%.9g, %.9g);\n", m_localAnchorB.x, m_localAnchorB.y); + b2Dump(" jd.localAxisA.Set(%.9g, %.9g);\n", m_localXAxisA.x, m_localXAxisA.y); + b2Dump(" jd.referenceAngle = %.9g;\n", m_referenceAngle); + b2Dump(" jd.enableLimit = bool(%d);\n", m_enableLimit); + b2Dump(" jd.lowerTranslation = %.9g;\n", m_lowerTranslation); + b2Dump(" jd.upperTranslation = %.9g;\n", m_upperTranslation); + b2Dump(" jd.enableMotor = bool(%d);\n", m_enableMotor); + b2Dump(" jd.motorSpeed = %.9g;\n", m_motorSpeed); + b2Dump(" jd.maxMotorForce = %.9g;\n", m_maxMotorForce); + b2Dump(" joints[%d] = m_world->CreateJoint(&jd);\n", m_index); } /// diff --git a/src/dynamics/b2_pulley_joint.cpp b/src/dynamics/b2_pulley_joint.cpp index d589b4073..20bec4856 100644 --- a/src/dynamics/b2_pulley_joint.cpp +++ b/src/dynamics/b2_pulley_joint.cpp @@ -331,18 +331,18 @@ void b2PulleyJoint::Dump() int32 indexA = m_bodyA->m_islandIndex; int32 indexB = m_bodyB->m_islandIndex; - b2Log(" b2PulleyJointDef jd;\n"); - b2Log(" jd.bodyA = bodies[%d];\n", indexA); - b2Log(" jd.bodyB = bodies[%d];\n", indexB); - b2Log(" jd.collideConnected = bool(%d);\n", m_collideConnected); - b2Log(" jd.groundAnchorA.Set(%.15lef, %.15lef);\n", m_groundAnchorA.x, m_groundAnchorA.y); - b2Log(" jd.groundAnchorB.Set(%.15lef, %.15lef);\n", m_groundAnchorB.x, m_groundAnchorB.y); - b2Log(" jd.localAnchorA.Set(%.15lef, %.15lef);\n", m_localAnchorA.x, m_localAnchorA.y); - b2Log(" jd.localAnchorB.Set(%.15lef, %.15lef);\n", m_localAnchorB.x, m_localAnchorB.y); - b2Log(" jd.lengthA = %.15lef;\n", m_lengthA); - b2Log(" jd.lengthB = %.15lef;\n", m_lengthB); - b2Log(" jd.ratio = %.15lef;\n", m_ratio); - b2Log(" joints[%d] = m_world->CreateJoint(&jd);\n", m_index); + b2Dump(" b2PulleyJointDef jd;\n"); + b2Dump(" jd.bodyA = bodies[%d];\n", indexA); + b2Dump(" jd.bodyB = bodies[%d];\n", indexB); + b2Dump(" jd.collideConnected = bool(%d);\n", m_collideConnected); + b2Dump(" jd.groundAnchorA.Set(%.15lef, %.15lef);\n", m_groundAnchorA.x, m_groundAnchorA.y); + b2Dump(" jd.groundAnchorB.Set(%.15lef, %.15lef);\n", m_groundAnchorB.x, m_groundAnchorB.y); + b2Dump(" jd.localAnchorA.Set(%.15lef, %.15lef);\n", m_localAnchorA.x, m_localAnchorA.y); + b2Dump(" jd.localAnchorB.Set(%.15lef, %.15lef);\n", m_localAnchorB.x, m_localAnchorB.y); + b2Dump(" jd.lengthA = %.15lef;\n", m_lengthA); + b2Dump(" jd.lengthB = %.15lef;\n", m_lengthB); + b2Dump(" jd.ratio = %.15lef;\n", m_ratio); + b2Dump(" joints[%d] = m_world->CreateJoint(&jd);\n", m_index); } void b2PulleyJoint::ShiftOrigin(const b2Vec2& newOrigin) diff --git a/src/dynamics/b2_revolute_joint.cpp b/src/dynamics/b2_revolute_joint.cpp index c7d43d96e..abd0c4310 100644 --- a/src/dynamics/b2_revolute_joint.cpp +++ b/src/dynamics/b2_revolute_joint.cpp @@ -498,18 +498,18 @@ void b2RevoluteJoint::Dump() int32 indexA = m_bodyA->m_islandIndex; int32 indexB = m_bodyB->m_islandIndex; - b2Log(" b2RevoluteJointDef jd;\n"); - b2Log(" jd.bodyA = bodies[%d];\n", indexA); - b2Log(" jd.bodyB = bodies[%d];\n", indexB); - b2Log(" jd.collideConnected = bool(%d);\n", m_collideConnected); - b2Log(" jd.localAnchorA.Set(%.15lef, %.15lef);\n", m_localAnchorA.x, m_localAnchorA.y); - b2Log(" jd.localAnchorB.Set(%.15lef, %.15lef);\n", m_localAnchorB.x, m_localAnchorB.y); - b2Log(" jd.referenceAngle = %.15lef;\n", m_referenceAngle); - b2Log(" jd.enableLimit = bool(%d);\n", m_enableLimit); - b2Log(" jd.lowerAngle = %.15lef;\n", m_lowerAngle); - b2Log(" jd.upperAngle = %.15lef;\n", m_upperAngle); - b2Log(" jd.enableMotor = bool(%d);\n", m_enableMotor); - b2Log(" jd.motorSpeed = %.15lef;\n", m_motorSpeed); - b2Log(" jd.maxMotorTorque = %.15lef;\n", m_maxMotorTorque); - b2Log(" joints[%d] = m_world->CreateJoint(&jd);\n", m_index); + b2Dump(" b2RevoluteJointDef jd;\n"); + b2Dump(" jd.bodyA = bodies[%d];\n", indexA); + b2Dump(" jd.bodyB = bodies[%d];\n", indexB); + b2Dump(" jd.collideConnected = bool(%d);\n", m_collideConnected); + b2Dump(" jd.localAnchorA.Set(%.15lef, %.15lef);\n", m_localAnchorA.x, m_localAnchorA.y); + b2Dump(" jd.localAnchorB.Set(%.15lef, %.15lef);\n", m_localAnchorB.x, m_localAnchorB.y); + b2Dump(" jd.referenceAngle = %.15lef;\n", m_referenceAngle); + b2Dump(" jd.enableLimit = bool(%d);\n", m_enableLimit); + b2Dump(" jd.lowerAngle = %.15lef;\n", m_lowerAngle); + b2Dump(" jd.upperAngle = %.15lef;\n", m_upperAngle); + b2Dump(" jd.enableMotor = bool(%d);\n", m_enableMotor); + b2Dump(" jd.motorSpeed = %.15lef;\n", m_motorSpeed); + b2Dump(" jd.maxMotorTorque = %.15lef;\n", m_maxMotorTorque); + b2Dump(" joints[%d] = m_world->CreateJoint(&jd);\n", m_index); } diff --git a/src/dynamics/b2_rope_joint.cpp b/src/dynamics/b2_rope_joint.cpp index bf4f5aa47..ca7899ada 100644 --- a/src/dynamics/b2_rope_joint.cpp +++ b/src/dynamics/b2_rope_joint.cpp @@ -234,12 +234,12 @@ void b2RopeJoint::Dump() int32 indexA = m_bodyA->m_islandIndex; int32 indexB = m_bodyB->m_islandIndex; - b2Log(" b2RopeJointDef jd;\n"); - b2Log(" jd.bodyA = bodies[%d];\n", indexA); - b2Log(" jd.bodyB = bodies[%d];\n", indexB); - b2Log(" jd.collideConnected = bool(%d);\n", m_collideConnected); - b2Log(" jd.localAnchorA.Set(%.15lef, %.15lef);\n", m_localAnchorA.x, m_localAnchorA.y); - b2Log(" jd.localAnchorB.Set(%.15lef, %.15lef);\n", m_localAnchorB.x, m_localAnchorB.y); - b2Log(" jd.maxLength = %.15lef;\n", m_maxLength); - b2Log(" joints[%d] = m_world->CreateJoint(&jd);\n", m_index); + b2Dump(" b2RopeJointDef jd;\n"); + b2Dump(" jd.bodyA = bodies[%d];\n", indexA); + b2Dump(" jd.bodyB = bodies[%d];\n", indexB); + b2Dump(" jd.collideConnected = bool(%d);\n", m_collideConnected); + b2Dump(" jd.localAnchorA.Set(%.15lef, %.15lef);\n", m_localAnchorA.x, m_localAnchorA.y); + b2Dump(" jd.localAnchorB.Set(%.15lef, %.15lef);\n", m_localAnchorB.x, m_localAnchorB.y); + b2Dump(" jd.maxLength = %.15lef;\n", m_maxLength); + b2Dump(" joints[%d] = m_world->CreateJoint(&jd);\n", m_index); } diff --git a/src/dynamics/b2_weld_joint.cpp b/src/dynamics/b2_weld_joint.cpp index c505a1134..07c95528d 100644 --- a/src/dynamics/b2_weld_joint.cpp +++ b/src/dynamics/b2_weld_joint.cpp @@ -335,14 +335,14 @@ void b2WeldJoint::Dump() int32 indexA = m_bodyA->m_islandIndex; int32 indexB = m_bodyB->m_islandIndex; - b2Log(" b2WeldJointDef jd;\n"); - b2Log(" jd.bodyA = bodies[%d];\n", indexA); - b2Log(" jd.bodyB = bodies[%d];\n", indexB); - b2Log(" jd.collideConnected = bool(%d);\n", m_collideConnected); - b2Log(" jd.localAnchorA.Set(%.15lef, %.15lef);\n", m_localAnchorA.x, m_localAnchorA.y); - b2Log(" jd.localAnchorB.Set(%.15lef, %.15lef);\n", m_localAnchorB.x, m_localAnchorB.y); - b2Log(" jd.referenceAngle = %.15lef;\n", m_referenceAngle); - b2Log(" jd.frequencyHz = %.15lef;\n", m_frequencyHz); - b2Log(" jd.dampingRatio = %.15lef;\n", m_dampingRatio); - b2Log(" joints[%d] = m_world->CreateJoint(&jd);\n", m_index); + b2Dump(" b2WeldJointDef jd;\n"); + b2Dump(" jd.bodyA = bodies[%d];\n", indexA); + b2Dump(" jd.bodyB = bodies[%d];\n", indexB); + b2Dump(" jd.collideConnected = bool(%d);\n", m_collideConnected); + b2Dump(" jd.localAnchorA.Set(%.15lef, %.15lef);\n", m_localAnchorA.x, m_localAnchorA.y); + b2Dump(" jd.localAnchorB.Set(%.15lef, %.15lef);\n", m_localAnchorB.x, m_localAnchorB.y); + b2Dump(" jd.referenceAngle = %.15lef;\n", m_referenceAngle); + b2Dump(" jd.frequencyHz = %.15lef;\n", m_frequencyHz); + b2Dump(" jd.dampingRatio = %.15lef;\n", m_dampingRatio); + b2Dump(" joints[%d] = m_world->CreateJoint(&jd);\n", m_index); } diff --git a/src/dynamics/b2_wheel_joint.cpp b/src/dynamics/b2_wheel_joint.cpp index f9fbad539..3e76678bf 100644 --- a/src/dynamics/b2_wheel_joint.cpp +++ b/src/dynamics/b2_wheel_joint.cpp @@ -620,19 +620,19 @@ void b2WheelJoint::Dump() int32 indexA = m_bodyA->m_islandIndex; int32 indexB = m_bodyB->m_islandIndex; - b2Log(" b2WheelJointDef jd;\n"); - b2Log(" jd.bodyA = bodies[%d];\n", indexA); - b2Log(" jd.bodyB = bodies[%d];\n", indexB); - b2Log(" jd.collideConnected = bool(%d);\n", m_collideConnected); - b2Log(" jd.localAnchorA.Set(%.9g, %.9g);\n", m_localAnchorA.x, m_localAnchorA.y); - b2Log(" jd.localAnchorB.Set(%.9g, %.9g);\n", m_localAnchorB.x, m_localAnchorB.y); - b2Log(" jd.localAxisA.Set(%.9g, %.9g);\n", m_localXAxisA.x, m_localXAxisA.y); - b2Log(" jd.enableMotor = bool(%d);\n", m_enableMotor); - b2Log(" jd.motorSpeed = %.9g;\n", m_motorSpeed); - b2Log(" jd.maxMotorTorque = %.9g;\n", m_maxMotorTorque); - b2Log(" jd.stiffness = %.9g;\n", m_stiffness); - b2Log(" jd.damping = %.9g;\n", m_damping); - b2Log(" joints[%d] = m_world->CreateJoint(&jd);\n", m_index); + b2Dump(" b2WheelJointDef jd;\n"); + b2Dump(" jd.bodyA = bodies[%d];\n", indexA); + b2Dump(" jd.bodyB = bodies[%d];\n", indexB); + b2Dump(" jd.collideConnected = bool(%d);\n", m_collideConnected); + b2Dump(" jd.localAnchorA.Set(%.9g, %.9g);\n", m_localAnchorA.x, m_localAnchorA.y); + b2Dump(" jd.localAnchorB.Set(%.9g, %.9g);\n", m_localAnchorB.x, m_localAnchorB.y); + b2Dump(" jd.localAxisA.Set(%.9g, %.9g);\n", m_localXAxisA.x, m_localXAxisA.y); + b2Dump(" jd.enableMotor = bool(%d);\n", m_enableMotor); + b2Dump(" jd.motorSpeed = %.9g;\n", m_motorSpeed); + b2Dump(" jd.maxMotorTorque = %.9g;\n", m_maxMotorTorque); + b2Dump(" jd.stiffness = %.9g;\n", m_stiffness); + b2Dump(" jd.damping = %.9g;\n", m_damping); + b2Dump(" joints[%d] = m_world->CreateJoint(&jd);\n", m_index); } /// diff --git a/src/dynamics/b2_world.cpp b/src/dynamics/b2_world.cpp index d48ae6b6f..6f59762b9 100644 --- a/src/dynamics/b2_world.cpp +++ b/src/dynamics/b2_world.cpp @@ -1277,11 +1277,14 @@ void b2World::Dump() return; } - b2Log("b2Vec2 g(%.15lef, %.15lef);\n", m_gravity.x, m_gravity.y); - b2Log("m_world->SetGravity(g);\n"); + b2OpenDump("box2d_dump.inl"); + + b2Dump("b2Vec2 g(%.15lef, %.15lef);\n", m_gravity.x, m_gravity.y); + b2Dump("m_world->SetGravity(g);\n"); + + b2Dump("b2Body** bodies = (b2Body**)b2Alloc(%d * sizeof(b2Body*));\n", m_bodyCount); + b2Dump("b2Joint** joints = (b2Joint**)b2Alloc(%d * sizeof(b2Joint*));\n", m_jointCount); - b2Log("b2Body** bodies = (b2Body**)b2Alloc(%d * sizeof(b2Body*));\n", m_bodyCount); - b2Log("b2Joint** joints = (b2Joint**)b2Alloc(%d * sizeof(b2Joint*));\n", m_jointCount); int32 i = 0; for (b2Body* b = m_bodyList; b; b = b->m_next) { @@ -1305,9 +1308,9 @@ void b2World::Dump() continue; } - b2Log("{\n"); + b2Dump("{\n"); j->Dump(); - b2Log("}\n"); + b2Dump("}\n"); } // Second pass on joints, only gear joints. @@ -1318,13 +1321,15 @@ void b2World::Dump() continue; } - b2Log("{\n"); + b2Dump("{\n"); j->Dump(); - b2Log("}\n"); + b2Dump("}\n"); } - b2Log("b2Free(joints);\n"); - b2Log("b2Free(bodies);\n"); - b2Log("joints = nullptr;\n"); - b2Log("bodies = nullptr;\n"); + b2Dump("b2Free(joints);\n"); + b2Dump("b2Free(bodies);\n"); + b2Dump("joints = nullptr;\n"); + b2Dump("bodies = nullptr;\n"); + + b2CloseDump(); } diff --git a/testbed/test.h b/testbed/test.h index ae09e7cd3..d4f36c7a7 100644 --- a/testbed/test.h +++ b/testbed/test.h @@ -92,7 +92,7 @@ class Test : public b2ContactListener void ShiftMouseDown(const b2Vec2& p); virtual void MouseDown(const b2Vec2& p); virtual void MouseUp(const b2Vec2& p); - void MouseMove(const b2Vec2& p); + virtual void MouseMove(const b2Vec2& p); void LaunchBomb(); void LaunchBomb(const b2Vec2& position, const b2Vec2& velocity);