X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Fengine%2Fe_input.pas;h=5cf17a788264ffc00dde1b8f1e524135680878a0;hb=d7d166dc3cd287276202e862746208892c4cc89f;hp=b16508fb3a4171a85f99630c9b18776be47a27e3;hpb=e06da872a0a072eea1117350ed6c14a709328807;p=d2df-sdl.git diff --git a/src/engine/e_input.pas b/src/engine/e_input.pas index b16508f..5cf17a7 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 . + *) +{$INCLUDE ../shared/a_modes.inc} 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 @@ -89,6 +105,9 @@ function e_JoyAxisToKey(id: Word; ax: Byte; dir: Byte): Word; 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; @@ -118,6 +137,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 +147,7 @@ var function OpenJoysticks(): Byte; var - i, k, c: Integer; + i, j, k, c: Integer; joy: PSDL_Joystick; begin Result := 0; @@ -140,7 +160,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) + ':', TMsgType.Notify); SetLength(Joysticks, c); with Joysticks[c-1] do begin @@ -149,8 +170,10 @@ 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); + IntToStr(Hats) + ' hats.', TMsgType.Notify); end; end; end; @@ -168,20 +191,39 @@ begin 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; @@ -247,7 +289,7 @@ end; function e_InitInput(): Boolean; begin Result := False; - + e_JoysticksAvailable := OpenJoysticks(); e_EnableInput := True; GenerateKeyNames(); @@ -324,9 +366,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