Kumo
A hand-rolled game engine.
git clone https://git.sentomk.me/Kumo.git
loop.cpp (782B) · raw
1 #include "runtime/loop.h" 2 3 namespace kumo { 4 5 Loop::Loop(Clock& clock, LoopConfig config) 6 : timer_(clock), stepper_(config.step, config.max_frame) {} 7 8 FrameReport Loop::step_frame(Game& game, FrameBuffer& frame) { 9 const int updates = stepper_.advance(timer_.tick()); 10 for (int i = 0; i < updates; ++i) { 11 const Tick tick = {next_tick_index_, stepper_.step()}; 12 game.fixed_update(tick); 13 ++next_tick_index_; 14 } 15 const Fixed alpha = stepper_.alpha_fixed(); 16 game.render(frame, alpha); 17 return {updates, next_tick_index_, alpha}; 18 } 19 20 void Loop::step_ticks(Game& game, uint64_t count) { 21 for (uint64_t i = 0; i < count; ++i) { 22 const Tick tick = {next_tick_index_, stepper_.step()}; 23 game.fixed_update(tick); 24 ++next_tick_index_; 25 } 26 } 27 28 } // namespace kumo
