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 FastTickThread extends EngineThread {

    public FastTickThread(EngineInstance engineInstance, GameLogic appLogic){
        super(engineInstance, appLogic, "Fast");
        UpdateTickRateThreshold();
    }

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

    }
    @Override
    public void CycleEvent(){

    }
    @Override
    public void SecondEvent(){
        EngineConfig.FrameRate_FASTENGINETHREAD = Frames;
        Logger.info(ThreadName + " Thread FPS: " + EngineConfig.FrameRate_FASTENGINETHREAD + "   TPS: " + TickFrames);
    }

    public void UpdateTickRateThreshold(){
        CappedToTickRate = EngineConfig.getInstance().GetFastTickCap();
        TickRate = EngineConfig.getInstance().GetFastTickrate();
        if (CappedToTickRate){
            TickThreshold = (double) 1000000000 / (double) TickRate;
        } else{
            TickThreshold = 0;
        }
    }


}
