Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Centralize input handling #21

Closed
Tracked by #42
nmlgc opened this issue Sep 1, 2022 · 0 comments
Closed
Tracked by #42

Centralize input handling #21

nmlgc opened this issue Sep 1, 2022 · 0 comments
Assignees
Labels
Bug Something isn't working Input Keyboard and joypad input. ~≤0.33 pushes Projected number of pushes needed. Might turn out to get more expensive!

Comments

@nmlgc
Copy link
Owner

nmlgc commented Sep 1, 2022

The game calls Key_Read() in way too many places. It would be cleaner to do it once in WinMain(), and then pass the current inputs to the game state procedures as a parameter.

By itself, this would only be an architectural concern. What turns this into an actual bug is that the Game Over and High Score screens repeatedly call Key_Read() in a blocking while loop:

ssg/GIAN07/GAMEMAIN.CPP

Lines 931 to 932 in 7dcab4f

while(Key_Data == 0) Key_Read();
while(Key_Data != 0) Key_Read();

You really should not do this in a single-threaded Windows application. This completely prevents the Windows message loop from running, which in turn makes your program unresponsive to any sort of Windows event. Apart from pressing a key to end the loop, the only thing you can do in this state is to quit the program via the Task Manager or other equally forceful methods.

In fact, you would expect even key presses to be blocked in this state. It only works for the original game because DirectInput 7 installs its own low-level keyboard hook (WH_KEYBOARD_LL) that bypasses the Windows message system.

Fixing this would require a slight rearchitecture of the Game Over and High Score screens, replacing the blocking loops with proper wait states.

@nmlgc nmlgc added the Bug Something isn't working label Sep 1, 2022
@nmlgc nmlgc added the ~≤0.66 pushes Projected number of pushes needed. Might turn out to get more expensive! label Sep 25, 2022
@nmlgc nmlgc mentioned this issue Jul 20, 2023
20 tasks
@nmlgc nmlgc self-assigned this Aug 2, 2023
@nmlgc nmlgc added ~≤0.1 pushes Projected number of pushes needed. Might turn out to get more expensive! ~≤0.33 pushes Projected number of pushes needed. Might turn out to get more expensive! and removed ~≤0.66 pushes Projected number of pushes needed. Might turn out to get more expensive! ~≤0.1 pushes Projected number of pushes needed. Might turn out to get more expensive! labels Aug 6, 2023
@nmlgc nmlgc added the Input Keyboard and joypad input. label Aug 31, 2023
@nmlgc nmlgc closed this as completed in 7d83337 Sep 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Input Keyboard and joypad input. ~≤0.33 pushes Projected number of pushes needed. Might turn out to get more expensive!
Projects
None yet
Development

No branches or pull requests

1 participant