Merged screen and graphics lib into new gpu lib

This commit is contained in:
Alessandro Proto 2023-01-20 19:18:56 +01:00
parent c6e3fa99c8
commit 107019b68f
2 changed files with 73 additions and 104 deletions

View file

@ -6,15 +6,36 @@ using System.Collections.Generic;
namespace Capy64.LuaRuntime.Libraries; namespace Capy64.LuaRuntime.Libraries;
public class Graphics : IPlugin public class GPU : IPlugin
{ {
private static IGame _game; private static IGame _game;
public Graphics(IGame game) public GPU(IGame game)
{ {
_game = 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() new()
{ {
name = "plot", name = "plot",
@ -70,15 +91,61 @@ public class Graphics : IPlugin
public void LuaInit(Lua state) 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); var l = Lua.FromIntPtr(state);
l.NewLib(GfxLib); l.NewLib(gpuLib);
return 1; 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) private static int L_Plot(IntPtr state)
{ {

View file

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