Conditionally compile Windows code, make Throttle class portable, and add dummy input/audio implementations for non-Windows

This is (almost, bar some local resource hacks) enough to start the
emulator on Linux/Mono, load a ROM and watch the demo (input and
audio don't work yet).
This commit is contained in:
peter 2012-03-12 04:44:34 +00:00
parent 1d111ce0ff
commit e310e90d9f
12 changed files with 159 additions and 35 deletions

View File

@ -35,13 +35,14 @@
<UseApplicationTrust>false</UseApplicationTrust> <UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled> <BootstrapperEnabled>true</BootstrapperEnabled>
<TargetFrameworkProfile /> <TargetFrameworkProfile />
<DefineConstants Condition=" '$(OS)' == 'Windows_NT' ">WINDOWS</DefineConstants>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType> <DebugType>full</DebugType>
<Optimize>false</Optimize> <Optimize>false</Optimize>
<OutputPath>output\</OutputPath> <OutputPath>output\</OutputPath>
<DefineConstants>DEBUG</DefineConstants> <DefineConstants>$(DefineConstants);DEBUG</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<PlatformTarget>x86</PlatformTarget> <PlatformTarget>x86</PlatformTarget>
@ -53,8 +54,6 @@
<DebugType>pdbonly</DebugType> <DebugType>pdbonly</DebugType>
<Optimize>true</Optimize> <Optimize>true</Optimize>
<OutputPath>output\</OutputPath> <OutputPath>output\</OutputPath>
<DefineConstants>
</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<PlatformTarget>x86</PlatformTarget> <PlatformTarget>x86</PlatformTarget>
@ -66,11 +65,11 @@
<NoWin32Manifest>true</NoWin32Manifest> <NoWin32Manifest>true</NoWin32Manifest>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="LuaInterface, Version=2.0.0.16708, Culture=neutral, processorArchitecture=x86"> <Reference Include="LuaInterface, Version=2.0.0.16708, Culture=neutral, processorArchitecture=x86" Condition=" '$(OS)' == 'Windows_NT' ">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>.\LuaInterface.dll</HintPath> <HintPath>.\LuaInterface.dll</HintPath>
</Reference> </Reference>
<Reference Include="Microsoft.VisualBasic" /> <Reference Include="Microsoft.VisualBasic" Condition=" '$(OS)' == 'Windows_NT' " />
<Reference Include="Newtonsoft.Json, Version=1.3.0.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="Newtonsoft.Json, Version=1.3.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>..\Newtonsoft.Json.dll</HintPath> <HintPath>..\Newtonsoft.Json.dll</HintPath>
@ -86,11 +85,11 @@
<RequiredTargetFramework>3.5</RequiredTargetFramework> <RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference> </Reference>
<Reference Include="System.Data" /> <Reference Include="System.Data" />
<Reference Include="System.Deployment" /> <Reference Include="System.Deployment" Condition=" '$(OS)' == 'Windows_NT' " />
<Reference Include="System.Drawing" /> <Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" /> <Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
<Reference Include="SlimDX, Version=2.0.10.43, Culture=neutral, PublicKeyToken=b1b0c32fd1ffe4f9"> <Reference Include="SlimDX, Version=2.0.10.43, Culture=neutral, PublicKeyToken=b1b0c32fd1ffe4f9" Condition=" '$(OS)' == 'Windows_NT' ">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>..\SlimDX.dll</HintPath> <HintPath>..\SlimDX.dll</HintPath>
</Reference> </Reference>
@ -166,7 +165,7 @@
<Compile Include="Global.cs" /> <Compile Include="Global.cs" />
<Compile Include="HawkFile.cs" /> <Compile Include="HawkFile.cs" />
<Compile Include="Input\ControllerBinding.cs" /> <Compile Include="Input\ControllerBinding.cs" />
<Compile Include="Input\GamePad.cs" /> <Compile Include="Input\GamePad.cs" Condition=" '$(OS)' == 'Windows_NT' " />
<Compile Include="Input\Input.cs" /> <Compile Include="Input\Input.cs" />
<Compile Include="LogConsole.cs" /> <Compile Include="LogConsole.cs" />
<Compile Include="LogWindow.cs"> <Compile Include="LogWindow.cs">
@ -185,8 +184,8 @@
<DependentUpon>EditCommentsForm.cs</DependentUpon> <DependentUpon>EditCommentsForm.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="movie\InputAdapters.cs" /> <Compile Include="movie\InputAdapters.cs" />
<Compile Include="Input\Keyboard.cs" /> <Compile Include="Input\Keyboard.cs" Condition=" '$(OS)' == 'Windows_NT' " />
<Compile Include="LuaImplementation.cs" /> <Compile Include="LuaImplementation.cs" Condition=" '$(OS)' == 'Windows_NT' " />
<Compile Include="MainForm.cs"> <Compile Include="MainForm.cs">
<SubType>Form</SubType> <SubType>Form</SubType>
</Compile> </Compile>
@ -373,18 +372,18 @@
<Compile Include="tools\HexEditor.Designer.cs"> <Compile Include="tools\HexEditor.Designer.cs">
<DependentUpon>HexEditor.cs</DependentUpon> <DependentUpon>HexEditor.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="tools\LuaConsole.cs"> <Compile Include="tools\LuaConsole.cs" Condition=" '$(OS)' == 'Windows_NT' ">
<SubType>Form</SubType> <SubType>Form</SubType>
</Compile> </Compile>
<Compile Include="tools\LuaConsole.Designer.cs"> <Compile Include="tools\LuaConsole.Designer.cs" Condition=" '$(OS)' == 'Windows_NT' ">
<DependentUpon>LuaConsole.cs</DependentUpon> <DependentUpon>LuaConsole.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="tools\LuaFiles.cs" /> <Compile Include="tools\LuaFiles.cs" Condition=" '$(OS)' == 'Windows_NT' " />
<Compile Include="tools\LuaText.cs" /> <Compile Include="tools\LuaText.cs" Condition=" '$(OS)' == 'Windows_NT' " />
<Compile Include="tools\LuaWindow.cs"> <Compile Include="tools\LuaWindow.cs" Condition=" '$(OS)' == 'Windows_NT' ">
<SubType>Form</SubType> <SubType>Form</SubType>
</Compile> </Compile>
<Compile Include="tools\LuaWindow.Designer.cs"> <Compile Include="tools\LuaWindow.Designer.cs" Condition=" '$(OS)' == 'Windows_NT' ">
<DependentUpon>LuaWindow.cs</DependentUpon> <DependentUpon>LuaWindow.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="tools\MemoryViewer.cs"> <Compile Include="tools\MemoryViewer.cs">

View File

@ -1,15 +1,19 @@
using BizHawk.DiscSystem; using BizHawk.DiscSystem;
using System.Collections.Generic; using System.Collections.Generic;
#if WINDOWS
using SlimDX.Direct3D9; using SlimDX.Direct3D9;
using SlimDX.DirectSound; using SlimDX.DirectSound;
#endif
namespace BizHawk.MultiClient namespace BizHawk.MultiClient
{ {
public static class Global public static class Global
{ {
public static MainForm MainForm; public static MainForm MainForm;
#if WINDOWS
public static DirectSound DSound; public static DirectSound DSound;
public static Direct3D Direct3D; public static Direct3D Direct3D;
#endif
public static Sound Sound; public static Sound Sound;
public static IRenderer RenderPanel; public static IRenderer RenderPanel;
public static Config Config; public static Config Config;

View File

@ -3,7 +3,9 @@ using System.Linq;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading; using System.Threading;
using System.Windows.Forms; using System.Windows.Forms;
#if WINDOWS
using SlimDX.DirectInput; using SlimDX.DirectInput;
#endif
namespace BizHawk.MultiClient namespace BizHawk.MultiClient
{ {
@ -54,15 +56,19 @@ namespace BizHawk.MultiClient
private Input() private Input()
{ {
#if WINDOWS
UpdateThread = new Thread(UpdateThreadProc); UpdateThread = new Thread(UpdateThreadProc);
UpdateThread.IsBackground = true; UpdateThread.IsBackground = true;
UpdateThread.Start(); UpdateThread.Start();
#endif
} }
public static void Initialize() public static void Initialize()
{ {
#if WINDOWS
KeyInput.Initialize(); KeyInput.Initialize();
GamePad.Initialize(); GamePad.Initialize();
#endif
Instance = new Input(); Instance = new Input();
} }
@ -192,6 +198,7 @@ namespace BizHawk.MultiClient
} }
} }
#if WINDOWS
void UpdateThreadProc() void UpdateThreadProc()
{ {
for (; ; ) for (; ; )
@ -241,7 +248,7 @@ namespace BizHawk.MultiClient
Thread.Sleep(10); Thread.Sleep(10);
} }
} }
#endif
public void Update() public void Update()
{ {

View File

@ -63,7 +63,9 @@ namespace BizHawk.MultiClient
public ToolBox ToolBox1 = new ToolBox(); public ToolBox ToolBox1 = new ToolBox();
public TI83KeyPad TI83KeyPad1 = new TI83KeyPad(); public TI83KeyPad TI83KeyPad1 = new TI83KeyPad();
public TAStudio TAStudio1 = new TAStudio(); public TAStudio TAStudio1 = new TAStudio();
#if WINDOWS
public LuaConsole LuaConsole1 = new LuaConsole(); public LuaConsole LuaConsole1 = new LuaConsole();
#endif
public MainForm(string[] args) public MainForm(string[] args)
{ {
@ -139,7 +141,11 @@ namespace BizHawk.MultiClient
Global.Emulator = new NullEmulator(); Global.Emulator = new NullEmulator();
Global.ActiveController = Global.NullControls; Global.ActiveController = Global.NullControls;
Global.AutoFireController = Global.AutofireNullControls; Global.AutoFireController = Global.AutofireNullControls;
#if WINDOWS
Global.Sound = new Sound(Handle, Global.DSound); Global.Sound = new Sound(Handle, Global.DSound);
#else
Global.Sound = new Sound();
#endif
Global.Sound.StartSound(); Global.Sound.StartSound();
RewireInputChain(); RewireInputChain();
//TODO - replace this with some kind of standard dictionary-yielding parser in a separate component //TODO - replace this with some kind of standard dictionary-yielding parser in a separate component
@ -262,10 +268,12 @@ namespace BizHawk.MultiClient
void SyncPresentationMode() void SyncPresentationMode()
{ {
#if WINDOWS
bool gdi = Global.Config.DisplayGDI; bool gdi = Global.Config.DisplayGDI;
if (Global.Direct3D == null) if (Global.Direct3D == null)
gdi = true; gdi = true;
#endif
if (renderTarget != null) if (renderTarget != null)
{ {
@ -276,19 +284,26 @@ namespace BizHawk.MultiClient
if (retainedPanel != null) retainedPanel.Dispose(); if (retainedPanel != null) retainedPanel.Dispose();
if (Global.RenderPanel != null) Global.RenderPanel.Dispose(); if (Global.RenderPanel != null) Global.RenderPanel.Dispose();
#if WINDOWS
if (gdi) if (gdi)
#endif
renderTarget = retainedPanel = new RetainedViewportPanel(); renderTarget = retainedPanel = new RetainedViewportPanel();
#if WINDOWS
else renderTarget = new ViewportPanel(); else renderTarget = new ViewportPanel();
#endif
Controls.Add(renderTarget); Controls.Add(renderTarget);
Controls.SetChildIndex(renderTarget, 0); Controls.SetChildIndex(renderTarget, 0);
renderTarget.Dock = DockStyle.Fill; renderTarget.Dock = DockStyle.Fill;
renderTarget.BackColor = Color.Black; renderTarget.BackColor = Color.Black;
#if WINDOWS
if (gdi) if (gdi)
{ {
#endif
Global.RenderPanel = new SysdrawingRenderPanel(retainedPanel); Global.RenderPanel = new SysdrawingRenderPanel(retainedPanel);
retainedPanel.ActivateThreaded(); retainedPanel.ActivateThreaded();
#if WINDOWS
} }
else else
{ {
@ -306,6 +321,7 @@ namespace BizHawk.MultiClient
SyncPresentationMode(); SyncPresentationMode();
} }
} }
#endif
} }
void SyncThrottle() void SyncThrottle()
@ -1163,7 +1179,9 @@ namespace BizHawk.MultiClient
TAStudio1.Restart(); TAStudio1.Restart();
Cheats1.Restart(); Cheats1.Restart();
ToolBox1.Restart(); ToolBox1.Restart();
#if WINDOWS
LuaConsole1.Restart(); LuaConsole1.Restart();
#endif
if (Global.Config.LoadCheatFileByGame) if (Global.Config.LoadCheatFileByGame)
{ {
@ -1648,6 +1666,7 @@ namespace BizHawk.MultiClient
{ {
Global.RenderPanel.ClearGUIText(); Global.RenderPanel.ClearGUIText();
//client input-related duties //client input-related duties
#if WINDOWS
if (LuaConsole1.IsRunning()) if (LuaConsole1.IsRunning())
{ {
LuaConsole1.WaitOne(); LuaConsole1.WaitOne();
@ -1657,6 +1676,7 @@ namespace BizHawk.MultiClient
{ {
Global.MainForm.MainWait.Set(); Global.MainForm.MainWait.Set();
} }
#endif
runloop_fps++; runloop_fps++;
bool ff = Global.ClientControls["Fast Forward"]; bool ff = Global.ClientControls["Fast Forward"];
@ -2255,7 +2275,9 @@ namespace BizHawk.MultiClient
TI83KeyPad1.Restart(); TI83KeyPad1.Restart();
Cheats1.Restart(); Cheats1.Restart();
ToolBox1.Restart(); ToolBox1.Restart();
#if WINDOWS
LuaConsole1.Restart(); LuaConsole1.Restart();
#endif
Text = "BizHawk" + (INTERIM ? " (interim) " : ""); Text = "BizHawk" + (INTERIM ? " (interim) " : "");
HandlePlatformMenus(); HandlePlatformMenus();
StateSlots.Clear(); StateSlots.Clear();
@ -2283,7 +2305,9 @@ namespace BizHawk.MultiClient
CloseForm(Cheats1); CloseForm(Cheats1);
CloseForm(TI83KeyPad1); CloseForm(TI83KeyPad1);
CloseForm(TAStudio1); CloseForm(TAStudio1);
#if WINDOWS
CloseForm(LuaConsole1); CloseForm(LuaConsole1);
#endif
if (Global.Config.ShowLogWindow) LogConsole.SaveConfigSettings(); if (Global.Config.ShowLogWindow) LogConsole.SaveConfigSettings();
ConfigService.Save(PathManager.DefaultIniPath, Global.Config); ConfigService.Save(PathManager.DefaultIniPath, Global.Config);
} }
@ -2537,6 +2561,7 @@ namespace BizHawk.MultiClient
public void OpenLuaConsole() public void OpenLuaConsole()
{ {
#if WINDOWS
if (!LuaConsole1.IsHandleCreated || LuaConsole1.IsDisposed) if (!LuaConsole1.IsHandleCreated || LuaConsole1.IsDisposed)
{ {
LuaConsole1 = new LuaConsole(); LuaConsole1 = new LuaConsole();
@ -2544,6 +2569,9 @@ namespace BizHawk.MultiClient
} }
else else
LuaConsole1.Focus(); LuaConsole1.Focus();
#else
MessageBox.Show("Sorry, Lua is not supported on this platform.", "Lua not supported", MessageBoxButtons.OK, MessageBoxIcon.Error);
#endif
} }
public void OpenGameboyDebugger() public void OpenGameboyDebugger()

View File

@ -1,8 +1,10 @@
using System; using System;
using System.Windows.Forms; using System.Windows.Forms;
#if WINDOWS
using SlimDX.Direct3D9; using SlimDX.Direct3D9;
using SlimDX.DirectSound; using SlimDX.DirectSound;
using Microsoft.VisualBasic.ApplicationServices; using Microsoft.VisualBasic.ApplicationServices;
#endif
namespace BizHawk.MultiClient namespace BizHawk.MultiClient
{ {
@ -16,6 +18,7 @@ namespace BizHawk.MultiClient
Global.Config = ConfigService.Load<Config>(PathManager.DefaultIniPath); Global.Config = ConfigService.Load<Config>(PathManager.DefaultIniPath);
#if WINDOWS
try { Global.DSound = new DirectSound(); } try { Global.DSound = new DirectSound(); }
catch catch
{ {
@ -29,9 +32,11 @@ namespace BizHawk.MultiClient
if (!Global.Config.DisplayGDI) if (!Global.Config.DisplayGDI)
DisplayDirect3DError(); DisplayDirect3DError();
} }
#endif
try try
{ {
#if WINDOWS
if (Global.Config.SingleInstanceMode) if (Global.Config.SingleInstanceMode)
{ {
SingleInstanceController controller = new SingleInstanceController(args); SingleInstanceController controller = new SingleInstanceController(args);
@ -39,17 +44,21 @@ namespace BizHawk.MultiClient
} }
else else
{ {
#endif
var mf = new MainForm(args); var mf = new MainForm(args);
var title = mf.Text; var title = mf.Text;
mf.Show(); mf.Show();
mf.Text = title; mf.Text = title;
mf.ProgramRunLoop(); mf.ProgramRunLoop();
#if WINDOWS
} }
#endif
} }
catch (Exception e) catch (Exception e)
{ {
MessageBox.Show(e.ToString(), "Oh, no, a terrible thing happened!\n\n" + e.ToString()); MessageBox.Show(e.ToString(), "Oh, no, a terrible thing happened!\n\n" + e.ToString());
} }
#if WINDOWS
finally finally
{ {
if (Global.DSound != null && Global.DSound.Disposed == false) if (Global.DSound != null && Global.DSound.Disposed == false)
@ -57,9 +66,10 @@ namespace BizHawk.MultiClient
if (Global.Direct3D != null && Global.Direct3D.Disposed == false) if (Global.Direct3D != null && Global.Direct3D.Disposed == false)
Global.Direct3D.Dispose(); Global.Direct3D.Dispose();
} }
#endif
} }
#if WINDOWS
public class SingleInstanceController : WindowsFormsApplicationBase public class SingleInstanceController : WindowsFormsApplicationBase
{ {
MainForm mf; MainForm mf;
@ -92,5 +102,6 @@ namespace BizHawk.MultiClient
{ {
MessageBox.Show("Failure to initialize Direct3D, reverting to GDI+ display method. Change the option in Config > GUI or install DirectX web update.", "Initialization Error", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show("Failure to initialize Direct3D, reverting to GDI+ display method. Change the option in Config > GUI or install DirectX web update.", "Initialization Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
} }
#endif
} }
} }

View File

@ -7,13 +7,16 @@ using System.IO;
using System.Threading; using System.Threading;
using System.Text; using System.Text;
using System.Windows.Forms; using System.Windows.Forms;
#if WINDOWS
using SlimDX; using SlimDX;
using SlimDX.Direct3D9; using SlimDX.Direct3D9;
using Font = SlimDX.Direct3D9.Font; using Font = SlimDX.Direct3D9.Font;
#endif
using BizHawk.Core; using BizHawk.Core;
namespace BizHawk.MultiClient namespace BizHawk.MultiClient
{ {
#if WINDOWS
public class ImageTexture : IDisposable public class ImageTexture : IDisposable
{ {
public Device GraphicsDevice; public Device GraphicsDevice;
@ -105,6 +108,7 @@ namespace BizHawk.MultiClient
} }
} }
} }
#endif
public interface IRenderer : IDisposable public interface IRenderer : IDisposable
{ {
@ -148,7 +152,7 @@ namespace BizHawk.MultiClient
public void ClearGUIText() { } public void ClearGUIText() { }
} }
#if WINDOWS
public class Direct3DRenderPanel : IRenderer public class Direct3DRenderPanel : IRenderer
{ {
public Color BackgroundColor { get; set; } public Color BackgroundColor { get; set; }
@ -546,6 +550,7 @@ namespace BizHawk.MultiClient
return ""; return "";
} }
} }
#endif
class UIMessage class UIMessage
{ {

View File

@ -1,12 +1,15 @@
using System; using System;
using BizHawk.Emulation.Sound; using BizHawk.Emulation.Sound;
#if WINDOWS
using SlimDX.DirectSound; using SlimDX.DirectSound;
using SlimDX.Multimedia; using SlimDX.Multimedia;
#endif
using BizHawk.Emulation.Consoles.Nintendo; using BizHawk.Emulation.Consoles.Nintendo;
namespace BizHawk.MultiClient namespace BizHawk.MultiClient
{ {
#if WINDOWS
public class Sound : IDisposable public class Sound : IDisposable
{ {
public bool Muted = false; public bool Muted = false;
@ -192,4 +195,65 @@ namespace BizHawk.MultiClient
} }
} }
} }
#else
// Dummy implementation for non-Windows platforms for now.
public class Sound
{
public bool Muted = false;
public bool needDiscard;
public Sound()
{
}
public void StartSound()
{
}
public bool IsPlaying = false;
public void StopSound()
{
}
public void Dispose()
{
}
int SNDDXGetAudioSpace()
{
return 0;
}
public void UpdateSound(ISoundProvider soundProvider)
{
soundProvider.DiscardSamples();
}
/// <summary>
/// Range: 0-100
/// </summary>
/// <param name="vol"></param>
public void ChangeVolume(int vol)
{
Global.Config.SoundVolume = vol;
UpdateSoundSettings();
}
/// <summary>
/// Uses Global.Config.SoundEnabled, this just notifies the object to read it
/// </summary>
public void UpdateSoundSettings()
{
if (Global.Emulator is NES)
{
NES n = Global.Emulator as NES;
if (Global.Config.SoundEnabled == false)
n.SoundOn = false;
else
n.SoundOn = true;
}
}
}
#endif
} }

View File

@ -102,6 +102,7 @@ namespace BizHawk.MultiClient
static ulong GetCurTime() static ulong GetCurTime()
{ {
#if WINDOWS
if (tmethod == 1) if (tmethod == 1)
{ {
ulong tmp; ulong tmp;
@ -110,13 +111,15 @@ namespace BizHawk.MultiClient
} }
else else
{ {
return (ulong)GetTickCount(); #endif
return (ulong)Environment.TickCount;
#if WINDOWS
} }
#endif
} }
[DllImport("kernel32.dll")]
static extern uint GetTickCount();
#if WINDOWS
[DllImport("kernel32.dll", SetLastError = true)] [DllImport("kernel32.dll", SetLastError = true)]
static extern bool QueryPerformanceCounter(out ulong lpPerformanceCount); static extern bool QueryPerformanceCounter(out ulong lpPerformanceCount);
@ -129,15 +132,15 @@ namespace BizHawk.MultiClient
[DllImport("winmm.dll", EntryPoint = "timeBeginPeriod")] [DllImport("winmm.dll", EntryPoint = "timeBeginPeriod")]
static extern uint timeBeginPeriod(uint uMilliseconds); static extern uint timeBeginPeriod(uint uMilliseconds);
[DllImport("kernel32.dll")]
static extern bool SwitchToThread();
static int tmethod; static int tmethod;
#endif
static ulong afsfreq; static ulong afsfreq;
static ulong tfreq; static ulong tfreq;
static Throttle() static Throttle()
{ {
#if WINDOWS
timeBeginPeriod(1); timeBeginPeriod(1);
tmethod = 0; tmethod = 0;
if (QueryPerformanceFrequency(out afsfreq)) if (QueryPerformanceFrequency(out afsfreq))
@ -145,6 +148,9 @@ namespace BizHawk.MultiClient
else else
afsfreq = 1000; afsfreq = 1000;
Console.WriteLine("throttle method: {0}; resolution: {1}", tmethod, afsfreq); Console.WriteLine("throttle method: {0}; resolution: {1}", tmethod, afsfreq);
#else
afsfreq = 1000;
#endif
tfreq = afsfreq << 16; tfreq = afsfreq << 16;
} }
@ -323,7 +329,7 @@ namespace BizHawk.MultiClient
} }
else if (sleepy > 0) // spin for <1 millisecond waits else if (sleepy > 0) // spin for <1 millisecond waits
{ {
SwitchToThread(); // limit to other threads on the same CPU core for other short waits Thread.Yield(); // limit to other threads on the same CPU core for other short waits
} }
goto waiter; goto waiter;
} }