added caching for much better performance

This commit is contained in:
2024-05-28 00:07:31 +02:00
committed by T.v.Dein
parent ba247d0606
commit 8cb5585456
2 changed files with 32 additions and 52 deletions

40
main.go
View File

@@ -5,7 +5,6 @@ import (
"log"
"os"
"runtime/pprof"
"time"
_ "net/http/pprof"
@@ -26,7 +25,8 @@ func main() {
game := NewGame(config, Play)
if config.ProfileFile != "" {
// enable cpu profiling and use fake game loop
// enable cpu profiling. Do NOT use q to stop the game but
// close the window to get a profile
fd, err := os.Create(config.ProfileFile)
if err != nil {
log.Fatal(err)
@@ -35,13 +35,6 @@ func main() {
pprof.StartCPUProfile(fd)
defer pprof.StopCPUProfile()
Ebitfake(game)
pprof.StopCPUProfile()
fd.Close()
os.Exit(0)
}
// main loop
@@ -49,32 +42,3 @@ func main() {
log.Fatal(err)
}
}
// fake game loop, required to be able to profile the program using
// pprof. Otherwise any kind of program exit leads to an empty profile
// file.
func Ebitfake(game *Game) {
screen := ebiten.NewImage(game.ScreenWidth, game.ScreenHeight)
var loops int64
for {
err := game.Update()
if err != nil {
log.Fatal(err)
}
if game.Config.ProfileDraw {
game.Draw(screen)
}
fmt.Print(".")
time.Sleep(16 * time.Millisecond) // around 60 TPS
if loops >= game.Config.ProfileMaxLoops {
break
}
loops++
}
}