nmlgc / ssg

秋霜玉 / Shuusou Gyoku
MIT License
20 stars 5 forks source link

Centralize input handling #21

Closed nmlgc closed 1 year ago

nmlgc commented 2 years ago

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: https://github.com/nmlgc/ssg/blob/7dcab4f00881e7d9211b3f9d4229a78fe9a509e9/GIAN07/GAMEMAIN.CPP#L931-L932

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.