Skip to content

Commit

Permalink
ui: Improve comments about Game interface
Browse files Browse the repository at this point in the history
This change also fixes comments in uiConttext, which seems pretty
old.
  • Loading branch information
hajimehoshi committed Mar 30, 2020
1 parent f01f504 commit 35eb9e7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
11 changes: 9 additions & 2 deletions run.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,23 @@ type Game interface {
// Basically Update updates the game logic, and whether Update draws the screen depends on the existence of
// Draw implementation.
//
// The give argument represents a screen image. Whether the updated content is used or not
// depends on the existence of Draw definition.
//
// With Draw, Update updates only the game logic and Draw draws the screen. This is recommended.
// In this case, the argument screen's updated content is not adopted and is always cleared.
//
// Without Draw, Update updates the game logic and also draws the screen. This is a legacy way.
Update(*Image) error
// In this case, the argument screen's updated content is adopted as the actual game screen.
Update(screen *Image) error

// Draw draws the game screen by one frame.
//
// The give argument represents a screen image. The updated content is adopted as the game screen.
//
// Draw is an optional function for backward compatibility.
//
// Draw(*Image) error
// Draw(screen *Image) error

// Layout accepts a native outside size in device-independent pixels and returns the game's logical screen
// size.
Expand Down
7 changes: 4 additions & 3 deletions uicontext.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,22 +259,23 @@ func (c *uiContext) update(afterFrameUpdate func()) error {
if err := hooks.RunBeforeUpdateHooks(); err != nil {
return err
}

// Multiple successive Clear call should be integrated into one graphics command, then
// calling Clear on every Update should not affect the performance.
c.offscreen.Clear()
if err := c.game.Update(c.offscreen); err != nil {
return err
}
uiDriver().Input().ResetForFrame()
afterFrameUpdate()
}

// Mipmap images should be disposed by Clear.
c.offscreen.Clear()

game.Draw(c.offscreen)
} else {
for i := 0; i < updateCount; i++ {
c.updateOffscreen()

// Mipmap images should be disposed by Clear.
c.offscreen.Clear()

setDrawingSkipped(i < updateCount-1)
Expand Down

0 comments on commit 35eb9e7

Please sign in to comment.