X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Fengine%2Fe_input.pas;h=0baad37ff55abaea386a336cfe7008aeed982f5c;hb=57a682f2f493bb3a3ac4072d0b7dd7b4863dc6cf;hp=d4081ee5615075eaa89c26fb80962c47e82e1dda;hpb=c98b33270a7b8f65385b754ff17f5f2338fa39e2;p=d2df-sdl.git diff --git a/src/engine/e_input.pas b/src/engine/e_input.pas index d4081ee..0baad37 100644 --- a/src/engine/e_input.pas +++ b/src/engine/e_input.pas @@ -1,4 +1,4 @@ -(* Copyright (C) DooM 2D:Forever Developers +(* 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 @@ -13,7 +13,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . *) -{$MODE DELPHI} +{$INCLUDE ../shared/a_modes.inc} unit e_input; interface @@ -94,7 +94,8 @@ const function e_InitInput(): Boolean; procedure e_ReleaseInput(); procedure e_ClearInputBuffer(); -function e_PollInput(): Boolean; +//function e_PollInput(): Boolean; +procedure e_PollJoysticks(); // call this from message loop to update joysticks function e_KeyPressed(Key: Word): Boolean; function e_AnyKeyPressed(): Boolean; function e_GetFirstKeyPressed(): Word; @@ -105,6 +106,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; @@ -158,7 +162,7 @@ begin begin Inc(c); e_WriteLog('Input: Opened SDL joystick ' + IntToStr(i) + ' (' + SDL_JoystickName(joy) + - ') as joystick ' + IntToStr(c) + ':', MSG_NOTIFY); + ') as joystick ' + IntToStr(c) + ':', TMsgType.Notify); SetLength(Joysticks, c); with Joysticks[c-1] do begin @@ -170,7 +174,7 @@ begin // 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; @@ -188,37 +192,55 @@ 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; +procedure e_PollJoysticks(); var i, j: Word; hat: Byte; begin - Result := False; + //Result := False; if (Joysticks = nil) or (e_JoysticksAvailable = 0) then Exit; SDL_JoystickUpdate(); for j := Low(Joysticks) to High(Joysticks) do + begin with Joysticks[j] do begin - for i := 0 to Buttons do - ButtBuf[i] := SDL_JoystickGetButton(Handle, i) <> 0; - for i := 0 to Axes do - AxisBuf[i] := SDL_JoystickGetAxis(Handle, i); + for i := 0 to Buttons do ButtBuf[i] := SDL_JoystickGetButton(Handle, i) <> 0; + for i := 0 to Axes do AxisBuf[i] := SDL_JoystickGetAxis(Handle, i); for i := 0 to Hats do begin hat := SDL_JoystickGetHat(Handle, i); @@ -228,6 +250,7 @@ begin HatBuf[i, HAT_RIGHT] := LongBool(hat and SDL_HAT_RIGHT); end; end; + end; end; procedure GenerateKeyNames(); @@ -300,15 +323,17 @@ begin end; end; +{ function e_PollInput(): Boolean; var kb, js: Boolean; begin kb := PollKeyboard(); - js := PollJoysticks(); + js := e_PollJoysticks(); Result := kb or js; end; +} function e_KeyPressed(Key: Word): Boolean; var