Kumo
A hand-rolled game engine.
git clone https://git.sentomk.me/Kumo.git
game.h (1178B) · raw
1 /// @file runtime/game.h 2 /// @brief The Tick value and the Game interface driven by the runtime loop. 3 #pragma once 4 5 #include "core/clock.h" 6 #include "core/fixed.h" 7 #include "core/types.h" 8 9 namespace kumo { 10 11 struct FrameBuffer; 12 13 /// @brief Information about one fixed simulation update. 14 struct Tick { 15 uint64_t index; ///< Zero-based index of the update being executed. 16 Nanoseconds dt; ///< Fixed duration of this update. 17 18 /// @brief Duration of this update in seconds, as a deterministic Fixed. 19 constexpr Fixed dt_seconds() const { 20 return Fixed::ratio(dt, kNanosecondsPerSecond); 21 } 22 }; 23 24 /// @brief Game logic driven by the engine's main loop. 25 /// 26 /// The caller owns the game and keeps it alive while running. 27 class Game { 28 public: 29 virtual ~Game() = default; 30 31 /// @brief Advances the simulation by exactly one fixed step. 32 virtual void fixed_update(const Tick& tick) = 0; 33 34 /// @brief Draws the game without advancing the simulation. 35 /// 36 /// @param frame Pixel buffer to draw into. 37 /// @param alpha Interpolation fraction in [0, 1), between the last two ticks. 38 virtual void render(FrameBuffer& frame, Fixed alpha) const = 0; 39 }; 40 41 } // namespace kumo
