Project cleanup, welcome beta version!

This commit is contained in:
Alessandro Proto 2023-03-18 18:43:15 +01:00
parent 8121920ad7
commit 451abe6b86
26 changed files with 48 additions and 72 deletions

View file

@ -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;

View file

@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<RollForward>Major</RollForward>
<PublishReadyToRun>false</PublishReadyToRun>

View file

@ -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);

View file

@ -31,7 +31,7 @@ public class Drawing : IDisposable
private Texture2D _whitePixel;
private RenderTarget2D _canvas;
private bool _isDrawing;
private HashSet<Texture2D> _disposeTextures = new();
private readonly HashSet<Texture2D> _disposeTextures = new();
public RenderTarget2D Canvas
{
get => _canvas;

View file

@ -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<Keys> pressedKeys = new();
private readonly HashSet<Keys> pressedKeys = new();
private readonly Game _game;
private readonly EventEmitter _eventEmitter;

View file

@ -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! */

View file

@ -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()

View file

@ -21,7 +21,7 @@ namespace Capy64.PluginManager
{
class PluginLoadContext : AssemblyLoadContext
{
private AssemblyDependencyResolver _resolver;
private readonly AssemblyDependencyResolver _resolver;
public PluginLoadContext(string pluginPath)
{

View file

@ -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;

View file

@ -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()
{

View file

@ -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");
}

View file

@ -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",

View file

@ -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",

View file

@ -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;
}

View file

@ -30,7 +30,7 @@ public class Machine : IComponent
_game = game;
}
private static LuaRegister[] MachineLib = new LuaRegister[]
private static readonly LuaRegister[] MachineLib = new LuaRegister[]
{
new()
{

View file

@ -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()
{

View file

@ -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;

View file

@ -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<uint, System.Timers.Timer> timers = new();
private static readonly ConcurrentDictionary<uint, System.Timers.Timer> 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 _);

View file

@ -23,7 +23,7 @@ namespace Capy64.Runtime;
public class ObjectManager : IComponent
{
private static ConcurrentDictionary<nint, object> _objects = new();
private static readonly ConcurrentDictionary<nint, object> _objects = new();
private static IGame _game;
public ObjectManager(IGame game)

View file

@ -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;
}

View file

@ -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()
{

View file

@ -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",

View file

@ -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()
{

View file

@ -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;

View file

@ -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.");
}

View file

@ -15,7 +15,6 @@
using Capy64.API;
using Capy64.Eventing.Events;
using Capy64.Extensions;
using Capy64.Runtime.Libraries;
using KeraLua;
using System;