public void StartWork() { if (allWorkThread != null) { PauseWork(); } currentWorkStatus = WorkStatus.inRun; allWorkThread = new Thread(() => { Thread.CurrentThread.Priority = ThreadPriority.AboveNormal; while (allWorkThread == Thread.CurrentThread && currentWorkStatus == WorkStatus.inRun) { var invokedBuf = invoked.ToArray(); foreach (var method in invokedBuf) { method(); invoked.Remove(method); } UniverseProperty.DoUniverseTick(); ImageSource img = RenderManagerMainFieldProperty.RenderField(UniverseProperty.GetAllDescriptors()); img.Freeze(); ImageSource info = RenderManagerInfoTextProperty.DrawUniverseInfo(UniverseProperty, maxInfoTextWidth, infoTextFontSize, Brushes.Black); info.Freeze(); universeOutputUIElement.ImageUniverseField.Dispatcher.Invoke(() => { try { universeOutputUIElement.ImageUniverseField.Source = img; } catch { } }); universeOutputUIElement.ImageInfo.Dispatcher.Invoke(() => { try { universeOutputUIElement.ImageInfo.Source = info; } catch { } }); Thread.Sleep(PauseBetweenRender); } }); allWorkThread.Start(); }
/// <summary> /// It attaches events to IUniverseOutputUIElement. /// <para></para> /// Прикрепляет к IUniverseOutputUIElement события. /// </summary> void InitializeEvents() { mouseDownOnFieldImage = (s, ev) => { try { if (UniverseProperty != null) { Image image = s as Image; Point pos = ev.GetPosition(image); PointInt posCube = RenderManagerMainFieldProperty.GetCubePosition(pos.X, pos.Y, image.ActualWidth, image.ActualHeight); UniverseObject uo = UniverseProperty.GetMatrixElement(posCube.X, posCube.Y); if (uo is Cell) { WindowImage.ShowModal( RenderManagerInfoTextProperty.DrawCellInfo(uo as Cell, maxInfoTextWidth, infoTextFontSize, Brushes.Black), LanguageHandler.GetInstance().CellInfoWindowTitle ); } } } catch { } }; universeOutputUIElement.ImageUniverseField.MouseDown += mouseDownOnFieldImage; universeOutputUIElement.OnStart = delegate { StartWork(); }; universeOutputUIElement.OnPause = delegate { PauseWorkAsync(); }; universeOutputUIElement.OnExit = delegate { Dispose(); }; universeOutputUIElement.OnOpenUniverseConstsRedactor = delegate { OpenUniverseConstsRedactor(); }; universeOutputUIElement.OnOpenFoodPlaceRedactor = delegate { OpenFoodPlaceRedactor(); }; universeOutputUIElement.OnOpenPoisonPlaceRedactor = delegate { OpenPoisonPlaceRedactor();; }; universeOutputUIElement.OnClearUniverseField = delegate { ClearUniverseField(); }; universeOutputUIElement.OnGenerateCells = delegate { if (universeOutputUIElement.CountOfCellsToGenerate != null) { GenerateCells((int)universeOutputUIElement.CountOfCellsToGenerate); } }; universeOutputUIElement.OnGenerateFoodOnAllField = delegate { GenerateFoodOnAllField(); }; universeOutputUIElement.OnResetResolution = delegate { if (universeOutputUIElement.ResolutionToReset == null) { return; } Size resolution = (Size)universeOutputUIElement.ResolutionToReset; ResetResolution(resolution.Width, resolution.Height); }; universeOutputUIElement.OnSaveUniverse = delegate { SaveUniverse(); }; universeOutputUIElement.OnGetWorkDeley = delegate { GetWorkDelay(); }; }