Skip to content

Commit 0aa4657

Browse files
committed
Add game controller mappings from SDL_GameControllerDB
1 parent a4bea3d commit 0aa4657

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

Makefile

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
CONFIG ?= config.default
22
-include $(CONFIG)
33

4-
54
BINARY ?= wolf3d
65
PREFIX ?= /usr/local
76
DATADIR ?= $(PREFIX)/share/games/wolf3d/
@@ -44,6 +43,31 @@ CCFLAGS += -Wsequence-point
4443

4544
CXXFLAGS += $(CFLAGS)
4645

46+
# Add controller mappings
47+
define DOUBLESPACE
48+
49+
endef
50+
define SINGLESPACE
51+
52+
endef
53+
define SDLDELIMITER
54+
,
55+
endef
56+
define SDLNEWLINE
57+
,\n
58+
endef
59+
define SDLGREPUNIX
60+
grep -v '^#' SDL_GameControllerDB/gamecontrollerdb.txt
61+
endef
62+
define SDLGREPWINDOWS
63+
findstr /B /V # SDL_GameControllerDB/gamecontrollerdb.txt
64+
endef
65+
SDLGREPCMD := $(if $(filter $(OS),Windows_NT),$(SDLGREPWINDOWS),$(SDLGREPUNIX))
66+
SDLMAPPINGS := $(shell $(SDLGREPCMD))
67+
SDLMAPPINGS := $(subst $(DOUBLESPACE),$(SINGLESPACE),${SDLMAPPINGS})
68+
SDLMAPPINGS := $(subst $(SDLDELIMITER),$(SDLNEWLINE),${SDLMAPPINGS})
69+
CXXFLAGS += -DSDLMAPPINGS="\"$(SDLMAPPINGS)\""
70+
4771
LDFLAGS += $(LDFLAGS_SDL)
4872
LDFLAGS += -lSDL2_mixer
4973
ifneq (,$(findstring MINGW,$(shell uname -s)))

id_in.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,16 @@ IN_Startup(void)
412412
// Manually work around RetroPi's funky xpad triggers_to_buttons bit
413413
SDL_GameControllerAddMapping("030000005e040000dd02000003020000,Microsoft X-Box One pad (Firmware 2015),platform:Linux,a:b0,b:b1,x:b2,y:b3,back:b8,guide:b10,start:b9,leftstick:b11,rightstick:b12,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7");
414414

415+
// Add passed-in controller mappings
416+
char str[] = SDLMAPPINGS;
417+
char * pch;
418+
pch = strtok (str,"\n");
419+
while (pch != NULL)
420+
{
421+
SDL_GameControllerAddMapping(pch);
422+
pch = strtok (NULL, "\n");
423+
}
424+
415425
if (IN_Started)
416426
return;
417427

0 commit comments

Comments
 (0)