Break off IsLagFrame and LagCount from IEmulator and put into its own interface IInputPollable, and refactor cores as necessary. EmuHawk - account for the possibility that a core is not an IInputPollable, and do things like disable the lag counter menu item. Still some front end todos. Also still todo, move the InputCallbackSystem from CoreComm to IInputPollable

This commit is contained in:
adelikat 2014-11-30 20:29:30 +00:00
parent 5ce1d02df7
commit a83d714c42
35 changed files with 96 additions and 102 deletions

View File

@ -148,18 +148,34 @@ namespace BizHawk.Client.Common
"islagged",
"returns whether or not the current frame is a lag frame"
)]
public static bool IsLagged()
public bool IsLagged()
{
return Global.Emulator.IsLagFrame;
if (Global.Emulator.CanPollInput())
{
return (Global.Emulator as IInputPollable).IsLagFrame;
}
else
{
Log("Can not get lag information, core does not implement IInputPollable");
return false;
}
}
[LuaMethodAttributes(
"lagcount",
"Returns the current lag count"
)]
public static int LagCount()
public int LagCount()
{
return Global.Emulator.LagCount;
if (Global.Emulator.CanPollInput())
{
return (Global.Emulator as IInputPollable).LagCount;
}
else
{
Log("Can not get lag information, core does not implement IInputPollable");
return 0;
}
}
[LuaMethodAttributes(

View File

@ -3,6 +3,8 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using BizHawk.Emulation.Common;
namespace BizHawk.Client.Common
{
public class TasLagLog
@ -21,10 +23,10 @@ namespace BizHawk.Client.Common
{
if (frame == LagLog.Count)
{
LagLog[frame] = Global.Emulator.IsLagFrame; // Note: Side effects!
LagLog[frame] = (Global.Emulator as IInputPollable).IsLagFrame; // Note: Side effects!
}
return Global.Emulator.IsLagFrame;
return (Global.Emulator as IInputPollable).IsLagFrame;
}
return null;

View File

@ -15,7 +15,7 @@ namespace BizHawk.Client.Common
base.RecordFrame(frame, source);
LagLog.RemoveFrom(frame);
LagLog[frame] = Global.Emulator.IsLagFrame;
LagLog[frame] = (Global.Emulator as IInputPollable).IsLagFrame;
StateManager.Capture();
}

View File

@ -306,7 +306,7 @@ namespace BizHawk.Client.Common
{
if (frame == Global.Emulator.Frame) // Take this opportunity to capture lag and state info if we do not have it
{
LagLog[Global.Emulator.Frame] = Global.Emulator.IsLagFrame;
LagLog[Global.Emulator.Frame] = (Global.Emulator as IInputPollable).IsLagFrame;
if (!StateManager.HasState(frame))
{

View File

@ -4,6 +4,8 @@ using System.Text;
using System.Drawing;
using System.Collections.Generic;
using BizHawk.Emulation.Common;
using BizHawk.Emulation.Common.IEmulatorExtensions;
using BizHawk.Client.Common;
using BizHawk.Client.Common.InputAdapterExtensions;
using BizHawk.Bizware.BizwareGL;
@ -325,7 +327,7 @@ namespace BizHawk.Client.EmuHawk
DrawOsdMessage(g, message, Color.FromArgb(Global.Config.MessagesColor), x, y);
if (Global.Emulator.IsLagFrame)
if (GlobalWin.MainForm.IsLagFrame)
{
DrawOsdMessage(g, Global.Emulator.Frame.ToString(), FixedAlertMessageColor, x, y);
}
@ -386,9 +388,9 @@ namespace BizHawk.Client.EmuHawk
DrawOsdMessage(g, FPS, FixedMessagesColor, x, y);
}
if (Global.Config.DisplayLagCounter)
if (Global.Config.DisplayLagCounter && Global.Emulator.CanPollInput())
{
var counter = Global.Emulator.LagCount.ToString();
var counter = (Global.Emulator as IInputPollable).LagCount.ToString();
var x = GetX(g, Global.Config.DispLagx, Global.Config.DispLaganchor, counter);
var y = GetY(g, Global.Config.DispLagy, Global.Config.DispLaganchor, counter);

View File

@ -673,6 +673,8 @@ namespace BizHawk.Client.EmuHawk
DisplayStatusBarMenuItem.Checked = Global.Config.DisplayStatusBar;
DisplayLogWindowMenuItem.Checked = Global.Config.ShowLogWindow;
DisplayLagCounterMenuItem.Enabled = Global.Emulator.CanPollInput();
}
private void WindowSizeSubMenu_DropDownOpened(object sender, EventArgs e)

View File

@ -2646,6 +2646,19 @@ namespace BizHawk.Client.EmuHawk
StepRunLoop_Core(true);
}
public bool IsLagFrame
{
get
{
if (Global.Emulator.CanPollInput())
{
return (Global.Emulator as IInputPollable).IsLagFrame;
}
return false;
}
}
private void StepRunLoop_Core(bool force = false)
{
var runFrame = false;
@ -2656,7 +2669,7 @@ namespace BizHawk.Client.EmuHawk
double frameAdvanceTimestampDelta = (now - _frameAdvanceTimestamp).TotalMilliseconds;
bool frameProgressTimeElapsed = Global.Config.FrameProgressDelayMs < frameAdvanceTimestampDelta;
if (Global.Config.SkipLagFrame && Global.Emulator.IsLagFrame && frameProgressTimeElapsed && Global.Emulator.Frame > 0)
if (Global.Config.SkipLagFrame && IsLagFrame && frameProgressTimeElapsed && Global.Emulator.Frame > 0)
{
runFrame = true;
}
@ -2802,7 +2815,7 @@ namespace BizHawk.Client.EmuHawk
AvFrameAdvance();
}
if (Global.Emulator.IsLagFrame && Global.Config.AutofireLagFrames)
if (IsLagFrame && Global.Config.AutofireLagFrames)
{
Global.AutoFireController.IncrementStarts();
}

View File

@ -2,9 +2,12 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BizHawk.Client.Common;
using BizHawk.Emulation.Common;
using BizHawk.Common;
using BizHawk.Emulation.Common;
using BizHawk.Emulation.Common.IEmulatorExtensions;
using BizHawk.Client.Common;
namespace BizHawk.Client.EmuHawk
{
@ -180,7 +183,7 @@ namespace BizHawk.Client.EmuHawk
// some cores really really really like it if you drain their audio every frame
emu.SyncSoundProvider.GetSamples(out samp, out nsamp);
current.Frames++;
if (emu.IsLagFrame)
if (emu.CanPollInput() && (emu as IInputPollable).IsLagFrame)
current.LaggedFrames++;
}
catch (Exception e)

View File

@ -64,6 +64,7 @@
<Compile Include="Interfaces\ICoreService.cs" />
<Compile Include="Interfaces\IDebuggable.cs" />
<Compile Include="Interfaces\IEmulator.cs" />
<Compile Include="Interfaces\IInputPollable.cs" />
<Compile Include="Interfaces\IMemoryDomains.cs" />
<Compile Include="Interfaces\ISaveRam.cs" />
<Compile Include="Interfaces\ISettable.cs" />

View File

@ -27,6 +27,11 @@ namespace BizHawk.Emulation.Common.IEmulatorExtensions
return core is IStatable;
}
public static bool CanPollInput(this IEmulator core)
{
return core is IInputPollable;
}
public static bool IsNull(this IEmulator core)
{
return core == null || core is NullEmulator;

View File

@ -65,9 +65,6 @@ namespace BizHawk.Emulation.Common
public IController Controller { get; set; }
public int Frame { get; set; }
public int LagCount { get { return 0; } set { return; } }
public bool IsLagFrame { get { return false; } }
public bool DeterministicEmulation { get { return true; } }
public int[] GetVideoBuffer() { return frameBuffer; }

View File

@ -47,17 +47,6 @@ namespace BizHawk.Emulation.Common
/// </summary>
int Frame { get; }
/// <summary>
/// The lag count.
/// </summary>
int LagCount { get; set; }
/// <summary>
/// If the current frame is a lag frame.
/// All cores should define it the same, a lag frame is a frame in which input was not polled.
/// </summary>
bool IsLagFrame { get; }
/// <summary>
/// The unique Id of the given core, for instance "NES"
/// </summary>

View File

@ -0,0 +1,16 @@
namespace BizHawk.Emulation.Common
{
public interface IInputPollable : ICoreService, IEmulator
{
/// <summary>
/// The lag count.
/// </summary>
int LagCount { get; set; }
/// <summary>
/// If the current frame is a lag frame.
/// All cores should define it the same, a lag frame is a frame in which input was not polled.
/// </summary>
bool IsLagFrame { get; }
}
}

View File

@ -19,7 +19,7 @@ namespace BizHawk.Emulation.Cores.Calculators
isPorted: false,
isReleased: true
)]
public partial class TI83 : IEmulator, IMemoryDomains, IStatable, IDebuggable, ISettable<TI83.TI83Settings, object>
public partial class TI83 : IEmulator, IMemoryDomains, IStatable, IDebuggable, IInputPollable, ISettable<TI83.TI83Settings, object>
{
//hardware
private readonly Z80A cpu = new Z80A();

View File

@ -13,7 +13,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
isPorted: false,
isReleased: false
)]
sealed public partial class C64 : IEmulator, IMemoryDomains, IStatable
sealed public partial class C64 : IEmulator, IMemoryDomains, IStatable, IInputPollable
{
// internal variables
private bool _islag = true;

View File

@ -15,7 +15,7 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600
isPorted: false,
isReleased: true
)]
public partial class Atari2600 : IEmulator, IMemoryDomains, IStatable, IDebuggable, ISettable<Atari2600.A2600Settings, Atari2600.A2600SyncSettings>
public partial class Atari2600 : IEmulator, IMemoryDomains, IStatable, IDebuggable, IInputPollable, ISettable<Atari2600.A2600Settings, Atari2600.A2600SyncSettings>
{
private readonly GameInfo _game;
private bool _islag = true;

View File

@ -16,7 +16,7 @@ namespace BizHawk.Emulation.Cores.Atari.Atari7800
portedVersion: "v1.5",
portedUrl: "http://emu7800.sourceforge.net/"
)]
public partial class Atari7800 : IEmulator, IMemoryDomains, ISaveRam, IDebuggable, IStatable
public partial class Atari7800 : IEmulator, IMemoryDomains, ISaveRam, IDebuggable, IStatable, IInputPollable
{
// TODO:
// some things don't work when you try to plug in a 2600 game

View File

@ -12,7 +12,7 @@ using Newtonsoft.Json;
namespace BizHawk.Emulation.Cores.Atari.Lynx
{
[CoreAttributes("Handy", "K. Wilkins", true, true, "mednafen 0-9-34-1", "http://mednafen.sourceforge.net/")]
public class Lynx : IEmulator, IVideoProvider, ISyncSoundProvider, IMemoryDomains, ISaveRam, IStatable
public class Lynx : IEmulator, IVideoProvider, ISyncSoundProvider, IMemoryDomains, ISaveRam, IStatable, IInputPollable
{
IntPtr Core;

View File

@ -17,7 +17,7 @@ namespace BizHawk.Emulation.Cores.ColecoVision
isPorted: false,
isReleased: true
)]
public sealed partial class ColecoVision : IEmulator, IMemoryDomains, IDebuggable, ISettable<object, ColecoVision.ColecoSyncSettings>
public sealed partial class ColecoVision : IEmulator, IMemoryDomains, IDebuggable, IInputPollable, ISettable<object, ColecoVision.ColecoSyncSettings>
{
// ROM
public byte[] RomData;

View File

@ -134,14 +134,6 @@ namespace BizHawk.Emulation.Cores.Intellivision
public IController Controller { get; set; }
public int Frame { get; set; }
public int LagCount
{
get { return 0; }
set { }
}
public bool IsLagFrame { get { return false; } }
public string SystemId
{
get { return "INTV"; }
@ -155,8 +147,6 @@ namespace BizHawk.Emulation.Cores.Intellivision
public void ResetCounters()
{
Frame = 0;
LagCount = 0;
//IsLagFrame = false;
}
public CoreComm CoreComm { get; private set; }

View File

@ -14,7 +14,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
isPorted: true,
isReleased: false
)]
public class GBA : IEmulator, IVideoProvider, ISyncSoundProvider, IGBAGPUViewable, IMemoryDomains, ISaveRam, IDebuggable, IStatable
public class GBA : IEmulator, IVideoProvider, ISyncSoundProvider, IGBAGPUViewable, IMemoryDomains, ISaveRam, IDebuggable, IStatable, IInputPollable
{
public IDictionary<string, int> GetCpuFlagsAndRegisters()
{

View File

@ -14,7 +14,7 @@ using BizHawk.Common;
namespace BizHawk.Emulation.Cores.Nintendo.GBA
{
[CoreAttributes("VBA-Next", "many authors", true, true, "cd508312a29ed8c29dacac1b11c2dce56c338a54", "https://github.com/libretro/vba-next")]
public class VBANext : IEmulator, IVideoProvider, ISyncSoundProvider,
public class VBANext : IEmulator, IVideoProvider, ISyncSoundProvider, IInputPollable,
IGBAGPUViewable, IMemoryDomains, ISaveRam, IStatable, IDebuggable, ISettable<object, VBANext.SyncSettings>
{
IntPtr Core;

View File

@ -22,7 +22,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
portedVersion: "SVN 344",
portedUrl: "http://gambatte.sourceforge.net/"
)]
public class Gameboy : IEmulator, IVideoProvider, ISyncSoundProvider, ISaveRam, IStatable,
public class Gameboy : IEmulator, IVideoProvider, ISyncSoundProvider, ISaveRam, IStatable, IInputPollable,
IMemoryDomains, IDebuggable, ISettable<Gameboy.GambatteSettings, Gameboy.GambatteSyncSettings>
{
#region ALL SAVESTATEABLE STATE GOES HERE

View File

@ -17,7 +17,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
isPorted: true,
isReleased: true
)]
public class GambatteLink : IEmulator, IVideoProvider, ISyncSoundProvider,
public class GambatteLink : IEmulator, IVideoProvider, ISyncSoundProvider, IInputPollable, ISaveRam, IStatable,
IDebuggable, ISettable<GambatteLink.GambatteLinkSettings, GambatteLink.GambatteLinkSyncSettings>
{
bool disposed = false;

View File

@ -17,7 +17,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64
portedVersion: "2.0",
portedUrl: "https://code.google.com/p/mupen64plus/"
)]
public partial class N64 : IEmulator, IMemoryDomains, ISaveRam, IDebuggable, IStatable,
public partial class N64 : IEmulator, IMemoryDomains, ISaveRam, IDebuggable, IStatable, IInputPollable,
ISettable<N64Settings, N64SyncSettings>
{
private readonly N64Input _inputProvider;

View File

@ -17,7 +17,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
isPorted: false,
isReleased: true
)]
public partial class NES : IEmulator, IMemoryDomains, ISaveRam, IDebuggable, IStatable,
public partial class NES : IEmulator, IMemoryDomains, ISaveRam, IDebuggable, IStatable, IInputPollable,
ISettable<NES.NESSettings, NES.NESSyncSettings>
{
static readonly bool USE_DATABASE = true;

View File

@ -22,8 +22,8 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES
portedVersion: "0.7.0",
portedUrl: "https://github.com/kode54/QuickNES"
)]
public class QuickNES : IEmulator, IVideoProvider, ISyncSoundProvider, IMemoryDomains, ISaveRam, IStatable,
IDebuggable, ISettable<QuickNES.QuickNESSettings, QuickNES.QuickNESSyncSettings>
public class QuickNES : IEmulator, IVideoProvider, ISyncSoundProvider, IMemoryDomains, ISaveRam, IInputPollable,
IStatable, IDebuggable, ISettable<QuickNES.QuickNESSettings, QuickNES.QuickNESSyncSettings>
{
#region FPU precision

View File

@ -29,7 +29,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
portedVersion: "v87",
portedUrl: "http://byuu.org/"
)]
public unsafe class LibsnesCore : IEmulator, IVideoProvider, IMemoryDomains, ISaveRam, IStatable,
public unsafe class LibsnesCore : IEmulator, IVideoProvider, IMemoryDomains, ISaveRam, IStatable, IInputPollable,
IDebuggable, ISettable<LibsnesCore.SnesSettings, LibsnesCore.SnesSyncSettings>
{
public LibsnesCore(GameInfo game, byte[] romData, bool deterministicEmulation, byte[] xmlData, CoreComm comm, object Settings, object SyncSettings)

View File

@ -41,19 +41,13 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES9X
Frame++;
LibSnes9x.debug_advance(_vbuff);
if (IsLagFrame)
LagCount++;
}
public int Frame { get; private set; }
public int LagCount { get; set; }
public bool IsLagFrame { get { return true; } }
public void ResetCounters()
{
Frame = 0;
LagCount = 0;
}
public string SystemId { get { return "SNES"; } }

