Skip to content

Commit

Permalink
Consume less energy when screen is standing still
Browse files Browse the repository at this point in the history
For static editors too much energy is being consumed in order to draw the screen pixels each frame.

This commit changes how often screen pixels are replaced in graphics card memory.
  • Loading branch information
elgopher committed Oct 5, 2023
1 parent f592ff6 commit ebbd15a
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions ebitengine/game.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ package ebitengine

import (
_ "embed"
"fmt"
"slices"

Check failure on line 9 in ebitengine/game.go

View workflow job for this annotation

GitHub Actions / all (1.20)

package slices is not in GOROOT (/opt/hostedtoolcache/go/1.20.8/x64/src/slices)

Check failure on line 9 in ebitengine/game.go

View workflow job for this annotation

GitHub Actions / all (1.20)

package slices is not in GOROOT (/opt/hostedtoolcache/go/1.20.8/x64/src/slices)

Check failure on line 9 in ebitengine/game.go

View workflow job for this annotation

GitHub Actions / all (1.20)

package slices is not in GOROOT (/opt/hostedtoolcache/go/1.20.8/x64/src/slices)

Check failure on line 9 in ebitengine/game.go

View workflow job for this annotation

GitHub Actions / all (1.20)

package slices is not in GOROOT (/opt/hostedtoolcache/go/1.20.8/x64/src/slices)

Check failure on line 9 in ebitengine/game.go

View workflow job for this annotation

GitHub Actions / all (1.20)

package slices is not in GOROOT (/opt/hostedtoolcache/go/1.20.8/x64/src/slices)

Check failure on line 9 in ebitengine/game.go

View workflow job for this annotation

GitHub Actions / all (1.20)

package slices is not in GOROOT (/opt/hostedtoolcache/go/1.20.8/x64/src/slices)

Check failure on line 9 in ebitengine/game.go

View workflow job for this annotation

GitHub Actions / all (1.20)

package slices is not in GOROOT (/opt/hostedtoolcache/go/1.20.8/x64/src/slices)

Check failure on line 9 in ebitengine/game.go

View workflow job for this annotation

GitHub Actions / all (1.20)

package slices is not in GOROOT (/opt/hostedtoolcache/go/1.20.8/x64/src/slices)

Check failure on line 9 in ebitengine/game.go

View workflow job for this annotation

GitHub Actions / all (1.20)

package slices is not in GOROOT (/opt/hostedtoolcache/go/1.20.8/x64/src/slices)

Check failure on line 9 in ebitengine/game.go

View workflow job for this annotation

GitHub Actions / all (1.20)

package slices is not in GOROOT (/opt/hostedtoolcache/go/1.20.8/x64/src/slices)
"sync/atomic"
"time"

Expand All @@ -19,6 +21,7 @@ type game struct {
screenDataRGBA []byte // reused RGBA pixels
screenChanged bool
shouldSkipNextDraw bool
lastScreenDrawn []byte
}

func (e *game) Update() error {
Expand Down Expand Up @@ -56,9 +59,18 @@ func (e *game) Update() error {
if elapsed.Seconds() > 1/float64(tps) {
e.shouldSkipNextDraw = true
}
}

e.screenChanged = true
scrPix := pi.Scr().Pix()
if !slices.Equal(e.lastScreenDrawn, scrPix) { // TODO And palette + clipping region not changed
e.screenChanged = true
if len(e.lastScreenDrawn) != len(scrPix) {
e.lastScreenDrawn = make([]byte, len(scrPix))
}
copy(e.lastScreenDrawn, scrPix)
} else {
fmt.Println("skipping")
}
}

return nil
}
Expand Down

0 comments on commit ebbd15a

Please sign in to comment.