From 513fc61d34a3719d8e3830e229e750f6c8710937 Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Mon, 19 Aug 2024 10:43:07 -0400 Subject: [PATCH] Add test loop in main.cpp --- .gitlab-ci.yml | 3 ++- source/main.cpp | 25 +++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d0e2ef8..5d56855 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -30,5 +30,6 @@ run_tests: - Xvfb :99 -screen 0 1024x768x24 & - sleep 5 - export DISPLAY=:99 + - export TEST_MODE=1 - cd build - - timeout 30s ./TerraVisor + - ./TerraVisor diff --git a/source/main.cpp b/source/main.cpp index ea27254..ca19995 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -107,7 +107,7 @@ void MainLoop(GLFWwindow* window, Scene& scene) { auto frame_duration = frame_end - frame_start; if (frame_duration < kFrameDuration) { - std::this_thread::sleep_for(kFrameDuration - frame_duration); + std::this_thread::sleep_for(kFrameDuration - frame_duration); } auto current_frame_time = std::chrono::high_resolution_clock::now(); @@ -117,6 +117,21 @@ void MainLoop(GLFWwindow* window, Scene& scene) { } } +void TestLoop(GLFWwindow* window, Scene& scene) { + auto start = std::chrono::steady_clock::now(); + + while (!glfwWindowShouldClose(window)) { + scene.Idle(); + scene.Display(window); + glfwPollEvents(); + + auto now = std::chrono::steady_clock::now(); + if(std::chrono::duration_cast(now - start).count() > 5) { + break; + } + } +} + } // namespace int main() { @@ -132,7 +147,13 @@ int main() { scene.Init(); InitializeImGui(window); - MainLoop(window, scene); + // Check if we're in test mode + const char* testEnv = std::getenv("TEST_MODE"); + if(testEnv) { + TestLoop(window, scene); + } else { + MainLoop(window, scene); + } CleanupImGui(); glfwDestroyWindow(window);