Skip to content

A lightweight Clip Studio Paint alternative with real-time multiplayer collaborative drawing. Built with Tauri and React.

968 B
Raw Blame
//! Monotonic high-resolution QPC clock in milliseconds, sharing the exact same
//! timebase as `src-tauri/src/tablet_input.rs` for accurate input-to-present telemetry.

#[cfg(target_os = "windows")]
pub fn now_ms() -> f64 {
    use std::sync::LazyLock;
    use windows_sys::Win32::System::Performance::{
        QueryPerformanceCounter, QueryPerformanceFrequency,
    };

    static FREQ_PER_MS: LazyLock<f64> = LazyLock::new(|| unsafe {
        let mut f = 0i64;
        QueryPerformanceFrequency(&mut f);
        if f > 0 {
            f as f64 / 1000.0
        } else {
            1.0
        }
    });

    unsafe {
        let mut now = 0i64;
        QueryPerformanceCounter(&mut now);
        (now as f64) / *FREQ_PER_MS
    }
}

#[cfg(not(target_os = "windows"))]
pub fn now_ms() -> f64 {
    use std::sync::LazyLock;
    use std::time::Instant;

    static EPOCH: LazyLock<Instant> = LazyLock::new(Instant::now);
    EPOCH.elapsed().as_secs_f64() * 1000.0
}