Skip to content
On this page

Chrono

ll/api/chrono/ · Common

Overview

The Chrono module provides game-specific time types based on std::chrono, including game tick durations, game-time clocks, and user-defined literals for expressing game time.

Headers

HeaderDescription
ll/api/chrono/GameChrono.hGame tick durations, clocks, and literals

Game Tick Durations

Game time is measured in ticks (20 ticks = 1 real-time second). The following duration types are provided:

TypeDefinitionEquivalent
game::ticksduration<int64, ratio<1, 20>>1 tick = 50ms
game::days24000 ticks1 Minecraft day
game::hours1000 ticks1 Minecraft hour
game::minutes~16.67 ticks1 Minecraft minute
game::weeks7 game days1 Minecraft week
game::months~1/12 of a game year1 Minecraft month
game::years365 game days1 Minecraft year

User-Defined Literals

C++
#include "ll/api/chrono/GameChrono.h"

using namespace ll::chrono_literals;

auto tenTicks   = 10_tick;
auto halfDay    = 12000_tick;

Clocks

GameTickClock

A clock that tracks game ticks. Time advances only when the game is ticking.

C++
#include "ll/api/chrono/GameChrono.h"

auto now = ll::chrono::GameTickClock::now();
auto tp  = ll::chrono::GameTickClock::fromTick(100);

ServerClock

A clock that tracks real wall-clock time on the server.

C++
auto serverNow = ll::chrono::ServerClock::now();

Usage

Measuring Game Time Intervals

C++
#include "ll/api/chrono/GameChrono.h"

void onTick() {
    using namespace ll::chrono;
    static auto lastCheck = GameTickClock::now();

    auto elapsed = GameTickClock::now() - lastCheck;
    if (elapsed >= game::days{1}) {
        // One in-game day has passed
        lastCheck = GameTickClock::now();
    }
}

Converting Between Durations

C++
#include "ll/api/chrono/GameChrono.h"
#include <chrono>

using namespace ll::chrono;

// Convert game ticks to real-time seconds
auto ticks = game::ticks{100};
auto realSeconds = std::chrono::duration_cast<std::chrono::seconds>(ticks); // 5 seconds
  • Thread — TickSyncSleep uses game chrono types
  • Coroutine — SleepAwaiter works with chrono durations