Update to v094r24 release.

byuu says:

Finally!! Compilation works once again on Windows.

However, it's pretty buggy. Modality isn't really working right, you can
still poke at other windows, but when you select ListView items, they
redraw as empty boxes (need to process WM_DRAWITEM before checking
modality.)

The program crashes when you close it (probably a ruby driver's term()
function, that's what it usually is.)

The Layout::setEnabled(false) call isn't working right, so you get that
annoying chiming sound and cursor movement when mapping keyboard keys to
game inputs.

The column sizing seems off a bit on first display for the Hotkeys tab.

And probably lots more.
This commit is contained in:
Tim Allen
2015-06-12 23:14:38 +10:00
parent 314aee8c5c
commit f0c17ffc0d
188 changed files with 5474 additions and 3834 deletions

View File

@@ -3,13 +3,13 @@
namespace ruby {
BOOL CALLBACK DirectInput_EnumJoypadsCallback(const DIDEVICEINSTANCE* instance, void* p);
BOOL CALLBACK DirectInput_EnumJoypadAxesCallback(const DIDEVICEOBJECTINSTANCE* instance, void* p);
BOOL CALLBACK DirectInput_EnumJoypadEffectsCallback(const DIDEVICEOBJECTINSTANCE* instance, void* p);
auto CALLBACK DirectInput_EnumJoypadsCallback(const DIDEVICEINSTANCE* instance, void* p) -> BOOL;
auto CALLBACK DirectInput_EnumJoypadAxesCallback(const DIDEVICEOBJECTINSTANCE* instance, void* p) -> BOOL;
auto CALLBACK DirectInput_EnumJoypadEffectsCallback(const DIDEVICEOBJECTINSTANCE* instance, void* p) -> BOOL;
struct InputJoypadDirectInput {
struct Joypad {
HID::Joypad hid;
shared_pointer<HID::Joypad> hid{new HID::Joypad};
LPDIRECTINPUTDEVICE8 device = nullptr;
LPDIRECTINPUTEFFECT effect = nullptr;
@@ -27,14 +27,14 @@ struct InputJoypadDirectInput {
bool xinputAvailable = false;
unsigned effects = 0;
void assign(HID::Joypad& hid, unsigned groupID, unsigned inputID, int16_t value) {
auto& group = hid.group[groupID];
if(group.input[inputID].value == value) return;
if(input.onChange) input.onChange(hid, groupID, inputID, group.input[inputID].value, value);
group.input[inputID].value = value;
auto assign(shared_pointer<HID::Joypad> hid, unsigned groupID, unsigned inputID, int16_t value) -> void {
auto& group = hid->group(groupID);
if(group.input(inputID).value() == value) return;
if(input.onChange) input.onChange(hid, groupID, inputID, group.input(inputID).value(), value);
group.input(inputID).setValue(value);
}
void poll(vector<HID::Device*>& devices) {
auto poll(vector<shared_pointer<HID::Device>>& devices) -> void {
for(auto& jp : joypads) {
if(FAILED(jp.device->Poll())) jp.device->Acquire();
@@ -68,13 +68,13 @@ struct InputJoypadDirectInput {
assign(jp.hid, HID::Joypad::GroupID::Button, n, (bool)state.rgbButtons[n]);
}
devices.append(&jp.hid);
devices.append(jp.hid);
}
}
bool rumble(uint64_t id, bool enable) {
auto rumble(uint64_t id, bool enable) -> bool {
for(auto& jp : joypads) {
if(jp.hid.id != id) continue;
if(jp.hid->id() != id) continue;
if(jp.effect == nullptr) continue;
if(enable) jp.effect->Start(1, 0);
@@ -85,7 +85,7 @@ struct InputJoypadDirectInput {
return false;
}
bool init(uintptr_t handle, LPDIRECTINPUT8 context, bool xinputAvailable) {
auto init(uintptr_t handle, LPDIRECTINPUT8 context, bool xinputAvailable) -> bool {
this->handle = handle;
this->context = context;
this->xinputAvailable = xinputAvailable;
@@ -93,7 +93,7 @@ struct InputJoypadDirectInput {
return true;
}
void term() {
auto term() -> void {
for(auto& jp : joypads) {
jp.device->Unacquire();
if(jp.effect) jp.effect->Release();
@@ -103,7 +103,7 @@ struct InputJoypadDirectInput {
context = nullptr;
}
bool initJoypad(const DIDEVICEINSTANCE* instance) {
auto initJoypad(const DIDEVICEINSTANCE* instance) -> bool {
Joypad jp;
jp.vendorID = instance->guidProduct.Data1 >> 0;
jp.productID = instance->guidProduct.Data1 >> 16;
@@ -127,7 +127,7 @@ struct InputJoypadDirectInput {
effects = 0;
device->EnumObjects(DirectInput_EnumJoypadAxesCallback, (void*)this, DIDFT_ABSAXIS);
device->EnumObjects(DirectInput_EnumJoypadEffectsCallback, (void*)this, DIDFT_FFACTUATOR);
jp.hid.rumble = effects > 0;
jp.hid->setRumble(effects > 0);
DIPROPGUIDANDPATH property;
memset(&property, 0, sizeof(DIPROPGUIDANDPATH));
@@ -138,9 +138,9 @@ struct InputJoypadDirectInput {
device->GetProperty(DIPROP_GUIDANDPATH, &property.diph);
string devicePath = (const char*)utf8_t(property.wszPath);
jp.pathID = Hash::CRC32(devicePath.data(), devicePath.size()).value();
jp.hid.id = (uint64_t)jp.pathID << 32 | jp.vendorID << 16 | jp.productID << 0;
jp.hid->setID((uint64_t)jp.pathID << 32 | jp.vendorID << 16 | jp.productID << 0);
if(jp.hid.rumble) {
if(jp.hid->rumble()) {
//disable auto-centering spring for rumble support
DIPROPDWORD property;
memset(&property, 0, sizeof(DIPROPDWORD));
@@ -174,15 +174,15 @@ struct InputJoypadDirectInput {
device->CreateEffect(GUID_ConstantForce, &effect, &jp.effect, NULL);
}
for(unsigned n = 0; n < 6; n++) jp.hid.axis().append({n});
for(unsigned n = 0; n < 8; n++) jp.hid.hat().append({n});
for(unsigned n = 0; n < 128; n++) jp.hid.button().append({n});
for(unsigned n = 0; n < 6; n++) jp.hid->axes().append(n);
for(unsigned n = 0; n < 8; n++) jp.hid->hats().append(n);
for(unsigned n = 0; n < 128; n++) jp.hid->buttons().append(n);
joypads.append(jp);
return DIENUM_CONTINUE;
}
bool initAxis(const DIDEVICEOBJECTINSTANCE* instance) {
auto initAxis(const DIDEVICEOBJECTINSTANCE* instance) -> bool {
DIPROPRANGE range;
memset(&range, 0, sizeof(DIPROPRANGE));
range.diph.dwSize = sizeof(DIPROPRANGE);
@@ -195,21 +195,21 @@ struct InputJoypadDirectInput {
return DIENUM_CONTINUE;
}
bool initEffect(const DIDEVICEOBJECTINSTANCE* instance) {
auto initEffect(const DIDEVICEOBJECTINSTANCE* instance) -> bool {
effects++;
return DIENUM_CONTINUE;
}
};
BOOL CALLBACK DirectInput_EnumJoypadsCallback(const DIDEVICEINSTANCE* instance, void* p) {
auto CALLBACK DirectInput_EnumJoypadsCallback(const DIDEVICEINSTANCE* instance, void* p) -> BOOL {
return ((InputJoypadDirectInput*)p)->initJoypad(instance);
}
BOOL CALLBACK DirectInput_EnumJoypadAxesCallback(const DIDEVICEOBJECTINSTANCE* instance, void* p) {
auto CALLBACK DirectInput_EnumJoypadAxesCallback(const DIDEVICEOBJECTINSTANCE* instance, void* p) -> BOOL {
return ((InputJoypadDirectInput*)p)->initAxis(instance);
}
BOOL CALLBACK DirectInput_EnumJoypadEffectsCallback(const DIDEVICEOBJECTINSTANCE* instance, void* p) {
auto CALLBACK DirectInput_EnumJoypadEffectsCallback(const DIDEVICEOBJECTINSTANCE* instance, void* p) -> BOOL {
return ((InputJoypadDirectInput*)p)->initEffect(instance);
}

View File

@@ -27,19 +27,19 @@ struct InputJoypadXInput {
pXInputSetState XInputSetState = nullptr;
struct Joypad {
HID::Joypad hid;
unsigned id;
shared_pointer<HID::Joypad> hid{new HID::Joypad};
unsigned id = 0;
};
vector<Joypad> joypads;
void assign(HID::Joypad& hid, unsigned groupID, unsigned inputID, int16_t value) {
auto& group = hid.group[groupID];
if(group.input[inputID].value == value) return;
if(input.onChange) input.onChange(hid, groupID, inputID, group.input[inputID].value, value);
group.input[inputID].value = value;
auto assign(shared_pointer<HID::Joypad> hid, unsigned groupID, unsigned inputID, int16_t value) -> void {
auto& group = hid->group(groupID);
if(group.input(inputID).value() == value) return;
if(input.onChange) input.onChange(hid, groupID, inputID, group.input(inputID).value(), value);
group.input(inputID).setValue(value);
}
void poll(vector<HID::Device*>& devices) {
auto poll(vector<shared_pointer<HID::Device>>& devices) -> void {
for(auto& jp : joypads) {
XINPUT_STATE state;
if(XInputGetStateEx(jp.id, &state) != ERROR_SUCCESS) continue;
@@ -83,13 +83,13 @@ struct InputJoypadXInput {
assign(jp.hid, HID::Joypad::GroupID::Button, 9, (bool)(state.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_THUMB));
assign(jp.hid, HID::Joypad::GroupID::Button, 10, (bool)(state.Gamepad.wButtons & XINPUT_GAMEPAD_GUIDE));
devices.append(&jp.hid);
devices.append(jp.hid);
}
}
bool rumble(uint64_t id, bool enable) {
auto rumble(uint64_t id, bool enable) -> bool {
for(auto& jp : joypads) {
if(jp.hid.id != id) continue;
if(jp.hid->id() != id) continue;
XINPUT_VIBRATION vibration;
memset(&vibration, 0, sizeof(XINPUT_VIBRATION));
@@ -102,7 +102,7 @@ struct InputJoypadXInput {
return false;
}
bool init() {
auto init() -> bool {
if(!libxinput) libxinput = LoadLibraryA("xinput1_3.dll");
if(!libxinput) return false;
@@ -118,30 +118,31 @@ struct InputJoypadXInput {
for(unsigned id = 0; id < 4; id++) {
Joypad jp;
jp.id = id;
jp.hid.id = (uint64_t)(1 + id) << 32 | 0x045e << 16 | 0x028e << 0; //Xbox 360 Player# + VendorID + ProductID
jp.hid->setID((uint64_t)(1 + id) << 32 | 0x045e << 16 | 0x028e << 0); //Xbox 360 Player# + VendorID + ProductID
jp.hid->setRumble(true);
jp.hid.axis().append({"LeftThumbX"});
jp.hid.axis().append({"LeftThumbY"});
jp.hid.axis().append({"RightThumbX"});
jp.hid.axis().append({"RightThumbY"});
jp.hid->axes().append("LeftThumbX");
jp.hid->axes().append("LeftThumbY");
jp.hid->axes().append("RightThumbX");
jp.hid->axes().append("RightThumbY");
jp.hid.hat().append({"HatX"});
jp.hid.hat().append({"HatY"});
jp.hid->hats().append("HatX");
jp.hid->hats().append("HatY");
jp.hid.trigger().append({"LeftTrigger"});
jp.hid.trigger().append({"RightTrigger"});
jp.hid->triggers().append("LeftTrigger");
jp.hid->triggers().append("RightTrigger");
jp.hid.button().append({"A"});
jp.hid.button().append({"B"});
jp.hid.button().append({"X"});
jp.hid.button().append({"Y"});
jp.hid.button().append({"Back"});
jp.hid.button().append({"Start"});
jp.hid.button().append({"LeftShoulder"});
jp.hid.button().append({"RightShoulder"});
jp.hid.button().append({"LeftThumb"});
jp.hid.button().append({"RightThumb"});
jp.hid.button().append({"Guide"});
jp.hid->buttons().append("A");
jp.hid->buttons().append("B");
jp.hid->buttons().append("X");
jp.hid->buttons().append("Y");
jp.hid->buttons().append("Back");
jp.hid->buttons().append("Start");
jp.hid->buttons().append("LeftShoulder");
jp.hid->buttons().append("RightShoulder");
jp.hid->buttons().append("LeftThumb");
jp.hid->buttons().append("RightThumb");
jp.hid->buttons().append("Guide");
joypads.append(jp);
}
@@ -149,7 +150,7 @@ struct InputJoypadXInput {
return true;
}
void term() {
auto term() -> void {
if(!libxinput) return;
FreeLibrary(libxinput);

View File

@@ -13,10 +13,10 @@ struct InputKeyboardRawInput {
vector<Key> keys;
struct Keyboard {
HID::Keyboard hid;
shared_pointer<HID::Keyboard> hid{new HID::Keyboard};
} kb;
void update(RAWINPUT* input) {
auto update(RAWINPUT* input) -> void {
unsigned code = input->data.keyboard.MakeCode;
unsigned flag = input->data.keyboard.Flags;
@@ -26,19 +26,19 @@ struct InputKeyboardRawInput {
}
}
void assign(unsigned inputID, bool value) {
auto& group = kb.hid.group[HID::Keyboard::GroupID::Button];
if(group.input[inputID].value == value) return;
if(input.onChange) input.onChange(kb.hid, HID::Keyboard::GroupID::Button, inputID, group.input[inputID].value, value);
group.input[inputID].value = value;
auto assign(unsigned inputID, bool value) -> void {
auto& group = kb.hid->buttons();
if(group.input(inputID).value() == value) return;
if(input.onChange) input.onChange(kb.hid, HID::Keyboard::GroupID::Button, inputID, group.input(inputID).value(), value);
group.input(inputID).setValue(value);
}
void poll(vector<HID::Device*>& devices) {
auto poll(vector<shared_pointer<HID::Device>>& devices) -> void {
for(unsigned n = 0; n < keys.size(); n++) assign(n, keys[n].value);
devices.append(&kb.hid);
devices.append(kb.hid);
}
bool init() {
auto init() -> bool {
rawinput.updateKeyboard = {&InputKeyboardRawInput::update, this};
//Pause sends 0x001d,4 + 0x0045,0; NumLock sends only 0x0045,0
@@ -163,8 +163,8 @@ struct InputKeyboardRawInput {
keys.append({0x005c, 2, "RightSuper"});
keys.append({0x005d, 2, "Menu"});
kb.hid.id = 1;
for(auto& key : keys) kb.hid.button().append({key.name});
kb.hid->setID(1);
for(auto& key : keys) kb.hid->buttons().append(key.name);
return true;
}

View File

@@ -8,7 +8,7 @@ struct InputMouseRawInput {
bool mouseAcquired = false;
struct Mouse {
HID::Mouse hid;
shared_pointer<HID::Mouse> hid{new HID::Mouse};
signed relativeX = 0;
signed relativeY = 0;
@@ -16,7 +16,7 @@ struct InputMouseRawInput {
bool buttons[5] = {0};
} ms;
bool acquire() {
auto acquire() -> bool {
if(mouseAcquired == false) {
mouseAcquired = true;
ShowCursor(false);
@@ -24,17 +24,17 @@ struct InputMouseRawInput {
return true;
}
bool unacquire() {
auto unacquire() -> bool {
if(mouseAcquired == true) {
mouseAcquired = false;
ReleaseCapture();
ClipCursor(NULL);
ClipCursor(nullptr);
ShowCursor(true);
}
return true;
}
bool acquired() {
auto acquired() -> bool {
if(mouseAcquired == true) {
SetFocus((HWND)handle);
SetCapture((HWND)handle);
@@ -45,7 +45,7 @@ struct InputMouseRawInput {
return GetCapture() == (HWND)handle;
}
void update(RAWINPUT* input) {
auto update(RAWINPUT* input) -> void {
if((input->data.mouse.usFlags & 1) == MOUSE_MOVE_RELATIVE) {
ms.relativeX += input->data.mouse.lLastX;
ms.relativeY += input->data.mouse.lLastY;
@@ -67,14 +67,14 @@ struct InputMouseRawInput {
if(input->data.mouse.usButtonFlags & RI_MOUSE_BUTTON_5_UP ) ms.buttons[4] = 0;
}
void assign(unsigned groupID, unsigned inputID, int16_t value) {
auto& group = ms.hid.group[groupID];
if(group.input[inputID].value == value) return;
if(input.onChange) input.onChange(ms.hid, groupID, inputID, group.input[inputID].value, value);
group.input[inputID].value = value;
auto assign(unsigned groupID, unsigned inputID, int16_t value) -> void {
auto& group = ms.hid->group(groupID);
if(group.input(inputID).value() == value) return;
if(input.onChange) input.onChange(ms.hid, groupID, inputID, group.input(inputID).value(), value);
group.input(inputID).setValue(value);
}
void poll(vector<HID::Device*>& devices) {
auto poll(vector<shared_pointer<HID::Device>>& devices) -> void {
assign(HID::Mouse::GroupID::Axis, 0, ms.relativeX);
assign(HID::Mouse::GroupID::Axis, 1, ms.relativeY);
assign(HID::Mouse::GroupID::Axis, 2, ms.relativeZ);
@@ -91,29 +91,29 @@ struct InputMouseRawInput {
ms.relativeY = 0;
ms.relativeZ = 0;
devices.append(&ms.hid);
devices.append(ms.hid);
}
bool init(uintptr_t handle) {
auto init(uintptr_t handle) -> bool {
this->handle = handle;
ms.hid.id = 2;
ms.hid->setID(2);
ms.hid.axis().append({"X"});
ms.hid.axis().append({"Y"});
ms.hid.axis().append({"Z"});
ms.hid->axes().append("X");
ms.hid->axes().append("Y");
ms.hid->axes().append("Z");
ms.hid.button().append({"Left"});
ms.hid.button().append({"Middle"});
ms.hid.button().append({"Right"});
ms.hid.button().append({"Up"});
ms.hid.button().append({"Down"});
ms.hid->buttons().append("Left");
ms.hid->buttons().append("Middle");
ms.hid->buttons().append("Right");
ms.hid->buttons().append("Up");
ms.hid->buttons().append("Down");
rawinput.updateMouse = {&InputMouseRawInput::update, this};
return true;
}
void term() {
auto term() -> void {
unacquire();
}
};

View File

@@ -3,18 +3,18 @@
namespace ruby {
LRESULT CALLBACK RawInputWindowProc(HWND, UINT, WPARAM, LPARAM);
auto CALLBACK RawInputWindowProc(HWND, UINT, WPARAM, LPARAM) -> LRESULT;
struct RawInput {
HANDLE mutex;
HWND hwnd;
HANDLE mutex = nullptr;
HWND hwnd = nullptr;
bool ready = false;
bool initialized = false;
function<void (RAWINPUT*)> updateKeyboard;
function<void (RAWINPUT*)> updateMouse;
struct Device {
HANDLE handle;
HANDLE handle = nullptr;
string path;
enum class Type : unsigned { Keyboard, Mouse, Joypad } type;
uint16_t vendorID = 0;
@@ -23,14 +23,14 @@ struct RawInput {
};
vector<Device> devices;
maybe<Device&> find(uint16_t vendorID, uint16_t productID) {
auto find(uint16_t vendorID, uint16_t productID) -> maybe<Device&> {
for(auto& device : devices) {
if(device.vendorID == vendorID && device.productID == productID) return device;
}
return nothing;
}
void scanDevices() {
auto scanDevices() -> void {
devices.reset();
unsigned deviceCount = 0;
@@ -79,7 +79,7 @@ struct RawInput {
delete[] list;
}
LRESULT windowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
auto windowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) -> LRESULT {
if(msg != WM_INPUT) return DefWindowProc(hwnd, msg, wparam, lparam);
unsigned size = 0;
@@ -102,7 +102,7 @@ struct RawInput {
return result;
}
void main() {
auto main() -> void {
WNDCLASS wc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
@@ -148,12 +148,12 @@ struct RawInput {
static RawInput rawinput;
DWORD WINAPI RawInputThreadProc(void*) {
auto WINAPI RawInputThreadProc(void*) -> DWORD {
rawinput.main();
return 0;
}
LRESULT CALLBACK RawInputWindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
auto CALLBACK RawInputWindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) -> LRESULT {
return rawinput.windowProc(hwnd, msg, wparam, lparam);
}

View File

@@ -22,7 +22,11 @@ struct pInputWindows {
uintptr_t handle = 0;
} settings;
bool cap(const string& name) {
~pInputWindows() {
term();
}
auto cap(const string& name) -> bool {
if(name == Input::Handle) return true;
if(name == Input::KeyboardSupport) return true;
if(name == Input::MouseSupport) return true;
@@ -31,33 +35,33 @@ struct pInputWindows {
return false;
}
any get(const string& name) {
auto get(const string& name) -> any {
if(name == Input::Handle) return (uintptr_t)settings.handle;
return false;
return {};
}
bool set(const string& name, const any& value) {
if(name == Input::Handle) {
settings.handle = any_cast<uintptr_t>(value);
auto set(const string& name, const any& value) -> bool {
if(name == Input::Handle && value.is<uintptr_t>()) {
settings.handle = value.get<uintptr_t>();
return true;
}
return false;
}
bool acquire() {
auto acquire() -> bool {
return rawinputMouse.acquire();
}
bool unacquire() {
auto unacquire() -> bool {
return rawinputMouse.unacquire();
}
bool acquired() {
auto acquired() -> bool {
return rawinputMouse.acquired();
}
vector<HID::Device*> poll() {
vector<HID::Device*> devices;
auto poll() -> vector<shared_pointer<HID::Device>> {
vector<shared_pointer<HID::Device>> devices;
rawinputKeyboard.poll(devices);
rawinputMouse.poll(devices);
xinput.poll(devices);
@@ -65,13 +69,13 @@ struct pInputWindows {
return devices;
}
bool rumble(uint64_t id, bool enable) {
auto rumble(uint64_t id, bool enable) -> bool {
if(xinput.rumble(id, enable)) return true;
if(directinput.rumble(id, enable)) return true;
return false;
}
bool init() {
auto init() -> bool {
if(rawinput.initialized == false) {
rawinput.initialized = true;
rawinput.mutex = CreateMutex(NULL, FALSE, NULL);
@@ -94,7 +98,7 @@ struct pInputWindows {
return true;
}
void term() {
auto term() -> void {
rawinputKeyboard.term();
rawinputMouse.term();
xinput.term();