diff --git a/src/engine/e_input.pas b/src/engine/e_input.pas
index b16508fb3a4171a85f99630c9b18776be47a27e3..072dccb44cd6d592f369191e12a8b5988c6b14e9 100644 (file)
--- a/src/engine/e_input.pas
+++ b/src/engine/e_input.pas
+(* Copyright (C) DooM 2D:Forever Developers
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *)
+{$INCLUDE ../shared/a_modes.inc}
unit e_input;
interface
e_MaxKbdKeys = SDL_NUM_SCANCODES;
e_MaxJoys = 4;
e_MaxJoyBtns = 32;
- e_MaxJoyAxes = 4;
- e_MaxJoyHats = 4;
+ e_MaxJoyAxes = 8;
+ e_MaxJoyHats = 8;
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 +)
+ // $$$..$$$ - 8*2 Joystick axes (- and +)
// $$$..$$$ - 4*4 Joystick hats (L U R D)
// these are apparently used in g_gui and g_game and elsewhere
function e_JoyHatToKey(id: Word; hat: Byte; dir: Byte): Word;
procedure e_SetKeyState(key: Word; state: Integer);
+procedure e_UnpressAllKeys ();
+procedure e_KeyUpDown (key: Word; down: Boolean);
+
var
{e_MouseInfo: TMouseInfo;}
e_EnableInput: Boolean = False;
Hats: Byte;
ButtBuf: array [0..e_MaxJoyBtns] of Boolean;
AxisBuf: array [0..e_MaxJoyAxes] of Integer;
+ AxisZero: array [0..e_MaxJoyAxes] of Integer;
HatBuf: array [0..e_MaxJoyHats] of array [HAT_LEFT..HAT_DOWN] of Boolean;
end;
function OpenJoysticks(): Byte;
var
- i, k, c: Integer;
+ i, j, k, c: Integer;
joy: PSDL_Joystick;
begin
Result := 0;
if joy <> nil then
begin
Inc(c);
- e_WriteLog('Input: Opened SDL joystick ' + IntToStr(i) + ' as joystick ' + IntToStr(c) + ':', MSG_NOTIFY);
+ e_WriteLog('Input: Opened SDL joystick ' + IntToStr(i) + ' (' + SDL_JoystickName(joy) +
+ ') as joystick ' + IntToStr(c) + ':', MSG_NOTIFY);
SetLength(Joysticks, c);
with Joysticks[c-1] do
begin
Axes := Min(e_MaxJoyAxes, SDL_JoystickNumAxes(joy));
Buttons := Min(e_MaxJoyBtns, SDL_JoystickNumButtons(joy));
Hats := Min(e_MaxJoyHats, SDL_JoystickNumHats(joy));
+ // TODO: find proper solution for this xbox trigger shit
+ for j := 0 to Axes do AxisZero[j] := SDL_JoystickGetAxis(joy, j);
e_WriteLog(' ' + IntToStr(Axes) + ' axes, ' + IntToStr(Buttons) + ' buttons, ' +
IntToStr(Hats) + ' hats.', MSG_NOTIFY);
end;
SetLength(Joysticks, 0);
end;
+
+procedure e_UnpressAllKeys ();
+var
+ i: Integer;
+begin
+ for i := 0 to High(KeyBuffer) do KeyBuffer[i] := False;
+end;
+
+
+procedure e_KeyUpDown (key: Word; down: Boolean);
+begin
+ if (key > 0) and (key < Length(KeyBuffer)) then KeyBuffer[key] := down;
+end;
+
+
function PollKeyboard(): Boolean;
+{
var
Keys: PByte;
NKeys: Integer;
- i: Cardinal;
+ i: NativeUInt;
+}
begin
Result := False;
+ {
Keys := SDL_GetKeyboardState(@NKeys);
- if (Keys = nil) or (NKeys < 1) then
- Exit;
+ if (Keys = nil) or (NKeys < 1) then Exit;
for i := 0 to NKeys do
- KeyBuffer[i] := ((PByte(Cardinal(Keys) + i)^) <> 0);
- for i := NKeys to High(KeyBuffer) do
- KeyBuffer[i] := False;
+ begin
+ if ((PByte(NativeUInt(Keys) + i)^) <> 0) then KeyBuffer[i] := false;
+ end;
+ for i := NKeys to High(KeyBuffer) do KeyBuffer[i] := False;
+ }
end;
function PollJoysticks(): Boolean;
function e_InitInput(): Boolean;
begin
Result := False;
-
+
e_JoysticksAvailable := OpenJoysticks();
e_EnableInput := True;
GenerateKeyNames();
Key := (Key - JOYA_BEG) mod (e_MaxJoyAxes*2);
dir := Key mod 2;
if dir = AX_MINUS then
- Result := Joysticks[JoyI].AxisBuf[Key div 2] < -e_JoystickDeadzones[JoyI]
+ Result := Joysticks[JoyI].AxisBuf[Key div 2] <
+ Joysticks[JoyI].AxisZero[Key div 2] - e_JoystickDeadzones[JoyI]
else
- Result := Joysticks[JoyI].AxisBuf[Key div 2] > e_JoystickDeadzones[JoyI]
+ Result := Joysticks[JoyI].AxisBuf[Key div 2] >
+ Joysticks[JoyI].AxisZero[Key div 2] + e_JoystickDeadzones[JoyI]
end;
end