Skip to content

Commit

Permalink
Fix issue 257
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielChappuis committed Jun 23, 2022
1 parent b289487 commit f6db3a7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
39 changes: 34 additions & 5 deletions include/reactphysics3d/utils/DefaultLogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <sstream>
#include <iomanip>
#include <mutex>
#include <ctime>

/// ReactPhysics3D namespace
namespace reactphysics3d {
Expand Down Expand Up @@ -80,6 +81,27 @@ class DefaultLogger : public Logger {
/// Format a log message
virtual std::string format(const time_t& time, const std::string& physicsWorldName, const std::string& message, Level level, Category category,
const char* filename, int lineNumber) = 0;

/// Return the current date and time
std::tm getLocalTime(const std::time_t& time) const {

std::tm bt = std::tm();

// This is because std::localtime is not thread-safe

#if defined(__unix__)
localtime_r(&time, &bt);
#elif defined(_MSC_VER)
localtime_s(&bt, &time);
#else
static std::mutex mtx;
std::lock_guard<std::mutex> lock(mtx);
bt = *std::localtime(&time);
#endif

return bt;
}

};

class TextFormatter : public Formatter {
Expand All @@ -101,12 +123,14 @@ class DefaultLogger : public Logger {

// Get current date
auto now = std::chrono::system_clock::now();
auto time = std::chrono::system_clock::to_time_t(now);
std::time_t time = std::chrono::system_clock::to_time_t(now);

auto localTime = getLocalTime(time);

std::stringstream ss;
ss << "ReactPhysics3D Logs" << std::endl;
ss << "ReactPhysics3D Version: " << RP3D_VERSION << std::endl;
ss << "Date: " << std::put_time(std::localtime(&time), "%Y-%m-%d") << std::endl;
ss << "Date: " << std::put_time(&localTime, "%Y-%m-%d") << std::endl;
ss << "---------------------------------------------------------" << std::endl;

return ss.str();
Expand All @@ -117,8 +141,10 @@ class DefaultLogger : public Logger {
Level level, Category category, const char* filename, int lineNumber) override {
std::stringstream ss;

auto localTime = getLocalTime(time);

// Time
ss << std::put_time(std::localtime(&time), "%X") << " ";
ss << std::put_time(&localTime, "%X") << " ";

// World
ss << "World:" << physicsWorldName << std::endl;
Expand Down Expand Up @@ -152,6 +178,7 @@ class DefaultLogger : public Logger {
// Get current date
auto now = std::chrono::system_clock::now();
auto time = std::chrono::system_clock::to_time_t(now);
auto localTime = getLocalTime(time);

std::stringstream ss;
ss << "<!DOCTYPE HTML>" << std::endl;
Expand All @@ -164,7 +191,7 @@ class DefaultLogger : public Logger {
ss << "<h1>ReactPhysics3D Logs</h1>" << std::endl;
ss << "<div class='general_info'>" << std::endl;
ss << "<p>ReactPhysics3D version: " << RP3D_VERSION << "</p>" << std::endl;
ss << "<p>Date: " << std::put_time(std::localtime(&time), "%Y-%m-%d") << "</p>" << std::endl;
ss << "<p>Date: " << std::put_time(&localTime, "%Y-%m-%d") << "</p>" << std::endl;
ss << "</div>" << std::endl;
ss << "<hr>";

Expand Down Expand Up @@ -275,11 +302,13 @@ class DefaultLogger : public Logger {

std::stringstream ss;

auto localTime = getLocalTime(time);

ss << "<div class='line " + toLowerCase(getCategoryName(category)) + " " + toLowerCase(getLevelName(level)) + "'>";

// Time
ss << "<div class='time'>";
ss << std::put_time(std::localtime(&time), "%X");
ss << std::put_time(&localTime, "%X");
ss << "</div>";

// Message
Expand Down
4 changes: 2 additions & 2 deletions src/systems/CollisionDetectionSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -499,8 +499,8 @@ void CollisionDetectionSystem::computeConvexVsConcaveMiddlePhase(OverlappingPair
const bool isCollider2Trigger = mCollidersComponents.mIsTrigger[collider2Index];
reportContacts = reportContacts && !isCollider1Trigger && !isCollider2Trigger;

CollisionShape* shape1;
CollisionShape* shape2;
CollisionShape* shape1 = nullptr;
CollisionShape* shape2 = nullptr;

if (overlappingPair.isShape1Convex) {
shape1 = convexShape;
Expand Down

0 comments on commit f6db3a7

Please sign in to comment.