Skip to content

Commit

Permalink
multimonitor sync done
Browse files Browse the repository at this point in the history
  • Loading branch information
perdidor committed Mar 25, 2024
1 parent fdd8762 commit 4557bbc
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 68 deletions.
2 changes: 1 addition & 1 deletion AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 6 additions & 9 deletions ColBitMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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]);
Expand Down
25 changes: 25 additions & 0 deletions ScreenSaver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Windows.Forms;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Linq;

namespace ScreenSaver
{
Expand Down Expand Up @@ -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<Task> tasklist = new List<Task>();
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);
}
}

}
}
109 changes: 51 additions & 58 deletions ScreenSaverForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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--)
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 4557bbc

Please sign in to comment.