summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 31039aa)
raw | patch | inline | side by side (parent: 31039aa)
author | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Fri, 5 Apr 2019 16:38:18 +0000 (19:38 +0300) | ||
committer | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Fri, 5 Apr 2019 22:19:50 +0000 (01:19 +0300) |
src/engine/e_input.pas | patch | blob | history | |
src/game/g_console.pas | patch | blob | history | |
src/game/g_window.pas | patch | blob | history |
diff --git a/src/engine/e_input.pas b/src/engine/e_input.pas
index b93ca59c869d64a7cc99435c66557fc14cb0a99b..83508f3ae090329f44ee33599377eceb31c9e6c1 100644 (file)
--- a/src/engine/e_input.pas
+++ b/src/engine/e_input.pas
procedure e_UnpressAllKeys ();
procedure e_KeyUpDown (key: Word; down: Boolean);
+type
+ TJoystick = record
+ ID: Byte;
+ Handle: PSDL_Joystick;
+ Axes: Byte;
+ Buttons: Byte;
+ 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;
+
var
{e_MouseInfo: TMouseInfo;}
e_EnableInput: Boolean = False;
e_JoysticksAvailable: Byte = 0;
e_JoystickDeadzones: array [0..e_MaxJoys-1] of Integer = (8192, 8192, 8192, 8192);
e_KeyNames: array [0..e_MaxInputKeys] of String;
+ Joysticks: array of TJoystick = nil;
implementation
VIRT_BEG = JOYH_END;
VIRT_END = VIRT_BEG + e_MaxVirtKeys;
-type
- TJoystick = record
- ID: Byte;
- Handle: PSDL_Joystick;
- Axes: Byte;
- Buttons: Byte;
- 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;
-
var
KeyBuffer: array [0..e_MaxKbdKeys] of Boolean;
+ JoyBuffer: array [JOYK_BEG..JOYH_END] of Boolean;
VirtBuffer: array [0..e_MaxVirtKeys] of Boolean;
- Joysticks: array of TJoystick = nil;
function OpenJoysticks(): Byte;
var
i: Integer;
begin
for i := 0 to High(KeyBuffer) do KeyBuffer[i] := False;
+ for i := JOYK_BEG to JOYH_END do JoyBuffer[i] := False;
for i := 0 to High(VirtBuffer) do VirtBuffer[i] := False;
end;
procedure e_KeyUpDown (key: Word; down: Boolean);
begin
if (key > 0) and (key < Length(KeyBuffer)) then KeyBuffer[key] := down
+ else if (key >= JOYK_BEG) and (key < JOYH_END) then JoyBuffer[key] := down
else if (key >= VIRT_BEG) and (key < VIRT_END) then VirtBuffer[key - VIRT_BEG] := down
end;
begin
for i := Low(KeyBuffer) to High(KeyBuffer) do
KeyBuffer[i] := False;
+ for i := JOYK_BEG to JOYH_END do
+ JoyBuffer[i] := False;
+ for i := Low(VirtBuffer) to High(VirtBuffer) do
+ VirtBuffer[i] := False;
+(***
if (Joysticks = nil) or (e_JoysticksAvailable = 0) then
for i := Low(Joysticks) to High(Joysticks) do
begin
for d := Low(Joysticks[i].HatBuf[j]) to High(Joysticks[i].HatBuf[j]) do
Joysticks[i].HatBuf[j, d] := False;
end;
- for i := Low(VirtBuffer) to High(VirtBuffer) do
- VirtBuffer[i] := False;
+***)
end;
{
if (Key = IK_INVALID) or (Key = 0) then Exit;
if (Key < KBRD_END) then
- begin // Keyboard buttons/keys
- Result := KeyBuffer[Key];
- end
+ Result := KeyBuffer[Key]
+ else if (Key >= JOYK_BEG) and (Key < JOYH_END) then
+ Result := JoyBuffer[Key]
+ else if (Key >= VIRT_BEG) and (Key < VIRT_END) then
+ Result := VirtBuffer[Key - VIRT_BEG]
+(***
else if (Key >= JOYK_BEG) and (Key < JOYK_END) then
begin // Joystick buttons
JoyI := (Key - JOYK_BEG) div e_MaxJoyBtns;
Result := Joysticks[JoyI].HatBuf[Key div 4, dir];
end;
end
-
- else if (Key >= VIRT_BEG) and (Key < VIRT_END) then
- Result := VirtBuffer[Key - VIRT_BEG]
+***)
end;
procedure e_SetKeyState(key: Word; state: Integer);
if (Key = IK_INVALID) or (Key = 0) then Exit;
if (Key < KBRD_END) then
- begin // Keyboard buttons/keys
- keyBuffer[key] := (state <> 0);
- end
+ keyBuffer[key] := (state <> 0)
+ else if (Key >= JOYK_BEG) and (Key <= JOYH_END) then
+ JoyBuffer[key] := (state <> 0)
+ else if (Key >= VIRT_BEG) and (Key <= VIRT_END) then
+ VirtBuffer[Key - VIRT_BEG] := (state <> 0)
+(***
else if (Key >= JOYK_BEG) and (Key < JOYK_END) then
begin // Joystick buttons
JoyI := (Key - JOYK_BEG) div e_MaxJoyBtns;
Joysticks[JoyI].HatBuf[Key div 4, dir] := (state <> 0);
end;
end
-
- else if (Key >= VIRT_BEG) and (Key < VIRT_END) then
- VirtBuffer[Key - VIRT_BEG] := (state <> 0)
+***)
end;
function e_AnyKeyPressed(): Boolean;
diff --git a/src/game/g_console.pas b/src/game/g_console.pas
index fd8e24b3cf1bd05371a5d9a1c277fc4bdb194418..2de108c09633767360ea3874fd5ff1b57049011d 100644 (file)
--- a/src/game/g_console.pas
+++ b/src/game/g_console.pas
(* for i := 0 to e_MaxJoys - 1 do *)
for i := 0 to 1 do
begin
- g_Console_BindKey(e_JoyAxisToKey(i, 0, 0), '+p' + IntToStr(i mod 2 + 1) + '_moveleft', '-p' + IntToStr(i mod 2 + 1) + '_moveleft');
- g_Console_BindKey(e_JoyAxisToKey(i, 0, 1), '+p' + IntToStr(i mod 2 + 1) + '_moveright', '-p' + IntToStr(i mod 2 + 1) + '_moveright');
- g_Console_BindKey(e_JoyAxisToKey(i, 1, 0), '+p' + IntToStr(i mod 2 + 1) + '_lookup', '-p' + IntToStr(i mod 2 + 1) + '_lookup');
- g_Console_BindKey(e_JoyAxisToKey(i, 1, 1), '+p' + IntToStr(i mod 2 + 1) + '_lookdown', '-p' + IntToStr(i mod 2 + 1) + '_lookdown');
+ g_Console_BindKey(e_JoyAxisToKey(i, 0, AX_MINUS), '+p' + IntToStr(i mod 2 + 1) + '_moveleft', '-p' + IntToStr(i mod 2 + 1) + '_moveleft');
+ g_Console_BindKey(e_JoyAxisToKey(i, 0, AX_PLUS), '+p' + IntToStr(i mod 2 + 1) + '_moveright', '-p' + IntToStr(i mod 2 + 1) + '_moveright');
+ g_Console_BindKey(e_JoyAxisToKey(i, 1, AX_MINUS), '+p' + IntToStr(i mod 2 + 1) + '_lookup', '-p' + IntToStr(i mod 2 + 1) + '_lookup');
+ g_Console_BindKey(e_JoyAxisToKey(i, 1, AX_PLUS), '+p' + IntToStr(i mod 2 + 1) + '_lookdown', '-p' + IntToStr(i mod 2 + 1) + '_lookdown');
g_Console_BindKey(e_JoyButtonToKey(i, 2), '+p' + IntToStr(i mod 2 + 1) + '_jump', '-p' + IntToStr(i mod 2 + 1) + '_jump');
g_Console_BindKey(e_JoyButtonToKey(i, 0), '+p' + IntToStr(i mod 2 + 1) + '_attack', '-p' + IntToStr(i mod 2 + 1) + '_attack');
g_Console_BindKey(e_JoyButtonToKey(i, 3), '+p' + IntToStr(i mod 2 + 1) + '_activate', '-p' + IntToStr(i mod 2 + 1) + '_activate');
diff --git a/src/game/g_window.pas b/src/game/g_window.pas
index a5dd79cfb415955850270e0e2bdf8bc1f2820ff0..5689ceb04d822cf81896f28629ec50ee6a58f23f 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_MaxJoyHats, HAT_LEFT..HAT_DOWN] of Boolean;
procedure KillGLWindow (preserveGL: Boolean);
begin
key, keychr: Word;
uc: UnicodeChar;
down: Boolean;
+ i: Integer;
+ hat: array [HAT_LEFT..HAT_DOWN] of Boolean;
begin
result := false;
if down then KeyPress(key);
end;
+ SDL_JOYBUTTONDOWN, SDL_JOYBUTTONUP:
+ if (ev.jbutton.which < e_MaxJoys) and (ev.jbutton.button < e_MaxJoyBtns) then
+ begin
+ key := e_JoyButtonToKey(ev.jbutton.which, ev.jbutton.button);
+ down := ev.type_ = SDL_JOYBUTTONDOWN;
+ e_KeyUpDown(key, down);
+ g_Console_ProcessBind(key, down);
+ if down then KeyPress(key)
+ end;
+
+ SDL_JOYAXISMOTION:
+ if (ev.jaxis.which < e_MaxJoys) and (ev.jaxis.axis < e_MaxJoyAxes) then
+ begin
+ down := ev.jaxis.value <> Joysticks[ev.jaxis.which].AxisZero[ev.jaxis.axis];
+ if ev.jaxis.value < Joysticks[ev.jaxis.which].AxisZero[ev.jaxis.axis] - e_JoystickDeadzones[ev.jaxis.which] then
+ key := e_JoyAxisToKey(ev.jaxis.which, ev.jaxis.axis, AX_MINUS)
+ else
+ key := e_JoyAxisToKey(ev.jaxis.which, ev.jaxis.axis, AX_PLUS);
+ e_KeyUpDown(key, down);
+ g_Console_ProcessBind(key, down);
+ if down then KeyPress(key)
+ end;
+
+ SDL_JOYHATMOTION:
+ if (ev.jhat.which < e_MaxJoys) and (ev.jhat.hat < e_MaxJoyHats) then
+ begin
+ hat[HAT_UP] := LongBool(ev.jhat.value and SDL_HAT_UP);
+ hat[HAT_DOWN] := LongBool(ev.jhat.value and SDL_HAT_DOWN);
+ hat[HAT_LEFT] := LongBool(ev.jhat.value and SDL_HAT_LEFT);
+ hat[HAT_RIGHT] := LongBool(ev.jhat.value and SDL_HAT_RIGHT);
+ for i := HAT_LEFT to HAT_DOWN do
+ begin
+ if JoystickHatState[ev.jhat.which, i] <> hat[i] then
+ begin
+ down := hat[i];
+ 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] := hat
+ end;
+
+(*
+ SDL_JOYDEVICEADDED, SDL_JOYDEVICEREMOVED:
+ begin
+ // TODO update menu here
+ end
+*)
+
{$IF not DEFINED(HEADLESS) and DEFINED(ENABLE_HOLMES)}
SDL_MOUSEBUTTONDOWN, SDL_MOUSEBUTTONUP, SDL_MOUSEWHEEL, SDL_MOUSEMOTION:
fuiOnSDLEvent(ev);
EventHandler(ev);
if (ev.type_ = SDL_QUITEV) then break;
end;
- e_PollJoysticks();
+ //e_PollJoysticks();
if (ev.type_ = SDL_QUITEV) or (gExit = EXIT_QUIT) then
begin
result := EventHandler(ev);
if (ev.type_ = SDL_QUITEV) then exit;
end;
- e_PollJoysticks();
+ //e_PollJoysticks();
end;