View File

@ -22,7 +22,7 @@ namespace BizHawk.Emulation.Cores.PCEngine
isPorted: false,
isReleased: true
)]
public sealed partial class PCEngine : IEmulator, IMemoryDomains, ISaveRam, IStatable,
public sealed partial class PCEngine : IEmulator, IMemoryDomains, ISaveRam, IStatable, IInputPollable,
IDebuggable, ISettable<PCEngine.PCESettings, PCEngine.PCESyncSettings>
{
// ROM

View File

@ -21,7 +21,7 @@ namespace BizHawk.Emulation.Cores.Sega.Genesis
isPorted: false,
isReleased: false
)]
public sealed partial class Genesis : IEmulator, IMemoryDomains, IDebuggable, ISaveRam, IStatable
public sealed partial class Genesis : IEmulator, IMemoryDomains, IDebuggable, ISaveRam, IStatable, IInputPollable
{
private int _lagcount = 0;
private bool lagged = true;

View File

@ -25,7 +25,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx
portedUrl: "https://code.google.com/p/genplus-gx/"
)]
public class GPGX : IEmulator, ISyncSoundProvider, IVideoProvider, IMemoryDomains, ISaveRam, IStatable,
IDebuggable, ISettable<GPGX.GPGXSettings, GPGX.GPGXSyncSettings>
IInputPollable, IDebuggable, ISettable<GPGX.GPGXSettings, GPGX.GPGXSyncSettings>
{
static GPGX AttachedCore = null;

View File

@ -123,26 +123,6 @@ namespace BizHawk.Emulation.Cores.Sony.PSP
get { return 0; }
}
public int LagCount
{
[FeatureNotImplemented]
get
{
return 0;
}
[FeatureNotImplemented]
set
{
}
}
public bool IsLagFrame
{
[FeatureNotImplemented]
get { return true; }
}
[FeatureNotImplemented]
public void ResetCounters()
{

View File

@ -214,13 +214,11 @@ namespace BizHawk.Emulation.Cores.Sony.PSX
}
}
[FeatureNotImplemented]
public void ResetCounters()
{
// FIXME when all this stuff is implemented
Frame = 0;
LagCount = 0;
//IsLagFrame = false;
}
public void FrameAdvance(bool render, bool rendersound)
@ -268,20 +266,6 @@ namespace BizHawk.Emulation.Cores.Sony.PSX
set;
}
public int LagCount
{
[FeatureNotImplemented]
get { return 0; }
[FeatureNotImplemented]
set { return; }
}
public bool IsLagFrame
{
[FeatureNotImplemented]
get { return false; }
}
[FeatureNotImplemented]
public bool DeterministicEmulation { get { return true; } }

View File

@ -13,7 +13,7 @@ namespace BizHawk.Emulation.Cores.WonderSwan
{
[CoreAttributes("Cygne/Mednafen", "Dox", true, true, "0.9.36.5", "http://mednafen.sourceforge.net/")]
public class WonderSwan : IEmulator, IVideoProvider, ISyncSoundProvider, IMemoryDomains, ISaveRam, IStatable,
IDebuggable, ISettable<WonderSwan.Settings, WonderSwan.SyncSettings>
IInputPollable, IDebuggable, ISettable<WonderSwan.Settings, WonderSwan.SyncSettings>
{
#region Controller