X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;ds=inline;f=src%2Fgame%2Fg_window.pas;h=df44683f8276c42d790daa11396ed1d141f32a33;hb=4de34c0c003869d8f125768be330702020f3c514;hp=3950137c0361ab6a7aca40eca9e30c385cf280de;hpb=08f291733a98bcae9336acc77a3bbb4ba63f9175;p=d2df-sdl.git diff --git a/src/game/g_window.pas b/src/game/g_window.pas index 3950137..df44683 100644 --- a/src/game/g_window.pas +++ b/src/game/g_window.pas @@ -85,8 +85,9 @@ var ticksOverflow: Int64 = -1; lastTicks: Uint32 = 0; // to detect overflow {$ENDIF} - JoystickHatState: array [0..e_MaxJoys, 0..e_MaxJoyHats, HAT_LEFT..HAT_DOWN] of Boolean; - JoystickZeroAxes: array [0..e_MaxJoys, 0..e_MaxJoyAxes] of Integer; + JoystickHandle: array [0..e_MaxJoys - 1] of PSDL_Joystick; + JoystickHatState: array [0..e_MaxJoys - 1, 0..e_MaxJoyHats - 1, HAT_LEFT..HAT_DOWN] of Boolean; + JoystickZeroAxes: array [0..e_MaxJoys - 1, 0..e_MaxJoyAxes - 1] of Integer; procedure KillGLWindow (preserveGL: Boolean); begin @@ -469,7 +470,6 @@ var down: Boolean; i: Integer; hat: array [HAT_LEFT..HAT_DOWN] of Boolean; - joy: PSDL_Joystick; begin result := false; @@ -515,7 +515,6 @@ begin e_KeyUpDown(key, down); g_Console_ProcessBind(key, down) end; - if down then KeyPress(key); end; SDL_JOYBUTTONDOWN, SDL_JOYBUTTONUP: @@ -527,7 +526,6 @@ begin e_LogWritefln('Input Debug: jbutton, joy=%s, button=%s, keycode=%s, press=%s', [ev.jbutton.which, ev.jbutton.button, key, down]); e_KeyUpDown(key, down); g_Console_ProcessBind(key, down); - if down then KeyPress(key) end else begin @@ -556,7 +554,6 @@ begin end; e_KeyUpDown(minuskey, True); g_Console_ProcessBind(minuskey, True); - KeyPress(minuskey); end else if ev.jaxis.value > JoystickZeroAxes[ev.jaxis.which, ev.jaxis.axis] + e_JoystickDeadzones[ev.jaxis.which] then begin @@ -567,7 +564,6 @@ begin end; e_KeyUpDown(key, True); g_Console_ProcessBind(key, True); - KeyPress(key); end else begin @@ -606,7 +602,6 @@ begin key := e_JoyHatToKey(ev.jhat.which, ev.jhat.hat, i); e_KeyUpDown(key, down); g_Console_ProcessBind(key, down); - if down then KeyPress(key) end end; JoystickHatState[ev.jhat.which, ev.jhat.hat] := hat @@ -620,13 +615,16 @@ begin SDL_JOYDEVICEADDED: if (ev.jdevice.which < e_MaxJoys) then begin - joy := SDL_JoystickOpen(ev.jdevice.which); - ASSERT(joy <> nil); - e_LogWritefln('Added Joystick %s', [ev.jdevice.which]); - e_JoystickAvailable[ev.jdevice.which] := True; - for i := 0 to Min(SDL_JoystickNumAxes(joy), e_MaxJoyAxes) do - JoystickZeroAxes[ev.jdevice.which, i] := SDL_JoystickGetAxis(joy, i); - SDL_JoystickClose(joy) + JoystickHandle[ev.jdevice.which] := SDL_JoystickOpen(ev.jdevice.which); + if JoystickHandle[ev.jdevice.which] <> nil then + begin + e_LogWritefln('Added Joystick %s', [ev.jdevice.which]); + e_JoystickAvailable[ev.jdevice.which] := True; + for i := 0 to Min(SDL_JoystickNumAxes(JoystickHandle[ev.jdevice.which]), e_MaxJoyAxes) - 1 do + JoystickZeroAxes[ev.jdevice.which, i] := SDL_JoystickGetAxis(JoystickHandle[ev.jdevice.which], i) + end + else + e_LogWritefln('Warning! Failed to open Joystick %s', [ev.jdevice.which]) end else begin @@ -637,7 +635,12 @@ begin begin e_LogWritefln('Removed Joystick %s', [ev.jdevice.which]); if (ev.jdevice.which < e_MaxJoys) then - e_JoystickAvailable[ev.jdevice.which] := False + begin + e_JoystickAvailable[ev.jdevice.which] := False; + if JoystickHandle[ev.jdevice.which] <> nil then + SDL_JoystickClose(JoystickHandle[ev.jdevice.which]); + JoystickHandle[ev.jdevice.which] := nil + end end; {$IF not DEFINED(HEADLESS) and DEFINED(ENABLE_HOLMES)}