This commit is contained in:
Alessandro Proto 2023-02-17 19:22:24 +01:00
parent 40295112fe
commit e606dfee95
27 changed files with 35 additions and 91 deletions

View file

@ -17,8 +17,9 @@ using Capy64.API;
using Capy64.Core; using Capy64.Core;
using Capy64.Eventing; using Capy64.Eventing;
using Capy64.Extensions; using Capy64.Extensions;
using Capy64.Runtime; using Capy64.Integrations;
using Capy64.PluginManager; using Capy64.PluginManager;
using Capy64.Runtime;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
@ -27,7 +28,6 @@ using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using static Capy64.Utils; using static Capy64.Utils;
using Capy64.Integrations;
namespace Capy64; namespace Capy64;
@ -121,8 +121,8 @@ public class Capy64 : Game, IGame
if (Window.IsMaximized()) if (Window.IsMaximized())
{ {
var vertical = bounds.Height - Height * Scale; var vertical = bounds.Height - (Height * Scale);
var horizontal = bounds.Width - Width * Scale; var horizontal = bounds.Width - (Width * Scale);
Borders.Top = (int)Math.Floor(vertical / 2d); Borders.Top = (int)Math.Floor(vertical / 2d);
Borders.Bottom = (int)Math.Ceiling(vertical / 2d); Borders.Bottom = (int)Math.Ceiling(vertical / 2d);

View file

@ -146,7 +146,7 @@ public class Audio : IDisposable
Waveform.Square => GetSquarePoint(frequency, x), Waveform.Square => GetSquarePoint(frequency, x),
Waveform.Triangle => GetTrianglePoint(frequency, x), Waveform.Triangle => GetTrianglePoint(frequency, x),
Waveform.Sawtooth => GetSawtoothPoint(frequency, x), Waveform.Sawtooth => GetSawtoothPoint(frequency, x),
Waveform.Noise => rng.NextDouble() * 2 - 1, Waveform.Noise => (rng.NextDouble() * 2) - 1,
_ => throw new NotImplementedException(), _ => throw new NotImplementedException(),
}; };
@ -184,8 +184,8 @@ public class Audio : IDisposable
double v = 0; double v = 0;
for (int k = 1; k <= 25; k++) for (int k = 1; k <= 25; k++)
{ {
v += (Math.Pow(-1, k) / Math.Pow(2 * k - 1, 2)) v += Math.Pow(-1, k) / Math.Pow((2 * k) - 1, 2)
* Math.Sin(frequency * 2 * Math.PI * (2 * k - 1) * x); * Math.Sin(frequency * 2 * Math.PI * ((2 * k) - 1) * x);
} }
return -(8 / Math.Pow(Math.PI, 2)) * v; return -(8 / Math.Pow(Math.PI, 2)) * v;
} }
@ -195,7 +195,7 @@ public class Audio : IDisposable
double v = 0; double v = 0;
for (int k = 1; k <= 50; k++) 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; return -(2 / Math.PI) * v;
} }

View file

@ -14,11 +14,6 @@
// limitations under the License. // limitations under the License.
using Capy64.Extensions.Bindings; using Capy64.Extensions.Bindings;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Capy64.Core; namespace Capy64.Core;

View file

@ -163,7 +163,8 @@ public class EventEmitter
public void RaiseOverlay(OverlayEvent ev) public void RaiseOverlay(OverlayEvent ev)
{ {
if(OnOverlay is not null) { if (OnOverlay is not null)
{
OnOverlay(this, ev); OnOverlay(this, ev);
} }
} }

View file

@ -14,7 +14,6 @@
// limitations under the License. // limitations under the License.
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using System; using System;
namespace Capy64.Eventing.Events; namespace Capy64.Eventing.Events;

View file

@ -13,7 +13,6 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
using Microsoft.Xna.Framework.Input;
using System; using System;
namespace Capy64.Eventing.Events; namespace Capy64.Eventing.Events;

View file

@ -14,7 +14,6 @@
// limitations under the License. // limitations under the License.
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System; using System;
namespace Capy64.Eventing.Events; namespace Capy64.Eventing.Events;

View file

