From fb5e567aced81f511fac040eeaf57ee332fe857d Mon Sep 17 00:00:00 2001 From: Graham Pentheny Date: Sun, 3 Aug 2025 19:16:38 -0400 Subject: [PATCH] Consolidate some constants --- RecastDemo/Source/main.cpp | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/RecastDemo/Source/main.cpp b/RecastDemo/Source/main.cpp index ccf596b3..6e961b16 100644 --- a/RecastDemo/Source/main.cpp +++ b/RecastDemo/Source/main.cpp @@ -53,16 +53,19 @@ struct SampleItem std::function create; }; +// Constants namespace { +constexpr float FRAME_TIME = 1.0f / 20.0f; +constexpr float MIN_FRAME_TIME = 1.0f / 40.0f; +constexpr float fogColor[4] = {0.32f, 0.31f, 0.30f, 1.0f}; + SampleItem g_samples[] = { {"Solo Mesh", []() { return new Sample_SoloMesh(); } }, {"Tile Mesh", []() { return new Sample_TileMesh(); } }, {"Temp Obstacles", []() { return new Sample_TempObstacles(); }}, }; constexpr int g_nsamples = sizeof(g_samples) / sizeof(SampleItem); - -constexpr float fogColor[4] = {0.32f, 0.31f, 0.30f, 1.0f}; } struct AppData @@ -466,23 +469,22 @@ int main(int /*argc*/, char** /*argv*/) } } - // Update sample simulation. - constexpr float SIM_RATE = 20; - constexpr float DELTA_TIME = 1.0f / SIM_RATE; - app.timeAcc = rcClamp(app.timeAcc + dt, -1.0f, 1.0f); - int simIter = 0; - while (app.timeAcc > DELTA_TIME) + if (app.sample) { - app.timeAcc -= DELTA_TIME; - if (simIter < 5 && app.sample) + // Update sample simulation. + app.timeAcc = rcClamp(app.timeAcc + dt, -1.0f, 1.0f); + while (app.timeAcc > FRAME_TIME) { - app.sample->handleUpdate(DELTA_TIME); + app.timeAcc -= FRAME_TIME; + app.sample->handleUpdate(FRAME_TIME); } - simIter++; + } + else + { + app.timeAcc = 0; } // Clamp the framerate so that we do not hog all the CPU. - constexpr float MIN_FRAME_TIME = 1.0f / 40.0f; if (dt < MIN_FRAME_TIME) { int ms = static_cast((MIN_FRAME_TIME - dt) * 1000.0f);