Move Lua hacks to Lua libs
Changed parameter of IInputMovie.SetRerecordCount to ulong to match internal
This commit is contained in:
parent
861f238cc1
commit
8f93a954e1
|
@ -352,29 +352,29 @@ namespace BizHawk.Client.Common
|
|||
|
||||
return false;
|
||||
}
|
||||
public void SetRenderPlanes(params bool[] luaParam)
|
||||
public void SetRenderPlanes(params bool[] args)
|
||||
{
|
||||
if (Emulator is GPGX gpgx)
|
||||
{
|
||||
var s = gpgx.GetSettings();
|
||||
s.DrawBGA = luaParam[0];
|
||||
s.DrawBGB = luaParam[1];
|
||||
s.DrawBGW = luaParam[2];
|
||||
s.DrawObj = luaParam[3];
|
||||
s.DrawBGA = args[0];
|
||||
s.DrawBGB = args[1];
|
||||
s.DrawBGW = args[2];
|
||||
s.DrawObj = args[3];
|
||||
gpgx.PutSettings(s);
|
||||
|
||||
}
|
||||
else if (Emulator is LibsnesCore snes)
|
||||
{
|
||||
var s = snes.GetSettings();
|
||||
s.ShowBG1_0 = s.ShowBG1_1 = luaParam[0];
|
||||
s.ShowBG2_0 = s.ShowBG2_1 = luaParam[1];
|
||||
s.ShowBG3_0 = s.ShowBG3_1 = luaParam[2];
|
||||
s.ShowBG4_0 = s.ShowBG4_1 = luaParam[3];
|
||||
s.ShowOBJ_0 = luaParam[4];
|
||||
s.ShowOBJ_1 = luaParam[5];
|
||||
s.ShowOBJ_2 = luaParam[6];
|
||||
s.ShowOBJ_3 = luaParam[7];
|
||||
s.ShowBG1_0 = s.ShowBG1_1 = args[0];
|
||||
s.ShowBG2_0 = s.ShowBG2_1 = args[1];
|
||||
s.ShowBG3_0 = s.ShowBG3_1 = args[2];
|
||||
s.ShowBG4_0 = s.ShowBG4_1 = args[3];
|
||||
s.ShowOBJ_0 = args[4];
|
||||
s.ShowOBJ_1 = args[5];
|
||||
s.ShowOBJ_2 = args[6];
|
||||
s.ShowOBJ_3 = args[7];
|
||||
snes.PutSettings(s);
|
||||
}
|
||||
else if (Emulator is NES nes)
|
||||
|
@ -382,8 +382,8 @@ namespace BizHawk.Client.Common
|
|||
// in the future, we could do something more arbitrary here.
|
||||
// but this isn't any worse than the old system
|
||||
var s = nes.GetSettings();
|
||||
s.DispSprites = luaParam[0];
|
||||
s.DispBackground = luaParam[1];
|
||||
s.DispSprites = args[0];
|
||||
s.DispBackground = args[1];
|
||||
nes.PutSettings(s);
|
||||
}
|
||||
else if (Emulator is QuickNES quicknes)
|
||||
|
@ -391,7 +391,7 @@ namespace BizHawk.Client.Common
|
|||
var s = quicknes.GetSettings();
|
||||
|
||||
// this core doesn't support disabling BG
|
||||
bool showSp = GetSetting(0, luaParam);
|
||||
bool showSp = GetSetting(0, args);
|
||||
if (showSp && s.NumSprites == 0)
|
||||
{
|
||||
s.NumSprites = 8;
|
||||
|
@ -406,12 +406,12 @@ namespace BizHawk.Client.Common
|
|||
else if (Emulator is PCEngine pce)
|
||||
{
|
||||
var s = pce.GetSettings();
|
||||
s.ShowOBJ1 = GetSetting(0, luaParam);
|
||||
s.ShowBG1 = GetSetting(1, luaParam);
|
||||
if (luaParam.Length > 2)
|
||||
s.ShowOBJ1 = GetSetting(0, args);
|
||||
s.ShowBG1 = GetSetting(1, args);
|
||||
if (args.Length > 2)
|
||||
{
|
||||
s.ShowOBJ2 = GetSetting(2, luaParam);
|
||||
s.ShowBG2 = GetSetting(3, luaParam);
|
||||
s.ShowOBJ2 = GetSetting(2, args);
|
||||
s.ShowBG2 = GetSetting(3, args);
|
||||
}
|
||||
|
||||
pce.PutSettings(s);
|
||||
|
@ -419,16 +419,16 @@ namespace BizHawk.Client.Common
|
|||
else if (Emulator is SMS sms)
|
||||
{
|
||||
var s = sms.GetSettings();
|
||||
s.DispOBJ = GetSetting(0, luaParam);
|
||||
s.DispBG = GetSetting(1, luaParam);
|
||||
s.DispOBJ = GetSetting(0, args);
|
||||
s.DispBG = GetSetting(1, args);
|
||||
sms.PutSettings(s);
|
||||
}
|
||||
else if (Emulator is WonderSwan ws)
|
||||
{
|
||||
var s = ws.GetSettings();
|
||||
s.EnableSprites = GetSetting(0, luaParam);
|
||||
s.EnableFG = GetSetting(1, luaParam);
|
||||
s.EnableBG = GetSetting(2, luaParam);
|
||||
s.EnableSprites = GetSetting(0, args);
|
||||
s.EnableFG = GetSetting(1, args);
|
||||
s.EnableBG = GetSetting(2, args);
|
||||
ws.PutSettings(s);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,10 +44,6 @@ namespace BizHawk.Client.Common
|
|||
}
|
||||
}
|
||||
|
||||
buttons["clear"] = null;
|
||||
buttons["getluafunctionslist"] = null;
|
||||
buttons["output"] = null;
|
||||
|
||||
return buttons;
|
||||
}
|
||||
|
||||
|
@ -77,12 +73,12 @@ namespace BizHawk.Client.Common
|
|||
|
||||
foreach (var button in lg.Definition.BoolButtons)
|
||||
{
|
||||
Global.LuaAndAdaptor.SetButton(button, lg.IsPressed(button));
|
||||
Global.ButtonOverrideAdaptor.SetButton(button, lg.IsPressed(button));
|
||||
}
|
||||
|
||||
foreach (var floatButton in lg.Definition.FloatControls)
|
||||
{
|
||||
Global.LuaAndAdaptor.SetFloat(floatButton, lg.GetFloat(floatButton));
|
||||
Global.ButtonOverrideAdaptor.SetFloat(floatButton, lg.GetFloat(floatButton));
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
|
@ -132,19 +128,19 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
if (theValue.HasValue) // Force
|
||||
{
|
||||
Global.LuaAndAdaptor.SetButton(toPress, theValue.Value);
|
||||
Global.ActiveController.Overrides(Global.LuaAndAdaptor);
|
||||
Global.ButtonOverrideAdaptor.SetButton(toPress, theValue.Value);
|
||||
Global.ActiveController.Overrides(Global.ButtonOverrideAdaptor);
|
||||
}
|
||||
else // Unset
|
||||
{
|
||||
Global.LuaAndAdaptor.UnSet(toPress);
|
||||
Global.ActiveController.Overrides(Global.LuaAndAdaptor);
|
||||
Global.ButtonOverrideAdaptor.UnSet(toPress);
|
||||
Global.ActiveController.Overrides(Global.ButtonOverrideAdaptor);
|
||||
}
|
||||
}
|
||||
else // Inverse
|
||||
{
|
||||
Global.LuaAndAdaptor.SetInverse(toPress);
|
||||
Global.ActiveController.Overrides(Global.LuaAndAdaptor);
|
||||
Global.ButtonOverrideAdaptor.SetInverse(toPress);
|
||||
Global.ActiveController.Overrides(Global.ButtonOverrideAdaptor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -163,10 +159,10 @@ namespace BizHawk.Client.Common
|
|||
toPress = $"P{controller} {button}";
|
||||
}
|
||||
if (state.HasValue)
|
||||
Global.LuaAndAdaptor.SetButton(toPress, state.Value);
|
||||
Global.ButtonOverrideAdaptor.SetButton(toPress, state.Value);
|
||||
else
|
||||
Global.LuaAndAdaptor.UnSet(toPress);
|
||||
Global.ActiveController.Overrides(Global.LuaAndAdaptor);
|
||||
Global.ButtonOverrideAdaptor.UnSet(toPress);
|
||||
Global.ActiveController.Overrides(Global.ButtonOverrideAdaptor);
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
|
|
@ -74,20 +74,6 @@ namespace BizHawk.Client.Common
|
|||
Global.MovieSession.ReadOnly = readOnly;
|
||||
}
|
||||
|
||||
public static void SetRerecordCount(double count)
|
||||
{
|
||||
// Lua numbers are always double, integer precision holds up
|
||||
// to 53 bits, so throw an error if it's bigger than that.
|
||||
const double PrecisionLimit = 9007199254740992d;
|
||||
|
||||
if (count > PrecisionLimit)
|
||||
{
|
||||
throw new Exception("Rerecord count exceeds Lua integer precision.");
|
||||
}
|
||||
|
||||
Global.MovieSession.Movie.Rerecords = (ulong)count;
|
||||
}
|
||||
|
||||
public static void SetRerecordCounting(bool counting)
|
||||
{
|
||||
Global.MovieSession.Movie.IsCountingRerecords = counting;
|
||||
|
@ -272,10 +258,7 @@ namespace BizHawk.Client.Common
|
|||
MoviePluginStatic.SetReadOnly(readOnly);
|
||||
}
|
||||
|
||||
public void SetRerecordCount(double count)
|
||||
{
|
||||
MoviePluginStatic.SetRerecordCount(count);
|
||||
}
|
||||
public void SetRerecordCount(ulong count) => Global.MovieSession.Movie.Rerecords = count;
|
||||
|
||||
public void SetRerecordCounting(bool counting)
|
||||
{
|
||||
|
|
|
@ -27,6 +27,6 @@ namespace BizHawk.Client.Common
|
|||
string GetBoardName();
|
||||
object GetSettings();
|
||||
bool PutSettings(object settings);
|
||||
void SetRenderPlanes(params bool[] param);
|
||||
void SetRenderPlanes(params bool[] args);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ namespace BizHawk.Client.Common
|
|||
string Mode();
|
||||
void Save(string filename = "");
|
||||
void SetReadOnly(bool readOnly);
|
||||
void SetRerecordCount(double count);
|
||||
void SetRerecordCount(ulong count);
|
||||
void SetRerecordCounting(bool counting);
|
||||
void Stop();
|
||||
double GetFps();
|
||||
|
|
|
@ -58,9 +58,9 @@ namespace BizHawk.Client.Common
|
|||
public static readonly StickyXorAdapter StickyXORAdapter = new StickyXorAdapter();
|
||||
|
||||
/// <summary>
|
||||
/// Used to AND to another controller, used for Joypad.Set()
|
||||
/// Used to AND to another controller, used for <see cref="JoypadApi.Set(System.Collections.Generic.Dictionary{string,bool},System.Nullable{int})">JoypadApi.Set</see>
|
||||
/// </summary>
|
||||
public static readonly OverrideAdaptor LuaAndAdaptor = new OverrideAdaptor();
|
||||
public static readonly OverrideAdaptor ButtonOverrideAdaptor = new OverrideAdaptor();
|
||||
|
||||
/// <summary>
|
||||
/// fire off one-frame logical button clicks here. useful for things like ti-83 virtual pad and reset buttons
|
||||
|
|
|
@ -20,9 +20,11 @@ namespace BizHawk.Client.Common
|
|||
[LuaMethod("get", "returns a lua table of the controller buttons pressed. If supplied, it will only return a table of buttons for the given controller")]
|
||||
public LuaTable Get(int? controller = null)
|
||||
{
|
||||
return APIs.Joypad
|
||||
.Get(controller)
|
||||
.ToLuaTable(Lua);
|
||||
var table = APIs.Joypad.Get(controller).ToLuaTable(Lua);
|
||||
table["clear"] = null;
|
||||
table["getluafunctionslist"] = null;
|
||||
table["output"] = null;
|
||||
return table;
|
||||
}
|
||||
|
||||
[LuaMethodExample("local nljoyget = joypad.getimmediate( );")]
|
||||
|
|
|
@ -74,7 +74,7 @@ namespace BizHawk.Client.Common
|
|||
|
||||
[LuaMethodExample("movie.setrerecordcount( 20.0 );")]
|
||||
[LuaMethod("setrerecordcount", "Sets the rerecord count of the current movie.")]
|
||||
public void SetRerecordCount(double count) => APIs.Movie.SetRerecordCount(count);
|
||||
public void SetRerecordCount(double count) => APIs.Movie.SetRerecordCount((ulong) count.AsInteger());
|
||||
|
||||
[LuaMethodExample("movie.setrerecordcounting( true );")]
|
||||
[LuaMethod("setrerecordcounting", "Sets whether or not the current movie will increment the rerecord counter on loadstate")]
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using NLua;
|
||||
|
@ -7,6 +8,17 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
public static class LuaExtensions
|
||||
{
|
||||
private const double PrecisionLimit = 0x20000000000000 + 0.0;
|
||||
|
||||
/// <remarks>
|
||||
/// Lua numbers are always double-length floats, so integers whose magnitude is at least 2^53 may not fit in the 53-bit mantissa (the sign is stored separately).
|
||||
/// These extremely large values aren't that useful, so we'll just assume they're erroneous and give the script author an error.
|
||||
/// </remarks>
|
||||
/// <exception cref="ArithmeticException"><paramref name="d"/> ≥ 2^53 or <paramref name="d"/> ≤ -2^53</exception>
|
||||
public static long AsInteger(this double d) => -PrecisionLimit < d && d < PrecisionLimit
|
||||
? (long) d
|
||||
: throw new ArithmeticException("integer value exceeds the precision of Lua's integer-as-double");
|
||||
|
||||
public static LuaTable EnumerateToLuaTable<T>(this IEnumerable<T> list, Lua lua) => list.ToList().ToLuaTable(lua);
|
||||
|
||||
public static LuaTable ToLuaTable<T>(this IList<T> list, Lua lua, int indexFrom = 0)
|
||||
|
|
|
@ -571,7 +571,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
|
||||
// autohold/autofire must not be affected by the following inputs
|
||||
Global.ActiveController.Overrides(Global.LuaAndAdaptor);
|
||||
Global.ActiveController.Overrides(Global.ButtonOverrideAdaptor);
|
||||
|
||||
if (GlobalWin.Tools.Has<LuaConsole>() && !SuppressLua)
|
||||
{
|
||||
|
@ -2971,7 +2971,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
// zero 03-may-2014 - moved this before call to UpdateToolsBefore(), since it seems to clear the state which a lua event.framestart is going to want to alter
|
||||
Global.ClickyVirtualPadController.FrameTick();
|
||||
Global.LuaAndAdaptor.FrameTick();
|
||||
Global.ButtonOverrideAdaptor.FrameTick();
|
||||
|
||||
if (GlobalWin.Tools.Has<LuaConsole>() && !SuppressLua)
|
||||
{
|
||||
|
|
|
@ -935,7 +935,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
foreach (var button in lg.Definition.BoolButtons)
|
||||
{
|
||||
// TODO: make an input adapter specifically for the bot?
|
||||
Global.LuaAndAdaptor.SetButton(button, lg.IsPressed(button));
|
||||
Global.ButtonOverrideAdaptor.SetButton(button, lg.IsPressed(button));
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
|
@ -32,12 +32,12 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
foreach (var button in lg.Definition.BoolButtons)
|
||||
{
|
||||
Global.LuaAndAdaptor.SetButton(button, lg.IsPressed(button));
|
||||
Global.ButtonOverrideAdaptor.SetButton(button, lg.IsPressed(button));
|
||||
}
|
||||
|
||||
foreach (var floatButton in lg.Definition.FloatControls)
|
||||
{
|
||||
Global.LuaAndAdaptor.SetFloat(floatButton, lg.GetFloat(floatButton));
|
||||
Global.ButtonOverrideAdaptor.SetFloat(floatButton, lg.GetFloat(floatButton));
|
||||
}
|
||||
|
||||
return lg;
|
||||
|
|
Loading…
Reference in New Issue