diff --git a/src/engine/e_input.pas b/src/engine/e_input.pas
index 15cc2aa6ff3a348cf6271fb7b9d1023a668d53a6..021c3ddadf72452b8c4b11358877cf0da23662e5 100644 (file)
--- a/src/engine/e_input.pas
+++ b/src/engine/e_input.pas
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*)
-{$MODE DELPHI}
+{$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
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;
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;
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