summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 3fa8762)
raw | patch | inline | side by side (parent: 3fa8762)
author | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Mon, 8 Apr 2019 18:13:17 +0000 (21:13 +0300) | ||
committer | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Mon, 8 Apr 2019 18:13:17 +0000 (21:13 +0300) |
src/game/g_window.pas | patch | blob | history |
diff --git a/src/game/g_window.pas b/src/game/g_window.pas
index 3950137c0361ab6a7aca40eca9e30c385cf280de..50fccd40a095fc55d7e64c5f7b73d80b2c3c94b5 100644 (file)
--- a/src/game/g_window.pas
+++ b/src/game/g_window.pas
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
down: Boolean;
i: Integer;
hat: array [HAT_LEFT..HAT_DOWN] of Boolean;
- joy: PSDL_Joystick;
begin
result := false;
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
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)}