using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Net; using System.Text; using System.Threading; using System.Threading.Tasks; namespace ImpulseVision { public static class Animator { public static List AnimationList = new List(); public static int Count() { return AnimationList.Count; } private static Thread AnimatorThread; private static double Interval; public static bool IsWork = false; public static void Start() { if (IsWork) return; IsWork = true; Interval = 14; // FPS ~66 AnimatorThread = new Thread(AnimationInvoker) { IsBackground = true, Name = "UI Animation" }; AnimatorThread.Start(); } private static void AnimationInvoker() { while (IsWork) { AnimationList.RemoveAll(a => a == null || a.Status == Animation.AnimationStatus.Completed); Parallel.For(0, Count(), index => { try { AnimationList[index].UpdateFrame(); } catch { } }); Thread.Sleep((int)Interval); } } public static void Request(Animation Anim, bool ReplaceIfExists = true) { if (AnimatorThread == null || IsWork == false) { Start(); } Debug.WriteLine("Запуск анимации: " + Anim.ID + "| TargetValue: " + Anim.TargetValue); Anim.Status = Animation.AnimationStatus.Requested; Animation dupAnim = GetDuplicate(Anim); if (dupAnim != null) { if (ReplaceIfExists == true) { dupAnim.Status = Animation.AnimationStatus.Completed; } else { return; } } AnimationList.Add(Anim); } private static Animation GetDuplicate(Animation Anim) { try { //if (Anim.ID != null) return AnimationList.Find(a => a.ID == Anim.ID); } catch { return null; } } } }