From 107019b68f5d2753f2367b66439dc6363794a183 Mon Sep 17 00:00:00 2001 From: Alessandro Proto Date: Fri, 20 Jan 2023 19:18:56 +0100 Subject: [PATCH] Merged screen and graphics lib into new gpu lib --- .../Libraries/{Graphics.cs => GPU.cs} | 79 +++++++++++++-- Capy64/LuaRuntime/Libraries/Screen.cs | 98 ------------------- 2 files changed, 73 insertions(+), 104 deletions(-) rename Capy64/LuaRuntime/Libraries/{Graphics.cs => GPU.cs} (82%) delete mode 100644 Capy64/LuaRuntime/Libraries/Screen.cs diff --git a/Capy64/LuaRuntime/Libraries/Graphics.cs b/Capy64/LuaRuntime/Libraries/GPU.cs similarity index 82% rename from Capy64/LuaRuntime/Libraries/Graphics.cs rename to Capy64/LuaRuntime/Libraries/GPU.cs index 032f882..7c848e2 100644 --- a/Capy64/LuaRuntime/Libraries/Graphics.cs +++ b/Capy64/LuaRuntime/Libraries/GPU.cs @@ -6,15 +6,36 @@ using System.Collections.Generic; namespace Capy64.LuaRuntime.Libraries; -public class Graphics : IPlugin +public class GPU : IPlugin { + private static IGame _game; - public Graphics(IGame game) + public GPU(IGame game) { _game = game; } - private LuaRegister[] GfxLib = new LuaRegister[] { + private LuaRegister[] gpuLib = new LuaRegister[] { + new() + { + name = "getSize", + function = L_GetSize, + }, + new() + { + name = "setSize", + function = L_SetSize, + }, + new() + { + name = "getScale", + function = L_GetScale, + }, + new() + { + name = "setScale", + function = L_SetScale, + }, new() { name = "plot", @@ -70,15 +91,61 @@ public class Graphics : IPlugin public void LuaInit(Lua state) { - state.RequireF("graphics", Open, false); + state.RequireF("gpu", OpenLib, false); } - public int Open(IntPtr state) + public int OpenLib(IntPtr state) { var l = Lua.FromIntPtr(state); - l.NewLib(GfxLib); + l.NewLib(gpuLib); return 1; } + private static int L_GetSize(IntPtr state) + { + var L = Lua.FromIntPtr(state); + + L.PushInteger(_game.Width); + L.PushInteger(_game.Height); + + return 2; + } + + private static int L_SetSize(IntPtr state) + { + var L = Lua.FromIntPtr(state); + + var w = L.CheckInteger(1); + var h = L.CheckInteger(2); + + _game.Width = (int)w; + _game.Height = (int)h; + + _game.UpdateSize(); + + return 0; + } + + private static int L_GetScale(IntPtr state) + { + var L = Lua.FromIntPtr(state); + + L.PushNumber(_game.Scale); + + return 1; + } + + private static int L_SetScale(IntPtr state) + { + var L = Lua.FromIntPtr(state); + + var s = L.CheckNumber(1); + + _game.Scale = (float)s; + + _game.UpdateSize(); + + return 0; + } private static int L_Plot(IntPtr state) { diff --git a/Capy64/LuaRuntime/Libraries/Screen.cs b/Capy64/LuaRuntime/Libraries/Screen.cs deleted file mode 100644 index 80642a9..0000000 --- a/Capy64/LuaRuntime/Libraries/Screen.cs +++ /dev/null @@ -1,98 +0,0 @@ -using Capy64.API; -using KeraLua; -using System; - -namespace Capy64.LuaRuntime.Libraries; - -public class Screen : IPlugin -{ - private static IGame _game; - public Screen(IGame game) - { - _game = game; - } - - private LuaRegister[] ScreenLib = new LuaRegister[] { - new() - { - name = "getSize", - function = L_GetSize, - }, - new() - { - name = "setSize", - function = L_SetSize, - }, - new() - { - name = "getScale", - function = L_GetScale, - }, - new() - { - name = "setScale", - function = L_SetScale, - }, - new(), // NULL - }; - - public void LuaInit(Lua state) - { - state.RequireF("screen", Open, false); - } - - public int Open(IntPtr state) - { - var l = Lua.FromIntPtr(state); - l.NewLib(ScreenLib); - return 1; - } - - private static int L_GetSize(IntPtr state) - { - var L = Lua.FromIntPtr(state); - - L.PushInteger(_game.Width); - L.PushInteger(_game.Height); - - return 2; - } - - private static int L_SetSize(IntPtr state) - { - var L = Lua.FromIntPtr(state); - - var w = L.CheckInteger(1); - var h = L.CheckInteger(2); - - _game.Width = (int)w; - _game.Height = (int)h; - - _game.UpdateSize(); - - return 0; - } - - private static int L_GetScale(IntPtr state) - { - var L = Lua.FromIntPtr(state); - - L.PushNumber(_game.Scale); - - return 1; - } - - private static int L_SetScale(IntPtr state) - { - var L = Lua.FromIntPtr(state); - - var s = L.CheckNumber(1); - - _game.Scale = (float)s; - - _game.UpdateSize(); - - return 0; - } - -}