// C++20 — 固定タイムステップ+補間のゲームループ(docs/04_game_patterns/game_loop_and_update.md)
// デモ用に「実時間」を擬似的に進める(実ゲームはClock::now()を使う)
#include <cstdio>

int main() {
    constexpr float kFixedDt = 1.0f / 60.0f;
    constexpr int kMaxStepsPerFrame = 5;          // 死のスパイラル防止の上限

    float accumulator = 0.0f;
    float simTime = 0.0f;
    float pos = 0.0f, vel = 60.0f;                // 60単位/秒で移動する物体

    // 擬似フレーム時間列(重いフレームが混ざる想定)
    const float frameTimes[] = {0.016f, 0.016f, 0.100f, 0.016f, 0.033f};

    for (float frameDt : frameTimes) {
        accumulator += frameDt;
        int steps = 0;
        while (accumulator >= kFixedDt && steps < kMaxStepsPerFrame) {
            pos += vel * kFixedDt;                // 物理は常に1/60秒刻み(決定的)
            simTime += kFixedDt;
            accumulator -= kFixedDt;
            ++steps;
        }
        float alpha = accumulator / kFixedDt;     // 端数は描画補間に使う
        std::printf("frame(dt=%.3f): steps=%d simTime=%.3f pos=%.2f renderAlpha=%.2f\n",
                    frameDt, steps, simTime, pos, alpha);
    }
    return 0;
}
