FPSCounter = {
    ["updateTimer1"] = 0.5, -- Time to wait between each update of the FPS
    ["frameNbr"]     = 0,   -- Frame counter
    ["FPS"]          = 0,   -- The FPS as it is displayed on the screen
    
    ["updateTimer2"]    = 0.2, -- Time to wait between each update of the render time
    ["totalRenderTime"] = 0,   -- Total render time between each update
    ["frameNbr2"]       = 0,   -- Total number of frames between two updates
    ["renderTime"]      = 0,   -- Render time displayed on screen
};

function FPSCounter.OnUpdate()
    FPSCounter.updateTimer1 = FPSCounter.updateTimer1 + arg1;
    FPSCounter.frameNbr = FPSCounter.frameNbr + 1;
    if (FPSCounter.updateTimer1 >= 0.5) then
        FPSCounter.FPS = math.floor(FPSCounter.frameNbr / FPSCounter.updateTimer1);
        FPSCounter.updateTimer1 = 0;
        FPSCounter.frameNbr = 0;
    end
    
    local chunk, vertex, renderTime = GetRenderStats();
    
    FPSCounter.updateTimer2 = FPSCounter.updateTimer2 + arg1;
    FPSCounter.frameNbr2 = FPSCounter.frameNbr2 + 1;
    FPSCounter.totalRenderTime = FPSCounter.totalRenderTime + renderTime;
    if (FPSCounter.updateTimer2 >= 0.2) then
        FPSCounter.renderTime = math.floor(FPSCounter.totalRenderTime / FPSCounter.frameNbr2);
        FPSCounter.updateTimer2 = 0;
        FPSCounter.frameNbr2 = 0;
        FPSCounter.totalRenderTime = 0;
    end
    
    FPSCounter_Text:SetText("FPS : "..FPSCounter.FPS.."\nRender : "..FPSCounter.renderTime.."\nChunks : "..chunk.."\nVertex : "..vertex);
        
    local x, y, z = GetSelectedBlockPos();
    if (x and y and z) then
        Info_Text:SetText("x : "..x..", y : "..y..", z : "..z);
    else
        Info_Text:SetText("x : --, y : --, z : --");
    end
end
