Opened 6 years ago

Closed 4 years ago

#5055 closed defect (fixed)

Lagging while pressing the Shift hotkey

Reported by: elexis Owned by: bb
Priority: Release Blocker Milestone: Alpha 24
Component: Core engine Keywords:
Cc: Krinkle Patch: Phab:D1398

Description

As reported on the forums by wowgetoffyourcellphone and confirmed by LionKanzen in https://wildfiregames.com/forum/index.php?/topic/24062-lagging-when-using-shift-modifier-key/ on windows, but apparently not on linux the game is lagging while pressing shift.

This is most likely due to the key event frequency being different on windows, thus the selection panels and barter dialog being updated way more often than on linux.

Setting a max update frequency in JS would be sufficient to remove the FPS drainage.

Not sure if it is a good idea or worth the effort to set a fixed event frequency in the C++ part for all input events.

Attachments (1)

repeatkeyhack.diff (1.5 KB ) - added by bb 6 years ago.
hack as discribed above for massbarter

Download all attachments as: .zip

Change History (12)

comment:1 by Vladislav Belov, 6 years ago

I don't think, that we should make the frequency lower. Because then players with a fast pressing may notice, that keys aren't handled immediately. So I suggest to add a logic/flag about press/release: if a key is pressed/down, then send an event only once and don't send until it'll be released/up.

comment:2 by bb, 6 years ago

In 21542:

Improve the massbarter onPress scripts, by inlining stuff used only once and uninlining mapped arrays used twice
refs #5055

comment:3 by bb, 6 years ago

Last couple of days I have been looking into this with the idea to split the "Press" action into two parts: one which acts like the current hotkey (1 break, spam) and one which only fires once. The gui page could then simply specify which of the two it wants/needs and f.e. the massbarter and batchtrain could use the "once" option.

However I ran into some SDL issues: the exists a repeat flag which should specify if it is the first or nonfirst message, but "should". On my machine the flag is empty on all calls (for both Xorg and wayland) on for Imarok it contains 4 on all calls (no idea what "4" means here), thus that flag seems bugged on SDL side. Ofc it wouldn't be hard to just keep trac of the pressed hotkeys and so filter out the repeated keys, but that sounds hackish.

by bb, 6 years ago

Attachment: repeatkeyhack.diff added

hack as discribed above for massbarter

comment:4 by elexis, 6 years ago

Looks like SDL_EnableKeyRepeat doesn't exist anymore in SDL2: https://www.libsdl.org/release/SDL-1.2.15/docs/html/sdlenablekeyrepeat.html

The repeat flag is documented here: https://wiki.libsdl.org/SDL_KeyboardEvent It would be much better to use one of the two functions to identify keyrepetitions.

Looking at the diff you have tested with Imarok https://pastebin.com/LG7ghpdA that is a HotkeyDown event and not a KeyDown event and you should only print that repeat flag if the event is actually a keydown event to exclude false positives. That number was 59 when I tried it the first time and I think that's just an uninitialized value that I'm surprised even compiles. (Also the code in your paste shouldnt trigger release events on repeated keydown events.)

To me it looks like the repeat flag should be read from the SDL_KEYDOWN event and copied to the SDL_HOTKEYDOWN event we construct in Hotkey.cpp.

comment:5 by bb, 6 years ago

Patch: D1398

comment:6 by elexis, 6 years ago

Patch: D1398Phab:D1398

comment:7 by Itms, 6 years ago

Milestone: Alpha 23Alpha 24

Pushing to the next development cycle.

comment:8 by Itms, 5 years ago

Component: UI & SimulationCore engine

comment:9 by elexis, 5 years ago

Priority: Should HaveRelease Blocker

comment:10 by Krinkle, 5 years ago

Cc: Krinkle added

comment:11 by bb, 4 years ago

Owner: set to bb
Resolution: fixed
Status: newclosed

In 23701:

Implement keyDown event
Change HotkeyPress event to be non-repeating (HotkeyDown to replace the repeating case)
Fix shiftlag
Make toggle hotkeys only respond to the first SDL event.

Many iterations of review by: elexis

Test done by: Imarok
Comments By: vladislav, Stan
Reviewed By: wraitii
Fixes: #5055
Differential Revision: https://code.wildfiregames.com/D1398

Note: See TracTickets for help on using tickets.