mirror of
https://github.com/XProger/OpenLara.git
synced 2025-08-11 23:54:09 +02:00
Merge branch 'master' of https://github.com/XProger/OpenLara
This commit is contained in:
@@ -277,21 +277,23 @@ void joyUpdate() {
|
|||||||
|
|
||||||
switch (event.number) {
|
switch (event.number) {
|
||||||
// Left stick
|
// Left stick
|
||||||
case 0 : joy.L.x = joyAxisValue(event.value); break;
|
case ABS_X : joy.L.x = joyAxisValue(event.value); break;
|
||||||
case 1 : joy.L.y = joyAxisValue(event.value); break;
|
case ABS_Y : joy.L.y = joyAxisValue(event.value); break;
|
||||||
// Right stick
|
// Right stick
|
||||||
case 3 : joy.R.x = joyAxisValue(event.value); break;
|
case ABS_RX : joy.R.x = joyAxisValue(event.value); break;
|
||||||
case 4 : joy.R.y = joyAxisValue(event.value); break;
|
case ABS_RY : joy.R.y = joyAxisValue(event.value); break;
|
||||||
// Left trigger
|
// Left trigger
|
||||||
case 2 : Input::setJoyPos(i, jkLT, joyTrigger(event.value)); break;
|
case ABS_Z : Input::setJoyPos(i, jkLT, joyTrigger(event.value)); break;
|
||||||
// Right trigger
|
// Right trigger
|
||||||
case 5 : Input::setJoyPos(i, jkRT, joyTrigger(event.value)); break;
|
case ABS_RZ : Input::setJoyPos(i, jkRT, joyTrigger(event.value)); break;
|
||||||
// D-PAD
|
// D-PAD
|
||||||
case 6 :
|
case ABS_HAT0X :
|
||||||
|
case ABS_THROTTLE :
|
||||||
Input::setJoyDown(i, jkLeft, event.value < -0x4000);
|
Input::setJoyDown(i, jkLeft, event.value < -0x4000);
|
||||||
Input::setJoyDown(i, jkRight, event.value > 0x4000);
|
Input::setJoyDown(i, jkRight, event.value > 0x4000);
|
||||||
break;
|
break;
|
||||||
case 7 :
|
case ABS_HAT0Y :
|
||||||
|
case ABS_RUDDER :
|
||||||
Input::setJoyDown(i, jkUp, event.value < -0x4000);
|
Input::setJoyDown(i, jkUp, event.value < -0x4000);
|
||||||
Input::setJoyDown(i, jkDown, event.value > 0x4000);
|
Input::setJoyDown(i, jkDown, event.value > 0x4000);
|
||||||
break;
|
break;
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <linux/input.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
@@ -200,7 +201,7 @@ int udevMon_fd;
|
|||||||
vec2 joyL, joyR;
|
vec2 joyL, joyR;
|
||||||
|
|
||||||
bool osJoyReady(int index) {
|
bool osJoyReady(int index) {
|
||||||
return true; // TODO
|
return index == 0; // TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
void osJoyVibrate(int index, float L, float R) {
|
void osJoyVibrate(int index, float L, float R) {
|
||||||
@@ -357,6 +358,23 @@ void inputFree() {
|
|||||||
udev_unref(udevObj);
|
udev_unref(udevObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define JOY_DEAD_ZONE_STICK 8192
|
||||||
|
|
||||||
|
float joyAxisValue(int value) {
|
||||||
|
if (value > -JOY_DEAD_ZONE_STICK && value < JOY_DEAD_ZONE_STICK)
|
||||||
|
return 0.0f;
|
||||||
|
return value / 32767.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
float joyTrigger(int value) {
|
||||||
|
return min(1.0f, value / 255.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
vec2 joyDir(const vec2 &value) {
|
||||||
|
float dist = min(1.0f, value.length());
|
||||||
|
return value.normal() * dist;
|
||||||
|
}
|
||||||
|
|
||||||
void inputUpdate() {
|
void inputUpdate() {
|
||||||
// get input events
|
// get input events
|
||||||
input_event events[16];
|
input_event events[16];
|
||||||
@@ -365,6 +383,8 @@ void inputUpdate() {
|
|||||||
if (inputDevices[i] == -1) continue;
|
if (inputDevices[i] == -1) continue;
|
||||||
int rb = read(inputDevices[i], events, sizeof(events));
|
int rb = read(inputDevices[i], events, sizeof(events));
|
||||||
|
|
||||||
|
int joyIndex = 0; // TODO: joy index
|
||||||
|
|
||||||
input_event *e = events;
|
input_event *e = events;
|
||||||
while (rb > 0) {
|
while (rb > 0) {
|
||||||
switch (e->type) {
|
switch (e->type) {
|
||||||
@@ -376,7 +396,7 @@ void inputUpdate() {
|
|||||||
Input::setDown(key, e->value != 0);
|
Input::setDown(key, e->value != 0);
|
||||||
} else {
|
} else {
|
||||||
JoyKey key = codeToJoyKey(e->code);
|
JoyKey key = codeToJoyKey(e->code);
|
||||||
Input::setJoyDown(0, key, e->value != 0);
|
Input::setJoyDown(joyIndex, key, e->value != 0);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -387,13 +407,32 @@ void inputUpdate() {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case EV_ABS : {
|
case EV_ABS : {
|
||||||
float v = float(e->value) / 128.0f - 1.0f;
|
|
||||||
switch (e->code) {
|
switch (e->code) {
|
||||||
case ABS_X : joyL.x = v; break;
|
// Left stick
|
||||||
case ABS_Y : joyL.y = v; break;
|
case ABS_X : joyL.x = joyAxisValue(e->value); break;
|
||||||
case ABS_Z : joyR.x = v; break;
|
case ABS_Y : joyL.y = joyAxisValue(e->value); break;
|
||||||
case ABS_RZ : joyR.y = v; break;
|
// Right stick
|
||||||
|
case ABS_RX : joyR.x = joyAxisValue(e->value); break;
|
||||||
|
case ABS_RY : joyR.y = joyAxisValue(e->value); break;
|
||||||
|
// Left trigger
|
||||||
|
case ABS_Z : Input::setJoyPos(joyIndex, jkLT, joyTrigger(e->value)); break;
|
||||||
|
// Right trigger
|
||||||
|
case ABS_RZ : Input::setJoyPos(joyIndex, jkRT, joyTrigger(e->value)); break;
|
||||||
|
// D-PAD
|
||||||
|
case ABS_HAT0X :
|
||||||
|
case ABS_THROTTLE :
|
||||||
|
Input::setJoyDown(joyIndex, jkLeft, e->value < 0);
|
||||||
|
Input::setJoyDown(joyIndex, jkRight, e->value > 0);
|
||||||
|
break;
|
||||||
|
case ABS_HAT0Y :
|
||||||
|
case ABS_RUDDER :
|
||||||
|
Input::setJoyDown(joyIndex, jkUp, e->value < 0);
|
||||||
|
Input::setJoyDown(joyIndex, jkDown, e->value > 0);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Input::setJoyPos(joyIndex, jkL, joyDir(joyL));
|
||||||
|
Input::setJoyPos(joyIndex, jkR, joyDir(joyR));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//LOG("input: type = %d, code = %d, value = %d\n", int(e->type), int(e->code), int(e->value));
|
//LOG("input: type = %d, code = %d, value = %d\n", int(e->type), int(e->code), int(e->value));
|
||||||
@@ -401,8 +440,7 @@ void inputUpdate() {
|
|||||||
rb -= sizeof(events[0]);
|
rb -= sizeof(events[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Input::setJoyPos(0, jkL, joyL);
|
|
||||||
Input::setJoyPos(0, jkR, joyR);
|
|
||||||
// monitoring plug and unplug input devices
|
// monitoring plug and unplug input devices
|
||||||
fd_set fds;
|
fd_set fds;
|
||||||
FD_ZERO(&fds);
|
FD_ZERO(&fds);
|
||||||
|
Reference in New Issue
Block a user