Fixed the game would freeze when the mouse moving over the window. #46
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Phenomenon:
After executing spaceInvaders.exe, if you moving the mouse over the window, the game freezes!
Root cause:
When Yampa's sensing action takes window inputs, if the input is a
HGL.MouseMove
event, it will callmmFilter
to consume all subsequent "redundant"HGL.MouseMove
events. If there are several hundredHGL.MouseMove
events,mmFilter
will be recursively called several hundreds of times.The
mmFilter
further callsgwi win
to take events, andgwi win
callsHGL.getWindowTick win
to yield some time slices to ensure that the thread actually receiving WM events gets a chance to work.This leads to a problem:
Since
HGL.getWindowTick win
is a blocking operation (i.e. waiting for a tickRate time), if there are 100 subsequentHGL.MouseMove
, it will wait for "100 x tickRate time", which is unacceptable. Moreover, during this waiting period, there might be further mouse move events generated!This patch fixed the issue by placing
HGL.getWindowTick win
at the beginning of a frame, i.e. at the entry point ofgetTimeInput
, rather than insidegwi win
.Related issue: #44
P.s. This PR is the same as the old one #45. I have to open a new PR because the old PR #45 used
develop
branch, which is difficult to maintain (rename branch close the old PR automatically).