X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Fengine%2Fe_input.pas;h=269a1d17c85c81e277f6ffeaaca4f20a3cba179f;hb=2a785940b8e595cffcc9e9d652c2ae9248c989ee;hp=b16508fb3a4171a85f99630c9b18776be47a27e3;hpb=e06da872a0a072eea1117350ed6c14a709328807;p=d2df-sdl.git diff --git a/src/engine/e_input.pas b/src/engine/e_input.pas index b16508f..269a1d1 100644 --- a/src/engine/e_input.pas +++ b/src/engine/e_input.pas @@ -1,3 +1,19 @@ +(* 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 . + *) +{$MODE DELPHI} unit e_input; interface @@ -11,15 +27,15 @@ const 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 @@ -118,6 +134,7 @@ type 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; @@ -127,7 +144,7 @@ var function OpenJoysticks(): Byte; var - i, k, c: Integer; + i, j, k, c: Integer; joy: PSDL_Joystick; begin Result := 0; @@ -140,7 +157,8 @@ begin 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 @@ -149,6 +167,8 @@ 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; @@ -172,14 +192,14 @@ 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; for i := 0 to NKeys do - KeyBuffer[i] := ((PByte(Cardinal(Keys) + i)^) <> 0); + KeyBuffer[i] := ((PByte(NativeUInt(Keys) + i)^) <> 0); for i := NKeys to High(KeyBuffer) do KeyBuffer[i] := False; end; @@ -247,7 +267,7 @@ end; function e_InitInput(): Boolean; begin Result := False; - + e_JoysticksAvailable := OpenJoysticks(); e_EnableInput := True; GenerateKeyNames(); @@ -324,9 +344,11 @@ begin 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