diff options
Diffstat (limited to 'simloop/test/simloop_test.c')
| -rw-r--r-- | simloop/test/simloop_test.c | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/simloop/test/simloop_test.c b/simloop/test/simloop_test.c index 41f9ac2..e8efd94 100644 --- a/simloop/test/simloop_test.c +++ b/simloop/test/simloop_test.c | |||
| @@ -65,10 +65,14 @@ TEST_CASE(simloop_initial_render_not_retriggered) { | |||
| 65 | /// 1. Updates based on the desired update frame rate. | 65 | /// 1. Updates based on the desired update frame rate. |
| 66 | /// 2. Renders at every loop (provided there are updates). | 66 | /// 2. Renders at every loop (provided there are updates). |
| 67 | TEST_CASE(simloop_no_render_frame_cap) { | 67 | TEST_CASE(simloop_no_render_frame_cap) { |
| 68 | constexpr int UPDATE_FPS = 10; | 68 | constexpr int UPDATE_FPS = 10; // 100ms delta |
| 69 | const time_delta EXPECT_UPDATE = sec_to_time_delta(1.0 / (double)UPDATE_FPS); | 69 | const time_delta UPDATE_DDT = sec_to_time_delta(1.0 / (double)UPDATE_FPS); |
| 70 | const time_delta STEP = sec_to_time_delta(1); | 70 | const time_delta STEP = sec_to_time_delta(1); |
| 71 | const time_delta SIM_TIME_SEC = sec_to_time_delta(30); | 71 | const time_delta SIM_TIME_SEC = sec_to_time_delta(30); |
| 72 | |||
| 73 | // We need simulation time to be an exact multiple of the desired deltas for | ||
| 74 | // the modulo comparisons below. | ||
| 75 | TEST_TRUE((STEP % UPDATE_DDT) == 0); | ||
| 72 | 76 | ||
| 73 | Timer timer = {}; | 77 | Timer timer = {}; |
| 74 | Simloop simloop = | 78 | Simloop simloop = |
| @@ -78,7 +82,7 @@ TEST_CASE(simloop_no_render_frame_cap) { | |||
| 78 | for (time_delta t = 0; t < SIM_TIME_SEC; t += STEP) { | 82 | for (time_delta t = 0; t < SIM_TIME_SEC; t += STEP) { |
| 79 | timer_advance(&timer, t); | 83 | timer_advance(&timer, t); |
| 80 | simloop_update(&simloop, &simout); | 84 | simloop_update(&simloop, &simout); |
| 81 | const bool expect_update = (t > 0) && ((t % EXPECT_UPDATE) == 0); | 85 | const bool expect_update = (t > 0) && ((t % UPDATE_DDT) == 0); |
| 82 | // A render is still expected at time 0. | 86 | // A render is still expected at time 0. |
| 83 | TEST_EQUAL(simout.should_render, (t == 0) || expect_update); | 87 | TEST_EQUAL(simout.should_render, (t == 0) || expect_update); |
| 84 | TEST_EQUAL(simout.should_update, expect_update); | 88 | TEST_EQUAL(simout.should_update, expect_update); |
| @@ -89,12 +93,17 @@ TEST_CASE(simloop_no_render_frame_cap) { | |||
| 89 | /// 1. Updates based on the desired update frame rate. | 93 | /// 1. Updates based on the desired update frame rate. |
| 90 | /// 2. Renders based on the desired render frame rate. | 94 | /// 2. Renders based on the desired render frame rate. |
| 91 | TEST_CASE(simloop_with_render_frame_cap) { | 95 | TEST_CASE(simloop_with_render_frame_cap) { |
| 92 | constexpr int UPDATE_FPS = 10; | 96 | constexpr int UPDATE_FPS = 10; // 100ms delta |
| 93 | constexpr int RENDER_FPS = 5; | 97 | constexpr int RENDER_FPS = 5; // 200ms delta |
| 94 | const time_delta EXPECT_UPDATE = sec_to_time_delta(1.0 / (double)UPDATE_FPS); | 98 | const time_delta UPDATE_DDT = sec_to_time_delta(1.0 / (double)UPDATE_FPS); |
| 95 | const time_delta EXPECT_RENDER = sec_to_time_delta(1.0 / (double)RENDER_FPS); | 99 | const time_delta RENDER_DDT = sec_to_time_delta(1.0 / (double)RENDER_FPS); |
| 96 | const time_delta STEP = sec_to_time_delta(0.1); | 100 | const time_delta STEP = sec_to_time_delta(0.1); // 100ms |
| 97 | const time_delta SIM_TIME_SEC = sec_to_time_delta(30); | 101 | const time_delta SIM_TIME_SEC = sec_to_time_delta(30); |
| 102 | |||
| 103 | // We need simulation time to be an exact multiple of the desired deltas for | ||
| 104 | // the modulo comparisons below. | ||
| 105 | TEST_TRUE((UPDATE_DDT % STEP) == 0); | ||
| 106 | TEST_TRUE((RENDER_DDT % STEP) == 0); | ||
| 98 | 107 | ||
| 99 | Timer timer = {}; | 108 | Timer timer = {}; |
| 100 | Simloop simloop = simloop_make(&(SimloopArgs){ | 109 | Simloop simloop = simloop_make(&(SimloopArgs){ |
| @@ -105,8 +114,8 @@ TEST_CASE(simloop_with_render_frame_cap) { | |||
| 105 | timer_advance(&timer, t); | 114 | timer_advance(&timer, t); |
| 106 | simloop_update(&simloop, &simout); | 115 | simloop_update(&simloop, &simout); |
| 107 | // A render is still expected at time 0. | 116 | // A render is still expected at time 0. |
| 108 | TEST_EQUAL(simout.should_render, (t % EXPECT_RENDER) == 0); | 117 | TEST_EQUAL(simout.should_render, (t % RENDER_DDT) == 0); |
| 109 | TEST_EQUAL(simout.should_update, (t > 0) && ((t % EXPECT_UPDATE) == 0)); | 118 | TEST_EQUAL(simout.should_update, (t > 0) && ((t % UPDATE_DDT) == 0)); |
| 110 | } | 119 | } |
| 111 | } | 120 | } |
| 112 | 121 | ||
