bsnes/ruby/input/windows.cpp
Tim Allen 5d135b556d Update to v106r53 release.
byuu says:

Okay, so the WIPs-within-WIPs thing wasn't achieving its desired effect,
and it ended up causing me to have to redo some work on hiro since my
last local snapshot was of r52. So, heck it. I'll just do mostly
non-functional WIPs for a bit, and worry about the fallout years later
when I'm trying to find an emulation regression and cursing that the
WIPs aren't compiling.

I ported all of the ruby input drivers to the new syntax, as well as the
OpenAL driver. If you patch the ruby drivers for Linux with this in
mind, bsnes should compile and run there again.

Also, the bsnes program icon has returned, now that the new hiro layout
code is mature enough and I can simply add and remove the icon as a
Canvas instead of having to try and render into a viewport. The icon
shows up instantly with the main window.
2018-08-01 19:07:28 +10:00

94 lines
2.7 KiB
C++

#include <xinput.h>
#define DIRECTINPUT_VERSION 0x0800
#include <dinput.h>
#include "shared/rawinput.cpp"
#include "keyboard/rawinput.cpp"
#include "mouse/rawinput.cpp"
#include "joypad/xinput.cpp"
#include "joypad/directinput.cpp"
struct InputWindows : InputDriver {
InputWindows(Input& driver) : InputDriver(super), keyboard(super), mouse(super), joypadXInput(super), joypadDirectInput(super) {}
~InputWindows() { terminate(); }
auto create() -> bool override {
return initialize();
}
auto driver() -> string override { return "Windows"; }
auto ready() -> bool override { return isReady; }
auto hasContext() -> bool override { return true; }
auto setContext(uintptr context) -> bool override { return initialize(); }
auto acquired() -> bool override { return mouse.acquired(); }
auto acquire() -> bool override { return mouse.acquire(); }
auto release() -> bool override { return mouse.release(); }
auto poll() -> vector<shared_pointer<HID::Device>> override {
vector<shared_pointer<HID::Device>> devices;
keyboard.poll(devices);
mouse.poll(devices);
joypadXInput.poll(devices);
joypadDirectInput.poll(devices);
return devices;
}
auto rumble(uint64_t id, bool enable) -> bool override {
if(joypadXInput.rumble(id, enable)) return true;
if(joypadDirectInput.rumble(id, enable)) return true;
return false;
}
private:
auto initialize() -> bool {
terminate();
if(!self.context) return false;
if(!rawinput.initialized) {
rawinput.initialized = true;
rawinput.mutex = CreateMutex(nullptr, false, nullptr);
CreateThread(nullptr, 0, RawInputThreadProc, 0, 0, nullptr);
do {
Sleep(1);
WaitForSingleObject(rawinput.mutex, INFINITE);
ReleaseMutex(rawinput.mutex);
} while(!rawinput.ready);
}
DirectInput8Create(GetModuleHandle(0), DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&directInputContext, 0);
if(!directInputContext) return false;
if(!keyboard.initialize()) return false;
if(!mouse.initialize(_context)) return false;
bool xinputAvailable = _joypadXInput.initialize();
if(!joypadDirectInput.initialize(self.context, directInputContext, xinputAvailable)) return false;
return isReady = true;
}
auto terminate() -> void {
isReady = false;
keyboard.terminate();
mouse.terminate();
joypadXInput.terminate();
joypadDirectInput.terminate();
if(directInputContext) {
directInputContext->Release();
directInputContext = nullptr;
}
}
InputWindows& self = *this;
bool isReady = false;
InputKeyboardRawInput keyboard;
InputMouseRawInput mouse;
InputJoypadXInput joypadXInput;
InputJoypadDirectInput joypadDirectInput;
LPDIRECTINPUT8 directInputContext = nullptr;
};