@ -423,7 +423,7 @@ public class InputManager
// D-PAD // D-PAD
var od = oldGamePadState.DPad; var od = oldGamePadState.DPad;
var d = state.DPad; var d = state.DPad;
if (od.Left != d.Left) if (od.Left != d.Left)
{ {
_eventEmitter.RaiseGamePadButton(new() _eventEmitter.RaiseGamePadButton(new()
@ -466,7 +466,7 @@ public class InputManager
if (ot.Left != t.Left) if (ot.Left != t.Left)
{ {
_eventEmitter.RaiseGamePadTrigger(new() _eventEmitter.RaiseGamePadTrigger(new()
{ {
Trigger = 1, // left Trigger = 1, // left

View file

@ -14,11 +14,7 @@
// limitations under the License. // limitations under the License.
using System; using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace Capy64.Extensions.Bindings; namespace Capy64.Extensions.Bindings;

View file

@ -15,7 +15,6 @@
using Capy64.API; using Capy64.API;
using Capy64.Core; using Capy64.Core;
using Capy64.Eventing;
using Capy64.Integrations; using Capy64.Integrations;
using Capy64.Runtime; using Capy64.Runtime;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;

View file

@ -18,12 +18,7 @@ using DiscordRPC;
using DiscordRPC.Logging; using DiscordRPC.Logging;
using DiscordRPC.Message; using DiscordRPC.Message;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using System; using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Capy64.Integrations; namespace Capy64.Integrations;

View file

@ -24,7 +24,7 @@ using IHost host = Host.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((context, c) => .ConfigureAppConfiguration((context, c) =>
{ {
var settingsPath = Path.Combine(Capy64.Capy64.AppDataPath, "settings.json"); 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); Directory.CreateDirectory(Capy64.Capy64.AppDataPath);
} }

View file

@ -15,12 +15,10 @@
using Capy64.Core; using Capy64.Core;
using Capy64.Eventing.Events; using Capy64.Eventing.Events;
using Capy64.Eventing;
using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Input;
using System; using System;
using System.Linq; using System.Linq;
using static Capy64.Eventing.InputManager; using static Capy64.Eventing.InputManager;
using Capy64.Runtime.Extensions;
namespace Capy64.Runtime; namespace Capy64.Runtime;
@ -187,7 +185,8 @@ internal class EventEmitter
if (SDL.HasClipboardText()) if (SDL.HasClipboardText())
{ {
var text = SDL.GetClipboardText(); var text = SDL.GetClipboardText();
_runtime.QueueEvent("paste", LK => { _runtime.QueueEvent("paste", LK =>
{
LK.PushString(text); LK.PushString(text);
return 1; return 1;
@ -199,7 +198,8 @@ internal class EventEmitter
private void OnChar(object sender, CharEvent e) private void OnChar(object sender, CharEvent e)
{ {
_runtime.QueueEvent("char", LK => { _runtime.QueueEvent("char", LK =>
{
LK.PushString(e.Character.ToString()); LK.PushString(e.Character.ToString());
return 1; return 1;

View file

@ -17,7 +17,6 @@ using Capy64.API;
using KeraLua; using KeraLua;
using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Audio;
using System; using System;
using System.Threading.Tasks;
using static Capy64.Core.Audio; using static Capy64.Core.Audio;
namespace Capy64.Runtime.Libraries; namespace Capy64.Runtime.Libraries;

View file

@ -16,10 +16,6 @@
using Capy64.API; using Capy64.API;
using KeraLua; using KeraLua;
using System; using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Capy64.Runtime.Libraries; namespace Capy64.Runtime.Libraries;

View file

@ -15,13 +15,12 @@
using Capy64.API; using Capy64.API;
using Capy64.Runtime.Extensions; using Capy64.Runtime.Extensions;
using Capy64.Runtime.Objects;
using KeraLua; using KeraLua;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Text;
using Capy64.Runtime.Objects;
namespace Capy64.Runtime.Libraries; namespace Capy64.Runtime.Libraries;
@ -430,7 +429,7 @@ public class FileSystem : IComponent
var attr = File.GetAttributes(path); var attr = File.GetAttributes(path);
if (attr.HasFlag(FileAttributes.Directory)) if (attr.HasFlag(FileAttributes.Directory))
{ {
if(!recursive && Directory.GetFileSystemEntries(path).Any()) if (!recursive && Directory.GetFileSystemEntries(path).Any())
{ {
L.Error("directory not empty"); L.Error("directory not empty");
return 0; return 0;

View file

@ -456,7 +456,7 @@ public class GPU : IComponent
var w = (int)L.CheckInteger(4); var w = (int)L.CheckInteger(4);
var h = (int)L.CheckInteger(5); 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"); L.Error("width and height do not match buffer size");
} }

View file

@ -18,10 +18,6 @@ using KeraLua;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Input;
using System; using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Capy64.Runtime.Libraries; namespace Capy64.Runtime.Libraries;

View file

@ -18,11 +18,8 @@ using Capy64.Eventing.Events;
using KeraLua; using KeraLua;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using MonoGame.Extended;
using Newtonsoft.Json.Linq;
using System; using System;
using static Capy64.Utils; using static Capy64.Utils;
using static System.Formats.Asn1.AsnWriter;
namespace Capy64.Runtime.Libraries; namespace Capy64.Runtime.Libraries;
@ -292,7 +289,7 @@ internal class Term : IComponent
if (cursorState) if (cursorState)
{ {
var realpos = ToRealPos(CursorPosition - Vector2.One); 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); _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 // RGB to ABGR
fgv = 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_FF_00U) | // move G
(fgv & 0x00_00_00_FFU) << 16 | // move B ((fgv & 0x00_00_00_FFU) << 16) | // move B
0xFF_00_00_00U; 0xFF_00_00_00U;
bgv = 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_FF_00U) | // move G
(bgv & 0x00_00_00_FFU) << 16 | // move B ((bgv & 0x00_00_00_FFU) << 16) | // move B
0xFF_00_00_00U; 0xFF_00_00_00U;

View file

@ -17,7 +17,6 @@ using Capy64.API;
using KeraLua; using KeraLua;
using System; using System;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Collections.Generic;
namespace Capy64.Runtime.Libraries; namespace Capy64.Runtime.Libraries;

View file

@ -15,10 +15,6 @@
using KeraLua; using KeraLua;
using System; using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Capy64.Runtime; namespace Capy64.Runtime;

View file

@ -18,11 +18,6 @@ using KeraLua;
using System; using System;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace Capy64.Runtime; namespace Capy64.Runtime;

View file

@ -16,11 +16,7 @@
using Capy64.API; using Capy64.API;
using KeraLua; using KeraLua;
using System; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Capy64.Runtime.Objects; namespace Capy64.Runtime.Objects;
@ -107,12 +103,13 @@ public class FileHandle : IComponent
{ {
var modes = "nlLa"; var modes = "nlLa";
mode = mode.TrimStart('*'); mode = mode.TrimStart('*');
if(string.IsNullOrEmpty(mode)) { if (string.IsNullOrEmpty(mode))
{
return '\0'; return '\0';
} }
var i = modes.IndexOf(mode[0]); var i = modes.IndexOf(mode[0]);
if(i == -1) if (i == -1)
return '\0'; return '\0';
return modes[i]; return modes[i];
@ -274,7 +271,7 @@ public class FileHandle : IComponent
var n = L.GetTop() - 1; var n = L.GetTop() - 1;
var stream = CheckStream(L, false); var stream = CheckStream(L, false);
L.ArgumentCheck(n <= maxargn, maxargn + 2, "too many arguments"); L.ArgumentCheck(n <= maxargn, maxargn + 2, "too many arguments");
L.PushCopy(1); L.PushCopy(1);
L.PushInteger(n); L.PushInteger(n);
L.PushBoolean(false); L.PushBoolean(false);
L.Rotate(2, 3); L.Rotate(2, 3);

View file

@ -16,7 +16,6 @@
using Capy64.API; using Capy64.API;
using KeraLua; using KeraLua;
using System; using System;
using System.IO;
namespace Capy64.Runtime.Objects; namespace Capy64.Runtime.Objects;
@ -111,9 +110,9 @@ public class GPUBuffer : IComponent
// ABGR to RGB // ABGR to RGB
value = 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_00_FF_00U) | // move G
(value & 0x00_FF_00_00U) >> 16; // move B ((value & 0x00_FF_00_00U) >> 16); // move B
L.PushInteger(value); L.PushInteger(value);
@ -146,11 +145,11 @@ public class GPUBuffer : IComponent
// RGB to ABGR // RGB to ABGR
value = 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_FF_00U) | // move G
(value & 0x00_00_00_FFU) << 16 | // move B ((value & 0x00_00_00_FFU) << 16) | // move B
0xFF_00_00_00U; 0xFF_00_00_00U;
buffer[key] = value; buffer[key] = value;

View file

@ -13,14 +13,8 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
using Capy64.Core;
using Capy64.Runtime.Libraries; using Capy64.Runtime.Libraries;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Capy64.Runtime; namespace Capy64.Runtime;

View file

@ -19,14 +19,8 @@ using Capy64.Extensions;
using Capy64.Runtime.Libraries; using Capy64.Runtime.Libraries;
using KeraLua; using KeraLua;
using System; using System;
using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Diagnostics.Tracing;
using System.IO; using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Capy64.Runtime; namespace Capy64.Runtime;

View file

@ -33,7 +33,7 @@ public static class Utils
return return
(color.R << 16) + (color.R << 16) +
(color.G << 8) + (color.G << 8) +
(color.B); color.B;
} }
public static void UnpackRGB(uint packed, out byte r, out byte g, out byte b) public static void UnpackRGB(uint packed, out byte r, out byte g, out byte b)