aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZach Latta <zach@zachlatta.com>2016-03-06 07:13:43 -0500
committerZach Latta <zach@zachlatta.com>2016-03-06 07:13:43 -0500
commiteed96ad961f6be502ab357c342923e2a9d80c794 (patch)
tree74fb1c5834b289ede7654a3886b60e8aea42dbe2
parentfe770d0a2d8f222d76bade5b742553d0db85e7da (diff)
downloadsshtron-eed96ad961f6be502ab357c342923e2a9d80c794.tar.gz
Optimize part of game render loop
-rw-r--r--game.go9
1 files changed, 5 insertions, 4 deletions
diff --git a/game.go b/game.go
index 8054c20..4015607 100644
--- a/game.go
+++ b/game.go
@@ -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 {
Un proyecto texto-plano.xyz