From: Ketmar Dark Date: Thu, 28 Sep 2017 14:00:42 +0000 (+0300) Subject: fixed keyboard polling (no more); ESC should work in several places where it should... X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=8aa3b888af2fecd61de66106bc2b027fda93914d;p=d2df-sdl.git fixed keyboard polling (no more); ESC should work in several places where it should work (sorry, my puns sux) --- diff --git a/src/engine/e_input.pas b/src/engine/e_input.pas index 5cf17a7..7783734 100644 --- a/src/engine/e_input.pas +++ b/src/engine/e_input.pas @@ -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; @@ -226,21 +227,20 @@ begin } 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); @@ -250,6 +250,7 @@ begin HatBuf[i, HAT_RIGHT] := LongBool(hat and SDL_HAT_RIGHT); end; end; + end; end; procedure GenerateKeyNames(); @@ -322,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 diff --git a/src/game/g_game.pas b/src/game/g_game.pas index 5328038..a505edc 100644 --- a/src/game/g_game.pas +++ b/src/game/g_game.pas @@ -1538,8 +1538,8 @@ begin Exit; end; -// ×èòàåì êëàâèàòóðó è äæîéñòèê, åñëè îêíî àêòèâíî: - e_PollInput(); + // ×èòàåì êëàâèàòóðó è äæîéñòèê, åñëè îêíî àêòèâíî + // no need to, as we'll do it in event handler // Îáíîâëÿåì êîíñîëü (äâèæåíèå è ñîîáùåíèÿ): g_Console_Update(); @@ -2182,7 +2182,8 @@ var begin e_TextureFontGetSize(gStdFont, ww2, hh2); - e_PollInput(); + g_ProcessMessages(); + if e_KeyPressed(IK_TAB) then begin if not gStatsPressed then @@ -4186,6 +4187,7 @@ begin enet_packet_destroy(NetEvent.packet); end else + begin if (NetEvent.kind = ENET_EVENT_TYPE_DISCONNECT) then begin State := 0; @@ -4195,12 +4197,11 @@ begin OuterLoop := False; Break; end; + end; end; ProcessLoading(true); - e_PollInput(); - if e_KeyPressed(IK_ESCAPE) or e_KeyPressed(IK_SPACE) then begin State := 0; diff --git a/src/game/g_net.pas b/src/game/g_net.pas index 85263e5..6d06e97 100644 --- a/src/game/g_net.pas +++ b/src/game/g_net.pas @@ -789,8 +789,6 @@ begin ProcessLoading(true); - e_PollInput(); - if e_KeyPressed(IK_ESCAPE) or e_KeyPressed(IK_SPACE) then OuterLoop := False; end; @@ -954,8 +952,6 @@ begin ProcessLoading(true); - e_PollInput(); - if e_KeyPressed(IK_ESCAPE) or e_KeyPressed(IK_SPACE) then break; end; diff --git a/src/game/g_netmaster.pas b/src/game/g_netmaster.pas index 9e96a45..14970ab 100644 --- a/src/game/g_netmaster.pas +++ b/src/game/g_netmaster.pas @@ -505,13 +505,15 @@ begin end; procedure g_Serverlist_Control(var SL: TNetServerList); +var + qm: Boolean; begin if gConsoleShow or gChatShow then Exit; - e_PollInput(); + qm := g_ProcessMessages(); // this updates kbd - if e_KeyPressed(IK_ESCAPE) then + if qm or e_KeyPressed(IK_ESCAPE) then begin SL := nil; gState := STATE_MENU; diff --git a/src/game/g_options.pas b/src/game/g_options.pas index 37aac9d..b24c6fa 100644 --- a/src/game/g_options.pas +++ b/src/game/g_options.pas @@ -437,7 +437,7 @@ begin wadoptFast := gSFSFastMode; e_FastScreenshots := config.ReadBool('Game', 'FastScreenshots', True); gDefaultMegawadStart := config.ReadStr('Game', 'DefaultMegawadStart', 'megawads/DOOM2D.WAD:\MAP01'); - gBerserkAutoswitch := config.ReadBool('Game', 'BerserkAutoswitch', False); + gBerserkAutoswitch := config.ReadBool('Game', 'BerserkAutoswitching', True); // Ãåéìïëåé â ñâîåé èãðå gcMap := config.ReadStr('GameplayCustom', 'Map', ''); @@ -672,7 +672,7 @@ begin config.WriteBool('Game', 'SFSFastMode', gSFSFastMode); config.WriteBool('Game', 'FastScreenshots', e_FastScreenshots); config.WriteStr('Game', 'DefaultMegawadStart', gDefaultMegawadStart); - config.WriteBool('Game', 'BerserkAutoswitch', gBerserkAutoswitch); + config.WriteBool('Game', 'BerserkAutoswitching', gBerserkAutoswitch); config.WriteStr ('GameplayCustom', 'Map', gcMap); config.WriteStr ('GameplayCustom', 'GameMode', gcGameMode); diff --git a/src/game/g_player.pas b/src/game/g_player.pas index bcad3ca..b03214f 100644 --- a/src/game/g_player.pas +++ b/src/game/g_player.pas @@ -2821,10 +2821,12 @@ begin else g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj.X, FObj.Y); - if gFlash = 1 then - if FPain < 50 then - FPain := min(FPain + 25, 50); - end else g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 3, FUID); + if (gFlash = 1) and (FPain < 50) then FPain := min(FPain + 25, 50); + end + else + begin + g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 3, FUID); + end; DidFire := True; FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap]; diff --git a/src/game/g_window.pas b/src/game/g_window.pas index 863072c..12a038f 100644 --- a/src/game/g_window.pas +++ b/src/game/g_window.pas @@ -37,6 +37,9 @@ function g_Window_SetSize (w, h: Word; fullscreen: Boolean): Boolean; procedure ProcessLoading (forceUpdate: Boolean=false); +// returns `true` if quit event was received +function g_ProcessMessages (): Boolean; + var gwin_dump_extensions: Boolean = false; @@ -543,8 +546,10 @@ begin while (SDL_PollEvent(@ev) > 0) do begin + EventHandler(ev); if (ev.type_ = SDL_QUITEV) then break; end; + e_PollJoysticks(); if (ev.type_ = SDL_QUITEV) or (gExit = EXIT_QUIT) then begin @@ -599,19 +604,26 @@ begin end; -function ProcessMessage (): Boolean; +function g_ProcessMessages (): Boolean; var - i, t: Integer; ev: TSDL_Event; begin result := false; FillChar(ev, SizeOf(ev), 0); - while (SDL_PollEvent(@ev) > 0) do begin result := EventHandler(ev); if (ev.type_ = SDL_QUITEV) then exit; end; + e_PollJoysticks(); +end; + + +function ProcessMessage (): Boolean; +var + i, t: Integer; +begin + result := g_ProcessMessages(); Time := GetTimer(); Time_Delta := Time-Time_Old;