From 4557bbcb3c444f3f01d622caa07126ed7bf5451d Mon Sep 17 00:00:00 2001 From: perdidor Date: Mon, 25 Mar 2024 19:44:59 +0300 Subject: [PATCH] multimonitor sync done --- AssemblyInfo.cs | 2 +- ColBitMap.cs | 15 +++---- ScreenSaver.cs | 25 +++++++++++ ScreenSaverForm.cs | 109 +++++++++++++++++++++------------------------ 4 files changed, 83 insertions(+), 68 deletions(-) diff --git a/AssemblyInfo.cs b/AssemblyInfo.cs index 1652ec4..844fbfb 100644 --- a/AssemblyInfo.cs +++ b/AssemblyInfo.cs @@ -25,7 +25,7 @@ // You can specify all the values or you can default the Revision and Build Numbers // by using the '*' as shown below: -[assembly: AssemblyVersion("0.9.1")] +[assembly: AssemblyVersion("0.9.3")] // // In order to sign your assembly you must specify a key to use. Refer to the diff --git a/ColBitMap.cs b/ColBitMap.cs index cac774e..ae2222b 100644 --- a/ColBitMap.cs +++ b/ColBitMap.cs @@ -19,7 +19,7 @@ public ColBitMap(int columnIndex, int scrNumber) public void InPlaceMutation() { - var movesdown = ScreenInstances.EntropySrc.Next(1,4); + var movesdown = ScreenInstances.EntropySrc.Next(0,4); for (int i = 0; i < movesdown; i++) { MoveDown(true); @@ -28,23 +28,20 @@ public void InPlaceMutation() { for (int i = 0; i < ScreenInstances.ScrForms[ScrNumber].SpriteRows; i++) { - var mutationdice = ScreenInstances.EntropySrc.Next(2); - var mutationdice2 = ScreenInstances.EntropySrc.Next(3); - if (!ScreenInstances.CheckIndexEmptySprite(ScreenInstances.ScrForms[ScrNumber].UsedKatakanaIndexes[ColumnIndex, i]) && mutationdice2 >= 0) + var mutationdice = ScreenInstances.EntropySrc.Next(4); + if (!ScreenInstances.CheckIndexEmptySprite(ScreenInstances.ScrForms[ScrNumber].UsedKatakanaIndexes[ColumnIndex, i])) { switch (mutationdice) { case 0: - { - ScreenInstances.ScrForms[ScrNumber].UsedKatakanaIndexes[ColumnIndex, i] = (ScreenInstances.ScrForms[ScrNumber].UsedKatakanaIndexes[ColumnIndex, i] + 120) % 480; - } - break; - case 1: { ScreenInstances.ScrForms[ScrNumber].UsedKatakanaIndexes[ColumnIndex, i] = ScreenInstances.EntropySrc.Next(480); } break; default: + { + ScreenInstances.ScrForms[ScrNumber].UsedKatakanaIndexes[ColumnIndex, i] = (ScreenInstances.ScrForms[ScrNumber].UsedKatakanaIndexes[ColumnIndex, i] + 120) % 480; + } break; } Bitmap resbitmap = ScreenInstances.GetKatakanaSprite(ScreenInstances.ScrForms[ScrNumber].UsedKatakanaIndexes[ColumnIndex, i]); diff --git a/ScreenSaver.cs b/ScreenSaver.cs index e6fccc8..15c0693 100644 --- a/ScreenSaver.cs +++ b/ScreenSaver.cs @@ -3,6 +3,7 @@ using System.Windows.Forms; using System.Collections.Generic; using System.Threading.Tasks; +using System.Linq; namespace ScreenSaver { @@ -41,8 +42,32 @@ static void Main(string[] args) ScreenInstances.ScrForms[i].Show(); } } + Task.Run(SSRunMMSync); Application.Run(ScreenInstances.ScrForms[0]); } + static async Task SSRunMMSync() + { + while (ScreenInstances.ScrForms.Count(x => x.Visible) != ScreenInstances.ScrForms.Count) + { + await Task.Delay(10); + } + while (!ScreenInstances.GlobalCTS.IsCancellationRequested) + { + List tasklist = new List(); + foreach (ScreenSaverForm ssform in ScreenInstances.ScrForms) + { + var newtask = new Task(() => + { + ssform.DoShowScreenSaverCycle(); + }, ScreenInstances.GlobalCTS.Token); + newtask.Start(); + tasklist.Add(newtask); + } + Task.WaitAll(tasklist.ToArray()); + await Task.Delay(10); + } + } + } } diff --git a/ScreenSaverForm.cs b/ScreenSaverForm.cs index 2045bdc..f2e5823 100644 --- a/ScreenSaverForm.cs +++ b/ScreenSaverForm.cs @@ -30,6 +30,8 @@ public class ScreenSaverForm : Form public bool DoShowCredits = true; //show credits on start public bool DoShowConsole = false; + private long Cycles = 0; + public void ReorderColumnIndexesDownMove(int colIndex, bool clearfirst = false) { for (int i = SpriteRows - 1; i > 0; i--) @@ -77,79 +79,70 @@ private void ScreenSaverForm_Load(object sender, EventArgs e) } ColBitMaps = new ColBitMap[SpriteColumns]; Array.Clear(ColBitMaps, 0, SpriteColumns); - ShowScreenSaver(); } - private void ShowScreenSaver() + public void DoShowScreenSaverCycle() { - Task.Run(async () => + try { - int cycles = 0; - while (true) + Invoke((MethodInvoker)delegate { - try + if (DoShowCredits) { - Invoke((MethodInvoker)delegate + ShowCredits(); + } + else + if (DoShowConsole) + { + ShowConsoleStrings(); + } + else + { + using (Graphics graphics = Graphics.FromImage(SSBitmap)) { - if (DoShowCredits) - { - ShowCredits(); - } - else - if (DoShowConsole) + int modcount = SpriteColumns / 10; //we will modify only 10% of columns per step + for (int i = 0; i < modcount; i++) { - ShowConsoleStrings(); - } - else - { - using (Graphics graphics = Graphics.FromImage(SSBitmap)) + var selectedcol = ScreenInstances.EntropySrc.Next(SpriteColumns); + TransformColumn(selectedcol); + if (ColBitMaps[selectedcol].IsModified) { - int modcount = SpriteColumns / 10; //we will modify only 10% of columns per step - for (int i = 0; i < modcount; i++) - { - var selectedcol = ScreenInstances.EntropySrc.Next(SpriteColumns); - TransformColumn(selectedcol); - if (ColBitMaps[selectedcol].IsModified) - { - Point sp = new Point(selectedcol * 16, 0); - graphics.DrawImageUnscaled(ColBitMaps[selectedcol].ColumnBitMap, sp); - } - } + Point sp = new Point(selectedcol * 16, 0); + graphics.DrawImageUnscaled(ColBitMaps[selectedcol].ColumnBitMap, sp); } } + } + } - if (!DoShowCredits) + if (!DoShowCredits) + { + if (Cycles < 3000) + { + Cycles++; + } + else + { + Cycles = 0; + DoShowCredits = true; + using (Graphics graphics = Graphics.FromImage(SSBitmap)) { - if (cycles < 3000) - { - cycles++; - } - else - { - cycles = 0; - DoShowCredits = true; - using (Graphics graphics = Graphics.FromImage(SSBitmap)) - { - graphics.Clear(Color.Black); - } - } + graphics.Clear(Color.Black); } - - SSPictureBox.Image = SSBitmap; - SSPictureBox.Refresh(); - }); - await Task.Delay(10); - } - catch (TaskCanceledException) - { - return; - } - catch (Exception ex) - { - var s = ex.ToString(); + } } - } - }, ScreenInstances.GlobalCTS.Token); + + SSPictureBox.Image = SSBitmap; + SSPictureBox.Refresh(); + }); + } + catch (TaskCanceledException) + { + return; + } + catch (Exception ex) + { + var s = ex.ToString(); + } } private void ShowCredits()