5 uint8_t mappings
[SDLK_LAST
];
7 bool inputs
[INPUT_COUNT
];
8 bool lastinputs
[INPUT_COUNT
];
14 memset(inputs
, 0, sizeof(inputs
));
15 memset(lastinputs
, 0, sizeof(lastinputs
));
16 memset(mappings
, 0xff, sizeof(mappings
));
19 mappings
[SDLK_LEFT
] = LEFTKEY
;
20 mappings
[SDLK_RIGHT
] = RIGHTKEY
;
21 mappings
[SDLK_UP
] = UPKEY
;
22 mappings
[SDLK_DOWN
] = DOWNKEY
;
23 mappings
[SDLK_z
] = JUMPKEY
;
24 mappings
[SDLK_x
] = FIREKEY
;
25 mappings
[SDLK_a
] = PREVWPNKEY
;
26 mappings
[SDLK_s
] = NEXTWPNKEY
;
27 mappings
[SDLK_q
] = INVENTORYKEY
;
28 mappings
[SDLK_w
] = MAPSYSTEMKEY
;
30 mappings
[SDLK_ESCAPE
] = ESCKEY
;
32 mappings
[SDLK_F1
] = F1KEY
;
33 mappings
[SDLK_F2
] = F2KEY
;
34 mappings
[SDLK_F3
] = F3KEY
;
35 mappings
[SDLK_F4
] = F4KEY
;
36 mappings
[SDLK_F5
] = F5KEY
;
37 mappings
[SDLK_F6
] = F6KEY
;
38 mappings
[SDLK_F7
] = F7KEY
;
39 mappings
[SDLK_F8
] = F8KEY
;
40 mappings
[SDLK_F9
] = F9KEY
;
41 mappings
[SDLK_F10
] = F10KEY
;
42 mappings
[SDLK_F11
] = F11KEY
;
43 mappings
[SDLK_F12
] = F12KEY
;
45 mappings
[SDLK_SPACE
] = FREEZE_FRAME_KEY
;
46 mappings
[SDLK_c
] = FRAME_ADVANCE_KEY
;
47 mappings
[SDLK_v
] = DEBUG_FLY_KEY
;
52 // set the SDL key that triggers an input
53 void input_remap(int keyindex
, int sdl_key
)
55 stat("input_remap(%d => %d)", keyindex
, sdl_key
);
56 int old_mapping
= input_get_mapping(keyindex
);
57 if (old_mapping
!= -1)
58 mappings
[old_mapping
] = 0xff;
60 mappings
[sdl_key
] = keyindex
;
63 // get which SDL key triggers a given input
64 int input_get_mapping(int keyindex
)
68 for(i
=0;i
<=SDLK_LAST
;i
++)
70 if (mappings
[i
] == keyindex
)
77 const char *input_get_name(int index
)
79 static const char *input_names
[] =
81 "left", "right", "up", "down",
82 "jump", "fire", "pervious wpn", "next wpn",
85 "f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8", "f9", "f10", "f11", "f12",
86 "freeze frame", "frame advance", "debug fly"
89 if (index
< 0 || index
>= INPUT_COUNT
)
92 return input_names
[index
];
95 void input_set_mappings(int *array
)
97 memset(mappings
, 0xff, sizeof(mappings
));
98 for(int i
=0;i
<INPUT_COUNT
;i
++)
99 mappings
[array
[i
]] = i
;
103 void c------------------------------() {}
106 void input_poll(void)
108 static uint8_t shiftstates
= 0;
109 extern bool freezeframe
;
114 while(SDL_PollEvent(&evt
))
121 key
= evt
.key
.keysym
.sym
;
123 if (console
.IsVisible() && !IsNonConsoleKey(key
))
125 if (key
== SDLK_LSHIFT
)
127 if (evt
.type
== SDL_KEYDOWN
)
128 shiftstates
|= LEFTMASK
;
130 shiftstates
&= ~LEFTMASK
;
132 else if (key
== SDLK_RSHIFT
)
134 if (evt
.type
== SDL_KEYDOWN
)
135 shiftstates
|= RIGHTMASK
;
137 shiftstates
&= ~RIGHTMASK
;
142 if (shiftstates
!= 0)
145 if (ch
== '.') ch
= '>';
146 if (ch
== '-') ch
= '_';
147 if (ch
== '/') ch
= '?';
148 if (ch
== '1') ch
= '!';
151 if (evt
.type
== SDL_KEYDOWN
)
152 console
.HandleKey(ch
);
154 console
.HandleKeyRelease(ch
);
160 if (ino
!= 0xff) inputs
[ino
] = (evt
.type
== SDL_KEYDOWN
);
162 if (evt
.type
== SDL_KEYDOWN
)
164 if (Replay::IsPlaying() && ino
<= LASTCONTROLKEY
)
166 stat("user interrupt - stopping playback of replay");
167 Replay::end_playback();
168 memset(inputs
, 0, sizeof(inputs
));
172 if (key
== '`') // bring up console
176 sound(SND_SWITCH_WEAPON
);
177 console
.SetVisible(true);
190 game
.running
= false;
196 // keys that we don't want to send to the console
197 // even if the console is up.
198 static int IsNonConsoleKey(int key
)
200 static const int nosend
[] = { SDLK_LEFT
, SDLK_RIGHT
, 0 };
202 for(int i
=0;nosend
[i
];i
++)
203 if (key
== nosend
[i
])
210 void input_close(void)
216 void c------------------------------() {}
219 static const int buttons
[] = { JUMPKEY
, FIREKEY
, 0 };
221 bool buttondown(void)
223 for(int i
=0;buttons
[i
];i
++)
225 if (inputs
[buttons
[i
]])
232 bool buttonjustpushed(void)
234 for(int i
=0;buttons
[i
];i
++)
236 if (inputs
[buttons
[i
]] && !lastinputs
[buttons
[i
]])
243 bool justpushed(int k
)
245 return (inputs
[k
] && !lastinputs
[k
]);