5 uint8_t mappings
[SDLK_LAST
];
7 bool inputs
[INPUT_COUNT
];
8 bool lastinputs
[INPUT_COUNT
];
13 memset(inputs
, 0, sizeof(inputs
));
14 memset(lastinputs
, 0, sizeof(lastinputs
));
15 memset(mappings
, 0xff, sizeof(mappings
));
20 mappings
[SDLK_LEFT
] = LEFTKEY
;
21 mappings
[SDLK_RIGHT
] = RIGHTKEY
;
22 mappings
[SDLK_UP
] = UPKEY
;
23 mappings
[SDLK_DOWN
] = DOWNKEY
;
25 mappings
[SDLK_BTN3
] = JUMPKEY
;
26 mappings
[SDLK_BTN4
] = FIREKEY
;
28 mappings
[SDLK_BTN1
] = INVENTORYKEY
;
29 mappings
[SDLK_BTN2
] = MAPSYSTEMKEY
;
31 mappings
[SDLK_JOGDIAL_UP
] = PREVWPNKEY
;
32 mappings
[SDLK_JOGDIAL_DOWN
] = NEXTWPNKEY
;
36 mappings
[SDLK_LEFT
] = LEFTKEY
;
37 mappings
[SDLK_RIGHT
] = RIGHTKEY
;
38 mappings
[SDLK_UP
] = UPKEY
;
39 mappings
[SDLK_DOWN
] = DOWNKEY
;
40 mappings
[SDLK_z
] = JUMPKEY
;
41 mappings
[SDLK_x
] = FIREKEY
;
42 mappings
[SDLK_a
] = PREVWPNKEY
;
43 mappings
[SDLK_s
] = NEXTWPNKEY
;
44 mappings
[SDLK_q
] = INVENTORYKEY
;
45 mappings
[SDLK_w
] = MAPSYSTEMKEY
;
47 mappings
[SDLK_ESCAPE
] = ESCKEY
;
49 mappings
[SDLK_F1
] = F1KEY
;
50 mappings
[SDLK_F2
] = F2KEY
;
51 mappings
[SDLK_F3
] = F3KEY
;
52 mappings
[SDLK_F4
] = F4KEY
;
53 mappings
[SDLK_F5
] = F5KEY
;
54 mappings
[SDLK_F6
] = F6KEY
;
55 mappings
[SDLK_F7
] = F7KEY
;
56 mappings
[SDLK_F8
] = F8KEY
;
57 mappings
[SDLK_F9
] = F9KEY
;
58 mappings
[SDLK_F10
] = F10KEY
;
59 mappings
[SDLK_F11
] = F11KEY
;
60 mappings
[SDLK_F12
] = F12KEY
;
62 mappings
[SDLK_SPACE
] = FREEZE_FRAME_KEY
;
63 mappings
[SDLK_c
] = FRAME_ADVANCE_KEY
;
64 mappings
[SDLK_v
] = DEBUG_FLY_KEY
;
72 // set the SDL key that triggers an input
73 void input_remap(int keyindex
, int sdl_key
)
75 stat("input_remap(%d => %d)", keyindex
, sdl_key
);
76 int old_mapping
= input_get_mapping(keyindex
);
77 if (old_mapping
!= -1)
78 mappings
[old_mapping
] = 0xff;
80 mappings
[sdl_key
] = keyindex
;
83 // get which SDL key triggers a given input
84 int input_get_mapping(int keyindex
)
88 for(i
=0;i
<=SDLK_LAST
;i
++)
90 if (mappings
[i
] == keyindex
)
97 const char *input_get_name(int index
)
99 static const char *input_names
[] =
101 "left", "right", "up", "down",
102 "jump", "fire", "pervious wpn", "next wpn",
105 "f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8", "f9", "f10", "f11", "f12",
106 "freeze frame", "frame advance", "debug fly"
109 if (index
< 0 || index
>= INPUT_COUNT
)
112 return input_names
[index
];
115 void input_set_mappings(int *array
)
117 memset(mappings
, 0xff, sizeof(mappings
));
118 for(int i
=0;i
<INPUT_COUNT
;i
++)
119 mappings
[array
[i
]] = i
;
123 void c------------------------------() {}
126 void input_poll(void)
131 while(SDL_PollEvent(&evt
))
138 key
= evt
.key
.keysym
.sym
;
141 static uint8_t shiftstates
= 0;
142 extern bool freezeframe
;
144 if (console
.IsVisible() && !IsNonConsoleKey(key
))
146 if (key
== SDLK_LSHIFT
)
148 if (evt
.type
== SDL_KEYDOWN
)
149 shiftstates
|= LEFTMASK
;
151 shiftstates
&= ~LEFTMASK
;
153 else if (key
== SDLK_RSHIFT
)
155 if (evt
.type
== SDL_KEYDOWN
)
156 shiftstates
|= RIGHTMASK
;
158 shiftstates
&= ~RIGHTMASK
;
163 if (shiftstates
!= 0)
166 if (ch
== '.') ch
= '>';
167 if (ch
== '-') ch
= '_';
168 if (ch
== '/') ch
= '?';
169 if (ch
== '1') ch
= '!';
172 if (evt
.type
== SDL_KEYDOWN
)
173 console
.HandleKey(ch
);
175 console
.HandleKeyRelease(ch
);
179 #endif // __SDLSHIM__
183 inputs
[ino
] = (evt
.type
== SDL_KEYDOWN
);
185 if (evt
.type
== SDL_KEYDOWN
)
187 if (Replay::IsPlaying() && ino
<= LASTCONTROLKEY
)
189 stat("user interrupt - stopping playback of replay");
190 Replay::end_playback();
191 memset(inputs
, 0, sizeof(inputs
));
196 if (key
== '`') // bring up console
200 sound(SND_SWITCH_WEAPON
);
201 console
.SetVisible(true);
216 inputs
[ESCKEY
] = true;
217 game
.running
= false;
224 // keys that we don't want to send to the console
225 // even if the console is up.
226 static int IsNonConsoleKey(int key
)
228 static const int nosend
[] = { SDLK_LEFT
, SDLK_RIGHT
, 0 };
230 for(int i
=0;nosend
[i
];i
++)
231 if (key
== nosend
[i
])
238 void input_close(void)
244 void c------------------------------() {}
247 static const int buttons
[] = { JUMPKEY
, FIREKEY
, 0 };
249 bool buttondown(void)
251 for(int i
=0;buttons
[i
];i
++)
253 if (inputs
[buttons
[i
]])
260 bool buttonjustpushed(void)
262 for(int i
=0;buttons
[i
];i
++)
264 if (inputs
[buttons
[i
]] && !lastinputs
[buttons
[i
]])
271 bool justpushed(int k
)
273 return (inputs
[k
] && !lastinputs
[k
]);