Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow 2.3 to be built and run w/ MSBuild and Wine+Mono on GNU+Linux #1237

Merged
merged 1 commit into from
Nov 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion BizHawk.Client.Common/Global.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;

using BizHawk.Emulation.Common;
using BizHawk.Emulation.Cores.Consoles.Nintendo.Gameboy;
Expand Down Expand Up @@ -156,5 +157,7 @@ public static SystemInfo SystemInfo
}

public static Dictionary<string, object> UserBag = new Dictionary<string, object>();

public static bool RunningOnUnix = Environment.OSVersion.Platform == PlatformID.Unix || Environment.OSVersion.Platform == PlatformID.MacOSX;
}
}
2 changes: 2 additions & 0 deletions BizHawk.Client.EmuHawk/BizHawk.Client.EmuHawk.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,8 @@
<Compile Include="Input\GamePad.cs" />
<Compile Include="Input\GamePad360.cs" />
<Compile Include="Input\Input.cs" />
<Compile Include="Input\OTK_Gamepad.cs" />
<Compile Include="Input\OTK_Keyboard.cs" />
<Compile Include="IControlMainform.cs" />
<Compile Include="Input\IPCKeyInput.cs" />
<Compile Include="JumpLists.cs" />
Expand Down
20 changes: 14 additions & 6 deletions BizHawk.Client.EmuHawk/Input/Input.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using System.Threading;
#if WINDOWS
using SlimDX.DirectInput;
#else
using OpenTK.Input;
#endif

using BizHawk.Common;
Expand Down Expand Up @@ -126,12 +128,18 @@ private Input()

public static void Initialize()
{
#if WINDOWS
KeyInput.Initialize();
IPCKeyInput.Initialize();
GamePad.Initialize();
GamePad360.Initialize();
#endif
if (Global.RunningOnUnix)
{
OTK_Keyboard.Initialize();
// OTK_Gamepad.Initialize();
}
else
{
KeyInput.Initialize();
IPCKeyInput.Initialize();
GamePad.Initialize();
GamePad360.Initialize();
}
Instance = new Input();
}

Expand Down
148 changes: 148 additions & 0 deletions BizHawk.Client.EmuHawk/Input/OTK_Gamepad.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
using System;
using System.Collections.Generic;
using OpenTK.Input;

