From 0b94d353c5e0ea791b04dd5240fe19ecfdd0523b Mon Sep 17 00:00:00 2001 From: xLinka Date: Mon, 6 Nov 2023 11:37:21 +0000 Subject: [PATCH] Cleanup --- .github/workflows/CI.yml | 57 ---------- Components/Networking/ART-NET/ARTNETCLIENT.cs | 104 ------------------ ProtoFlux/Networking/ART-NET/ArtNetConnect.cs | 27 ----- .../ART-NET/ArtNetConnectionEvents.cs | 52 --------- .../ART-NET/ArtNetDataChannelExtractor.cs | 49 --------- ProtoFlux/Networking/ART-NET/ArtNetEvents.cs | 41 ------- .../ART-NET/ArtNetUniverseDataReceiver.cs | 80 -------------- 7 files changed, 410 deletions(-) delete mode 100644 .github/workflows/CI.yml delete mode 100644 Components/Networking/ART-NET/ARTNETCLIENT.cs delete mode 100644 ProtoFlux/Networking/ART-NET/ArtNetConnect.cs delete mode 100644 ProtoFlux/Networking/ART-NET/ArtNetConnectionEvents.cs delete mode 100644 ProtoFlux/Networking/ART-NET/ArtNetDataChannelExtractor.cs delete mode 100644 ProtoFlux/Networking/ART-NET/ArtNetEvents.cs delete mode 100644 ProtoFlux/Networking/ART-NET/ArtNetUniverseDataReceiver.cs diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml deleted file mode 100644 index d7b91a5..0000000 --- a/.github/workflows/CI.yml +++ /dev/null @@ -1,57 +0,0 @@ -name: CI - -on: - push: - branches: [ "main" ] - pull_request: - branches: [ "main" ] - -env: - STEAMCMD_PATH: C:\SteamCMD - GAME_ID: 2519830 - SOLUTION_FILE_PATH: ProjectObsidian.sln - -jobs: - build: - runs-on: windows-latest - - steps: - - uses: actions/checkout@v3 - - # Download and install SteamCMD - - name: Install SteamCMD - run: | - $steamCmdPath = "${{env.STEAMCMD_PATH}}" - New-Item -Type Directory -Path $steamCmdPath -Force - Invoke-WebRequest -Uri "https://steamcdn-a.akamaihd.net/client/installer/steamcmd.zip" -OutFile "$steamCmdPath\steamcmd.zip" - Expand-Archive -Path "$steamCmdPath\steamcmd.zip" -DestinationPath $steamCmdPath -Force - Remove-Item "$steamCmdPath\steamcmd.zip" - - # Download Resonite using SteamCMD - - name: Download Resonite - shell: pwsh - run: | - $steamCmdPath = "${{env.STEAMCMD_PATH}}" - $gameId = "${{env.GAME_ID}}" - - cd $steamCmdPath - .\steamcmd.exe +@sSteamCmdForcePlatformType windows +force_install_dir "$steamCmdPath\Resonite" +login anonymous +app_update $gameId validate +quit - - # Extract the Resonite files - - name: Extract Resonite - shell: pwsh - run: | - $resoniteInstallPath = "C:\Resonite" - $steamCmdPath = "${{env.STEAMCMD_PATH}}" - - New-Item -Type Directory -Path $resoniteInstallPath -Force - cd $resoniteInstallPath - - $resoniteGamePath = "$steamCmdPath\Resonite\steamapps\common\Resonite" - - Copy-Item -Path $resoniteGamePath\* -Destination $resoniteInstallPath -Recurse - - # Build the Visual Studio solution - - name: Build Solution - working-directory: ${{env.GITHUB_WORKSPACE}} - run: msbuild /m /p:Configuration=Release ${{env.SOLUTION_FILE_PATH}} diff --git a/Components/Networking/ART-NET/ARTNETCLIENT.cs b/Components/Networking/ART-NET/ARTNETCLIENT.cs deleted file mode 100644 index dd261a3..0000000 --- a/Components/Networking/ART-NET/ARTNETCLIENT.cs +++ /dev/null @@ -1,104 +0,0 @@ -using System; -using System.Net; -using System.Net.Sockets; -using System.Threading.Tasks; -using Elements.Core; -using FrooxEngine; - -[Category("Obsidian/Network")] -public class ArtNetClient : Component -{ - public readonly Sync URL; - public readonly UserRef HandlingUser; - public readonly Sync AccessReason; - public readonly Sync ConnectRetryInterval; - public readonly Sync IsConnected; - - private Uri _currentURL; - private UdpClient _udpClient; - - public event Action Connected; - public event Action Closed; - public event Action Error; - public event Action PacketReceived; - - protected override void OnAwake() - { - base.OnAwake(); - ConnectRetryInterval.Value = 10f; - } - - protected override void OnChanges() - { - Uri uri = (Enabled ? URL.Value : null); - if (HandlingUser.Target != LocalUser) - { - uri = null; - } - if (uri != _currentURL) - { - _currentURL = uri; - CloseCurrent(); - IsConnected.Value = false; - if (_currentURL != null) - { - StartTask(async () => - { - await ConnectTo(_currentURL); - }); - } - } - } - - private async Task ConnectTo(Uri target) - { - if (target.Scheme != "artnet") - { - throw new ArgumentException("Invalid URL scheme. Expected 'artnet://'."); - } - - if (await Engine.Security.RequestAccessPermission(target.Host, target.Port, AccessReason.Value ?? "Art-Net Receiver") == HostAccessPermission.Allowed && target == _currentURL && !IsRemoved) - { - _udpClient = new UdpClient(target.Port); - IsConnected.Value = true; - Connected?.Invoke(this); - StartTask(ReceiveLoop); - } - } - - private async Task ReceiveLoop() - { - IPEndPoint remoteEndPoint = new IPEndPoint(IPAddress.Any, 0); - while (IsConnected.Value) - { - UdpReceiveResult result = await _udpClient.ReceiveAsync(); - byte[] receivedData = result.Buffer; - - PacketReceived?.Invoke(this, receivedData); - } - } - - protected override void OnDispose() - { - CloseCurrent(); - base.OnDispose(); - } - - private void CloseCurrent() - { - if (_udpClient != null) - { - UdpClient udpClient = _udpClient; - _udpClient = null; - try - { - Closed?.Invoke(this); - } - catch (Exception ex) - { - UniLog.Error($"Exception in running Closed event on ArtNetReceiver:\n{ex}"); - } - udpClient.Close(); - } - } -} diff --git a/ProtoFlux/Networking/ART-NET/ArtNetConnect.cs b/ProtoFlux/Networking/ART-NET/ArtNetConnect.cs deleted file mode 100644 index 412a6d1..0000000 --- a/ProtoFlux/Networking/ART-NET/ArtNetConnect.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System; -using FrooxEngine; -using FrooxEngine.ProtoFlux; -using ProtoFlux.Core; - -namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Networking.ArtNet -{ - [NodeCategory("Obsidian/Network/ArtNet")] - public class ArtNetConnectNode : ActionBreakableFlowNode - { - public ObjectInput Client; - public ObjectInput URL; - public ObjectInput HandlingUser; - - protected override bool Do(FrooxEngineContext context) - { - var artNetClient = Client.Evaluate(context); - if (artNetClient == null) - return false; - var uri = URL.Evaluate(context); - if (uri != null) artNetClient.URL.Value = uri; - artNetClient.HandlingUser.Target = HandlingUser.Evaluate(context, context.LocalUser); - return true; - } - } -} - diff --git a/ProtoFlux/Networking/ART-NET/ArtNetConnectionEvents.cs b/ProtoFlux/Networking/ART-NET/ArtNetConnectionEvents.cs deleted file mode 100644 index 70da9d3..0000000 --- a/ProtoFlux/Networking/ART-NET/ArtNetConnectionEvents.cs +++ /dev/null @@ -1,52 +0,0 @@ -using System; -using FrooxEngine.ProtoFlux; -using ProtoFlux.Core; - -namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Networking.ArtNet -{ - [NodeCategory("Obsidian/Network/ArtNet")] - public class ArtNetConnectionEvents : ArtNetEvents - { - public Call OnConnected; - public Call OnDisconnected; - - private ObjectStore> _connected; - private ObjectStore> _disconnected; - - protected override void Register(ArtNetClient client, NodeContextPath path, ExecutionEventDispatcher dispatcher, FrooxEngineContext context) - { - void Value(ArtNetClient obj) => dispatcher.ScheduleEvent(path, Connected); - - void Value2(ArtNetClient obj) => dispatcher.ScheduleEvent(path, Disconnected); - - client.Connected += Value; - client.Closed += Value2; - _connected.Write(Value, context); - _disconnected.Write(Value2, context); - } - - protected override void Unregister(ArtNetClient client, FrooxEngineContext context) - { - client.Connected -= _connected.Read(context); - client.Closed -= _disconnected.Read(context); - } - - protected override void Clear(FrooxEngineContext context) - { - _connected.Clear(context); - _disconnected.Clear(context); - } - - private void Connected(FrooxEngineContext context) - { - OnConnected.Execute(context); - } - - private void Disconnected(FrooxEngineContext context) - { - OnDisconnected.Execute(context); - } - } - - -} diff --git a/ProtoFlux/Networking/ART-NET/ArtNetDataChannelExtractor.cs b/ProtoFlux/Networking/ART-NET/ArtNetDataChannelExtractor.cs deleted file mode 100644 index ea5fe5d..0000000 --- a/ProtoFlux/Networking/ART-NET/ArtNetDataChannelExtractor.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System; -using FrooxEngine.ProtoFlux; -using ProtoFlux.Core; - -namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Networking.ArtNet -{ - [NodeCategory("Network/ART-NET")] - public class ArtNetDataChannelExtractor : ArtNetEvents - { - public readonly ObjectInput Data; - public readonly ObjectInput Channel; - public readonly ObjectInput StartIndex; - - public readonly Call OnEvaluationComplete; - - private ObjectStore> _handler; - - private NodeEventHandler _callback; - - public override bool CanBeEvaluated => false; - - protected override void Register(ArtNetClient client, NodeContextPath path, ExecutionEventDispatcher dispatcher, FrooxEngineContext context) - { - _callback ??= Receive; - - void Value(ArtNetClient c, byte[] d) => dispatcher.ScheduleEvent(path, _callback, d); - - client.PacketReceived += Value; - _handler.Write(Value, context); - } - - protected override void Unregister(ArtNetClient client, FrooxEngineContext context) => client.PacketReceived -= _handler.Read(context); - - protected override void Clear(FrooxEngineContext context) => _handler.Clear(context); - - private void Receive(FrooxEngineContext context, object data) - { - var receivedData = data as byte[]; - var channel = Channel.Evaluate(context); - var startIndex = StartIndex.Evaluate(context); - - if (receivedData == null || receivedData.Length <= startIndex + channel - 1) return; - var extractedValue = receivedData[startIndex + channel - 1]; - - // Triggering the OnEvaluationComplete call with the extracted value - OnEvaluationComplete.Execute(context); - } - } -} \ No newline at end of file diff --git a/ProtoFlux/Networking/ART-NET/ArtNetEvents.cs b/ProtoFlux/Networking/ART-NET/ArtNetEvents.cs deleted file mode 100644 index d2519be..0000000 --- a/ProtoFlux/Networking/ART-NET/ArtNetEvents.cs +++ /dev/null @@ -1,41 +0,0 @@ -using FrooxEngine.ProtoFlux; -using ProtoFlux.Core; -using ProtoFlux.Runtimes.Execution; - -[NodeCategory("Obsidian/Network/ArtNet")] -public abstract class ArtNetEvents : VoidNode -{ - public readonly GlobalRef Client; - - private ObjectStore _current; - - private void OnClientChanged(ArtNetClient client, FrooxEngineContext context) - { - var artNetClient = _current.Read(context); - if (client == artNetClient) return; - if (artNetClient != null) - { - Unregister(artNetClient, context); - } - if (client != null) - { - var path = context.CaptureContextPath(); - context.GetEventDispatcher(out var eventDispatcher); - Register(client, path, eventDispatcher, context); - _current.Write(client, context); - } - else - { - _current.Clear(context); - Clear(context); - } - } - - protected abstract void Register(ArtNetClient client, NodeContextPath path, ExecutionEventDispatcher dispatcher, FrooxEngineContext context); - - protected abstract void Unregister(ArtNetClient client, FrooxEngineContext context); - - protected abstract void Clear(FrooxEngineContext context); - - protected ArtNetEvents() => Client = new GlobalRef(this, 0); -} diff --git a/ProtoFlux/Networking/ART-NET/ArtNetUniverseDataReceiver.cs b/ProtoFlux/Networking/ART-NET/ArtNetUniverseDataReceiver.cs deleted file mode 100644 index ee33b7a..0000000 --- a/ProtoFlux/Networking/ART-NET/ArtNetUniverseDataReceiver.cs +++ /dev/null @@ -1,80 +0,0 @@ -using System; -using System.Text; -using FrooxEngine.ProtoFlux; -using ProtoFlux.Core; -using ProtoFlux.Runtimes.Execution; - -[NodeCategory("Network/ART-NET")] -public class ArtNetUniverseDataReceiver : ArtNetEvents -{ - public readonly ObjectInput UniverseID; - public readonly Call Received; - public readonly ObjectOutput Data; - - private ObjectStore> _handler; - private NodeEventHandler _callback; - - public override bool CanBeEvaluated => false; - - protected override void Register(ArtNetClient client, NodeContextPath path, ExecutionEventDispatcher dispatcher, FrooxEngineContext context) - { - _callback ??= Receive; - - void Value(ArtNetClient c, byte[] d) => dispatcher.ScheduleEvent(path, _callback, d); - - client.PacketReceived += Value; - _handler.Write(Value, context); - } - - protected override void Unregister(ArtNetClient client, FrooxEngineContext context) => client.PacketReceived -= _handler.Read(context); - - protected override void Clear(FrooxEngineContext context) => _handler.Clear(context); - - private void Receive(FrooxEngineContext context, object data) - { - var receivedData = data as byte[]; - var universeId = UniverseID.Evaluate(context); - - if (IsValidArtNetPacket(receivedData)) - { - var receivedUniverseId = ParseUniverseID(receivedData); - - if (receivedUniverseId != universeId) return; - var dmxData = ExtractDMXData(receivedData); - Data.Write(dmxData, context); - Received.Execute(context); - } - else if (IsValidDMXPacket(receivedData)) - { - var dmxData = ExtractDMXData(receivedData); - Data.Write(dmxData, context); - Received.Execute(context); - } - } - - private bool IsValidArtNetPacket(byte[] data) => data.Length >= 8 && Encoding.ASCII.GetString(data, 0, 7) == "Art-Net"; - - private bool IsValidDMXPacket(byte[] data) => data.Length >= 1 && data[0] == 0; - - private int ParseUniverseID(byte[] data) - { - const int universeIdOffsetLowByte = 14; - const int universeIdOffsetHighByte = 15; - - var universeId = (data[universeIdOffsetHighByte] << 8) | data[universeIdOffsetLowByte]; - - return universeId; - } - - private byte[] ExtractDMXData(byte[] data) - { - const int dmxDataOffset = 18; - const int dmxDataLength = 512; // fixed size of DMX data - - var dmxData = new byte[dmxDataLength]; - Array.Copy(data, dmxDataOffset, dmxData, 0, dmxDataLength); - - return dmxData; - } - -}