mirror of
https://github.com/XProger/OpenLara.git
synced 2025-08-05 20:57:46 +02:00
add rumble effect for GCW0
This commit is contained in:
@@ -179,7 +179,7 @@ static const OptionItem optSound[] = {
|
|||||||
#define INV_CTRL_START_OPTION 2
|
#define INV_CTRL_START_OPTION 2
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(_OS_WIN) || defined(_OS_LINUX) || defined(_OS_RPI)
|
#if defined(_OS_WIN) || defined(_OS_LINUX) || defined(_OS_RPI) || defined(_OS_GCW0)
|
||||||
#define INV_VIBRATION
|
#define INV_VIBRATION
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@@ -1,3 +1,3 @@
|
|||||||
set -e
|
set -e
|
||||||
/opt/gcw0-toolchain/usr/bin/mipsel-gcw0-linux-uclibc-g++ -o OpenLara -D__GCW0__ -std=c++11 -Os -s -g0 -mips32r2 -fno-exceptions -fno-rtti -ffunction-sections -fdata-sections -Wl,--gc-sections -Wno-invalid-source-encoding main.cpp ../../libs/stb_vorbis/stb_vorbis.c ../../libs/minimp3/minimp3.cpp ../../libs/tinf/tinflate.c -I/opt/vc/include -I../../ -L/opt/vc/lib/ -lGLESv2 -lEGL -lm -lrt -lpthread -lasound -ludev
|
/opt/gcw0-toolchain/usr/bin/mipsel-gcw0-linux-uclibc-g++ -o OpenLara -D__GCW0__ -std=c++11 -Os -s -g0 -mips32r2 -fno-exceptions -fno-rtti -ffunction-sections -fdata-sections -Wl,--gc-sections -Wno-invalid-source-encoding main.cpp ../../libs/stb_vorbis/stb_vorbis.c ../../libs/minimp3/minimp3.cpp ../../libs/tinf/tinflate.c -I/opt/vc/include -I../../ -L/opt/vc/lib/ -lGLESv2 -lEGL -lm -lpthread -lasound
|
||||||
/opt/gcw0-toolchain/usr/bin/mipsel-gcw0-linux-uclibc-strip ../../../bin/OpenLara --strip-all --remove-section=.comment --remove-section=.note
|
/opt/gcw0-toolchain/usr/bin/mipsel-gcw0-linux-uclibc-strip ../../../bin/OpenLara --strip-all --remove-section=.comment --remove-section=.note
|
||||||
|
@@ -10,7 +10,6 @@
|
|||||||
#include <EGL/egl.h>
|
#include <EGL/egl.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <linux/input.h>
|
#include <linux/input.h>
|
||||||
#include <libudev.h>
|
|
||||||
#include <alsa/asoundlib.h>
|
#include <alsa/asoundlib.h>
|
||||||
|
|
||||||
#include "game.h"
|
#include "game.h"
|
||||||
@@ -208,23 +207,44 @@ void eglFree() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Input
|
// Input
|
||||||
#define MAX_INPUT_DEVICES 16
|
int ev_buttons;
|
||||||
struct InputDevice {
|
int ev_haptic;
|
||||||
int fd;
|
ff_effect joy_ff;
|
||||||
} inputDevices[MAX_INPUT_DEVICES];
|
|
||||||
|
|
||||||
udev *udevObj;
|
#define JOY_RUMBLE_TIMER 50
|
||||||
udev_monitor *udevMon;
|
#define JOY_RUMBLE_GAIN 0xFFFF
|
||||||
int udevMon_fd;
|
|
||||||
|
|
||||||
vec2 joyL, joyR;
|
vec2 joyL, joyR;
|
||||||
|
float joyVGain, joyVGainOld;
|
||||||
|
int joyVTime;
|
||||||
|
|
||||||
bool osJoyReady(int index) {
|
bool osJoyReady(int index) {
|
||||||
return index == 0; // TODO
|
return index == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void osJoyVibrate(int index, float L, float R) {
|
void osJoyVibrate(int index, float L, float R) {
|
||||||
// TODO
|
if (ev_haptic == -1) return;
|
||||||
|
joyVGain = (L + R) * 0.5f;
|
||||||
|
}
|
||||||
|
|
||||||
|
float joyAxisValue(int value) {
|
||||||
|
return value / 1536.0f - 1.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
vec2 joyDir(const vec2 &value) {
|
||||||
|
float dist = min(1.0f, value.length());
|
||||||
|
return value.normal() * dist;
|
||||||
|
}
|
||||||
|
|
||||||
|
void joyRumble() {
|
||||||
|
if (joy_ff.id == -1 || joyVGain == joyVGainOld || osGetTimeMS() < joyVTime)
|
||||||
|
return;
|
||||||
|
|
||||||
|
joy_ff.u.rumble.strong_magnitude = int(JOY_RUMBLE_GAIN * joyVGain);
|
||||||
|
ioctl(ev_haptic, EVIOCSFF, &joy_ff);
|
||||||
|
|
||||||
|
joyVGainOld = joyVGain;
|
||||||
|
joyVTime = osGetTimeMS() + JOY_RUMBLE_TIMER;
|
||||||
}
|
}
|
||||||
|
|
||||||
JoyKey codeToJoyKey(int code) {
|
JoyKey codeToJoyKey(int code) {
|
||||||
@@ -254,85 +274,66 @@ JoyKey codeToJoyKey(int code) {
|
|||||||
return jkNone;
|
return jkNone;
|
||||||
}
|
}
|
||||||
|
|
||||||
int inputDevIndex(const char *node) {
|
void inputInit() {
|
||||||
const char *str = strstr(node, "/event");
|
joyL = joyR = vec2(0.0f);
|
||||||
if (str)
|
joyVGain = 0.0f;
|
||||||
return atoi(str + 6);
|
joyVGainOld = 0.0f;
|
||||||
return -1;
|
joyVTime = osGetTimeMS();
|
||||||
}
|
|
||||||
|
|
||||||
void inputDevAdd(const char *node, udev_device *device) {
|
memset(&joy_ff, 0, sizeof(joy_ff));
|
||||||
int index = inputDevIndex(node);
|
joy_ff.id = -1;
|
||||||
if (index != -1) {
|
|
||||||
InputDevice &item = inputDevices[index];
|
|
||||||
item.fd = open(node, O_RDONLY | O_NONBLOCK);
|
|
||||||
//ioctl(item.fd, EVIOCGRAB, 1);
|
|
||||||
//LOG("input: add %s (%d)\n", node, item.joyIndex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool inputInit() {
|
// TODO find compatible device instead of hardcode
|
||||||
joyL = joyR = vec2(0);
|
ev_buttons = open("/dev/input/event3", O_NONBLOCK | O_RDONLY);
|
||||||
|
ev_haptic = open("/dev/input/event1", O_RDWR);
|
||||||
|
|
||||||
for (int i = 0; i < MAX_INPUT_DEVICES; i++) {
|
if (ev_buttons == -1) {
|
||||||
inputDevices[i].fd = -1;
|
LOG("! input device was not found\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
udevObj = udev_new();
|
if (ev_haptic == -1) {
|
||||||
if (!udevObj)
|
LOG("! haptic device was not found\n");
|
||||||
return false;
|
} else {
|
||||||
|
joy_ff.type = FF_RUMBLE;
|
||||||
|
joy_ff.id = -1;
|
||||||
|
joy_ff.replay.length = 0;
|
||||||
|
joy_ff.replay.delay = 0;
|
||||||
|
joy_ff.u.rumble.strong_magnitude = 0x8000;
|
||||||
|
joy_ff.u.rumble.weak_magnitude = 0;
|
||||||
|
|
||||||
udevMon = udev_monitor_new_from_netlink(udevObj, "udev");
|
if (ioctl(ev_haptic, EVIOCSFF, &joy_ff) != -1) {
|
||||||
udev_monitor_filter_add_match_subsystem_devtype(udevMon, "input", NULL);
|
input_event gain;
|
||||||
udev_monitor_enable_receiving(udevMon);
|
gain.type = EV_FF;
|
||||||
udevMon_fd = udev_monitor_get_fd(udevMon);
|
gain.code = FF_GAIN;
|
||||||
|
gain.value = JOY_RUMBLE_GAIN;
|
||||||
|
write(ev_haptic, &gain, sizeof(gain));
|
||||||
|
|
||||||
udev_enumerate *e = udev_enumerate_new(udevObj);
|
input_event state;
|
||||||
udev_enumerate_add_match_subsystem(e, "input");
|
state.type = EV_FF;
|
||||||
udev_enumerate_scan_devices(e);
|
state.code = joy_ff.id;
|
||||||
udev_list_entry *devices = udev_enumerate_get_list_entry(e);
|
state.value = 1; // play
|
||||||
|
write(ev_haptic, &state, sizeof(state));
|
||||||
udev_list_entry *entry;
|
} else {
|
||||||
udev_list_entry_foreach(entry, devices) {
|
LOG("! can't initialize vibration\n");
|
||||||
const char *path, *node;
|
close(ev_haptic);
|
||||||
udev_device *device;
|
ev_haptic = -1;
|
||||||
|
}
|
||||||
path = udev_list_entry_get_name(entry);
|
|
||||||
device = udev_device_new_from_syspath(udevObj, path);
|
|
||||||
node = udev_device_get_devnode(device);
|
|
||||||
|
|
||||||
if (node)
|
|
||||||
inputDevAdd(node, device);
|
|
||||||
}
|
}
|
||||||
udev_enumerate_unref(e);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void inputFree() {
|
void inputFree() {
|
||||||
for (int i = 0; i < MAX_INPUT_DEVICES; i++)
|
if (ev_buttons != -1) close(ev_buttons);
|
||||||
if (inputDevices[i].fd != -1)
|
if (ev_haptic != -1) close(ev_haptic);
|
||||||
close(inputDevices[i].fd);
|
|
||||||
udev_monitor_unref(udevMon);
|
|
||||||
udev_unref(udevObj);
|
|
||||||
}
|
|
||||||
|
|
||||||
float joyAxisValue(int value) {
|
|
||||||
return value / 1536.0f - 1.0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
vec2 joyDir(const vec2 &value) {
|
|
||||||
float dist = min(1.0f, value.length());
|
|
||||||
return value.normal() * dist;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void inputUpdate() {
|
void inputUpdate() {
|
||||||
// get input events
|
joyRumble();
|
||||||
input_event events[16];
|
|
||||||
|
|
||||||
for (int i = 0; i < MAX_INPUT_DEVICES; i++) {
|
if (ev_buttons == -1) return;
|
||||||
if (inputDevices[i].fd == -1) continue;
|
|
||||||
int rb = read(inputDevices[i].fd, events, sizeof(events));
|
input_event events[64];
|
||||||
|
|
||||||
|
int rb = read(ev_buttons, events, sizeof(events));
|
||||||
|
|
||||||
input_event *e = events;
|
input_event *e = events;
|
||||||
while (rb > 0) {
|
while (rb > 0) {
|
||||||
@@ -359,7 +360,6 @@ void inputUpdate() {
|
|||||||
e++;
|
e++;
|
||||||
rb -= sizeof(events[0]);
|
rb -= sizeof(events[0]);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
|
Reference in New Issue
Block a user