doomgeneric: add env support for input selection and map esc to joystick

This commit is contained in:
Matheus
2026-05-15 15:23:37 -03:00
parent f6f4448d5c
commit 1bd3a5b6be
2 changed files with 61 additions and 9 deletions
+60 -8
View File
@@ -100,7 +100,7 @@ new file mode 100644
index 0000000..b8e0de9
--- /dev/null
+++ doomgeneric-workdir/doomgeneric/doomgeneric_astral.c
@@ -0,0 +1,441 @@
@@ -0,0 +1,479 @@
+#define _GNU_SOURCE
+#include "doomkeys.h"
+
@@ -108,6 +108,7 @@ index 0000000..b8e0de9
+
+#include <ctype.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/time.h>
@@ -226,12 +227,17 @@ index 0000000..b8e0de9
+ return 0;
+}
+
+static int open_evdev_path(const char *path)
+{
+ return open(path, O_RDONLY | O_NONBLOCK, 0);
+}
+
+static int open_evdev_device(int index)
+{
+ char path[32];
+
+ snprintf(path, sizeof(path), "/dev/input/event%d", index);
+ return open(path, O_RDONLY | O_NONBLOCK, 0);
+ return open_evdev_path(path);
+}
+
+static void init_axis(int fd, axis_state_t *axis)
@@ -247,6 +253,38 @@ index 0000000..b8e0de9
+
+static void init_evdev(void)
+{
+ const char *keyboard_path = getenv("DOOM_KEYBOARD");
+ const char *joystick_path = getenv("DOOM_JOYSTICK");
+
+ if (keyboard_path != NULL) {
+ kbfd = open_evdev_path(keyboard_path);
+ if (kbfd == -1) {
+ printf("doomgeneric: failed to open DOOM_KEYBOARD=%s: %s\n", keyboard_path, strerror(errno));
+ exit(errno);
+ }
+
+ if (!is_keyboard(kbfd)) {
+ printf("doomgeneric: DOOM_KEYBOARD=%s is not a keyboard\n", keyboard_path);
+ exit(ENODEV);
+ }
+ }
+
+ if (joystick_path != NULL) {
+ joyfd = open_evdev_path(joystick_path);
+ if (joyfd == -1) {
+ printf("doomgeneric: failed to open DOOM_JOYSTICK=%s: %s\n", joystick_path, strerror(errno));
+ exit(errno);
+ }
+
+ if (!is_joystick(joyfd)) {
+ printf("doomgeneric: DOOM_JOYSTICK=%s is not a joystick\n", joystick_path);
+ exit(ENODEV);
+ }
+
+ init_axis(joyfd, &joystick_axes[0]);
+ init_axis(joyfd, &joystick_axes[1]);
+ }
+
+ for (int i = 0; i < MAX_EVDEV_DEVICES; ++i) {
+ int fd = open_evdev_device(i);
+ if (fd == -1)
@@ -287,7 +325,7 @@ index 0000000..b8e0de9
+ return KEY_RIGHTARROW;
+ case KEY_ENTER:
+ case KEY_KPENTER:
+ return KEY_ENTER;
+ return '\r';
+ case KEY_LEFTCTRL:
+ case KEY_RIGHTCTRL:
+ return KEY_FIRE;
@@ -740,11 +778,11 @@ index bf63035..2c84bcc 100644
printf("I_InitGraphics: framebuffer: x_res: %d, y_res: %d, x_virtual: %d, y_virtual: %d, bpp: %d\n",
s_Fb.xres, s_Fb.yres, s_Fb.xres_virtual, s_Fb.yres_virtual, s_Fb.bits_per_pixel);
@@ -240,6 +241,7 @@ void I_StartFrame (void)
void I_StartTic (void)
{
I_GetEvent();
void I_StartTic (void)
{
I_GetEvent();
+ I_UpdateJoystick();
}
}
void I_UpdateNoBlit (void)
@@ -325,7 +327,7 @@ void I_SetPalette (byte* palette)
@@ -755,4 +793,18 @@ index bf63035..2c84bcc 100644
+
/* performance boost:
* map to the right pixel format over here! */
* map to the right pixel format over here! */
diff --git doomgeneric-clean/doomgeneric/m_controls.c doomgeneric-workdir/doomgeneric/m_controls.c
index 10e46aa..0f9d79d 100644
--- doomgeneric-clean/doomgeneric/m_controls.c
+++ doomgeneric-workdir/doomgeneric/m_controls.c
@@ -190,7 +190,7 @@ int joybjump = -1;
int joybprevweapon = -1;
int joybnextweapon = -1;
-int joybmenu = -1;
+int joybmenu = 4;
// Control whether if a mouse button is double clicked, it acts like
// "use" has been pressed
+1 -1
View File
@@ -1,5 +1,5 @@
name=doomgeneric
revision=2
revision=4
from_source=doomgeneric
imagedeps="build-essential"
hostdeps="xgcc xbinutils"