DEADSOFTWARE

engine: hack for missing anims
[d2df-sdl.git] / src / engine / e_input_stub.inc
1 interface
3 uses SysUtils;
5 const
6 e_MaxKbdKeys = 256;
7 e_MaxJoys = 4;
8 e_MaxJoyBtns = 32;
9 e_MaxJoyAxes = 8;
10 e_MaxJoyHats = 8;
11 e_MaxVirtKeys = 48;
13 e_MaxJoyKeys = e_MaxJoyBtns + e_MaxJoyAxes*2 + e_MaxJoyHats*4;
15 e_MaxInputKeys = e_MaxKbdKeys + e_MaxJoys*e_MaxJoyKeys + e_MaxVirtKeys - 1;
16 // $$$..$$$ - 321 Keyboard buttons/keys
17 // $$$..$$$ - 4*32 Joystick buttons
18 // $$$..$$$ - 8*2 Joystick axes (- and +)
19 // $$$..$$$ - 4*4 Joystick hats (L U R D)
20 // $$$..$$$ - 48 Virtual buttons/keys
22 KBRD_END = e_MaxKbdKeys;
23 JOYK_BEG = KBRD_END;
24 JOYK_END = JOYK_BEG + e_MaxJoyBtns*e_MaxJoys;
25 JOYA_BEG = JOYK_END;
26 JOYA_END = JOYA_BEG + e_MaxJoyAxes*2*e_MaxJoys;
27 JOYH_BEG = JOYA_END;
28 JOYH_END = JOYH_BEG + e_MaxJoyHats*4*e_MaxJoys;
29 VIRT_BEG = JOYH_END;
30 VIRT_END = VIRT_BEG + e_MaxVirtKeys;
32 // these are apparently used in g_gui and g_game and elsewhere
33 IK_INVALID = 0;
34 IK_ESCAPE = 1;
35 IK_RETURN = 2;
36 IK_KPRETURN= 3;
37 IK_ENTER = IK_RETURN;
38 IK_KPINSERT = 5;
39 IK_UP = 6;
40 IK_KPUP = 7;
41 IK_DOWN = 8;
42 IK_KPDOWN = 9;
43 IK_LEFT = 10;
44 IK_KPLEFT = 11;
45 IK_RIGHT = 12;
46 IK_KPRIGHT = 13;
47 IK_DELETE = 14;
48 IK_HOME = 15;
49 IK_KPHOME = 16;
50 IK_INSERT = 17;
51 IK_SPACE = 18;
52 IK_SHIFT = 20;
53 IK_ALT = 21;
54 IK_TAB = 22;
55 IK_PAGEUP = 23;
56 IK_KPPAGEUP= 24;
57 IK_PAGEDN = 25;
58 IK_KPPAGEDN= 26;
59 IK_KP5 = 27;
60 IK_NUMLOCK = 28;
61 IK_KPDIVIDE= 29;
62 IK_KPMULTIPLE= 30;
63 IK_KPMINUS = 31;
64 IK_KPPLUS = 32;
65 IK_KPENTER = IK_KPRETURN;
66 IK_KPDOT = 34;
67 IK_CAPSLOCK= 35;
68 IK_RSHIFT = 36;
69 IK_CTRL = 37;
70 IK_RCTRL = 38;
71 IK_RALT = 39;
72 IK_WIN = 40;
73 IK_RWIN = 41;
74 IK_MENU = 42;
75 IK_PRINTSCR= 43;
76 IK_SCROLLLOCK= 44;
77 IK_LBRACKET= 45;
78 IK_RBRACKET= 46;
79 IK_SEMICOLON= 47;
80 IK_QUOTE = 48;
81 IK_BACKSLASH= 49;
82 IK_SLASH = 50;
83 IK_COMMA = 51;
84 IK_DOT = 52;
85 IK_EQUALS = 53;
86 IK_0 = 54;
87 IK_1 = 55;
88 IK_2 = 56;
89 IK_3 = 57;
90 IK_4 = 58;
91 IK_5 = 59;
92 IK_6 = 60;
93 IK_7 = 61;
94 IK_8 = 62;
95 IK_9 = 63;
96 IK_F1 = 64;
97 IK_F2 = 65;
98 IK_F3 = 66;
99 IK_F4 = 67;
100 IK_F5 = 68;
101 IK_F6 = 69;
102 IK_F7 = 70;
103 IK_F8 = 71;
104 IK_F9 = 72;
105 IK_F10 = 73;
106 IK_F11 = 74;
107 IK_F12 = 75;
108 IK_END = 76;
109 IK_KPEND = 77;
110 IK_BACKSPACE = 78;
111 IK_BACKQUOTE = 79;
112 IK_GRAVE = IK_BACKQUOTE;
113 IK_PAUSE = 81;
114 IK_A = 82;
115 IK_B = 83;
116 IK_C = 84;
117 IK_D = 85;
118 IK_E = 86;
119 IK_F = 87;
120 IK_G = 88;
121 IK_H = 89;
122 IK_I = 90;
123 IK_J = 91;
124 IK_K = 92;
125 IK_L = 93;
126 IK_M = 94;
127 IK_N = 95;
128 IK_O = 96;
129 IK_P = 97;
130 IK_Q = 98;
131 IK_R = 99;
132 IK_S = 100;
133 IK_T = 101;
134 IK_U = 102;
135 IK_V = 103;
136 IK_W = 104;
137 IK_X = 105;
138 IK_Y = 106;
139 IK_Z = 107;
140 IK_MINUS = 108;
141 IK_RMETA = 109;
142 IK_LMETA = 110;
143 // TODO: think of something better than this shit
144 IK_LASTKEY = e_MaxKbdKeys-1;
146 VK_FIRSTKEY = e_MaxKbdKeys + e_MaxJoys*e_MaxJoyKeys;
147 VK_LEFT = VK_FIRSTKEY + 0;
148 VK_RIGHT = VK_FIRSTKEY + 1;
149 VK_UP = VK_FIRSTKEY + 2;
150 VK_DOWN = VK_FIRSTKEY + 3;
151 VK_FIRE = VK_FIRSTKEY + 4;
152 VK_OPEN = VK_FIRSTKEY + 5;
153 VK_JUMP = VK_FIRSTKEY + 6;
154 VK_CHAT = VK_FIRSTKEY + 7;
155 VK_ESCAPE = VK_FIRSTKEY + 8;
156 VK_0 = VK_FIRSTKEY + 9;
157 VK_1 = VK_FIRSTKEY + 10;
158 VK_2 = VK_FIRSTKEY + 11;
159 VK_3 = VK_FIRSTKEY + 12;
160 VK_4 = VK_FIRSTKEY + 13;
161 VK_5 = VK_FIRSTKEY + 14;
162 VK_6 = VK_FIRSTKEY + 15;
163 VK_7 = VK_FIRSTKEY + 16;
164 VK_8 = VK_FIRSTKEY + 17;
165 VK_9 = VK_FIRSTKEY + 18;
166 VK_A = VK_FIRSTKEY + 19;
167 VK_B = VK_FIRSTKEY + 20;
168 VK_C = VK_FIRSTKEY + 21;
169 VK_D = VK_FIRSTKEY + 22;
170 VK_E = VK_FIRSTKEY + 23;
171 VK_F = VK_FIRSTKEY + 24;
172 VK_CONSOLE = VK_FIRSTKEY + 25;
173 VK_STATUS = VK_FIRSTKEY + 26;
174 VK_TEAM = VK_FIRSTKEY + 27;
175 VK_PREV = VK_FIRSTKEY + 28;
176 VK_NEXT = VK_FIRSTKEY + 29;
177 VK_STRAFE = VK_FIRSTKEY + 30;
178 VK_LSTRAFE = VK_FIRSTKEY + 31;
179 VK_RSTRAFE = VK_FIRSTKEY + 32;
180 VK_PRINTSCR = VK_FIRSTKEY + 33;
181 VK_SHOWKBD = VK_FIRSTKEY + 34;
182 VK_HIDEKBD = VK_FIRSTKEY + 35;
183 VK_LASTKEY = e_MaxKbdKeys + e_MaxJoys*e_MaxJoyKeys + e_MaxVirtKeys - 1;
185 AX_MINUS = 0;
186 AX_PLUS = 1;
187 HAT_LEFT = 0;
188 HAT_UP = 1;
189 HAT_RIGHT = 2;
190 HAT_DOWN = 3;
192 JOY0_ATTACK = JOYK_BEG + 0*e_MaxJoyBtns + 0;
193 JOY1_ATTACK = JOYK_BEG + 1*e_MaxJoyBtns + 0;
194 JOY2_ATTACK = JOYK_BEG + 2*e_MaxJoyBtns + 0;
195 JOY3_ATTACK = JOYK_BEG + 3*e_MaxJoyBtns + 0;
196 JOY0_NEXT = JOYK_BEG + 0*e_MaxJoyBtns + 1;
197 JOY1_NEXT = JOYK_BEG + 1*e_MaxJoyBtns + 1;
198 JOY2_NEXT = JOYK_BEG + 2*e_MaxJoyBtns + 1;
199 JOY3_NEXT = JOYK_BEG + 3*e_MaxJoyBtns + 1;
200 JOY0_JUMP = JOYK_BEG + 0*e_MaxJoyBtns + 2;
201 JOY1_JUMP = JOYK_BEG + 1*e_MaxJoyBtns + 2;
202 JOY2_JUMP = JOYK_BEG + 2*e_MaxJoyBtns + 2;
203 JOY3_JUMP = JOYK_BEG + 3*e_MaxJoyBtns + 2;
204 JOY0_ACTIVATE = JOYK_BEG + 0*e_MaxJoyBtns + 3;
205 JOY1_ACTIVATE = JOYK_BEG + 1*e_MaxJoyBtns + 3;
206 JOY2_ACTIVATE = JOYK_BEG + 2*e_MaxJoyBtns + 3;
207 JOY3_ACTIVATE = JOYK_BEG + 3*e_MaxJoyBtns + 3;
208 JOY0_PREV = JOYK_BEG + 0*e_MaxJoyBtns + 4;
209 JOY1_PREV = JOYK_BEG + 1*e_MaxJoyBtns + 4;
210 JOY2_PREV = JOYK_BEG + 2*e_MaxJoyBtns + 4;
211 JOY3_PREV = JOYK_BEG + 3*e_MaxJoyBtns + 4;
213 JOY0_LEFT = JOYH_BEG + 0*e_MaxJoyHats*4 + 0*4 + HAT_LEFT;
214 JOY1_LEFT = JOYH_BEG + 1*e_MaxJoyHats*4 + 0*4 + HAT_LEFT;
215 JOY2_LEFT = JOYH_BEG + 2*e_MaxJoyHats*4 + 0*4 + HAT_LEFT;
216 JOY3_LEFT = JOYH_BEG + 3*e_MaxJoyHats*4 + 0*4 + HAT_LEFT;
217 JOY0_RIGHT = JOYH_BEG + 0*e_MaxJoyHats*4 + 0*4 + HAT_RIGHT;
218 JOY1_RIGHT = JOYH_BEG + 1*e_MaxJoyHats*4 + 0*4 + HAT_RIGHT;
219 JOY2_RIGHT = JOYH_BEG + 2*e_MaxJoyHats*4 + 0*4 + HAT_RIGHT;
220 JOY3_RIGHT = JOYH_BEG + 3*e_MaxJoyHats*4 + 0*4 + HAT_RIGHT;
221 JOY0_UP = JOYH_BEG + 0*e_MaxJoyHats*4 + 0*4 + HAT_UP;
222 JOY1_UP = JOYH_BEG + 1*e_MaxJoyHats*4 + 0*4 + HAT_UP;
223 JOY2_UP = JOYH_BEG + 2*e_MaxJoyHats*4 + 0*4 + HAT_UP;
224 JOY3_UP = JOYH_BEG + 3*e_MaxJoyHats*4 + 0*4 + HAT_UP;
225 JOY0_DOWN = JOYH_BEG + 0*e_MaxJoyHats*4 + 0*4 + HAT_DOWN;
226 JOY1_DOWN = JOYH_BEG + 1*e_MaxJoyHats*4 + 0*4 + HAT_DOWN;
227 JOY2_DOWN = JOYH_BEG + 2*e_MaxJoyHats*4 + 0*4 + HAT_DOWN;
228 JOY3_DOWN = JOYH_BEG + 3*e_MaxJoyHats*4 + 0*4 + HAT_DOWN;
230 function e_InitInput: Boolean;
231 procedure e_ReleaseInput;
232 procedure e_UnpressAllKeys;
233 procedure e_KeyUpDown (key: Integer; down: Boolean);
235 function e_KeyPressed (key: Integer): Boolean;
236 function e_AnyKeyPressed: Boolean;
237 function e_GetFirstKeyPressed: Integer;
238 function e_HasJoysticks: Boolean;
240 function e_JoyButtonToKey (id, btn: Integer): Integer;
241 function e_JoyAxisToKey (id, ax, dir: Integer): Integer;
242 function e_JoyHatToKey (id, hat, dir: Integer): Integer;
244 var
245 e_JoystickAvailable: array [0..e_MaxJoys - 1] of Boolean;
246 e_JoystickDeadzones: array [0..e_MaxJoys - 1] of Integer = (8192, 8192, 8192, 8192);
247 e_KeyNames: array [0..e_MaxInputKeys] of String;
249 implementation
251 var
252 InputBuffer: array [0..e_MaxInputKeys - 1] of Boolean;
254 procedure e_UnpressAllKeys;
255 var i: Integer;
256 begin
257 for i := 0 to High(InputBuffer) do
258 InputBuffer[i] := False
259 end;
261 procedure e_KeyUpDown (key: Integer; down: Boolean);
262 begin
263 ASSERT(key >= 0);
264 ASSERT(key < e_MaxInputKeys);
265 if key > 0 then
266 InputBuffer[key] := down
267 end;
269 procedure GenerateKeyNames;
270 var i, j, k: Integer;
271 begin
272 // keyboard key names
273 e_KeyNames[IK_0] := '0';
274 e_KeyNames[IK_1] := '1';
275 e_KeyNames[IK_2] := '2';
276 e_KeyNames[IK_3] := '3';
277 e_KeyNames[IK_4] := '4';
278 e_KeyNames[IK_5] := '5';
279 e_KeyNames[IK_6] := '6';
280 e_KeyNames[IK_7] := '7';
281 e_KeyNames[IK_8] := '8';
282 e_KeyNames[IK_9] := '9';
284 for i := IK_A to IK_Z do
285 e_KeyNames[i] := '' + chr(ord('a') + (i - IK_a));
287 e_KeyNames[IK_ESCAPE] := 'ESCAPE';
288 e_KeyNames[IK_ENTER] := 'ENTER';
289 e_KeyNames[IK_TAB] := 'TAB';
290 e_KeyNames[IK_BACKSPACE] := 'BACKSPACE';
291 e_KeyNames[IK_SPACE] := 'SPACE';
292 e_KeyNames[IK_UP] := 'UP';
293 e_KeyNames[IK_LEFT] := 'LEFT';
294 e_KeyNames[IK_RIGHT] := 'RIGHT';
295 e_KeyNames[IK_DOWN] := 'DOWN';
296 e_KeyNames[IK_INSERT] := 'INSERT';
297 e_KeyNames[IK_DELETE] := 'DELETE';
298 e_KeyNames[IK_HOME] := 'HOME';
299 e_KeyNames[IK_END] := 'END';
300 e_KeyNames[IK_PAGEUP] := 'PGUP';
301 e_KeyNames[IK_PAGEDN] := 'PGDOWN';
302 e_KeyNames[IK_KPINSERT] := 'PAD0';
303 e_KeyNames[IK_KPEND] := 'PAD1';
304 e_KeyNames[IK_KPDOWN] := 'PAD2';
305 e_KeyNames[IK_KPPAGEDN] := 'PAD3';
306 e_KeyNames[IK_KPLEFT] := 'PAD4';
307 e_KeyNames[IK_KP5] := 'PAD5';
308 e_KeyNames[IK_KPRIGHT] := 'PAD6';
309 e_KeyNames[IK_KPHOME] := 'PAD7';
310 e_KeyNames[IK_KPUP] := 'PAD8';
311 e_KeyNames[IK_KPPAGEUP] := 'PAD9';
312 e_KeyNames[IK_NUMLOCK] := 'NUM';
313 e_KeyNames[IK_KPDIVIDE] := 'PAD/';
314 e_KeyNames[IK_KPMULTIPLE] := 'PAD*';
315 e_KeyNames[IK_KPMINUS] := 'PAD-';
316 e_KeyNames[IK_KPPLUS] := 'PAD+';
317 e_KeyNames[IK_KPENTER] := 'PADENTER';
318 e_KeyNames[IK_KPDOT] := 'PAD.';
319 e_KeyNames[IK_CAPSLOCK] := 'CAPS';
320 e_KeyNames[IK_BACKQUOTE] := 'BACKQUOTE';
321 e_KeyNames[IK_F1] := 'F1';
322 e_KeyNames[IK_F2] := 'F2';
323 e_KeyNames[IK_F3] := 'F3';
324 e_KeyNames[IK_F4] := 'F4';
325 e_KeyNames[IK_F5] := 'F5';
326 e_KeyNames[IK_F6] := 'F6';
327 e_KeyNames[IK_F7] := 'F7';
328 e_KeyNames[IK_F8] := 'F8';
329 e_KeyNames[IK_F9] := 'F9';
330 e_KeyNames[IK_F10] := 'F10';
331 e_KeyNames[IK_F11] := 'F11';
332 e_KeyNames[IK_F12] := 'F12';
333 e_KeyNames[IK_SHIFT] := 'LSHIFT';
334 e_KeyNames[IK_RSHIFT] := 'RSHIFT';
335 e_KeyNames[IK_CTRL] := 'LCTRL';
336 e_KeyNames[IK_RCTRL] := 'RCTRL';
337 e_KeyNames[IK_ALT] := 'LALT';
338 e_KeyNames[IK_RALT] := 'RALT';
339 e_KeyNames[IK_WIN] := 'LWIN';
340 e_KeyNames[IK_RWIN] := 'RWIN';
341 e_KeyNames[IK_MENU] := 'MENU';
342 e_KeyNames[IK_PRINTSCR] := 'PSCRN';
343 e_KeyNames[IK_SCROLLLOCK] := 'SCROLL';
344 e_KeyNames[IK_PAUSE] := 'PAUSE';
345 e_KeyNames[IK_LBRACKET] := '[';
346 e_KeyNames[IK_RBRACKET] := ']';
347 e_KeyNames[IK_SEMICOLON] := ';';
348 e_KeyNames[IK_QUOTE] := '''';
349 e_KeyNames[IK_BACKSLASH] := '\';
350 e_KeyNames[IK_SLASH] := '/';
351 e_KeyNames[IK_COMMA] := ',';
352 e_KeyNames[IK_DOT] := '.';
353 e_KeyNames[IK_MINUS] := '-';
354 e_KeyNames[IK_EQUALS] := '=';
355 e_KeyNames[IK_RMETA] := 'RMETA';
356 e_KeyNames[IK_LMETA] := 'LMETA';
358 // joysticks
359 for j := 0 to e_MaxJoys-1 do
360 begin
361 k := JOYK_BEG + j * e_MaxJoyBtns;
362 // buttons
363 for i := 0 to e_MaxJoyBtns-1 do
364 e_KeyNames[k + i] := Format('JOY%dB%d', [j, i]);
365 k := JOYA_BEG + j * e_MaxJoyAxes * 2;
366 // axes
367 for i := 0 to e_MaxJoyAxes-1 do
368 begin
369 e_KeyNames[k + i*2 ] := Format('JOY%dA%d+', [j, i]);
370 e_KeyNames[k + i*2 + 1] := Format('JOY%dA%d-', [j, i]);
371 end;
372 k := JOYH_BEG + j * e_MaxJoyHats * 4;
373 // hats
374 for i := 0 to e_MaxJoyHats-1 do
375 begin
376 e_KeyNames[k + i*4 ] := Format('JOY%dD%dL', [j, i]);
377 e_KeyNames[k + i*4 + 1] := Format('JOY%dD%dU', [j, i]);
378 e_KeyNames[k + i*4 + 2] := Format('JOY%dD%dR', [j, i]);
379 e_KeyNames[k + i*4 + 3] := Format('JOY%dD%dD', [j, i]);
380 end;
381 end;
383 // vitrual keys
384 for i := 0 to e_MaxVirtKeys-1 do
385 e_KeyNames[VIRT_BEG + i] := 'VIRTUAL' + IntToStr(i);
386 end;
388 function e_HasJoysticks: Boolean;
389 var i: Integer;
390 begin
391 i := 0;
392 while (i < e_MaxJoys) and (e_JoystickAvailable[i] = False) do inc(i);
393 result := i < e_MaxJoys
394 end;
396 function e_InitInput: Boolean;
397 var i: Integer;
398 begin
399 for i := 0 to e_MaxJoys - 1 do
400 e_JoystickAvailable[i] := False;
401 GenerateKeyNames;
402 result := True
403 end;
405 procedure e_ReleaseInput;
406 var i: Integer;
407 begin
408 for i := 0 to e_MaxJoys - 1 do
409 e_JoystickAvailable[i] := False
410 end;
412 function e_KeyPressed (key: Integer): Boolean;
413 begin
414 ASSERT(key >= 0);
415 ASSERT(key < e_MaxInputKeys);
416 result := InputBuffer[key]
417 end;
419 function e_AnyKeyPressed: Boolean;
420 begin
421 result := e_GetFirstKeyPressed <> IK_INVALID;
422 end;
424 function e_GetFirstKeyPressed: Integer;
425 var i: Integer;
426 begin
427 i := 1;
428 while (i < e_MaxInputKeys) and (InputBuffer[i] = False) do inc(i);
429 if i < e_MaxInputKeys then
430 result := i
431 else
432 result := IK_INVALID
433 end;
435 function e_JoyButtonToKey (id, btn: Integer): Integer;
436 begin
437 ASSERT(id >= 0);
438 ASSERT(id < e_MaxJoys);
439 ASSERT(btn >= 0);
440 ASSERT(btn < e_MaxJoyBtns);
441 result := JOYK_BEG + id*e_MaxJoyBtns + btn
442 end;
444 function e_JoyAxisToKey (id, ax, dir: Integer): Integer;
445 begin
446 ASSERT(id >= 0);
447 ASSERT(id < e_MaxJoys);
448 ASSERT(ax >= 0);
449 ASSERT(ax < e_MaxJoyAxes);
450 ASSERT(dir in [AX_MINUS, AX_PLUS]);
451 result := JOYA_BEG + id*e_MaxJoyAxes*2 + ax*2 + dir
452 end;
454 function e_JoyHatToKey (id, hat, dir: Integer): Integer;
455 begin
456 ASSERT(id >= 0);
457 ASSERT(id < e_MaxJoys);
458 ASSERT(hat >= 0);
459 ASSERT(hat < e_MaxJoyHats);
460 ASSERT(dir in [HAT_LEFT, HAT_UP, HAT_RIGHT, HAT_DOWN]);
461 result := JOYH_BEG + id*e_MaxJoyHats*4 + hat*4 + dir
462 end;