internal/ui: bug fix: input states must be updated before the hook

Closes #2502
This commit is contained in:
Hajime Hoshi 2022-12-21 11:46:55 +09:00
parent 8ccfa7bec1
commit d3655940bd
2 changed files with 11 additions and 7 deletions

View File

@ -147,9 +147,11 @@ func (g *gameForUI) Layout(outsideWidth, outsideHeight float64) (float64, float6
return float64(sw), float64(sh) return float64(sw), float64(sh)
} }
func (g *gameForUI) Update(inputState ui.InputState) error { func (g *gameForUI) UpdateInputState(inputState ui.InputState) {
theInputState.set(inputState) theInputState.set(inputState)
}
func (g *gameForUI) Update() error {
if err := g.game.Update(); err != nil { if err := g.game.Update(); err != nil {
return err return err
} }

View File

@ -35,7 +35,8 @@ type Game interface {
NewOffscreenImage(width, height int) *Image NewOffscreenImage(width, height int) *Image
NewScreenImage(width, height int) *Image NewScreenImage(width, height int) *Image
Layout(outsideWidth, outsideHeight float64) (screenWidth, screenHeight float64) Layout(outsideWidth, outsideHeight float64) (screenWidth, screenHeight float64)
Update(InputState) error UpdateInputState(InputState)
Update() error
DrawOffscreen() error DrawOffscreen() error
DrawFinalScreen(scale, offsetX, offsetY float64) DrawFinalScreen(scale, offsetX, offsetY float64)
} }
@ -123,14 +124,15 @@ func (c *context) updateFrameImpl(graphicsDriver graphicsdriver.Graphics, update
// Update the game. // Update the game.
for i := 0; i < updateCount; i++ { for i := 0; i < updateCount; i++ {
if err := hooks.RunBeforeUpdateHooks(); err != nil {
return err
}
// Read the input state and use it for one tick to give a consistent result for one tick (#2496, #2501). // Read the input state and use it for one tick to give a consistent result for one tick (#2496, #2501).
var inputState InputState var inputState InputState
ui.readInputState(&inputState) ui.readInputState(&inputState)
if err := c.game.Update(inputState); err != nil { c.game.UpdateInputState(inputState)
if err := hooks.RunBeforeUpdateHooks(); err != nil {
return err
}
if err := c.game.Update(); err != nil {
return err return err
} }