This commit is contained in:
veclav talica 2024-07-08 23:50:01 +03:00
commit 96d1f5b7a2
4 changed files with 8 additions and 28 deletions

View File

@ -41,7 +41,6 @@ typedef struct context {
int64_t time_averager[4]; int64_t time_averager[4];
int64_t delta_time; /* preserves real time frame delta with no manipilation */ int64_t delta_time; /* preserves real time frame delta with no manipilation */
uint64_t tick_count; uint64_t tick_count;
uint64_t step_count;
/* set just once on startup */ /* set just once on startup */
uint64_t random_seed; uint64_t random_seed;

View File

@ -10,11 +10,6 @@
#include <stdint.h> #include <stdint.h>
void game_step(int64_t delta) {
(void)delta;
}
void game_tick(void) { void game_tick(void) {
if (ctx.tick_count == 0) { if (ctx.tick_count == 0) {
ctx.udata = ccalloc(1, sizeof (struct state)); ctx.udata = ccalloc(1, sizeof (struct state));

View File

@ -7,7 +7,6 @@
#include <stdint.h> #include <stdint.h>
void game_step(int64_t delta);
void game_tick(void); void game_tick(void);
void game_end(void); void game_end(void);

View File

@ -121,30 +121,18 @@ void main_loop(void) {
} }
/* finally, let's get to work */ /* finally, let's get to work */
poll_events();
input_state_update(&ctx.input);
/* do we _always_ have to be dry? */
if (ctx.frame_accumulator >= ctx.desired_frametime * ctx.update_multiplicity) {
while (ctx.frame_accumulator >= ctx.desired_frametime * ctx.update_multiplicity) { while (ctx.frame_accumulator >= ctx.desired_frametime * ctx.update_multiplicity) {
for (size_t i = 0; i < ctx.update_multiplicity; ++i) { for (size_t i = 0; i < ctx.update_multiplicity; ++i) {
render_queue_clear(); render_queue_clear();
poll_events();
input_state_update(&ctx.input);
game_tick(); game_tick();
ctx.frame_accumulator -= ctx.desired_frametime; ctx.frame_accumulator -= ctx.desired_frametime;
ctx.tick_count = (ctx.tick_count % ULLONG_MAX) + 1; ctx.tick_count = (ctx.tick_count % ULLONG_MAX) + 1;
} }
} }
} else {
render_queue_clear();
}
/* the "step" will always run as long as there is time to spare. */
/* without interpolation, this is preferable to fixed ticks if the additional */
/* delta time calculations (like in physics code) are acceptable */
game_step(delta_time);
ctx.step_count = (ctx.step_count % ULLONG_MAX) + 1;
render(); render();
} }
@ -240,7 +228,6 @@ static bool initialize(void) {
ctx.desired_frametime = ctx.clocks_per_second / TICKS_PER_SECOND; ctx.desired_frametime = ctx.clocks_per_second / TICKS_PER_SECOND;
ctx.frame_accumulator = 0; ctx.frame_accumulator = 0;
ctx.tick_count = 0; ctx.tick_count = 0;
ctx.step_count = 0;
/* delta time averaging */ /* delta time averaging */
ctx.delta_averager_residual = 0; ctx.delta_averager_residual = 0;