mirror of
https://github.com/Stone-Red-Code/RemSox.git
synced 2026-09-09 23:41:57 +02:00
Refactor process spawning command and move TestProcess to its own file
This commit is contained in:
@@ -24,7 +24,7 @@ public class Kernel : Sys.Kernel
|
|||||||
new HelpCommand(),
|
new HelpCommand(),
|
||||||
new ClearCommand(),
|
new ClearCommand(),
|
||||||
new HaltCommand(),
|
new HaltCommand(),
|
||||||
new SpawnTestProcessCommand(),
|
new SpawnProcessCommand(),
|
||||||
new ListProcessesCommand(),
|
new ListProcessesCommand(),
|
||||||
new StopProcessCommand(),
|
new StopProcessCommand(),
|
||||||
new StartGuiCommand(),
|
new StartGuiCommand(),
|
||||||
@@ -62,44 +62,6 @@ public class Kernel : Sys.Kernel
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class TestProcess() : Process("Test Process")
|
|
||||||
{
|
|
||||||
internal override void Start(string[] args)
|
|
||||||
{
|
|
||||||
Window window = WindowManager.CreateWindow(this, "Test Window", Point.Empty, new Size(200, 150));
|
|
||||||
window.AutoFlush = true;
|
|
||||||
|
|
||||||
Circle circle = window.CreateUIElement<UI.GUI.UIEelements.Shapes.Circle>(rect =>
|
|
||||||
{
|
|
||||||
rect.Position = new Point(10, 10);
|
|
||||||
rect.Radius = 50;
|
|
||||||
rect.Color = Color.Red;
|
|
||||||
});
|
|
||||||
|
|
||||||
circle.Radius = 40;
|
|
||||||
|
|
||||||
SendMessageToAllProcesses(new TestMessage { SenderProcessId = Id });
|
|
||||||
}
|
|
||||||
|
|
||||||
internal override void Tick()
|
|
||||||
{
|
|
||||||
// Example tick logic - could be used for animations, timed events, etc.
|
|
||||||
}
|
|
||||||
|
|
||||||
internal override void HandleInterProcessMessage(Message message)
|
|
||||||
{
|
|
||||||
if (message is TestMessage testMessage && message.SenderProcessId != Id)
|
|
||||||
{
|
|
||||||
Console.WriteLine($"Received message in {Name} (ID: {Id}): {testMessage.MessageText}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
internal class TestMessage : Message
|
|
||||||
{
|
|
||||||
public string MessageText { get; set; } = "Hello from TestMessage!";
|
|
||||||
}
|
|
||||||
|
|
||||||
public static unsafe partial class StartupCodeHelpers
|
public static unsafe partial class StartupCodeHelpers
|
||||||
{
|
{
|
||||||
[RuntimeExport("fmod")]
|
[RuntimeExport("fmod")]
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ internal class DesktopProcess() : Process("Desktop Manager")
|
|||||||
// Create a test window for new UI controls
|
// Create a test window for new UI controls
|
||||||
Window testWindow = WindowManager.CreateWindow(this, "UI Controls Test", new System.Drawing.Point(500, 50), new System.Drawing.Size(200, 180));
|
Window testWindow = WindowManager.CreateWindow(this, "UI Controls Test", new System.Drawing.Point(500, 50), new System.Drawing.Size(200, 180));
|
||||||
|
|
||||||
_ = testWindow.CreateUIElement<RemSox.UI.GUI.UIEelements.Controls.Button>(b =>
|
_ = testWindow.CreateUIElement<UI.GUI.UIEelements.Controls.Button>(b =>
|
||||||
{
|
{
|
||||||
b.Position = new System.Drawing.Point(20, 30);
|
b.Position = new System.Drawing.Point(20, 30);
|
||||||
b.Size = new System.Drawing.Size(100, 30);
|
b.Size = new System.Drawing.Size(100, 30);
|
||||||
@@ -38,14 +38,14 @@ internal class DesktopProcess() : Process("Desktop Manager")
|
|||||||
b.BackgroundColor = System.Drawing.Color.LightBlue;
|
b.BackgroundColor = System.Drawing.Color.LightBlue;
|
||||||
});
|
});
|
||||||
|
|
||||||
_ = testWindow.CreateUIElement<RemSox.UI.GUI.UIEelements.Controls.CheckBox>(c =>
|
_ = testWindow.CreateUIElement<UI.GUI.UIEelements.Controls.CheckBox>(c =>
|
||||||
{
|
{
|
||||||
c.Position = new System.Drawing.Point(20, 80);
|
c.Position = new System.Drawing.Point(20, 80);
|
||||||
c.Text = "Check Me";
|
c.Text = "Check Me";
|
||||||
c.IsChecked = true;
|
c.IsChecked = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
_ = testWindow.CreateUIElement<RemSox.UI.GUI.UIEelements.Shapes.Line>(l =>
|
_ = testWindow.CreateUIElement<UI.GUI.UIEelements.Shapes.Line>(l =>
|
||||||
{
|
{
|
||||||
l.Position = new System.Drawing.Point(20, 130);
|
l.Position = new System.Drawing.Point(20, 130);
|
||||||
l.EndPosition = new System.Drawing.Point(180, 130);
|
l.EndPosition = new System.Drawing.Point(180, 130);
|
||||||
@@ -62,7 +62,7 @@ internal class DesktopProcess() : Process("Desktop Manager")
|
|||||||
|
|
||||||
if (!ProcessManager.IsProcessRunning<TerminalProcess>())
|
if (!ProcessManager.IsProcessRunning<TerminalProcess>())
|
||||||
{
|
{
|
||||||
ProcessManager.SpawnProcess<TerminalProcess>();
|
_ = ProcessManager.SpawnProcess<TerminalProcess>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,49 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using RemSox.Processing;
|
||||||
|
using RemSox.Processing.IPC;
|
||||||
|
using RemSox.UI.GUI.UIEelements.Shapes;
|
||||||
|
using RemSox.UI.GUI.Windows;
|
||||||
|
|
||||||
|
namespace RemSox.Processes;
|
||||||
|
|
||||||
|
public class TestProcess() : Process("Test Process")
|
||||||
|
{
|
||||||
|
internal override void Start(string[] args)
|
||||||
|
{
|
||||||
|
Window window = WindowManager.CreateWindow(this, "Test Window", Point.Empty, new Size(200, 150));
|
||||||
|
window.AutoFlush = true;
|
||||||
|
|
||||||
|
Circle circle = window.CreateUIElement<Circle>(rect =>
|
||||||
|
{
|
||||||
|
rect.Position = new Point(10, 10);
|
||||||
|
rect.Radius = 50;
|
||||||
|
rect.Color = Color.Red;
|
||||||
|
});
|
||||||
|
|
||||||
|
circle.Radius = 40;
|
||||||
|
|
||||||
|
SendMessageToAllProcesses(new TestMessage { SenderProcessId = Id });
|
||||||
|
}
|
||||||
|
|
||||||
|
internal override void Tick()
|
||||||
|
{
|
||||||
|
// Example tick logic - could be used for animations, timed events, etc.
|
||||||
|
}
|
||||||
|
|
||||||
|
internal override void HandleInterProcessMessage(Message message)
|
||||||
|
{
|
||||||
|
if (message is TestMessage testMessage && message.SenderProcessId != Id)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Received message in {Name} (ID: {Id}): {testMessage.MessageText}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal class TestMessage : Message
|
||||||
|
{
|
||||||
|
public string MessageText { get; set; } = "Hello from TestMessage!";
|
||||||
|
}
|
||||||
@@ -1,17 +1,34 @@
|
|||||||
|
using RemSox.Processes;
|
||||||
using RemSox.Processing;
|
using RemSox.Processing;
|
||||||
|
|
||||||
namespace RemSox.UI.CLI.Commands;
|
namespace RemSox.UI.CLI.Commands;
|
||||||
|
|
||||||
public sealed class SpawnTestProcessCommand : ICommand
|
public sealed class SpawnProcessCommand : ICommand
|
||||||
{
|
{
|
||||||
public string Name => "spawn test";
|
public string Name => "spawn";
|
||||||
|
|
||||||
public string Description => "Spawn the test process";
|
public string Description => "Spawn a new process";
|
||||||
|
|
||||||
public void Execute(string? arguments, Action<string> printLine)
|
public void Execute(string? arguments, Action<string> printLine)
|
||||||
{
|
{
|
||||||
int processId = ProcessManager.SpawnProcess<TestProcess>();
|
arguments = arguments?.Trim();
|
||||||
printLine($"Spawned TestProcess with ID {processId}");
|
|
||||||
|
int? processId = arguments switch
|
||||||
|
{
|
||||||
|
"test" => ProcessManager.SpawnProcess<TestProcess>(),
|
||||||
|
"terminal" => ProcessManager.SpawnProcess<TerminalProcess>(),
|
||||||
|
_ => null
|
||||||
|
};
|
||||||
|
|
||||||
|
if (processId is not null)
|
||||||
|
{
|
||||||
|
printLine($"Spawned process with ID {processId}");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printLine("Usage: spawn <process-name>");
|
||||||
|
printLine("Available processes: test, terminal");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,10 +27,10 @@ public sealed class Window(string title, int processId, int id, IRenderSource re
|
|||||||
public bool AutoFlush { get; set; } = false;
|
public bool AutoFlush { get; set; } = false;
|
||||||
|
|
||||||
/// <summary> Event raised when a keyboard event is handled by this window. </summary>
|
/// <summary> Event raised when a keyboard event is handled by this window. </summary>
|
||||||
public event Action<Cosmos.Kernel.System.Keyboard.KeyEvent>? OnKeyEvent;
|
public event Action<Sys.Keyboard.KeyEvent>? OnKeyEvent;
|
||||||
|
|
||||||
/// <summary> Dispatches a key event to the window's registered event handlers. </summary>
|
/// <summary> Dispatches a key event to the window's registered event handlers. </summary>
|
||||||
public void HandleKeyEvent(Cosmos.Kernel.System.Keyboard.KeyEvent keyEvent)
|
public void HandleKeyEvent(Sys.Keyboard.KeyEvent keyEvent)
|
||||||
{
|
{
|
||||||
OnKeyEvent?.Invoke(keyEvent);
|
OnKeyEvent?.Invoke(keyEvent);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user