diff --git a/Capy64/Capy64.cs b/Capy64/Capy64.cs index 4b890ac..bb1387d 100644 --- a/Capy64/Capy64.cs +++ b/Capy64/Capy64.cs @@ -43,7 +43,7 @@ public enum EngineMode public class Capy64 : Game, IGame { - public const string Version = "0.0.10-alpha"; + public const string Version = "1.0.0-beta"; public static class DefaultParameters { @@ -51,7 +51,7 @@ public class Capy64 : Game, IGame public const int Height = 240; public const float Scale = 2f; public const float BorderMultiplier = 1.5f; - public readonly static EngineMode EngineMode = EngineMode.Classic; + public static readonly EngineMode EngineMode = EngineMode.Classic; public const int ClassicTickrate = 20; public const int FreeTickrate = 60; diff --git a/Capy64/Capy64.csproj b/Capy64/Capy64.csproj index e012d5b..b568af1 100644 --- a/Capy64/Capy64.csproj +++ b/Capy64/Capy64.csproj @@ -1,6 +1,6 @@  - WinExe + Exe net7.0 Major false diff --git a/Capy64/Core/Audio.cs b/Capy64/Core/Audio.cs index 1ccdf00..a2c0202 100644 --- a/Capy64/Core/Audio.cs +++ b/Capy64/Core/Audio.cs @@ -34,7 +34,7 @@ public class Audio : IDisposable public const AudioChannels AudioChannel = AudioChannels.Mono; public const int ChannelsCount = 8; public readonly DynamicSoundEffectInstance[] Channels = new DynamicSoundEffectInstance[ChannelsCount]; - private bool[] freeChannels = new bool[ChannelsCount]; + private readonly bool[] freeChannels = new bool[ChannelsCount]; public readonly DynamicSoundEffectInstance HQChannel = new(HQSampleRate, AudioChannel); diff --git a/Capy64/Core/Drawing.cs b/Capy64/Core/Drawing.cs index c331993..a651bf2 100644 --- a/Capy64/Core/Drawing.cs +++ b/Capy64/Core/Drawing.cs @@ -31,7 +31,7 @@ public class Drawing : IDisposable private Texture2D _whitePixel; private RenderTarget2D _canvas; private bool _isDrawing; - private HashSet _disposeTextures = new(); + private readonly HashSet _disposeTextures = new(); public RenderTarget2D Canvas { get => _canvas; diff --git a/Capy64/Eventing/InputManager.cs b/Capy64/Eventing/InputManager.cs index 57f26e8..04b8325 100644 --- a/Capy64/Eventing/InputManager.cs +++ b/Capy64/Eventing/InputManager.cs @@ -52,7 +52,7 @@ public class InputManager Ctrl = LCtrl | RCtrl, } - private static Keys[] IgnoredTextInputKeys = + private static readonly Keys[] IgnoredTextInputKeys = { Keys.Enter, Keys.Back, @@ -74,7 +74,7 @@ public class InputManager }; public Texture2D Texture { get; set; } - public float WindowScale => Capy64.Instance.Scale; + public static float WindowScale => Capy64.Instance.Scale; public const int MouseScrollDelta = 120; private Point mousePosition; @@ -82,7 +82,7 @@ public class InputManager private int hMouseScroll; private Modifiers keyboardMods = 0; - private HashSet pressedKeys = new(); + private readonly HashSet pressedKeys = new(); private readonly Game _game; private readonly EventEmitter _eventEmitter; diff --git a/Capy64/Extensions/Bindings/SDL2.cs b/Capy64/Extensions/Bindings/SDL2.cs index 5f1a783..d817c4f 100644 --- a/Capy64/Extensions/Bindings/SDL2.cs +++ b/Capy64/Extensions/Bindings/SDL2.cs @@ -105,7 +105,7 @@ public partial class SDL2 } char* chars = stackalloc char[len]; int strLen = System.Text.Encoding.UTF8.GetChars((byte*)s, len, chars, len); - string result = new string(chars, 0, strLen); + string result = new(chars, 0, strLen); #endif /* Some SDL functions will malloc, we have to free! */ diff --git a/Capy64/Integrations/DiscordIntegration.cs b/Capy64/Integrations/DiscordIntegration.cs index 1afcc86..810fb49 100644 --- a/Capy64/Integrations/DiscordIntegration.cs +++ b/Capy64/Integrations/DiscordIntegration.cs @@ -32,9 +32,10 @@ public class DiscordIntegration : IComponent _configuration = configuration; var discordConfig = _configuration.GetSection("Integrations:Discord"); - Client = new(discordConfig["ApplicationId"]); - - Client.Logger = new ConsoleLogger() { Level = DiscordRPC.Logging.LogLevel.Warning }; + Client = new(discordConfig["ApplicationId"]) + { + Logger = new ConsoleLogger() { Level = LogLevel.Warning } + }; Client.OnReady += OnReady; @@ -46,6 +47,7 @@ public class DiscordIntegration : IComponent } } +#nullable enable public void SetPresence(string details, string? state = null) { Client.SetPresence(new RichPresence() diff --git a/Capy64/PluginManager/PluginLoadContext.cs b/Capy64/PluginManager/PluginLoadContext.cs index 28b444f..2c674ed 100644 --- a/Capy64/PluginManager/PluginLoadContext.cs +++ b/Capy64/PluginManager/PluginLoadContext.cs @@ -21,7 +21,7 @@ namespace Capy64.PluginManager { class PluginLoadContext : AssemblyLoadContext { - private AssemblyDependencyResolver _resolver; + private readonly AssemblyDependencyResolver _resolver; public PluginLoadContext(string pluginPath) { diff --git a/Capy64/Runtime/EventEmitter.cs b/Capy64/Runtime/EventEmitter.cs index 83ca4ca..f60e567 100644 --- a/Capy64/Runtime/EventEmitter.cs +++ b/Capy64/Runtime/EventEmitter.cs @@ -13,7 +13,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -using Capy64.Core; using Capy64.Eventing.Events; using Microsoft.Xna.Framework.Input; using System; @@ -24,8 +23,8 @@ namespace Capy64.Runtime; internal class EventEmitter { - private Eventing.EventEmitter _eventEmitter; - private LuaState _runtime; + private readonly Eventing.EventEmitter _eventEmitter; + private readonly LuaState _runtime; private const int rebootDelay = 30; private int heldReboot = 0; diff --git a/Capy64/Runtime/Libraries/Audio.cs b/Capy64/Runtime/Libraries/Audio.cs index b09ac74..c22ab8d 100644 --- a/Capy64/Runtime/Libraries/Audio.cs +++ b/Capy64/Runtime/Libraries/Audio.cs @@ -32,7 +32,7 @@ public class Audio : IComponent _game.EventEmitter.OnClose += OnClose; } - private static LuaRegister[] AudioLib = new LuaRegister[] + private static readonly LuaRegister[] AudioLib = new LuaRegister[] { new() { diff --git a/Capy64/Runtime/Libraries/Event.cs b/Capy64/Runtime/Libraries/Event.cs index b060329..e1ab522 100644 --- a/Capy64/Runtime/Libraries/Event.cs +++ b/Capy64/Runtime/Libraries/Event.cs @@ -35,7 +35,7 @@ public class Event : IComponent _game = game; } - private static LuaRegister[] EventLib = new LuaRegister[] + private static readonly LuaRegister[] EventLib = new LuaRegister[] { new() { @@ -196,7 +196,7 @@ public class Event : IComponent L.CheckAny(2); L.ArgumentCheck(!L.IsNil(2), 2, "value cannot be nil"); - if(!task.UserTask) + if (!task.UserTask) { L.Error("attempt to fulfill machine task"); } @@ -226,7 +226,7 @@ public class Event : IComponent L.Error("attempt to reject machine task"); } - if(task.Status != TaskMeta.TaskStatus.Running) + if (task.Status != TaskMeta.TaskStatus.Running) { L.Error("attempt to reject a finished task"); } diff --git a/Capy64/Runtime/Libraries/FileSystem.cs b/Capy64/Runtime/Libraries/FileSystem.cs index 97c22a8..8daf2cf 100644 --- a/Capy64/Runtime/Libraries/FileSystem.cs +++ b/Capy64/Runtime/Libraries/FileSystem.cs @@ -37,7 +37,7 @@ public class FileSystem : IComponent } // functions to add to the library, always end libraries with null - private LuaRegister[] FsLib = new LuaRegister[] { + private readonly LuaRegister[] FsLib = new LuaRegister[] { new() { name = "list", diff --git a/Capy64/Runtime/Libraries/GPU.cs b/Capy64/Runtime/Libraries/GPU.cs index 924a246..1dd745d 100644 --- a/Capy64/Runtime/Libraries/GPU.cs +++ b/Capy64/Runtime/Libraries/GPU.cs @@ -14,17 +14,14 @@ // limitations under the License. using Capy64.API; -using Capy64.Core; using Capy64.Runtime.Objects; using KeraLua; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; -using Microsoft.Xna.Framework.Input; using System; using System.Collections.Generic; using System.IO; using System.Threading.Tasks; -using System.Xml.Linq; namespace Capy64.Runtime.Libraries; @@ -37,7 +34,7 @@ public class GPU : IComponent _game = game; } - private LuaRegister[] gpuLib = new LuaRegister[] { + private readonly LuaRegister[] gpuLib = new LuaRegister[] { new() { name = "getSize", diff --git a/Capy64/Runtime/Libraries/HTTP.cs b/Capy64/Runtime/Libraries/HTTP.cs index 37694f5..8dc0df5 100644 --- a/Capy64/Runtime/Libraries/HTTP.cs +++ b/Capy64/Runtime/Libraries/HTTP.cs @@ -25,7 +25,6 @@ using System.Net.Http; using System.Net.WebSockets; using System.Text; using System.Threading; -using System.Threading.Tasks; namespace Capy64.Runtime.Libraries; #nullable enable @@ -171,7 +170,7 @@ public class HTTP : IComponent options["method"] = L.CheckString(-2); break; case "binary": - options["binary"] = L.IsBoolean(-2) ? L.ToBoolean(-2) : false; + options["binary"] = L.ToBoolean(-2); break; } diff --git a/Capy64/Runtime/Libraries/Machine.cs b/Capy64/Runtime/Libraries/Machine.cs index 6f8341e..02b3342 100644 --- a/Capy64/Runtime/Libraries/Machine.cs +++ b/Capy64/Runtime/Libraries/Machine.cs @@ -30,7 +30,7 @@ public class Machine : IComponent _game = game; } - private static LuaRegister[] MachineLib = new LuaRegister[] + private static readonly LuaRegister[] MachineLib = new LuaRegister[] { new() { diff --git a/Capy64/Runtime/Libraries/TCP.cs b/Capy64/Runtime/Libraries/TCP.cs index a8d5988..ff2b1da 100644 --- a/Capy64/Runtime/Libraries/TCP.cs +++ b/Capy64/Runtime/Libraries/TCP.cs @@ -14,9 +14,7 @@ // limitations under the License. using Capy64.API; -using Capy64.Runtime.Objects; using KeraLua; -using System.IO; using System.Net.Sockets; namespace Capy64.Runtime.Libraries; @@ -31,7 +29,7 @@ public class TCP : IComponent Counter = 0; } - private static LuaRegister[] TCPLib = new LuaRegister[] + private static readonly LuaRegister[] TCPLib = new LuaRegister[] { new() { diff --git a/Capy64/Runtime/Libraries/Term.cs b/Capy64/Runtime/Libraries/Term.cs index 66d4fc4..bf305fd 100644 --- a/Capy64/Runtime/Libraries/Term.cs +++ b/Capy64/Runtime/Libraries/Term.cs @@ -14,7 +14,6 @@ // limitations under the License. using Capy64.API; -using Capy64.Core; using Capy64.Eventing.Events; using KeraLua; using Microsoft.Xna.Framework; @@ -73,7 +72,7 @@ internal class Term : IComponent _game.EventEmitter.OnScreenSizeChange += OnScreenSizeChange; } - private LuaRegister[] TermLib = new LuaRegister[] + private readonly LuaRegister[] TermLib = new LuaRegister[] { new() { @@ -217,12 +216,12 @@ internal class Term : IComponent _game.Drawing.DrawString(charpos, ch.ToString(), fg); } - catch (ArgumentException ex) // UTF-16 fuckery + catch (ArgumentException) // UTF-16 fuckery { _game.Drawing.DrawString(charpos, "\xFFFD", fg); } - if(underline) + if (underline) { _game.Drawing.DrawLine(charpos + new Vector2(0, CharHeight), charpos + new Vector2(CharWidth, CharHeight), fg); } @@ -313,7 +312,7 @@ internal class Term : IComponent if (cursorState) { var realpos = ToRealPos(CursorPosition - Vector2.One); - var charpos = (realpos * _game.Scale) + (CharOffset + new Vector2(0, 2)) * _game.Scale; + var charpos = (realpos * _game.Scale) + ((CharOffset + new Vector2(0, 2)) * _game.Scale); charpos += new Vector2(Capy64.Instance.Borders.Left, Capy64.Instance.Borders.Top); _game.Game.SpriteBatch.Draw(cursorTexture, charpos, null, ForegroundColor, 0f, Vector2.Zero, _game.Scale, SpriteEffects.None, 0); } @@ -396,7 +395,7 @@ internal class Term : IComponent { var L = Lua.FromIntPtr(state); - if(_game.EngineMode == EngineMode.Classic) + if (_game.EngineMode == EngineMode.Classic) { L.PushBoolean(false); return 1; @@ -538,8 +537,6 @@ internal class Term : IComponent private static int L_Clear(IntPtr state) { - var L = Lua.FromIntPtr(state); - Clear(); return 0; @@ -553,8 +550,6 @@ internal class Term : IComponent private static int L_ClearLine(IntPtr state) { - var L = Lua.FromIntPtr(state); - ClearLine(); return 0; diff --git a/Capy64/Runtime/Libraries/Timer.cs b/Capy64/Runtime/Libraries/Timer.cs index 35b168e..d0f9246 100644 --- a/Capy64/Runtime/Libraries/Timer.cs +++ b/Capy64/Runtime/Libraries/Timer.cs @@ -23,7 +23,7 @@ namespace Capy64.Runtime.Libraries; class Timer : IComponent { - private LuaRegister[] TimerLib = new LuaRegister[] + private readonly LuaRegister[] TimerLib = new LuaRegister[] { new() { @@ -47,7 +47,7 @@ class Timer : IComponent private static IGame _game; private static uint _timerId = 0; - private static ConcurrentDictionary timers = new(); + private static readonly ConcurrentDictionary timers = new(); public Timer(IGame game) { _game = game; @@ -128,7 +128,8 @@ class Timer : IComponent timer.Elapsed += (o, e) => { - task.Fulfill(lk => { + task.Fulfill(lk => + { lk.PushInteger(timerId); }); timers.TryRemove(timerId, out _); diff --git a/Capy64/Runtime/ObjectManager.cs b/Capy64/Runtime/ObjectManager.cs index 7b708b8..6c55530 100644 --- a/Capy64/Runtime/ObjectManager.cs +++ b/Capy64/Runtime/ObjectManager.cs @@ -23,7 +23,7 @@ namespace Capy64.Runtime; public class ObjectManager : IComponent { - private static ConcurrentDictionary _objects = new(); + private static readonly ConcurrentDictionary _objects = new(); private static IGame _game; public ObjectManager(IGame game) diff --git a/Capy64/Runtime/Objects/FileHandle.cs b/Capy64/Runtime/Objects/FileHandle.cs index a933ab0..f44ce81 100644 --- a/Capy64/Runtime/Objects/FileHandle.cs +++ b/Capy64/Runtime/Objects/FileHandle.cs @@ -24,7 +24,7 @@ public class FileHandle : IComponent { public const string ObjectType = "file"; - private static LuaRegister[] Methods = new LuaRegister[] + private static readonly LuaRegister[] Methods = new LuaRegister[] { new() { @@ -59,7 +59,7 @@ public class FileHandle : IComponent new(), }; - private static LuaRegister[] MetaMethods = new LuaRegister[] + private static readonly LuaRegister[] MetaMethods = new LuaRegister[] { new() { @@ -348,8 +348,7 @@ public class FileHandle : IComponent var L = Lua.FromIntPtr(state); var stream = ToStream(L, true); - if (stream is not null) - stream.Close(); + stream?.Close(); return 0; } diff --git a/Capy64/Runtime/Objects/GPUBufferMeta.cs b/Capy64/Runtime/Objects/GPUBufferMeta.cs index 32a88d7..c83d670 100644 --- a/Capy64/Runtime/Objects/GPUBufferMeta.cs +++ b/Capy64/Runtime/Objects/GPUBufferMeta.cs @@ -14,7 +14,6 @@ // limitations under the License. using Capy64.API; -using Capy64.Core; using KeraLua; using System; @@ -31,7 +30,7 @@ public class GPUBufferMeta : IComponent public int Height { get; set; } } - private static LuaRegister[] MetaMethods = new LuaRegister[] + private static readonly LuaRegister[] MetaMethods = new LuaRegister[] { new() { diff --git a/Capy64/Runtime/Objects/Socket.cs b/Capy64/Runtime/Objects/Socket.cs index 817f425..7069af2 100644 --- a/Capy64/Runtime/Objects/Socket.cs +++ b/Capy64/Runtime/Objects/Socket.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.Objects; @@ -33,18 +29,18 @@ public class Socket : IDisposable public class SocketLib : IComponent { - private static IGame _game; + private static readonly IGame _game; public SocketLib(IGame game) { } - private static LuaRegister[] Methods = new LuaRegister[] { + private static readonly LuaRegister[] Methods = new LuaRegister[] { new(), }; - private static LuaRegister[] MetaMethods = new LuaRegister[] { + private static readonly LuaRegister[] MetaMethods = new LuaRegister[] { new() { name = "__index", diff --git a/Capy64/Runtime/Objects/Task.cs b/Capy64/Runtime/Objects/Task.cs index 23f012a..745b17a 100644 --- a/Capy64/Runtime/Objects/Task.cs +++ b/Capy64/Runtime/Objects/Task.cs @@ -14,15 +14,8 @@ // limitations under the License. using Capy64.API; -using Cyotek.Drawing.BitmapFont; using KeraLua; using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading; -using System.Threading.Tasks; namespace Capy64.Runtime.Objects; @@ -69,7 +62,7 @@ public class TaskMeta : IComponent var container = tasks.NewThread(); lk(container); - if(container.IsNoneOrNil(-1)) + if (container.IsNoneOrNil(-1)) { throw new Exception("Task result cannot be nil"); } @@ -123,7 +116,7 @@ public class TaskMeta : IComponent } } - private static LuaRegister[] Methods = new LuaRegister[] + private static readonly LuaRegister[] Methods = new LuaRegister[] { new() { @@ -158,7 +151,7 @@ public class TaskMeta : IComponent new(), }; - private static LuaRegister[] MetaMethods = new LuaRegister[] + private static readonly LuaRegister[] MetaMethods = new LuaRegister[] { new() { diff --git a/Capy64/Runtime/Objects/WebSocketClient.cs b/Capy64/Runtime/Objects/WebSocketClient.cs index f45d764..c3e7e47 100644 --- a/Capy64/Runtime/Objects/WebSocketClient.cs +++ b/Capy64/Runtime/Objects/WebSocketClient.cs @@ -17,7 +17,6 @@ using Capy64.API; using Capy64.Runtime.Libraries; using KeraLua; using System; -using System.Collections.Generic; using System.Net.WebSockets; using System.Threading; diff --git a/Capy64/Runtime/PanicScreen.cs b/Capy64/Runtime/PanicScreen.cs index a8f4204..ee4dcfd 100644 --- a/Capy64/Runtime/PanicScreen.cs +++ b/Capy64/Runtime/PanicScreen.cs @@ -21,7 +21,7 @@ namespace Capy64.Runtime; public class PanicScreen { public static Color ForegroundColor = Color.White; - public static Color BackgroundColor = new Color(0, 51, 187); + public static Color BackgroundColor = new(0, 51, 187); public static void Render(string error, string details = null) { @@ -47,7 +47,7 @@ public class PanicScreen { Print(details); } - Term.SetCursorPosition(1, 19); + Term.SetCursorPosition(1, 23); Print("Hold CTRL + ALT + INSERT to reboot."); } diff --git a/Capy64/Runtime/RuntimeManager.cs b/Capy64/Runtime/RuntimeManager.cs index 55bf974..edb12bd 100644 --- a/Capy64/Runtime/RuntimeManager.cs +++ b/Capy64/Runtime/RuntimeManager.cs @@ -15,7 +15,6 @@ using Capy64.API; using Capy64.Eventing.Events; -using Capy64.Extensions; using Capy64.Runtime.Libraries; using KeraLua; using System;