diff --git a/CMakeLists.txt b/CMakeLists.txt index e66cf10..c5ce1f9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -73,10 +73,11 @@ target_sources(vissim PRIVATE # Tests add_executable(runtests) -target_sources(runtests PRIVATE tests/runtests.cc tests/CollisionTests.cc) +target_sources(runtests PRIVATE tests/runtests.cc tests/CollisionTests.cc src/utils.cc) target_include_directories( runtests PUBLIC $ + PUBLIC $ PUBLIC $ PUBLIC $) diff --git a/include/rbdlsim.h b/include/rbdlsim.h index bbbd1d8..3e32bd9 100644 --- a/include/rbdlsim.h +++ b/include/rbdlsim.h @@ -96,6 +96,7 @@ bool CheckPenetrationSphereVsPlane( SimBody CreateSphereBody( double mass, double radius, + double restitution, const Vector3d& pos, const Vector3d& vel); @@ -110,8 +111,8 @@ void PrepareConstraintImpulse( SimBody* body_b, CollisionInfo& cinfo); void CalcCollisions( - const SimBody& body_a, - const SimBody& body_b, + SimBody& body_a, + SimBody& body_b, std::vector& collisions); void CalcConstraintImpulse( SimBody* body_a, diff --git a/src/utils.cc b/src/utils.cc index 4ab7d6c..7c0dc7b 100644 --- a/src/utils.cc +++ b/src/utils.cc @@ -4,8 +4,21 @@ #include #include +static Timer sTimer; +Timer* gTimer = &sTimer; +double gTimeAtStart = 0; + FILE* gLogFile = NULL; +void gTimerInit() { + sTimer.mCurrentTime = 0.; + sTimer.mDeltaTime = 0.; + sTimer.mFrameTime = 0.; + sTimer.mPaused = false; + + gTimeAtStart = gGetCurrentTime(); +} + void GuiInputState_Init(GuiInputState* input_state) { input_state->mouseX = 0; input_state->mouseY = 0; diff --git a/src/utils.h b/src/utils.h index a438fc9..af01bc9 100644 --- a/src/utils.h +++ b/src/utils.h @@ -40,6 +40,16 @@ inline void gGetFileModTime(const char* filename, int* sec, int* nsec) { *nsec = attr.st_mtim.tv_nsec; } +typedef struct Timer { + float mCurrentTime; + float mFrameTime; + float mDeltaTime; + bool mPaused; +}Timer; + +extern Timer* gTimer; +void gTimerInit(); + inline double gGetCurrentTime() { struct timespec spec; clock_gettime(CLOCK_REALTIME, &spec); diff --git a/src/vissim.cc b/src/vissim.cc index a0a4d9c..f1663f0 100644 --- a/src/vissim.cc +++ b/src/vissim.cc @@ -21,17 +21,8 @@ #include "srender.h" #include "simulator.h" -struct Timer { - float mCurrentTime = 0.0f; - float mFrameTime = 0.0f; - float mDeltaTime = 0.0f; - bool mPaused = false; -}; - -Timer* gTimer = nullptr; GLFWwindow* gWindow = nullptr; GuiInputState* gGuiInputState = nullptr; -double gTimeAtStart = 0; // Rendering srndr* gRndr = nullptr; @@ -41,8 +32,6 @@ srcmdbuf* gRndrCmds = nullptr; double mouse_scroll_x = 0.; double mouse_scroll_y = 0.; -static Timer sTimer; - using namespace std; static void error_callback(int error, const char* description) { @@ -215,10 +204,7 @@ void DoRender() { } int main(void) { - gTimeAtStart = gGetCurrentTime(); - std::cout << "Time at start: " << gTimeAtStart << std::endl; - - gTimer = &sTimer; + gTimerInit(); LoggingInit(); diff --git a/tests/runtests.cc b/tests/runtests.cc index 48f1283..02399fd 100644 --- a/tests/runtests.cc +++ b/tests/runtests.cc @@ -1,2 +1,12 @@ -#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file -#include "catch.hpp" \ No newline at end of file +#define CATCH_CONFIG_RUNNER // This tells Catch to provide a main() - only do this in one cpp file +#include "catch.hpp" + +#include "utils.h" + +int main (int argc, char* argv[]) { + LoggingInit(); + + int result = Catch::Session().run(argc, argv); + + return result; +} \ No newline at end of file