
import * as PIXI from "../../pixi/pixi.mjs";
import { UIGameProfilerPipe } from "../UIPipes/UIPipes";

/**
 * How many times per second FPS will be updated
 */
const ProfilerIntervalScale = 2.0;

let _profilerInterval = 5;
let _counter = 0;
let _latency = 0;

/**
 * 
 * @param {PIXI._Ticker} tick 
 */
export function profileFPS(tick)
{
    _counter++;
    _latency += tick.elapsedMS;
    if(_counter >= _profilerInterval)
    {
        _counter = 0;
        UIGameProfilerPipe.update((s)=>{
            s.frameLatency = _latency / _profilerInterval;
        });
        _profilerInterval = 1000.0 / (_latency / _profilerInterval) / ProfilerIntervalScale;
        _latency = 0;
    }   
}

export function printOnScreenDebugMessage(text, time) {
    UIGameProfilerPipe.update((s)=>{
        s.profileMessages.push({text, time});
    });
}

export function profileDebugMessages(tick) {
    UIGameProfilerPipe.update((s)=>{
        s.profileMessages = [];
    });
}