First real iteration of the API.

This commit is contained in:
2025-03-17 22:45:04 -04:00
parent c4c7b99f4c
commit 6b10887599
3 changed files with 63 additions and 7 deletions

View File

@@ -15,7 +15,6 @@ struct axis_state {
short x, y;
};
int js_handle;
bool js_connected;
struct js_event event;
@@ -29,7 +28,6 @@ short r_trigger;
Vector2 dpad;
/// Reads a joystick event from the joystick device.
/// @returns 0 on success. Otherwise -1 is returned.
int read_event(int fd, struct js_event *event) {
@@ -78,6 +76,7 @@ bool jstick::Connect(int hwid) {
}
js_connected = true;
JoystickConnected.Invoke(js_handle);
return true;
}
@@ -87,6 +86,7 @@ bool jstick::Disconnect(int hwid) {
return false;
}
close(js_handle);
JoystickDisconnected.Invoke(js_handle);
js_connected = false;
return true;
}
@@ -136,11 +136,13 @@ void ProcessAxisEvent(uint8_t axis, short value) {
if (axis == 6) dpad.x = value;
if (axis == 7) dpad.y = value;
if (l_thumb.DistanceSq(prev_lthumb) > 1.f)
// TODO: Compare against the l_thumb from the last time the event was called.
if (l_thumb.DistanceSq(prev_lthumb) > 0.1f)
jstick::LeftThumbstickMoved.Invoke(l_thumb);
if (r_thumb.DistanceSq(prev_rthumb) > 1.f)
if (r_thumb.DistanceSq(prev_rthumb) > 0.1f)
jstick::RightThumbstickMoved.Invoke(r_thumb);
if (dpad.DistanceSq(prev_dp) > 1.f)
if (dpad.DistanceSq(prev_dp) > 0.1f)
jstick::DPadMoved.Invoke(dpad);
if (Math::Abs(l_trigger) - Math::Abs(prev_ltrigger) > 1.f)