/// @file runtime/game.h /// @brief The Tick value and the Game interface driven by the runtime loop. #pragma once #include "core/clock.h" #include "core/fixed.h" #include "core/types.h" namespace kumo { struct FrameBuffer; /// @brief Information about one fixed simulation update. struct Tick { uint64_t index; ///< Zero-based index of the update being executed. Nanoseconds dt; ///< Fixed duration of this update. /// @brief Duration of this update in seconds, as a deterministic Fixed. constexpr Fixed dt_seconds() const { return Fixed::ratio(dt, kNanosecondsPerSecond); } }; /// @brief Game logic driven by the engine's main loop. /// /// The caller owns the game and keeps it alive while running. class Game { public: virtual ~Game() = default; /// @brief Advances the simulation by exactly one fixed step. virtual void fixed_update(const Tick& tick) = 0; /// @brief Draws the game without advancing the simulation. /// /// @param frame Pixel buffer to draw into. /// @param alpha Interpolation fraction in [0, 1), between the last two ticks. virtual void render(FrameBuffer& frame, Fixed alpha) const = 0; }; } // namespace kumo