namespace BizHawk.Client.EmuHawk
{
public class OTK_GamePad
{
//Note: OpenTK has both Gamepad and Joystick classes. An OpenTK Gamepad is a simplified version of Joystick
//with pre-defined features that match an XInput controller. They did this to mimic XNA's controller API.
//We're going to use Joystick directly, because it gives us full access to all possible buttons.
//And it looks like GamePad itself isn't supported on OpenTK OS X.

public static List<OTK_GamePad> Devices;
private const int MAX_JOYSTICKS = 4; //They don't have a way to query this for some reason. 4 is the minimum promised.

public static void Initialize()
{
Devices = new List<OTK_GamePad>();

for (int i = 0; i < MAX_JOYSTICKS; i++)
{
JoystickState jss = Joystick.GetState(i);
if (jss.IsConnected)
{
Console.WriteLine(string.Format("joydevice index: {0}", i)); //OpenTK doesn't expose the GUID, even though it stores it internally...

OTK_GamePad ogp = new OTK_GamePad(i);
Devices.Add(ogp);
}
}

}

public static void UpdateAll()
{
foreach (var device in Devices)
device.Update();
}

public static void CloseAll()
{
if (Devices != null)
{
Devices.Clear();
}
}

// ********************************** Instance Members **********************************

readonly Guid _guid;
readonly int _stickIdx;
JoystickState state = new JoystickState();

OTK_GamePad(int index)
{
_guid = Guid.NewGuid();
_stickIdx = index;
Update();
InitializeCallbacks();
}

public void Update()
{
state = Joystick.GetState(_stickIdx);
}

public IEnumerable<Tuple<string, float>> GetFloats()
{
for (int pi = 0; pi < 64; pi++)
yield return new Tuple<string, float>(pi.ToString(), 10.0f * state.GetAxis(pi));
}

/// <summary>FOR DEBUGGING ONLY</summary>
public JoystickState GetInternalState()
{
return state;
}

public string Name { get { return "Joystick " + _stickIdx; } }
public Guid Guid { get { return _guid; } }


public string ButtonName(int index)
{
return names[index];
}
public bool Pressed(int index)
{
return actions[index]();
}
public int NumButtons { get; private set; }

private readonly List<string> names = new List<string>();
private readonly List<Func<bool>> actions = new List<Func<bool>>();

void AddItem(string _name, Func<bool> callback)
{
names.Add(_name);
actions.Add(callback);
NumButtons++;
}

void InitializeCallbacks()
{
const int dzp = 400;
const int dzn = -400;

names.Clear();
actions.Clear();
NumButtons = 0;

AddItem("X+", () => state.GetAxis(0) >= dzp);
AddItem("X-", () => state.GetAxis(0) <= dzn);
AddItem("Y+", () => state.GetAxis(1) >= dzp);
AddItem("Y-", () => state.GetAxis(1) <= dzn);
AddItem("Z+", () => state.GetAxis(2) >= dzp);
AddItem("Z-", () => state.GetAxis(2) <= dzn);

// Enjoy our delicious sliders. They're smaller than regular burgers but cost more.

int jb = 1;
for (int i = 0; i < 64; i++)
{
AddItem(string.Format("B{0}", jb), () => state.GetButton(i)==ButtonState.Pressed);
jb++;
}

jb = 1;
foreach (JoystickHat enval in Enum.GetValues(typeof(JoystickHat)))
{
AddItem(string.Format("POV{0}U", jb), () => state.GetHat(enval).IsUp);
AddItem(string.Format("POV{0}D", jb), () => state.GetHat(enval).IsDown);
AddItem(string.Format("POV{0}L", jb), () => state.GetHat(enval).IsLeft);
AddItem(string.Format("POV{0}R", jb), () => state.GetHat(enval).IsRight);
jb++;
}
}

// Note that this does not appear to work at this time. I probably need to have more infos.
public void SetVibration(int left, int right)
{
//Not supported in OTK Joystick. It is supported for OTK Gamepad, but I have to use Joystick for reasons mentioned above.
}

}
}

90 changes: 90 additions & 0 deletions BizHawk.Client.EmuHawk/Input/OTK_Keyboard.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
using System.Collections.Generic;
using System.Text;
using OpenTK.Input;

namespace BizHawk.Client.EmuHawk
{
public static class OTK_Keyboard
{
private static OpenTK.Input.KeyboardState _kbState;

public static void Initialize ()
{
_kbState = OpenTK.Input.Keyboard.GetState();
}

public static void Update ()
{
try
{
_kbState = OpenTK.Input.Keyboard.GetState();
}
catch
{
//OpenTK's keyboard class isn't thread safe.
//In rare cases (sometimes it takes up to 10 minutes to occur) it will
//be updating the keyboard state when we call GetState() and choke.
//Until I fix OpenTK, it's fine to just swallow it because input continues working.
if(System.Diagnostics.Debugger.IsAttached)
{
System.Console.WriteLine("OpenTK Keyboard thread is angry.");
}
}
}

public static bool IsPressed (Key key)
{
return _kbState.IsKeyDown(key);
}

public static bool ShiftModifier {
get {
return IsPressed(Key.ShiftLeft) || IsPressed(Key.ShiftRight);
}
}

public static bool CtrlModifier {
get {
return IsPressed(Key.ControlLeft) || IsPressed(Key.ControlRight);
}
}

public static bool AltModifier {
get {
return IsPressed(Key.AltLeft) || IsPressed(Key.AltRight);
}
}

public static Input.ModifierKey GetModifierKeysAsKeys ()
{
Input.ModifierKey ret = Input.ModifierKey.None;
if (ShiftModifier)
ret |= Input.ModifierKey.Shift;
if (CtrlModifier)
ret |= Input.ModifierKey.Control;
if (AltModifier)
ret |= Input.ModifierKey.Alt;
return ret;
}
}

internal static class KeyExtensions
{
public static bool IsModifier (this Key key)
{
if (key == Key.ShiftLeft)
return true;
if (key == Key.ShiftRight)
return true;
if (key == Key.ControlLeft)
return true;
if (key == Key.ControlRight)
return true;
if (key == Key.AltLeft)
return true;
if (key == Key.AltRight)
return true;
return false;
}
}
}
Loading