Create a custom logger for the testbed application and edit demo scenes for this

This commit is contained in:
Daniel Chappuis 2021-10-06 21:22:33 +02:00
parent 975eb1c11f
commit 30ca167bf9
47 changed files with 312 additions and 224 deletions

View File

@ -91,6 +91,8 @@ set(TESTBED_SOURCES
src/SceneDemo.h
src/SceneDemo.cpp
src/Timer.h
src/TestbedLogger.h
src/TestbedLogger.cpp
)
# Common source files

View File

@ -32,8 +32,8 @@ using namespace openglframework;
using namespace ballandsocketjointscene;
// Constructor
BallAndSocketJointScene::BallAndSocketJointScene(const std::string& name, EngineSettings& settings)
: SceneDemo(name, settings, true, SCENE_RADIUS) {
BallAndSocketJointScene::BallAndSocketJointScene(const std::string& name, EngineSettings& settings, reactphysics3d::PhysicsCommon& physicsCommon)
: SceneDemo(name, settings, physicsCommon, true, SCENE_RADIUS) {
// Compute the radius and the center of the scene
openglframework::Vector3 center(0, 5, 0);
@ -42,13 +42,6 @@ BallAndSocketJointScene::BallAndSocketJointScene(const std::string& name, Engine
setScenePosition(center, SCENE_RADIUS);
mWorldSettings.worldName = name;
// Logger
rp3d::DefaultLogger* defaultLogger = mPhysicsCommon.createDefaultLogger();
uint logLevel = static_cast<uint>(rp3d::Logger::Level::Information) | static_cast<uint>(rp3d::Logger::Level::Warning) |
static_cast<uint>(rp3d::Logger::Level::Error);
defaultLogger->addFileDestination("rp3d_log_" + name + ".html", logLevel, rp3d::DefaultLogger::Format::HTML);
mPhysicsCommon.setLogger(defaultLogger);
}
// Destructor

View File

@ -70,7 +70,7 @@ class BallAndSocketJointScene : public SceneDemo {
// -------------------- Methods -------------------- //
/// Constructor
BallAndSocketJointScene(const std::string& name, EngineSettings& settings);
BallAndSocketJointScene(const std::string& name, EngineSettings& settings, reactphysics3d::PhysicsCommon& physicsCommon);
/// Destructor
virtual ~BallAndSocketJointScene() override ;

View File

@ -32,8 +32,8 @@ using namespace openglframework;
using namespace ballandsocketjointschainscene;
// Constructor
BallAndSocketJointsChainScene::BallAndSocketJointsChainScene(const std::string& name, EngineSettings& settings)
: SceneDemo(name, settings, true, SCENE_RADIUS) {
BallAndSocketJointsChainScene::BallAndSocketJointsChainScene(const std::string& name, EngineSettings& settings, reactphysics3d::PhysicsCommon& physicsCommon)
: SceneDemo(name, settings, physicsCommon, true, SCENE_RADIUS) {
std::string meshFolderPath("meshes/");
@ -44,13 +44,6 @@ BallAndSocketJointsChainScene::BallAndSocketJointsChainScene(const std::string&
setScenePosition(center, SCENE_RADIUS);
mWorldSettings.worldName = name;
// Logger
rp3d::DefaultLogger* defaultLogger = mPhysicsCommon.createDefaultLogger();
uint logLevel = static_cast<uint>(rp3d::Logger::Level::Information) | static_cast<uint>(rp3d::Logger::Level::Warning) |
static_cast<uint>(rp3d::Logger::Level::Error);
defaultLogger->addFileDestination("rp3d_log_" + name + ".html", logLevel, rp3d::DefaultLogger::Format::HTML);
mPhysicsCommon.setLogger(defaultLogger);
}
// Destructor

View File

@ -65,7 +65,7 @@ class BallAndSocketJointsChainScene : public SceneDemo {
// -------------------- Methods -------------------- //
/// Constructor
BallAndSocketJointsChainScene(const std::string& name, EngineSettings& settings);
BallAndSocketJointsChainScene(const std::string& name, EngineSettings& settings, reactphysics3d::PhysicsCommon& physicsCommon);
/// Destructor
virtual ~BallAndSocketJointsChainScene() override ;

View File

@ -32,8 +32,8 @@ using namespace openglframework;
using namespace ballandsocketjointsnetscene;
// Constructor
BallAndSocketJointsNetScene::BallAndSocketJointsNetScene(const std::string& name, EngineSettings& settings)
: SceneDemo(name, settings, true, SCENE_RADIUS) {
BallAndSocketJointsNetScene::BallAndSocketJointsNetScene(const std::string& name, EngineSettings& settings, reactphysics3d::PhysicsCommon& physicsCommon)
: SceneDemo(name, settings, physicsCommon, true, SCENE_RADIUS) {
std::string meshFolderPath("meshes/");
@ -49,13 +49,6 @@ BallAndSocketJointsNetScene::BallAndSocketJointsNetScene(const std::string& name
rp3d::PhysicsWorld::WorldSettings worldSettings;
worldSettings.worldName = name;
// Logger
rp3d::DefaultLogger* defaultLogger = mPhysicsCommon.createDefaultLogger();
uint logLevel = static_cast<uint>(rp3d::Logger::Level::Information) | static_cast<uint>(rp3d::Logger::Level::Warning) |
static_cast<uint>(rp3d::Logger::Level::Error);
defaultLogger->addFileDestination("rp3d_log_" + name + ".html", logLevel, rp3d::DefaultLogger::Format::HTML);
mPhysicsCommon.setLogger(defaultLogger);
// Create the physics world for the physics simulation
rp3d::PhysicsWorld* physicsWorld = mPhysicsCommon.createPhysicsWorld(worldSettings);
physicsWorld->setEventListener(this);

View File

@ -65,7 +65,7 @@ class BallAndSocketJointsNetScene : public SceneDemo {
// -------------------- Methods -------------------- //
/// Constructor
BallAndSocketJointsNetScene(const std::string& name, EngineSettings& settings);
BallAndSocketJointsNetScene(const std::string& name, EngineSettings& settings, reactphysics3d::PhysicsCommon& physicsCommon);
/// Destructor
virtual ~BallAndSocketJointsNetScene() override ;

View File

@ -31,8 +31,8 @@ using namespace openglframework;
using namespace boxtowerscene;
// Constructor
BoxTowerScene::BoxTowerScene(const std::string& name, EngineSettings& settings)
: SceneDemo(name, settings, true, SCENE_RADIUS) {
BoxTowerScene::BoxTowerScene(const std::string& name, EngineSettings& settings, reactphysics3d::PhysicsCommon& physicsCommon)
: SceneDemo(name, settings, physicsCommon, true, SCENE_RADIUS) {
std::string meshFolderPath("meshes/");
@ -46,13 +46,6 @@ BoxTowerScene::BoxTowerScene(const std::string& name, EngineSettings& settings)
rp3d::Vector3 gravity(0, -9.81f, 0);
mWorldSettings.worldName = name;
// Logger
rp3d::DefaultLogger* defaultLogger = mPhysicsCommon.createDefaultLogger();
uint logLevel = static_cast<uint>(rp3d::Logger::Level::Information) | static_cast<uint>(rp3d::Logger::Level::Warning) |
static_cast<uint>(rp3d::Logger::Level::Error);
defaultLogger->addFileDestination("rp3d_log_" + name + ".html", logLevel, rp3d::DefaultLogger::Format::HTML);
mPhysicsCommon.setLogger(defaultLogger);
}
// Destructor

View File

@ -77,7 +77,7 @@ class BoxTowerScene : public SceneDemo {
// -------------------- Methods -------------------- //
/// Constructor
BoxTowerScene(const std::string& name, EngineSettings& settings);
BoxTowerScene(const std::string& name, EngineSettings& settings, reactphysics3d::PhysicsCommon &physicsCommon);
/// Destructor
virtual ~BoxTowerScene() override;

View File

@ -32,8 +32,8 @@ using namespace openglframework;
using namespace bridgescene;
// Constructor
BridgeScene::BridgeScene(const std::string& name, EngineSettings& settings)
: SceneDemo(name, settings, true, SCENE_RADIUS) {
BridgeScene::BridgeScene(const std::string& name, EngineSettings& settings, reactphysics3d::PhysicsCommon& physicsCommon)
: SceneDemo(name, settings, physicsCommon, true, SCENE_RADIUS) {
std::string meshFolderPath("meshes/");
@ -44,13 +44,6 @@ BridgeScene::BridgeScene(const std::string& name, EngineSettings& settings)
setScenePosition(center, SCENE_RADIUS);
mWorldSettings.worldName = name;
// Logger
rp3d::DefaultLogger* defaultLogger = mPhysicsCommon.createDefaultLogger();
uint logLevel = static_cast<uint>(rp3d::Logger::Level::Information) | static_cast<uint>(rp3d::Logger::Level::Warning) |
static_cast<uint>(rp3d::Logger::Level::Error);
defaultLogger->addFileDestination("rp3d_log_" + name + ".html", logLevel, rp3d::DefaultLogger::Format::HTML);
mPhysicsCommon.setLogger(defaultLogger);
}
// Destructor

View File

@ -72,7 +72,7 @@ class BridgeScene : public SceneDemo {
// -------------------- Methods -------------------- //
/// Constructor
BridgeScene(const std::string& name, EngineSettings& settings);
BridgeScene(const std::string& name, EngineSettings& settings, reactphysics3d::PhysicsCommon& physicsCommon);
/// Destructor
virtual ~BridgeScene() override ;

View File

@ -33,8 +33,8 @@ using namespace openglframework;
using namespace collisiondetectionscene;
// Constructor
CollisionDetectionScene::CollisionDetectionScene(const std::string& name, EngineSettings& settings)
: SceneDemo(name, settings, SCENE_RADIUS, false), mMeshFolderPath("meshes/"),
CollisionDetectionScene::CollisionDetectionScene(const std::string& name, EngineSettings& settings, reactphysics3d::PhysicsCommon& physicsCommon)
: SceneDemo(name, settings, physicsCommon, SCENE_RADIUS, false), mMeshFolderPath("meshes/"),
mContactManager(mPhongShader, mMeshFolderPath, mSnapshotsContactPoints),
mAreNormalsDisplayed(false) {
@ -52,13 +52,6 @@ CollisionDetectionScene::CollisionDetectionScene(const std::string& name, Engine
rp3d::PhysicsWorld::WorldSettings worldSettings;
worldSettings.worldName = name;
// Logger
rp3d::DefaultLogger* defaultLogger = mPhysicsCommon.createDefaultLogger();
uint logLevel = static_cast<uint>(rp3d::Logger::Level::Information) | static_cast<uint>(rp3d::Logger::Level::Warning) |
static_cast<uint>(rp3d::Logger::Level::Error);
defaultLogger->addFileDestination("rp3d_log_" + name + ".html", logLevel, rp3d::DefaultLogger::Format::HTML);
mPhysicsCommon.setLogger(defaultLogger);
// Create the physics world for the physics simulation
mPhysicsWorld = mPhysicsCommon.createPhysicsWorld(worldSettings);

View File

@ -121,7 +121,7 @@ class CollisionDetectionScene : public SceneDemo {
// -------------------- Methods -------------------- //
/// Constructor
CollisionDetectionScene(const std::string& name, EngineSettings& settings);
CollisionDetectionScene(const std::string& name, EngineSettings& settings, reactphysics3d::PhysicsCommon& physicsCommon);
/// Destructor
virtual ~CollisionDetectionScene() override;

View File

@ -31,8 +31,8 @@ using namespace openglframework;
using namespace collisionshapesscene;
// Constructor
CollisionShapesScene::CollisionShapesScene(const std::string& name, EngineSettings& settings)
: SceneDemo(name, settings, true, SCENE_RADIUS) {
CollisionShapesScene::CollisionShapesScene(const std::string& name, EngineSettings& settings, reactphysics3d::PhysicsCommon& physicsCommon)
: SceneDemo(name, settings, physicsCommon, true, SCENE_RADIUS) {
std::string meshFolderPath("meshes/");
@ -43,13 +43,6 @@ CollisionShapesScene::CollisionShapesScene(const std::string& name, EngineSettin
setScenePosition(center, SCENE_RADIUS);
mWorldSettings.worldName = name;
// Logger
rp3d::DefaultLogger* defaultLogger = mPhysicsCommon.createDefaultLogger();
uint logLevel = static_cast<uint>(rp3d::Logger::Level::Information) | static_cast<uint>(rp3d::Logger::Level::Warning) |
static_cast<uint>(rp3d::Logger::Level::Error);
defaultLogger->addFileDestination("rp3d_log_" + name + ".html", logLevel, rp3d::DefaultLogger::Format::HTML);
mPhysicsCommon.setLogger(defaultLogger);
}
// Destructor

View File

@ -89,7 +89,7 @@ class CollisionShapesScene : public SceneDemo {
// -------------------- Methods -------------------- //
/// Constructor
CollisionShapesScene(const std::string& name, EngineSettings& settings);
CollisionShapesScene(const std::string& name, EngineSettings& settings, reactphysics3d::PhysicsCommon& physicsCommon);
/// Destructor
virtual ~CollisionShapesScene() override;

View File

@ -31,8 +31,8 @@ using namespace openglframework;
using namespace trianglemeshscene;
// Constructor
ConcaveMeshScene::ConcaveMeshScene(const std::string& name, EngineSettings& settings)
: SceneDemo(name, settings, true, SCENE_RADIUS) {
ConcaveMeshScene::ConcaveMeshScene(const std::string& name, EngineSettings& settings, reactphysics3d::PhysicsCommon& physicsCommon)
: SceneDemo(name, settings, physicsCommon, true, SCENE_RADIUS) {
std::string meshFolderPath("meshes/");
@ -43,13 +43,6 @@ ConcaveMeshScene::ConcaveMeshScene(const std::string& name, EngineSettings& sett
setScenePosition(center, SCENE_RADIUS);
mWorldSettings.worldName = name;
// Logger
rp3d::DefaultLogger* defaultLogger = mPhysicsCommon.createDefaultLogger();
uint logLevel = static_cast<uint>(rp3d::Logger::Level::Information) | static_cast<uint>(rp3d::Logger::Level::Warning) |
static_cast<uint>(rp3d::Logger::Level::Error);
defaultLogger->addFileDestination("rp3d_log_" + name + ".html", logLevel, rp3d::DefaultLogger::Format::HTML);
mPhysicsCommon.setLogger(defaultLogger);
}
// Destructor

View File

@ -87,7 +87,7 @@ class ConcaveMeshScene : public SceneDemo {
// -------------------- Methods -------------------- //
/// Constructor
ConcaveMeshScene(const std::string& name, EngineSettings& settings);
ConcaveMeshScene(const std::string& name, EngineSettings& settings, reactphysics3d::PhysicsCommon& physicsCommon);
/// Destructor
virtual ~ConcaveMeshScene() override;

View File

@ -31,8 +31,8 @@ using namespace openglframework;
using namespace cubesscene;
// Constructor
CubesScene::CubesScene(const std::string& name, EngineSettings& settings)
: SceneDemo(name, settings, true, SCENE_RADIUS) {
CubesScene::CubesScene(const std::string& name, EngineSettings& settings, reactphysics3d::PhysicsCommon& physicsCommon)
: SceneDemo(name, settings, physicsCommon, true, SCENE_RADIUS) {
iter = 0;
@ -43,13 +43,6 @@ CubesScene::CubesScene(const std::string& name, EngineSettings& settings)
setScenePosition(center, SCENE_RADIUS);
mWorldSettings.worldName = name;
// Logger
rp3d::DefaultLogger* defaultLogger = mPhysicsCommon.createDefaultLogger();
uint logLevel = static_cast<uint>(rp3d::Logger::Level::Information) | static_cast<uint>(rp3d::Logger::Level::Warning) |
static_cast<uint>(rp3d::Logger::Level::Error);
defaultLogger->addFileDestination("rp3d_log_" + name + ".html", logLevel, rp3d::DefaultLogger::Format::HTML);
mPhysicsCommon.setLogger(defaultLogger);
}
// Destructor

View File

@ -63,7 +63,7 @@ class CubesScene : public SceneDemo {
// -------------------- Methods -------------------- //
/// Constructor
CubesScene(const std::string& name, EngineSettings& settings);
CubesScene(const std::string& name, EngineSettings& settings, rp3d::PhysicsCommon& physicsCommon);
/// Destructor
virtual ~CubesScene() override;

View File

@ -31,8 +31,8 @@ using namespace openglframework;
using namespace cubestackscene;
// Constructor
CubeStackScene::CubeStackScene(const std::string& name, EngineSettings& settings)
: SceneDemo(name, settings, true, SCENE_RADIUS) {
CubeStackScene::CubeStackScene(const std::string& name, EngineSettings& settings, reactphysics3d::PhysicsCommon& physicsCommon)
: SceneDemo(name, settings, physicsCommon, true, SCENE_RADIUS) {
// Compute the radius and the center of the scene
openglframework::Vector3 center(0, 5, 0);
@ -41,13 +41,6 @@ CubeStackScene::CubeStackScene(const std::string& name, EngineSettings& settings
setScenePosition(center, SCENE_RADIUS);
mWorldSettings.worldName = name;
// Logger
rp3d::DefaultLogger* defaultLogger = mPhysicsCommon.createDefaultLogger();
uint logLevel = static_cast<uint>(rp3d::Logger::Level::Information) | static_cast<uint>(rp3d::Logger::Level::Warning) |
static_cast<uint>(rp3d::Logger::Level::Error);
defaultLogger->addFileDestination("rp3d_log_" + name + ".html", logLevel, rp3d::DefaultLogger::Format::HTML);
mPhysicsCommon.setLogger(defaultLogger);
}
// Create the physics world

View File

@ -61,7 +61,7 @@ class CubeStackScene : public SceneDemo {
// -------------------- Methods -------------------- //
/// Constructor
CubeStackScene(const std::string& name, EngineSettings& settings);
CubeStackScene(const std::string& name, EngineSettings& settings, reactphysics3d::PhysicsCommon& physicsCommon);
/// Destructor
virtual ~CubeStackScene() override;

View File

@ -32,8 +32,8 @@ using namespace openglframework;
using namespace fixedjointscene;
// Constructor
FixedJointScene::FixedJointScene(const std::string& name, EngineSettings& settings)
: SceneDemo(name, settings, true, SCENE_RADIUS) {
FixedJointScene::FixedJointScene(const std::string& name, EngineSettings& settings, reactphysics3d::PhysicsCommon& physicsCommon)
: SceneDemo(name, settings, physicsCommon, true, SCENE_RADIUS) {
// Compute the radius and the center of the scene
openglframework::Vector3 center(0, 5, 0);
@ -42,13 +42,6 @@ FixedJointScene::FixedJointScene(const std::string& name, EngineSettings& settin
setScenePosition(center, SCENE_RADIUS);
mWorldSettings.worldName = name;
// Logger
rp3d::DefaultLogger* defaultLogger = mPhysicsCommon.createDefaultLogger();
uint logLevel = static_cast<uint>(rp3d::Logger::Level::Information) | static_cast<uint>(rp3d::Logger::Level::Warning) |
static_cast<uint>(rp3d::Logger::Level::Error);
defaultLogger->addFileDestination("rp3d_log_" + name + ".html", logLevel, rp3d::DefaultLogger::Format::HTML);
mPhysicsCommon.setLogger(defaultLogger);
}
// Destructor

View File

@ -70,7 +70,7 @@ class FixedJointScene : public SceneDemo {
// -------------------- Methods -------------------- //
/// Constructor
FixedJointScene(const std::string& name, EngineSettings& settings);
FixedJointScene(const std::string& name, EngineSettings& settings, reactphysics3d::PhysicsCommon& physicsCommon);
/// Destructor
virtual ~FixedJointScene() override ;

View File

@ -31,8 +31,8 @@ using namespace openglframework;
using namespace heightfieldscene;
// Constructor
HeightFieldScene::HeightFieldScene(const std::string& name, EngineSettings& settings)
: SceneDemo(name, settings, true, SCENE_RADIUS) {
HeightFieldScene::HeightFieldScene(const std::string& name, EngineSettings& settings, reactphysics3d::PhysicsCommon& physicsCommon)
: SceneDemo(name, settings, physicsCommon, true, SCENE_RADIUS) {
mWorldSettings.gravity = rp3d::Vector3(settings.gravity.x, settings.gravity.y, settings.gravity.z);
@ -45,13 +45,6 @@ HeightFieldScene::HeightFieldScene(const std::string& name, EngineSettings& sett
setScenePosition(center, SCENE_RADIUS);
mWorldSettings.worldName = name;
// Logger
rp3d::DefaultLogger* defaultLogger = mPhysicsCommon.createDefaultLogger();
uint logLevel = static_cast<uint>(rp3d::Logger::Level::Information) | static_cast<uint>(rp3d::Logger::Level::Warning) |
static_cast<uint>(rp3d::Logger::Level::Error);
defaultLogger->addFileDestination("rp3d_log_" + name + ".html", logLevel, rp3d::DefaultLogger::Format::HTML);
mPhysicsCommon.setLogger(defaultLogger);
}
// Destructor

View File

@ -88,7 +88,7 @@ class HeightFieldScene : public SceneDemo {
// -------------------- Methods -------------------- //
/// Constructor
HeightFieldScene(const std::string& name, EngineSettings& settings);
HeightFieldScene(const std::string& name, EngineSettings& settings, reactphysics3d::PhysicsCommon& physicsCommon);
/// Destructor
virtual ~HeightFieldScene() override;

View File

@ -32,8 +32,8 @@ using namespace openglframework;
using namespace hingejointscene;
// Constructor
HingeJointScene::HingeJointScene(const std::string& name, EngineSettings& settings)
: SceneDemo(name, settings, true, SCENE_RADIUS) {
HingeJointScene::HingeJointScene(const std::string& name, EngineSettings& settings, reactphysics3d::PhysicsCommon& physicsCommon)
: SceneDemo(name, settings, physicsCommon, true, SCENE_RADIUS) {
// Compute the radius and the center of the scene
openglframework::Vector3 center(0, 5, 0);
@ -42,13 +42,6 @@ HingeJointScene::HingeJointScene(const std::string& name, EngineSettings& settin
setScenePosition(center, SCENE_RADIUS);
mWorldSettings.worldName = name;
// Logger
rp3d::DefaultLogger* defaultLogger = mPhysicsCommon.createDefaultLogger();
uint logLevel = static_cast<uint>(rp3d::Logger::Level::Information) | static_cast<uint>(rp3d::Logger::Level::Warning) |
static_cast<uint>(rp3d::Logger::Level::Error);
defaultLogger->addFileDestination("rp3d_log_" + name + ".html", logLevel, rp3d::DefaultLogger::Format::HTML);
mPhysicsCommon.setLogger(defaultLogger);
}
// Destructor

View File

@ -70,7 +70,7 @@ class HingeJointScene : public SceneDemo {
// -------------------- Methods -------------------- //
/// Constructor
HingeJointScene(const std::string& name, EngineSettings& settings);
HingeJointScene(const std::string& name, EngineSettings& settings, reactphysics3d::PhysicsCommon& physicsCommon);
/// Destructor
virtual ~HingeJointScene() override ;

View File

@ -32,8 +32,8 @@ using namespace openglframework;
using namespace hingejointschainscene;
// Constructor
HingeJointsChainScene::HingeJointsChainScene(const std::string& name, EngineSettings& settings)
: SceneDemo(name, settings, true, SCENE_RADIUS) {
HingeJointsChainScene::HingeJointsChainScene(const std::string& name, EngineSettings& settings, reactphysics3d::PhysicsCommon& physicsCommon)
: SceneDemo(name, settings, physicsCommon, true, SCENE_RADIUS) {
std::string meshFolderPath("meshes/");
@ -47,13 +47,6 @@ HingeJointsChainScene::HingeJointsChainScene(const std::string& name, EngineSett
rp3d::Vector3 gravity(0, rp3d::decimal(-9.81), 0);
mWorldSettings.worldName = name;
// Logger
rp3d::DefaultLogger* defaultLogger = mPhysicsCommon.createDefaultLogger();
uint logLevel = static_cast<uint>(rp3d::Logger::Level::Information) | static_cast<uint>(rp3d::Logger::Level::Warning) |
static_cast<uint>(rp3d::Logger::Level::Error);
defaultLogger->addFileDestination("rp3d_log_" + name + ".html", logLevel, rp3d::DefaultLogger::Format::HTML);
mPhysicsCommon.setLogger(defaultLogger);
}
// Destructor

View File

@ -65,7 +65,7 @@ class HingeJointsChainScene : public SceneDemo {
// -------------------- Methods -------------------- //
/// Constructor
HingeJointsChainScene(const std::string& name, EngineSettings& settings);
HingeJointsChainScene(const std::string& name, EngineSettings& settings, reactphysics3d::PhysicsCommon& physicsCommon);
/// Destructor
virtual ~HingeJointsChainScene() override ;

View File

@ -32,8 +32,8 @@ using namespace openglframework;
using namespace jointsscene;
// Constructor
JointsScene::JointsScene(const std::string& name, EngineSettings& settings)
: SceneDemo(name, settings, true, SCENE_RADIUS) {
JointsScene::JointsScene(const std::string& name, EngineSettings& settings, reactphysics3d::PhysicsCommon& physicsCommon)
: SceneDemo(name, settings, physicsCommon, true, SCENE_RADIUS) {
// Compute the radius and the center of the scene
openglframework::Vector3 center(0, 5, 0);
@ -45,13 +45,6 @@ JointsScene::JointsScene(const std::string& name, EngineSettings& settings)
rp3d::Vector3 gravity(0, rp3d::decimal(-9.81), 0);
mWorldSettings.worldName = name;
// Logger
rp3d::DefaultLogger* defaultLogger = mPhysicsCommon.createDefaultLogger();
uint logLevel = static_cast<uint>(rp3d::Logger::Level::Information) | static_cast<uint>(rp3d::Logger::Level::Warning) |
static_cast<uint>(rp3d::Logger::Level::Error);
defaultLogger->addFileDestination("rp3d_log_" + name + ".html", logLevel, rp3d::DefaultLogger::Format::HTML);
mPhysicsCommon.setLogger(defaultLogger);
}
// Destructor

View File

@ -115,7 +115,7 @@ class JointsScene : public SceneDemo {
// -------------------- Methods -------------------- //
/// Constructor
JointsScene(const std::string& name, EngineSettings& settings);
JointsScene(const std::string& name, EngineSettings& settings, reactphysics3d::PhysicsCommon& physicsCommon);
/// Destructor
virtual ~JointsScene() override ;

View File

@ -31,8 +31,8 @@ using namespace openglframework;
using namespace pilescene;
// Constructor
PileScene::PileScene(const std::string& name, EngineSettings& settings)
: SceneDemo(name, settings, true, SCENE_RADIUS) {
PileScene::PileScene(const std::string& name, EngineSettings& settings, reactphysics3d::PhysicsCommon& physicsCommon)
: SceneDemo(name, settings, physicsCommon, true, SCENE_RADIUS) {
std::string meshFolderPath("meshes/");
@ -43,13 +43,6 @@ PileScene::PileScene(const std::string& name, EngineSettings& settings)
setScenePosition(center, SCENE_RADIUS);
mWorldSettings.worldName = name;
// Logger
rp3d::DefaultLogger* defaultLogger = mPhysicsCommon.createDefaultLogger();
uint logLevel = static_cast<uint>(rp3d::Logger::Level::Information) | static_cast<uint>(rp3d::Logger::Level::Warning) |
static_cast<uint>(rp3d::Logger::Level::Error);
defaultLogger->addFileDestination("rp3d_log_" + name + ".html", logLevel, rp3d::DefaultLogger::Format::HTML);
mPhysicsCommon.setLogger(defaultLogger);
}
// Destructor

View File

@ -89,7 +89,7 @@ class PileScene : public SceneDemo {
// -------------------- Methods -------------------- //
/// Constructor
PileScene(const std::string& name, EngineSettings& settings);
PileScene(const std::string& name, EngineSettings& settings, reactphysics3d::PhysicsCommon& physicsCommon);
/// Destructor
virtual ~PileScene() override;

View File

@ -32,8 +32,8 @@ using namespace openglframework;
using namespace ragdollscene;
// Constructor
RagdollScene::RagdollScene(const std::string& name, EngineSettings& settings)
: SceneDemo(name, settings, true, SCENE_RADIUS) {
RagdollScene::RagdollScene(const std::string& name, EngineSettings& settings, reactphysics3d::PhysicsCommon& physicsCommon)
: SceneDemo(name, settings, physicsCommon, true, SCENE_RADIUS) {
// Compute the radius and the center of the scene
openglframework::Vector3 center(0, 5, 0);
@ -42,13 +42,6 @@ RagdollScene::RagdollScene(const std::string& name, EngineSettings& settings)
setScenePosition(center, SCENE_RADIUS);
mWorldSettings.worldName = name;
// Logger
rp3d::DefaultLogger* defaultLogger = mPhysicsCommon.createDefaultLogger();
uint logLevel = static_cast<uint>(rp3d::Logger::Level::Information) | static_cast<uint>(rp3d::Logger::Level::Warning) |
static_cast<uint>(rp3d::Logger::Level::Error);
defaultLogger->addFileDestination("rp3d_log_" + name + ".html", logLevel, rp3d::DefaultLogger::Format::HTML);
mPhysicsCommon.setLogger(defaultLogger);
}
// Destructor

View File

@ -145,7 +145,7 @@ class RagdollScene : public SceneDemo {
// -------------------- Methods -------------------- //
/// Constructor
RagdollScene(const std::string& name, EngineSettings& settings);
RagdollScene(const std::string& name, EngineSettings& settings, reactphysics3d::PhysicsCommon& physicsCommon);
/// Destructor
virtual ~RagdollScene() override ;

View File

@ -31,8 +31,8 @@ using namespace openglframework;
using namespace raycastscene;
// Constructor
RaycastScene::RaycastScene(const std::string& name, EngineSettings& settings)
: SceneDemo(name, settings, SCENE_RADIUS, false), mMeshFolderPath("meshes/"),
RaycastScene::RaycastScene(const std::string& name, EngineSettings& settings, reactphysics3d::PhysicsCommon& physicsCommon)
: SceneDemo(name, settings, physicsCommon, SCENE_RADIUS, false), mMeshFolderPath("meshes/"),
mRaycastManager(mMeshFolderPath, mSnapshotsContactPoints), mCurrentBodyIndex(-1),
mAreNormalsDisplayed(false), mVBOVertices(GL_ARRAY_BUFFER) {
@ -45,13 +45,6 @@ RaycastScene::RaycastScene(const std::string& name, EngineSettings& settings)
rp3d::PhysicsWorld::WorldSettings worldSettings;
worldSettings.worldName = name;
// Logger
rp3d::DefaultLogger* defaultLogger = mPhysicsCommon.createDefaultLogger();
uint logLevel = static_cast<uint>(rp3d::Logger::Level::Information) | static_cast<uint>(rp3d::Logger::Level::Warning) |
static_cast<uint>(rp3d::Logger::Level::Error);
defaultLogger->addFileDestination("rp3d_log_" + name + ".html", logLevel, rp3d::DefaultLogger::Format::HTML);
mPhysicsCommon.setLogger(defaultLogger);
// Create the physics world for the physics simulation
mPhysicsWorld = mPhysicsCommon.createPhysicsWorld(worldSettings);

View File

@ -146,7 +146,7 @@ class RaycastScene : public SceneDemo {
// -------------------- Methods -------------------- //
/// Constructor
RaycastScene(const std::string& name, EngineSettings& settings);
RaycastScene(const std::string& name, EngineSettings& settings, reactphysics3d::PhysicsCommon& physicsCommon);
/// Destructor
virtual ~RaycastScene() override;

View File

@ -32,8 +32,8 @@ using namespace openglframework;
using namespace ropescene;
// Constructor
RopeScene::RopeScene(const std::string& name, EngineSettings& settings)
: SceneDemo(name, settings, true, SCENE_RADIUS), nbIterations(0), nbTorqueIterations(200) {
RopeScene::RopeScene(const std::string& name, EngineSettings& settings, reactphysics3d::PhysicsCommon& physicsCommon)
: SceneDemo(name, settings, physicsCommon, true, SCENE_RADIUS), nbIterations(0), nbTorqueIterations(200) {
std::string meshFolderPath("meshes/");
@ -46,13 +46,6 @@ RopeScene::RopeScene(const std::string& name, EngineSettings& settings)
setScenePosition(center, SCENE_RADIUS);
mWorldSettings.worldName = name;
// Logger
rp3d::DefaultLogger* defaultLogger = mPhysicsCommon.createDefaultLogger();
uint logLevel = static_cast<uint>(rp3d::Logger::Level::Information) | static_cast<uint>(rp3d::Logger::Level::Warning) |
static_cast<uint>(rp3d::Logger::Level::Error);
defaultLogger->addFileDestination("rp3d_log_" + name + ".html", logLevel, rp3d::DefaultLogger::Format::HTML);
mPhysicsCommon.setLogger(defaultLogger);
}
// Destructor

View File

@ -81,7 +81,7 @@ class RopeScene : public SceneDemo {
// -------------------- Methods -------------------- //
/// Constructor
RopeScene(const std::string& name, EngineSettings& settings);
RopeScene(const std::string& name, EngineSettings& settings, reactphysics3d::PhysicsCommon& physicsCommon);
/// Destructor
virtual ~RopeScene() override ;

View File

@ -32,8 +32,8 @@ using namespace openglframework;
using namespace sliderjointscene;
// Constructor
SliderJointScene::SliderJointScene(const std::string& name, EngineSettings& settings)
: SceneDemo(name, settings, true, SCENE_RADIUS) {
SliderJointScene::SliderJointScene(const std::string& name, EngineSettings& settings, reactphysics3d::PhysicsCommon& physicsCommon)
: SceneDemo(name, settings, physicsCommon, true, SCENE_RADIUS) {
// Compute the radius and the center of the scene
openglframework::Vector3 center(0, 5, 0);
@ -42,13 +42,6 @@ SliderJointScene::SliderJointScene(const std::string& name, EngineSettings& sett
setScenePosition(center, SCENE_RADIUS);
mWorldSettings.worldName = name;
// Logger
rp3d::DefaultLogger* defaultLogger = mPhysicsCommon.createDefaultLogger();
uint logLevel = static_cast<uint>(rp3d::Logger::Level::Information) | static_cast<uint>(rp3d::Logger::Level::Warning) |
static_cast<uint>(rp3d::Logger::Level::Error);
defaultLogger->addFileDestination("rp3d_log_" + name + ".html", logLevel, rp3d::DefaultLogger::Format::HTML);
mPhysicsCommon.setLogger(defaultLogger);
}
// Destructor

View File

@ -67,7 +67,7 @@ class SliderJointScene : public SceneDemo {
// -------------------- Methods -------------------- //
/// Constructor
SliderJointScene(const std::string& name, EngineSettings& settings);
SliderJointScene(const std::string& name, EngineSettings& settings, reactphysics3d::PhysicsCommon& physicsCommon);
/// Destructor
virtual ~SliderJointScene() override ;

View File

@ -40,14 +40,14 @@ openglframework::Color SceneDemo::mSleepingColorDemo = Color(1.0f, 0.25f, 0.25f,
openglframework::Color SceneDemo::mSelectedObjectColorDemo = Color(0.09f, 0.59f, 0.88f, 1.0f);
// Constructor
SceneDemo::SceneDemo(const std::string& name, EngineSettings& settings, bool isPhysicsWorldSimulated, float sceneRadius, bool isShadowMappingEnabled)
SceneDemo::SceneDemo(const std::string& name, EngineSettings& settings, reactphysics3d::PhysicsCommon& physicsCommon, bool isPhysicsWorldSimulated, bool isShadowMappingEnabled)
: Scene(name, settings, isShadowMappingEnabled), mIsShadowMappingInitialized(false),
mDepthShader("shaders/depth.vert", "shaders/depth.frag"),
mPhongShader("shaders/phong.vert", "shaders/phong.frag"),
mColorShader("shaders/color.vert", "shaders/color.frag"),
mQuadShader("shaders/quad.vert", "shaders/quad.frag"),
mVBOQuad(GL_ARRAY_BUFFER), mDebugVBOLinesVertices(GL_ARRAY_BUFFER), mDebugVBOTrianglesVertices(GL_ARRAY_BUFFER),
mMeshFolderPath("meshes/"), mPhysicsWorld(nullptr), mIsPhysicsWorldSimulated(isPhysicsWorldSimulated),
mMeshFolderPath("meshes/"), mPhysicsCommon(physicsCommon), mPhysicsWorld(nullptr), mIsPhysicsWorldSimulated(isPhysicsWorldSimulated),
mIsMovingBody(false), mMovingBody(nullptr) {
shadowMapTextureLevel++;

View File

@ -31,6 +31,7 @@
#include "VisualContactPoint.h"
#include <reactphysics3d/reactphysics3d.h>
#include "PhysicsObject.h"
#include "TestbedLogger.h"
// Constants
const int SHADOWMAP_WIDTH = 2048;
@ -113,7 +114,7 @@ class SceneDemo : public Scene, rp3d::RaycastCallback {
std::string mMeshFolderPath;
rp3d::PhysicsCommon mPhysicsCommon;
rp3d::PhysicsCommon& mPhysicsCommon;
std::vector<PhysicsObject*> mPhysicsObjects;
@ -168,7 +169,7 @@ class SceneDemo : public Scene, rp3d::RaycastCallback {
// -------------------- Methods -------------------- //
/// Constructor
SceneDemo(const std::string& name, EngineSettings& settings, bool isPhysicsWorldSimulated, float sceneRadius, bool isShadowMappingEnabled = true);
SceneDemo(const std::string& name, EngineSettings& settings, rp3d::PhysicsCommon& physicsCommon, bool isPhysicsWorldSimulated, bool isShadowMappingEnabled = true);
/// Destructor
virtual ~SceneDemo() override;

View File

@ -105,6 +105,9 @@ TestbedApplication::~TestbedApplication() {
// Initialize the viewer
void TestbedApplication::init() {
// Logger
rp3d::PhysicsCommon::setLogger(&mLogger);
// Create all the scenes
createScenes();
@ -137,85 +140,128 @@ void TestbedApplication::init() {
// Create all the scenes
void TestbedApplication::createScenes() {
uint logLevel = static_cast<uint>(rp3d::Logger::Level::Information);
// Cubes scene
CubesScene* cubeScene = new CubesScene("Cubes", mDefaultEngineSettings);
std::string sceneName = "Cubes";
mLogger.addFileDestination(sceneName, logLevel, rp3d::DefaultLogger::Format::HTML);
CubesScene* cubeScene = new CubesScene(sceneName, mDefaultEngineSettings, mPhysicsCommon);
mScenes.push_back(cubeScene);
// Cube Stack scene
CubeStackScene* cubeStackScene = new CubeStackScene("Cube Stack", mDefaultEngineSettings);
sceneName = "Cube Stack";
mLogger.addFileDestination(sceneName, logLevel, rp3d::DefaultLogger::Format::HTML);
CubeStackScene* cubeStackScene = new CubeStackScene(sceneName, mDefaultEngineSettings, mPhysicsCommon);
mScenes.push_back(cubeStackScene);
// Joints scene
JointsScene* jointsScene = new JointsScene("Joints", mDefaultEngineSettings);
sceneName = "Joints";
mLogger.addFileDestination(sceneName, logLevel, rp3d::DefaultLogger::Format::HTML);
JointsScene* jointsScene = new JointsScene(sceneName, mDefaultEngineSettings, mPhysicsCommon);
mScenes.push_back(jointsScene);
// Collision shapes scene
CollisionShapesScene* collisionShapesScene = new CollisionShapesScene("Collision Shapes", mDefaultEngineSettings);
sceneName = "Collision Shapes";
mLogger.addFileDestination(sceneName, logLevel, rp3d::DefaultLogger::Format::HTML);
CollisionShapesScene* collisionShapesScene = new CollisionShapesScene(sceneName, mDefaultEngineSettings, mPhysicsCommon);
mScenes.push_back(collisionShapesScene);
// Heightfield shape scene
HeightFieldScene* heightFieldScene = new HeightFieldScene("Heightfield", mDefaultEngineSettings);
sceneName = "Heightfield";
mLogger.addFileDestination(sceneName, logLevel, rp3d::DefaultLogger::Format::HTML);
HeightFieldScene* heightFieldScene = new HeightFieldScene(sceneName, mDefaultEngineSettings, mPhysicsCommon);
mScenes.push_back(heightFieldScene);
// Raycast scene
RaycastScene* raycastScene = new RaycastScene("Raycast", mDefaultEngineSettings);
sceneName = "Raycast";
mLogger.addFileDestination(sceneName, logLevel, rp3d::DefaultLogger::Format::HTML);
RaycastScene* raycastScene = new RaycastScene(sceneName, mDefaultEngineSettings, mPhysicsCommon);
mScenes.push_back(raycastScene);
// Collision Detection scene
CollisionDetectionScene* collisionDetectionScene = new CollisionDetectionScene("Collision Detection", mDefaultEngineSettings);
sceneName = "Collision Detection";
mLogger.addFileDestination(sceneName, logLevel, rp3d::DefaultLogger::Format::HTML);
CollisionDetectionScene* collisionDetectionScene = new CollisionDetectionScene(sceneName, mDefaultEngineSettings, mPhysicsCommon);
mScenes.push_back(collisionDetectionScene);
// Concave Mesh scene
ConcaveMeshScene* concaveMeshScene = new ConcaveMeshScene("Concave Mesh", mDefaultEngineSettings);
sceneName = "Concave Mesh";
mLogger.addFileDestination(sceneName, logLevel, rp3d::DefaultLogger::Format::HTML);
ConcaveMeshScene* concaveMeshScene = new ConcaveMeshScene(sceneName, mDefaultEngineSettings, mPhysicsCommon);
mScenes.push_back(concaveMeshScene);
// Pile scene
PileScene* pileScene = new PileScene("Pile", mDefaultEngineSettings);
sceneName = "Pile";
mLogger.addFileDestination(sceneName, logLevel, rp3d::DefaultLogger::Format::HTML);
PileScene* pileScene = new PileScene(sceneName, mDefaultEngineSettings, mPhysicsCommon);
mScenes.push_back(pileScene);
// Ball and Socket joint scene
BallAndSocketJointScene* ballAndSocketJointScene = new BallAndSocketJointScene("Ball and Socket joint", mDefaultEngineSettings);
sceneName = "Ball and Socket joint";
mLogger.addFileDestination(sceneName, logLevel, rp3d::DefaultLogger::Format::HTML);
BallAndSocketJointScene* ballAndSocketJointScene = new BallAndSocketJointScene(sceneName, mDefaultEngineSettings, mPhysicsCommon);
mScenes.push_back(ballAndSocketJointScene);
// Box Tower scene
BoxTowerScene* boxTowerScene = new BoxTowerScene("Box Tower", mDefaultEngineSettings);
sceneName = "Box Tower";
mLogger.addFileDestination(sceneName, logLevel, rp3d::DefaultLogger::Format::HTML);
BoxTowerScene* boxTowerScene = new BoxTowerScene(sceneName, mDefaultEngineSettings, mPhysicsCommon);
mScenes.push_back(boxTowerScene);
// Ball and Socket joints Net scene
BallAndSocketJointsNetScene* ballAndSocketJointsNetScene = new BallAndSocketJointsNetScene("BallAndSocket Joints Net", mDefaultEngineSettings);
sceneName = "BallAndSocket Joints Net";
mLogger.addFileDestination(sceneName, logLevel, rp3d::DefaultLogger::Format::HTML);
BallAndSocketJointsNetScene* ballAndSocketJointsNetScene = new BallAndSocketJointsNetScene(sceneName, mDefaultEngineSettings, mPhysicsCommon);
mScenes.push_back(ballAndSocketJointsNetScene);
// Ball and Socket joints chain scene
BallAndSocketJointsChainScene* ballAndSocketJointsChainScene = new BallAndSocketJointsChainScene("BallAndSocket Joints Chain", mDefaultEngineSettings);
sceneName = "BallAndSoket Joints Chain";
mLogger.addFileDestination(sceneName, logLevel, rp3d::DefaultLogger::Format::HTML);
BallAndSocketJointsChainScene* ballAndSocketJointsChainScene = new BallAndSocketJointsChainScene(sceneName, mDefaultEngineSettings, mPhysicsCommon);
mScenes.push_back(ballAndSocketJointsChainScene);
// Hinge joints chain scene
HingeJointsChainScene* hingeJointsChainScene = new HingeJointsChainScene("Hinge Joints Chain", mDefaultEngineSettings);
sceneName = "Hinge Joints Chain";
mLogger.addFileDestination(sceneName, logLevel, rp3d::DefaultLogger::Format::HTML);
HingeJointsChainScene* hingeJointsChainScene = new HingeJointsChainScene(sceneName, mDefaultEngineSettings, mPhysicsCommon);
mScenes.push_back(hingeJointsChainScene);
// Bridge scene
BridgeScene* bridgeScene = new BridgeScene("Bridge", mDefaultEngineSettings);
sceneName = "Bridge";
mLogger.addFileDestination(sceneName, logLevel, rp3d::DefaultLogger::Format::HTML);
BridgeScene* bridgeScene = new BridgeScene(sceneName, mDefaultEngineSettings, mPhysicsCommon);
mScenes.push_back(bridgeScene);
// Fixed joint scene
FixedJointScene* fixedJointScene = new FixedJointScene("Fixed joint", mDefaultEngineSettings);
sceneName = "Fixed joint";
mLogger.addFileDestination(sceneName, logLevel, rp3d::DefaultLogger::Format::HTML);
FixedJointScene* fixedJointScene = new FixedJointScene(sceneName, mDefaultEngineSettings, mPhysicsCommon);
mScenes.push_back(fixedJointScene);
// Hinge joint scene
HingeJointScene* hingeJointScene = new HingeJointScene("Hinge joint", mDefaultEngineSettings);
sceneName = "Hinge joint";
mLogger.addFileDestination(sceneName, logLevel, rp3d::DefaultLogger::Format::HTML);
HingeJointScene* hingeJointScene = new HingeJointScene(sceneName, mDefaultEngineSettings, mPhysicsCommon);
mScenes.push_back(hingeJointScene);
// Slider joint scene
SliderJointScene* sliderJointScene = new SliderJointScene("Slider joint", mDefaultEngineSettings);
sceneName = "Slider joint";
mLogger.addFileDestination(sceneName, logLevel, rp3d::DefaultLogger::Format::HTML);
SliderJointScene* sliderJointScene = new SliderJointScene(sceneName, mDefaultEngineSettings, mPhysicsCommon);
mScenes.push_back(sliderJointScene);
// Ragdoll scene
RagdollScene* ragdollScene = new RagdollScene("Ragdoll", mDefaultEngineSettings);
sceneName = "Ragdoll";
mLogger.addFileDestination(sceneName, logLevel, rp3d::DefaultLogger::Format::HTML);
RagdollScene* ragdollScene = new RagdollScene(sceneName, mDefaultEngineSettings, mPhysicsCommon);
mScenes.push_back(ragdollScene);
// Rope scene
RopeScene* ropeScene = new RopeScene("Rope", mDefaultEngineSettings);
sceneName = "Rope";
mLogger.addFileDestination(sceneName, logLevel, rp3d::DefaultLogger::Format::HTML);
RopeScene* ropeScene = new RopeScene(sceneName, mDefaultEngineSettings, mPhysicsCommon);
mScenes.push_back(ropeScene);
assert(mScenes.size() > 0);
}

View File

@ -32,6 +32,7 @@
#include "Scene.h"
#include "Timer.h"
#include <GLFW/glfw3.h>
#include "TestbedLogger.h"
using namespace nanogui;
@ -56,6 +57,9 @@ class TestbedApplication : public Screen {
/// Timer
Timer mTimer;
/// Physics common object
rp3d::PhysicsCommon mPhysicsCommon;
/// List of 3D scenes
std::vector<Scene*> mScenes;
@ -127,6 +131,9 @@ class TestbedApplication : public Screen {
/// True if the debug renderer is enabled
bool mIsDebugRendererEnabled;
/// Logger
TestbedLogger mLogger;
// -------------------- Methods -------------------- //
/// Private copy-constructor (for the singleton class)

View File

@ -0,0 +1,98 @@
/********************************************************************************
* ReactPhysics3D physics library, http://www.reactphysics3d.com *
* Copyright (c) 2010-2021 Daniel Chappuis *
*********************************************************************************
* *
* This software is provided 'as-is', without any express or implied warranty. *
* In no event will the authors be held liable for any damages arising from the *
* use of this software. *
* *
* Permission is granted to anyone to use this software for any purpose, *
* including commercial applications, and to alter it and redistribute it *
* freely, subject to the following restrictions: *
* *
* 1. The origin of this software must not be misrepresented; you must not claim *
* that you wrote the original software. If you use this software in a *
* product, an acknowledgment in the product documentation would be *
* appreciated but is not required. *
* *
* 2. Altered source versions must be plainly marked as such, and must not be *
* misrepresented as being the original software. *
* *
* 3. This notice may not be removed or altered from any source distribution. *
* *
********************************************************************************/
// Libraries
#include "TestbedLogger.h"
using namespace reactphysics3d;
// Constructor
TestbedLogger::TestbedLogger() {
// Create the log formatters
mFormatters.insert({reactphysics3d::DefaultLogger::Format::Text, new reactphysics3d::DefaultLogger::TextFormatter()});
mFormatters.insert({reactphysics3d::DefaultLogger::Format::HTML, new reactphysics3d::DefaultLogger::HtmlFormatter()});
// Add destination to send warning and errors to standard output
uint warningsErrors = static_cast<uint>(reactphysics3d::Logger::Level::Warning);
addStreamDestination(std::cout, warningsErrors, reactphysics3d::DefaultLogger::Format::Text);
}
// Destructor
TestbedLogger::~TestbedLogger() {
// Delete all the destinations
for (auto& item: mMapWorldToDestinations) {
delete item.second;
}
delete mStandardOutputDestination;
}
// Log something
void TestbedLogger::log(Level level, const std::string& physicsWorldName, Category category, const std::string& message, const char* filename, int lineNumber) {
// Get current time
auto now = std::chrono::system_clock::now();
auto time = std::chrono::system_clock::to_time_t(now);
// Get the destination file for this world
DefaultLogger::Destination* destination = mMapWorldToDestinations[physicsWorldName];
mMutex.lock();
// Write the log file into the file of the corresponding scene
destination->write(time, physicsWorldName, message, level, category, filename, lineNumber);
// Write the log into the standard output
mStandardOutputDestination->write(time, physicsWorldName, message, level, category, filename, lineNumber);
mMutex.unlock();
}
// Return the corresponding format
DefaultLogger::Formatter* TestbedLogger::getFormatter(DefaultLogger::Format format) const {
auto it = mFormatters.find(format);
if (it != mFormatters.end()) {
return it->second;
}
return nullptr;
}
// Add a log file destination to the logger
void TestbedLogger::addFileDestination(const std::string& worldName, uint logLevelFlag, reactphysics3d::DefaultLogger::Format format) {
std::string filePath = "rp3d_log_" + worldName + ".html";
reactphysics3d::DefaultLogger::FileDestination* destination = new reactphysics3d::DefaultLogger::FileDestination(filePath, logLevelFlag, getFormatter(format));
mMapWorldToDestinations.insert({worldName, destination});
}
// Add a stream destination to the logger
void TestbedLogger::addStreamDestination(std::ostream& outputStream, uint logLevelFlag, reactphysics3d::DefaultLogger::Format format) {
mStandardOutputDestination = new reactphysics3d::DefaultLogger::StreamDestination(outputStream, logLevelFlag, getFormatter(format));
}

View File

@ -0,0 +1,74 @@
/********************************************************************************
* ReactPhysics3D physics library, http://www.reactphysics3d.com *
* Copyright (c) 2010-2016 Daniel Chappuis *
*********************************************************************************
* *
* This software is provided 'as-is', without any express or implied warranty. *
* In no event will the authors be held liable for any damages arising from the *
* use of this software. *
* *
* Permission is granted to anyone to use this software for any purpose, *
* including commercial applications, and to alter it and redistribute it *
* freely, subject to the following restrictions: *
* *
* 1. The origin of this software must not be misrepresented; you must not claim *
* that you wrote the original software. If you use this software in a *
* product, an acknowledgment in the product documentation would be *
* appreciated but is not required. *
* *
* 2. Altered source versions must be plainly marked as such, and must not be *
* misrepresented as being the original software. *
* *
* 3. This notice may not be removed or altered from any source distribution. *
* *
********************************************************************************/
#ifndef TESTBED_LOGGER_H
#define TESTBED_LOGGER_H
// Libraries
#include <reactphysics3d/utils/DefaultLogger.h>
#include <unordered_map>
#include <string>
/// Class TestbedApplication
class TestbedLogger : public reactphysics3d::Logger {
private:
/// Map a log format to the given formatter object
std::unordered_map<reactphysics3d::DefaultLogger::Format, reactphysics3d::DefaultLogger::Formatter*> mFormatters;
/// Map the name of a world with the corresponding log destination
std::unordered_map<std::string, reactphysics3d::DefaultLogger::Destination*> mMapWorldToDestinations;
reactphysics3d::DefaultLogger::StreamDestination* mStandardOutputDestination;
/// Mutex
std::mutex mMutex;
// -------------------- Methods -------------------- //
/// Return the corresponding formatter
reactphysics3d::DefaultLogger::Formatter* getFormatter(reactphysics3d::DefaultLogger::Format format) const;
/// Add a stream destination to the logger
void addStreamDestination(std::ostream& outputStream, uint logLevelFlag, reactphysics3d::DefaultLogger::Format format);
public:
/// Constructor
TestbedLogger();
/// Destructor
~TestbedLogger();
/// Add a log file destination to the logger
void addFileDestination(const std::string& worldName, uint logLevelFlag, reactphysics3d::DefaultLogger::Format format);
/// Log something
virtual void log(Level level, const std::string& physicsWorldName, Category category, const std::string& message, const char* filename, int lineNumber) override;
};
#endif