Ejemplo n.º 1
0
        private void Load()
        {
#if UNITY
            // In unity editor set synchronizer from the inspector
#else
            var path   = Path.Combine(RootPath, AssetBundleName);
            var bundle = AssetBundle.LoadFromFile(path);
            if (bundle == null)
            {
                PTLogger.Error($"Failed to load ParallelTasker asset bundle from {path}.");
                return;
            }

            var prefab = bundle.LoadAsset <GameObject>("Synchronizer");
            m_synchronizer = Instantiate(prefab);
            bundle.Unload(true);
#endif

            if (m_synchronizer == null)
            {
                PTLogger.Error("Could not load synchronizers");
                return;
            }
            m_synchronizer.SetActive(true);

            foreach (var sync in m_synchronizer.GetComponents <IPTSynchronizer>())
            {
                PTLogger.Debug($"Adding {sync} to known synchronizers");
                s_synchronizers.Add(sync.EventTime, sync);
            }
        }
Ejemplo n.º 2
0
 internal void OnSceneChange(Scene current, Scene next)
 {
     // in KSP scene changes are done through an intermediate loading buffer scene
     if (!ResetOnSceneChange)
     {
         return;
     }
     PTLogger.Debug($"Scene change: {current.name} -> {next.name}");
     Controller?.ResetCurrentTasks();
 }
Ejemplo n.º 3
0
 public PTThreadPool(int number)
 {
     PTLogger.Info($"Initializing threadpool with {number.ToString()} threads.");
     m_threads = new Thread[number];
     for (var i = 0; i < number; i++)
     {
         m_threads[i] = new Thread(ExecuteTasks);
         m_threads[i].Start();
     }
 }
Ejemplo n.º 4
0
 public void RunFinalizer()
 {
     try
     {
         finalize?.Invoke(argument);
     }
     catch (Exception ex)
     {
         PTLogger.Exception(ex);
     }
     Release();
 }
Ejemplo n.º 5
0
        public PTTaskQueue()
        {
            ResetCount();
#if DEBUG
            var sb      = new StringBuilder($"{this} dequeue order:\n");
            var counter = 0;
            foreach (var group in m_tasks.Keys)
            {
                sb.AppendLine($"  {(++counter).ToString()}. {group.ToString()}");
            }
            PTLogger.Debug(sb.ToString());
#endif
        }
Ejemplo n.º 6
0
 public static void Flush()
 {
     if (m_sb.Length <= 0)
     {
         return;
     }
     lock (m_lock)
     {
         m_sb.Insert(0, m_logStart);
         PTLogger.Info(m_sb.ToString());
         Clear();
     }
 }
Ejemplo n.º 7
0
 public PTThreadTask RunInitializer()
 {
     try
     {
         argument = initialize?.Invoke();
     }
     catch (Exception ex)
     {
         main     = null;
         finalize = null;
         PTLogger.Exception(ex);
     }
     return(this);
 }
Ejemplo n.º 8
0
 private void Awake()
 {
     if (m_instance == null)
     {
         PTLogger.Debug($"Singleton {this} is awake");
         m_instance = this as T;
         DontDestroyOnLoad(this);
         OnAwake();
     }
     else
     {
         PTLogger.Warning($"{this} is a Singleton but an instance already exists, destroying this instance");
         m_destroyingDuplicate = true;
         Destroy(this);
     }
 }
Ejemplo n.º 9
0
        private void Initialize(Func <PTTimePair, T> create)
        {
            var factory = create ?? (pair => default(T));

            foreach (var group in PTUtils.GetAllTimePairs())
            {
                try
                {
                    this[group] = factory(group);
                }
                catch (Exception)
                {
                    PTLogger.Error($"Error while initializing {this} with {group.ToString()}");
                    throw;
                }
            }
        }