diff --git a/src/engine/e_input.pas b/src/engine/e_input.pas
index 67e0b5d9a2201ad51cbbf4a4e310cf7f715a5f1d..40b7522c8690c3d0896fa842424fc0facccf5c30 100644 (file)
--- a/src/engine/e_input.pas
+++ b/src/engine/e_input.pas
e_MaxJoyBtns = 32;
e_MaxJoyAxes = 4;
e_MaxJoyHats = 4;
-
+
e_MaxJoyKeys = e_MaxJoyBtns + e_MaxJoyAxes*2 + e_MaxJoyHats*4;
-
+
e_MaxInputKeys = e_MaxKbdKeys + e_MaxJoys*e_MaxJoyKeys - 1;
// $$$..$$$ - 321 Keyboard buttons/keys
// $$$..$$$ - 4*32 Joystick buttons
// $$$..$$$ - 4*4 Joystick axes (- and +)
// $$$..$$$ - 4*4 Joystick hats (L U R D)
-
+
// these are apparently used in g_gui and g_game and elsewhere
IK_UNKNOWN = SDLK_UNKNOWN;
IK_INVALID = 65535;
IK_SHIFT = SDLK_LSHIFT;
IK_TAB = SDLK_TAB;
IK_PAGEUP = SDLK_PAGEUP;
- IK_PAGEDN = SDLK_PAGEDOWN;
+ IK_PAGEDN = SDLK_PAGEDOWN;
IK_F2 = SDLK_F2;
IK_F3 = SDLK_F3;
IK_F4 = SDLK_F4;
IK_PAUSE = SDLK_PAUSE;
// TODO: think of something better than this shit
IK_LASTKEY = 320;
-
+
AX_MINUS = 0;
AX_PLUS = 1;
HAT_LEFT = 0;
HAT_UP = 1;
HAT_RIGHT = 2;
HAT_DOWN = 3;
-
+
function e_InitInput(): Boolean;
procedure e_ReleaseInput();
procedure e_ClearInputBuffer();
var
KeyBuffer: array [0..e_MaxKbdKeys] of Boolean;
- Joysticks: array of TJoystick = nil;
+ Joysticks: array of TJoystick = nil;
function OpenJoysticks(): Byte;
var
SDL_JoystickClose(Handle);
SetLength(Joysticks, 0);
end;
-
+
function PollKeyboard(): Boolean;
var
Keys: PByte;
KeyBuffer[i] := ((PByte(Cardinal(Keys) + i)^) <> 0);
for i := NKeys to High(KeyBuffer) do
KeyBuffer[i] := False;
-end;
-
+end;
+
function PollJoysticks(): Boolean;
var
i, j: Word;
if e_KeyNames[i] = 'unknown key' then
e_KeyNames[i] := '';
end;
-
+
// joysticks
for j := 0 to e_MaxJoys-1 do
begin
end;
end;
end;
-
+
function e_InitInput(): Boolean;
begin
Result := False;
-
+
e_JoysticksAvailable := OpenJoysticks();
e_EnableInput := True;
GenerateKeyNames();
ReleaseJoysticks();
e_JoysticksAvailable := 0;
end;
-
+
procedure e_ClearInputBuffer();
var
i, j, d: Integer;
for j := Low(Joysticks[i].HatBuf) to High(Joysticks[i].HatBuf) do
for d := Low(Joysticks[i].HatBuf[j]) to High(Joysticks[i].HatBuf[j]) do
Joysticks[i].HatBuf[j, d] := False;
- end;
+ end;
end;
function e_PollInput(): Boolean;
begin
Result := False;
if (Key = IK_INVALID) or (Key = 0) then Exit;
-
+
if (Key < KBRD_END) then
begin // Keyboard buttons/keys
Result := KeyBuffer[Key];
end
-
+
else if (Key >= JOYK_BEG) and (Key < JOYK_END) then
begin // Joystick buttons
JoyI := (Key - JOYK_BEG) div e_MaxJoyBtns;
Result := Joysticks[JoyI].ButtBuf[Key];
end;
end
-
+
else if (Key >= JOYA_BEG) and (Key < JOYA_END) then
begin // Joystick axes
JoyI := (Key - JOYA_BEG) div (e_MaxJoyAxes*2);
dir := Key mod 2;
if dir = AX_MINUS then
Result := Joysticks[JoyI].AxisBuf[Key div 2] < -e_JoystickDeadzones[JoyI]
- else
+ else
Result := Joysticks[JoyI].AxisBuf[Key div 2] > e_JoystickDeadzones[JoyI]
- end;
+ end;
end
-
+
else if (Key >= JOYH_BEG) and (Key < JOYH_END) then
- begin // Joystick hats
+ begin // Joystick hats
JoyI := (Key - JOYH_BEG) div (e_MaxJoyHats*4);
if JoyI >= e_JoysticksAvailable then
Result := False
Key := (Key - JOYH_BEG) mod (e_MaxJoyHats*4);
dir := Key mod 4;
Result := Joysticks[JoyI].HatBuf[Key div 4, dir];
- end;
+ end;
end;
end;
JoyI, dir: Integer;
begin
if (Key = IK_INVALID) or (Key = 0) then Exit;
-
+
if (Key < KBRD_END) then
begin // Keyboard buttons/keys
keyBuffer[key] := (state <> 0);
end
-
+
else if (Key >= JOYK_BEG) and (Key < JOYK_END) then
begin // Joystick buttons
JoyI := (Key - JOYK_BEG) div e_MaxJoyBtns;
Joysticks[JoyI].ButtBuf[Key] := (state <> 0);
end;
end
-
+
else if (Key >= JOYA_BEG) and (Key < JOYA_END) then
- begin // Joystick axes
+ begin // Joystick axes
JoyI := (Key - JOYA_BEG) div (e_MaxJoyAxes*2);
if JoyI >= e_JoysticksAvailable then
Exit
begin
Key := (Key - JOYA_BEG) mod (e_MaxJoyAxes*2);
Joysticks[JoyI].AxisBuf[Key div 2] := state;
- end;
+ end;
end
-
+
else if (Key >= JOYH_BEG) and (Key < JOYH_END) then
- begin // Joystick hats
+ begin // Joystick hats
JoyI := (Key - JOYH_BEG) div (e_MaxJoyHats*4);
if JoyI >= e_JoysticksAvailable then
Exit
Key := (Key - JOYH_BEG) mod (e_MaxJoyHats*4);
dir := Key mod 4;
Joysticks[JoyI].HatBuf[Key div 4, dir] := (state <> 0);
- end;
+ end;
end;
end;