From e606dfee951020c8bd52683f666819d115368730 Mon Sep 17 00:00:00 2001 From: Alessandro Proto Date: Fri, 17 Feb 2023 19:22:24 +0100 Subject: [PATCH] Cleanup --- Capy64/Capy64.cs | 8 ++++---- Capy64/Core/Audio.cs | 8 ++++---- Capy64/Core/SDL.cs | 5 ----- Capy64/Eventing/EventEmitter.cs | 3 ++- Capy64/Eventing/Events/GamePadThumbstickEvent.cs | 1 - Capy64/Eventing/Events/GamePadTriggerEvent.cs | 1 - Capy64/Eventing/Events/OverlayEvent.cs | 1 - Capy64/Eventing/InputManager.cs | 4 ++-- Capy64/Extensions/Bindings/Common.cs | 4 ---- Capy64/IGame.cs | 1 - Capy64/Integrations/DiscordIntegration.cs | 5 ----- Capy64/Program.cs | 2 +- Capy64/Runtime/EventEmitter.cs | 8 ++++---- Capy64/Runtime/Libraries/Audio.cs | 1 - Capy64/Runtime/Libraries/Event.cs | 4 ---- Capy64/Runtime/Libraries/FileSystem.cs | 5 ++--- Capy64/Runtime/Libraries/GPU.cs | 2 +- Capy64/Runtime/Libraries/Machine.cs | 4 ---- Capy64/Runtime/Libraries/Term.cs | 13 +++++-------- Capy64/Runtime/Libraries/Timer.cs | 1 - Capy64/Runtime/LuaEvent.cs | 4 ---- Capy64/Runtime/ObjectManager.cs | 5 ----- Capy64/Runtime/Objects/FileHandle.cs | 11 ++++------- Capy64/Runtime/Objects/GPUBuffer.cs | 11 +++++------ Capy64/Runtime/PanicScreen.cs | 6 ------ Capy64/Runtime/RuntimeManager.cs | 6 ------ Capy64/Utils.cs | 2 +- 27 files changed, 35 insertions(+), 91 deletions(-) diff --git a/Capy64/Capy64.cs b/Capy64/Capy64.cs index 4b82760..6a26dcf 100644 --- a/Capy64/Capy64.cs +++ b/Capy64/Capy64.cs @@ -17,8 +17,9 @@ using Capy64.API; using Capy64.Core; using Capy64.Eventing; using Capy64.Extensions; -using Capy64.Runtime; +using Capy64.Integrations; using Capy64.PluginManager; +using Capy64.Runtime; using Microsoft.Extensions.DependencyInjection; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; @@ -27,7 +28,6 @@ using System.Collections.Generic; using System.IO; using System.Linq; using static Capy64.Utils; -using Capy64.Integrations; namespace Capy64; @@ -121,8 +121,8 @@ public class Capy64 : Game, IGame if (Window.IsMaximized()) { - var vertical = bounds.Height - Height * Scale; - var horizontal = bounds.Width - Width * Scale; + var vertical = bounds.Height - (Height * Scale); + var horizontal = bounds.Width - (Width * Scale); Borders.Top = (int)Math.Floor(vertical / 2d); Borders.Bottom = (int)Math.Ceiling(vertical / 2d); diff --git a/Capy64/Core/Audio.cs b/Capy64/Core/Audio.cs index 71d3467..1fd4bee 100644 --- a/Capy64/Core/Audio.cs +++ b/Capy64/Core/Audio.cs @@ -146,7 +146,7 @@ public class Audio : IDisposable Waveform.Square => GetSquarePoint(frequency, x), Waveform.Triangle => GetTrianglePoint(frequency, x), Waveform.Sawtooth => GetSawtoothPoint(frequency, x), - Waveform.Noise => rng.NextDouble() * 2 - 1, + Waveform.Noise => (rng.NextDouble() * 2) - 1, _ => throw new NotImplementedException(), }; @@ -184,8 +184,8 @@ public class Audio : IDisposable double v = 0; for (int k = 1; k <= 25; k++) { - v += (Math.Pow(-1, k) / Math.Pow(2 * k - 1, 2)) - * Math.Sin(frequency * 2 * Math.PI * (2 * k - 1) * x); + v += Math.Pow(-1, k) / Math.Pow((2 * k) - 1, 2) + * Math.Sin(frequency * 2 * Math.PI * ((2 * k) - 1) * x); } return -(8 / Math.Pow(Math.PI, 2)) * v; } @@ -195,7 +195,7 @@ public class Audio : IDisposable double v = 0; for (int k = 1; k <= 50; k++) { - v += (Math.Pow(-1, k) / k) * Math.Sin(frequency * 2 * Math.PI * k * x); + v += Math.Pow(-1, k) / k * Math.Sin(frequency * 2 * Math.PI * k * x); } return -(2 / Math.PI) * v; } diff --git a/Capy64/Core/SDL.cs b/Capy64/Core/SDL.cs index f7c73b2..a2a4423 100644 --- a/Capy64/Core/SDL.cs +++ b/Capy64/Core/SDL.cs @@ -14,11 +14,6 @@ // limitations under the License. using Capy64.Extensions.Bindings; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Capy64.Core; diff --git a/Capy64/Eventing/EventEmitter.cs b/Capy64/Eventing/EventEmitter.cs index 5a02e4d..8e10917 100644 --- a/Capy64/Eventing/EventEmitter.cs +++ b/Capy64/Eventing/EventEmitter.cs @@ -163,7 +163,8 @@ public class EventEmitter public void RaiseOverlay(OverlayEvent ev) { - if(OnOverlay is not null) { + if (OnOverlay is not null) + { OnOverlay(this, ev); } } diff --git a/Capy64/Eventing/Events/GamePadThumbstickEvent.cs b/Capy64/Eventing/Events/GamePadThumbstickEvent.cs index d2525a5..34beda8 100644 --- a/Capy64/Eventing/Events/GamePadThumbstickEvent.cs +++ b/Capy64/Eventing/Events/GamePadThumbstickEvent.cs @@ -14,7 +14,6 @@ // limitations under the License. using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Input; using System; namespace Capy64.Eventing.Events; diff --git a/Capy64/Eventing/Events/GamePadTriggerEvent.cs b/Capy64/Eventing/Events/GamePadTriggerEvent.cs index ad98982..152e4b0 100644 --- a/Capy64/Eventing/Events/GamePadTriggerEvent.cs +++ b/Capy64/Eventing/Events/GamePadTriggerEvent.cs @@ -13,7 +13,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -using Microsoft.Xna.Framework.Input; using System; namespace Capy64.Eventing.Events; diff --git a/Capy64/Eventing/Events/OverlayEvent.cs b/Capy64/Eventing/Events/OverlayEvent.cs index 66c7e1e..a0d026c 100644 --- a/Capy64/Eventing/Events/OverlayEvent.cs +++ b/Capy64/Eventing/Events/OverlayEvent.cs @@ -14,7 +14,6 @@ // limitations under the License. using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; using System; namespace Capy64.Eventing.Events; diff --git a/Capy64/Eventing/InputManager.cs b/Capy64/Eventing/InputManager.cs index 903d112..11c2afc 100644 --- a/Capy64/Eventing/InputManager.cs +++ b/Capy64/Eventing/InputManager.cs @@ -423,7 +423,7 @@ public class InputManager // D-PAD var od = oldGamePadState.DPad; var d = state.DPad; - + if (od.Left != d.Left) { _eventEmitter.RaiseGamePadButton(new() @@ -466,7 +466,7 @@ public class InputManager if (ot.Left != t.Left) { - + _eventEmitter.RaiseGamePadTrigger(new() { Trigger = 1, // left diff --git a/Capy64/Extensions/Bindings/Common.cs b/Capy64/Extensions/Bindings/Common.cs index 3221690..7a26a5c 100644 --- a/Capy64/Extensions/Bindings/Common.cs +++ b/Capy64/Extensions/Bindings/Common.cs @@ -14,11 +14,7 @@ // limitations under the License. using System; -using System.Collections.Generic; -using System.Linq; using System.Runtime.InteropServices; -using System.Text; -using System.Threading.Tasks; namespace Capy64.Extensions.Bindings; diff --git a/Capy64/IGame.cs b/Capy64/IGame.cs index adf2fc6..9a63019 100644 --- a/Capy64/IGame.cs +++ b/Capy64/IGame.cs @@ -15,7 +15,6 @@ using Capy64.API; using Capy64.Core; -using Capy64.Eventing; using Capy64.Integrations; using Capy64.Runtime; using Microsoft.Xna.Framework; diff --git a/Capy64/Integrations/DiscordIntegration.cs b/Capy64/Integrations/DiscordIntegration.cs index b8e205d..1afcc86 100644 --- a/Capy64/Integrations/DiscordIntegration.cs +++ b/Capy64/Integrations/DiscordIntegration.cs @@ -18,12 +18,7 @@ using DiscordRPC; using DiscordRPC.Logging; using DiscordRPC.Message; using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Logging; using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Capy64.Integrations; diff --git a/Capy64/Program.cs b/Capy64/Program.cs index d3935f6..6b78a4f 100644 --- a/Capy64/Program.cs +++ b/Capy64/Program.cs @@ -24,7 +24,7 @@ using IHost host = Host.CreateDefaultBuilder(args) .ConfigureAppConfiguration((context, c) => { var settingsPath = Path.Combine(Capy64.Capy64.AppDataPath, "settings.json"); - if(!Directory.Exists(Capy64.Capy64.AppDataPath)) + if (!Directory.Exists(Capy64.Capy64.AppDataPath)) { Directory.CreateDirectory(Capy64.Capy64.AppDataPath); } diff --git a/Capy64/Runtime/EventEmitter.cs b/Capy64/Runtime/EventEmitter.cs index 804ec04..c171a72 100644 --- a/Capy64/Runtime/EventEmitter.cs +++ b/Capy64/Runtime/EventEmitter.cs @@ -15,12 +15,10 @@ using Capy64.Core; using Capy64.Eventing.Events; -using Capy64.Eventing; using Microsoft.Xna.Framework.Input; using System; using System.Linq; using static Capy64.Eventing.InputManager; -using Capy64.Runtime.Extensions; namespace Capy64.Runtime; @@ -187,7 +185,8 @@ internal class EventEmitter if (SDL.HasClipboardText()) { var text = SDL.GetClipboardText(); - _runtime.QueueEvent("paste", LK => { + _runtime.QueueEvent("paste", LK => + { LK.PushString(text); return 1; @@ -199,7 +198,8 @@ internal class EventEmitter private void OnChar(object sender, CharEvent e) { - _runtime.QueueEvent("char", LK => { + _runtime.QueueEvent("char", LK => + { LK.PushString(e.Character.ToString()); return 1; diff --git a/Capy64/Runtime/Libraries/Audio.cs b/Capy64/Runtime/Libraries/Audio.cs index 90696ee..b09ac74 100644 --- a/Capy64/Runtime/Libraries/Audio.cs +++ b/Capy64/Runtime/Libraries/Audio.cs @@ -17,7 +17,6 @@ using Capy64.API; using KeraLua; using Microsoft.Xna.Framework.Audio; using System; -using System.Threading.Tasks; using static Capy64.Core.Audio; namespace Capy64.Runtime.Libraries; diff --git a/Capy64/Runtime/Libraries/Event.cs b/Capy64/Runtime/Libraries/Event.cs index 9338210..02f3514 100644 --- a/Capy64/Runtime/Libraries/Event.cs +++ b/Capy64/Runtime/Libraries/Event.cs @@ -16,10 +16,6 @@ using Capy64.API; using KeraLua; using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Capy64.Runtime.Libraries; diff --git a/Capy64/Runtime/Libraries/FileSystem.cs b/Capy64/Runtime/Libraries/FileSystem.cs index 15465d9..e70f38b 100644 --- a/Capy64/Runtime/Libraries/FileSystem.cs +++ b/Capy64/Runtime/Libraries/FileSystem.cs @@ -15,13 +15,12 @@ using Capy64.API; using Capy64.Runtime.Extensions; +using Capy64.Runtime.Objects; using KeraLua; using System; using System.Collections.Generic; using System.IO; using System.Linq; -using System.Text; -using Capy64.Runtime.Objects; namespace Capy64.Runtime.Libraries; @@ -430,7 +429,7 @@ public class FileSystem : IComponent var attr = File.GetAttributes(path); if (attr.HasFlag(FileAttributes.Directory)) { - if(!recursive && Directory.GetFileSystemEntries(path).Any()) + if (!recursive && Directory.GetFileSystemEntries(path).Any()) { L.Error("directory not empty"); return 0; diff --git a/Capy64/Runtime/Libraries/GPU.cs b/Capy64/Runtime/Libraries/GPU.cs index 571caf6..d479b79 100644 --- a/Capy64/Runtime/Libraries/GPU.cs +++ b/Capy64/Runtime/Libraries/GPU.cs @@ -456,7 +456,7 @@ public class GPU : IComponent var w = (int)L.CheckInteger(4); var h = (int)L.CheckInteger(5); - if(w * h != buffer.Length) + if (w * h != buffer.Length) { L.Error("width and height do not match buffer size"); } diff --git a/Capy64/Runtime/Libraries/Machine.cs b/Capy64/Runtime/Libraries/Machine.cs index 7544720..06e2e33 100644 --- a/Capy64/Runtime/Libraries/Machine.cs +++ b/Capy64/Runtime/Libraries/Machine.cs @@ -18,10 +18,6 @@ using KeraLua; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Input; using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Capy64.Runtime.Libraries; diff --git a/Capy64/Runtime/Libraries/Term.cs b/Capy64/Runtime/Libraries/Term.cs index 8363fc7..19638ea 100644 --- a/Capy64/Runtime/Libraries/Term.cs +++ b/Capy64/Runtime/Libraries/Term.cs @@ -18,11 +18,8 @@ using Capy64.Eventing.Events; using KeraLua; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; -using MonoGame.Extended; -using Newtonsoft.Json.Linq; using System; using static Capy64.Utils; -using static System.Formats.Asn1.AsnWriter; namespace Capy64.Runtime.Libraries; @@ -292,7 +289,7 @@ internal class Term : IComponent if (cursorState) { var realpos = ToRealPos(CursorPosition - Vector2.One); - var charpos = realpos * _game.Scale + CharOffset; + var charpos = (realpos * _game.Scale) + CharOffset; _game.Game.SpriteBatch.Draw(cursorTexture, charpos, null, ForegroundColor, 0f, Vector2.Zero, _game.Scale, SpriteEffects.None, 0); } } @@ -623,15 +620,15 @@ internal class Term : IComponent // RGB to ABGR fgv = - (fgv & 0x00_FF_00_00U) >> 16 | // move R + ((fgv & 0x00_FF_00_00U) >> 16) | // move R (fgv & 0x00_00_FF_00U) | // move G - (fgv & 0x00_00_00_FFU) << 16 | // move B + ((fgv & 0x00_00_00_FFU) << 16) | // move B 0xFF_00_00_00U; bgv = - (bgv & 0x00_FF_00_00U) >> 16 | // move R + ((bgv & 0x00_FF_00_00U) >> 16) | // move R (bgv & 0x00_00_FF_00U) | // move G - (bgv & 0x00_00_00_FFU) << 16 | // move B + ((bgv & 0x00_00_00_FFU) << 16) | // move B 0xFF_00_00_00U; diff --git a/Capy64/Runtime/Libraries/Timer.cs b/Capy64/Runtime/Libraries/Timer.cs index dbdb3ad..a687d93 100644 --- a/Capy64/Runtime/Libraries/Timer.cs +++ b/Capy64/Runtime/Libraries/Timer.cs @@ -17,7 +17,6 @@ using Capy64.API; using KeraLua; using System; using System.Collections.Concurrent; -using System.Collections.Generic; namespace Capy64.Runtime.Libraries; diff --git a/Capy64/Runtime/LuaEvent.cs b/Capy64/Runtime/LuaEvent.cs index a44c60a..873db83 100644 --- a/Capy64/Runtime/LuaEvent.cs +++ b/Capy64/Runtime/LuaEvent.cs @@ -15,10 +15,6 @@ using KeraLua; using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Capy64.Runtime; diff --git a/Capy64/Runtime/ObjectManager.cs b/Capy64/Runtime/ObjectManager.cs index b228e81..7b708b8 100644 --- a/Capy64/Runtime/ObjectManager.cs +++ b/Capy64/Runtime/ObjectManager.cs @@ -18,11 +18,6 @@ using KeraLua; using System; using System.Collections.Concurrent; using System.Collections.Generic; -using System.Linq; -using System.Reflection; -using System.Runtime.InteropServices; -using System.Text; -using System.Threading.Tasks; namespace Capy64.Runtime; diff --git a/Capy64/Runtime/Objects/FileHandle.cs b/Capy64/Runtime/Objects/FileHandle.cs index e13d99f..f5b3de0 100644 --- a/Capy64/Runtime/Objects/FileHandle.cs +++ b/Capy64/Runtime/Objects/FileHandle.cs @@ -16,11 +16,7 @@ using Capy64.API; using KeraLua; using System; -using System.Collections.Generic; using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Capy64.Runtime.Objects; @@ -107,12 +103,13 @@ public class FileHandle : IComponent { var modes = "nlLa"; mode = mode.TrimStart('*'); - if(string.IsNullOrEmpty(mode)) { + if (string.IsNullOrEmpty(mode)) + { return '\0'; } var i = modes.IndexOf(mode[0]); - if(i == -1) + if (i == -1) return '\0'; return modes[i]; @@ -274,7 +271,7 @@ public class FileHandle : IComponent var n = L.GetTop() - 1; var stream = CheckStream(L, false); L.ArgumentCheck(n <= maxargn, maxargn + 2, "too many arguments"); - L.PushCopy(1); + L.PushCopy(1); L.PushInteger(n); L.PushBoolean(false); L.Rotate(2, 3); diff --git a/Capy64/Runtime/Objects/GPUBuffer.cs b/Capy64/Runtime/Objects/GPUBuffer.cs index a8790b9..7b5540f 100644 --- a/Capy64/Runtime/Objects/GPUBuffer.cs +++ b/Capy64/Runtime/Objects/GPUBuffer.cs @@ -16,7 +16,6 @@ using Capy64.API; using KeraLua; using System; -using System.IO; namespace Capy64.Runtime.Objects; @@ -111,9 +110,9 @@ public class GPUBuffer : IComponent // ABGR to RGB value = - (value & 0x00_00_00_FFU) << 16 | // move R + ((value & 0x00_00_00_FFU) << 16) | // move R (value & 0x00_00_FF_00U) | // move G - (value & 0x00_FF_00_00U) >> 16; // move B + ((value & 0x00_FF_00_00U) >> 16); // move B L.PushInteger(value); @@ -146,11 +145,11 @@ public class GPUBuffer : IComponent // RGB to ABGR value = - (value & 0x00_FF_00_00U) >> 16 | // move R + ((value & 0x00_FF_00_00U) >> 16) | // move R (value & 0x00_00_FF_00U) | // move G - (value & 0x00_00_00_FFU) << 16 | // move B + ((value & 0x00_00_00_FFU) << 16) | // move B 0xFF_00_00_00U; - + buffer[key] = value; diff --git a/Capy64/Runtime/PanicScreen.cs b/Capy64/Runtime/PanicScreen.cs index 572051d..ff146c4 100644 --- a/Capy64/Runtime/PanicScreen.cs +++ b/Capy64/Runtime/PanicScreen.cs @@ -13,14 +13,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -using Capy64.Core; using Capy64.Runtime.Libraries; using Microsoft.Xna.Framework; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Capy64.Runtime; diff --git a/Capy64/Runtime/RuntimeManager.cs b/Capy64/Runtime/RuntimeManager.cs index 8df435f..54cfca9 100644 --- a/Capy64/Runtime/RuntimeManager.cs +++ b/Capy64/Runtime/RuntimeManager.cs @@ -19,14 +19,8 @@ using Capy64.Extensions; using Capy64.Runtime.Libraries; using KeraLua; using System; -using System.Collections.Generic; using System.Diagnostics; -using System.Diagnostics.Tracing; using System.IO; -using System.Linq; -using System.Text; -using System.Threading; -using System.Threading.Tasks; namespace Capy64.Runtime; diff --git a/Capy64/Utils.cs b/Capy64/Utils.cs index c6faae7..d011545 100644 --- a/Capy64/Utils.cs +++ b/Capy64/Utils.cs @@ -33,7 +33,7 @@ public static class Utils return (color.R << 16) + (color.G << 8) + - (color.B); + color.B; } public static void UnpackRGB(uint packed, out byte r, out byte g, out byte b)