nmlgc / ssg

秋霜玉 / Shuusou Gyoku

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Centralize input handling

nmlgc opened this issue · comments

commented

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.