package net.halbear.Terrain4J.EngineCore.Threads;

import net.halbear.Terrain4J.EngineCore.Logic.EngineConfig;
import net.halbear.Terrain4J.EngineCore.Logic.EngineInstance;
import net.halbear.Terrain4J.EngineCore.Logic.GameLogic;
import net.halbear.Terrain4J.EngineCore.Main.PrimaryRuntime;
import org.tinylog.Logger;

public class MainThread extends EngineThread  {

    @Override
    public void TickEvent(long nsTimeDiff){
        gameLogic.Update(PrimaryRuntime.GetEngineInstance(), nsTimeDiff);
    }
    @Override
    public void FrameEvent(long now, long InitialTime){
    }
    @Override
    public void CycleEvent(){

    }
    @Override
    public void SecondEvent(){
        EngineConfig.FrameRate_MAINENGINETHREAD = Frames;
        Logger.info(ThreadName + " Thread FPS: " + EngineConfig.FrameRate_MAINENGINETHREAD + "   TPS: " + TickFrames);
    }
    public void UpdateTickRateThreshold(){
        CappedToTickRate = EngineConfig.getInstance().GetMainTickCap();
        TickRate = EngineConfig.getInstance().GetMainTickrate();
        if (CappedToTickRate){
            TickThreshold = (double) 1000000000 / (double) TickRate;
        } else{
            TickThreshold = 0;
        }
    }
    public MainThread(EngineInstance engineInstance, GameLogic appLogic){
        super(engineInstance, appLogic, "Main");
        UpdateTickRateThreshold();
    }

}
