diff options
author | Zach Latta <zach@zachlatta.com> | 2016-03-06 07:13:43 -0500 |
---|---|---|
committer | Zach Latta <zach@zachlatta.com> | 2016-03-06 07:13:43 -0500 |
commit | eed96ad961f6be502ab357c342923e2a9d80c794 (patch) | |
tree | 74fb1c5834b289ede7654a3886b60e8aea42dbe2 | |
parent | fe770d0a2d8f222d76bade5b742553d0db85e7da (diff) | |
download | sshtron-eed96ad961f6be502ab357c342923e2a9d80c794.tar.gz |
Optimize part of game render loop
-rw-r--r-- | game.go | 9 |
1 files changed, 5 insertions, 4 deletions
@@ -2,6 +2,7 @@ package main import ( "bufio" + "bytes" "fmt" "github.com/dustinkirkland/golang-petname" "github.com/fatih/color" @@ -433,7 +434,6 @@ const ( // Warning: this will only work with square worlds func (g *Game) worldString(s *Session) string { - str := "" worldWidth := len(g.level) worldHeight := len(g.level[0]) @@ -556,18 +556,19 @@ func (g *Game) worldString(s *Session) string { } // Convert the rune slice to a string + buffer := bytes.NewBuffer(make([]byte, 0, worldWidth*worldHeight*2)) for y := 0; y < len(strWorld[0]); y++ { for x := 0; x < len(strWorld); x++ { - str += string(strWorld[x][y]) + buffer.WriteString(strWorld[x][y]) } // Don't add an extra newline if we're on the last iteration if y != len(strWorld[0])-1 { - str += "\r\n" + buffer.WriteString("\r\n") } } - return str + return buffer.String() } func (g *Game) WorldWidth() int { |