using System.Collections.Generic;
using UnityEngine;

namespace RebootKit.Engine.Foundation {
    public class AppLoopManager : MonoBehaviour {
        static readonly Logger s_Logger = new Logger(nameof(AppLoopManager));

        public delegate void TickDelegate(float dt);

        readonly List<TickDelegate> m_Delegates = new List<TickDelegate>();
        
        void Update() {
            float dt = Time.deltaTime;
            foreach (TickDelegate tick in m_Delegates) {
               tick(dt); 
            }
        }
        
        public void Add(TickDelegate tick) {
            if (m_Delegates.Contains(tick)) {
                s_Logger.Warning("Tick is already registered!");
            }

            m_Delegates.Add(tick);
        }
        
        public void Remove(TickDelegate tick) {
            m_Delegates.Remove(tick);
        }
    }
}