Only do expensive area coverage calculation if there where blocks loaded from database.

If there are not, nothing changed, so nothing to recalculate.
Takes a good deal from the clock.
This commit is contained in:
Sascha L. Teichmann 2017-02-26 12:57:38 +01:00
parent 7f78feb9bd
commit 3e3413566b
4 changed files with 39 additions and 20 deletions

View File

@ -8,6 +8,8 @@ import (
"flag" "flag"
"fmt" "fmt"
"log" "log"
"os"
"runtime/pprof"
"bitbucket.org/s_l_teichmann/mtsatellite/common" "bitbucket.org/s_l_teichmann/mtsatellite/common"
) )
@ -27,6 +29,7 @@ func main() {
transparent bool transparent bool
transparentDim float64 transparentDim float64
version bool version bool
cpuProfile string
) )
defaultBgColor := common.ColorToHex(common.BackgroundColor) defaultBgColor := common.ColorToHex(common.BackgroundColor)
@ -60,6 +63,7 @@ func main() {
"td", common.DefaultTransparentDim*100.0, "td", common.DefaultTransparentDim*100.0,
"Extra fimming of transparent nodes each depth meter in percent. (shorthand)") "Extra fimming of transparent nodes each depth meter in percent. (shorthand)")
flag.BoolVar(&version, "version", false, "Print version and exit.") flag.BoolVar(&version, "version", false, "Print version and exit.")
flag.StringVar(&cpuProfile, "c", "", "Dump pprof profile to file.")
flag.Parse() flag.Parse()
@ -67,6 +71,15 @@ func main() {
common.PrintVersionAndExit() common.PrintVersionAndExit()
} }
if cpuProfile != "" {
f, err := os.Create(cpuProfile)
if err != nil {
log.Fatal(err)
}
pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile()
}
bg := common.ParseColorDefault(bgColor, common.BackgroundColor) bg := common.ParseColorDefault(bgColor, common.BackgroundColor)
if !skipBaseLevel { if !skipBaseLevel {

View File

@ -48,7 +48,7 @@
<script type="text/javascript" src="js/leaflet.awesome-markers.js"></script> <script type="text/javascript" src="js/leaflet.awesome-markers.js"></script>
<script> <script>
var useWebsocket = false; // Set to true if you want websocket support var useWebsocket = true; // Set to true if you want websocket support
L.Projection.NoWrap = { L.Projection.NoWrap = {
project: function (latlng) { project: function (latlng) {

View File

@ -90,23 +90,23 @@ func (btc *BaseTileCreator) Close() error {
return btc.client.Close() return btc.client.Close()
} }
func (btc *BaseTileCreator) drawBlock(block *Block) {
if err := btc.yOrder.RenderBlock(block, btc.colors); err != nil {
log.Printf("WARN: rendering block failed: %s\n", err)
}
}
func (btc *BaseTileCreator) CreateTile(x, z int16, i, j int) (bool, error) { func (btc *BaseTileCreator) CreateTile(x, z int16, i, j int) (bool, error) {
btc.renderer.Reset() btc.renderer.Reset()
btc.renderer.SetPos(x, z) btc.renderer.SetPos(x, z)
btc.yOrder.Reset() btc.yOrder.Reset()
drawBlock := func(block *Block) {
if err := btc.yOrder.RenderBlock(block, btc.colors); err != nil {
log.Printf("WARN: rendering block failed: %s\n", err)
}
}
var c1, c2 Coord var c1, c2 Coord
nareas := make([]Area, 0, tileWidth*tileHeight/2) oareas := make([]Area, 0, tileWidth*tileHeight/2)
oareas := make([]Area, 1, tileWidth*tileHeight/2) nareas := make([]Area, 1, tileWidth*tileHeight/2)
oareas[0] = Area{ nareas[0] = Area{
X1: 0, Z1: 0, X1: 0, Z1: 0,
X2: int16(tileWidth) - 1, Z2: int16(tileHeight) - 1} X2: int16(tileWidth) - 1, Z2: int16(tileHeight) - 1}
@ -114,14 +114,11 @@ func (btc *BaseTileCreator) CreateTile(x, z int16, i, j int) (bool, error) {
if yRange[0] > btc.yMax || yRange[1] < btc.yMin { if yRange[0] > btc.yMax || yRange[1] < btc.yMin {
continue continue
} }
c1.Y = max16(yRange[0], btc.yMin) c1.Y = max16(yRange[0], btc.yMin)
c2.Y = min16(yRange[1], btc.yMax) c2.Y = min16(yRange[1], btc.yMax)
nareas = btc.renderer.UncoveredAreas(nareas, oareas) var allCount int
if len(nareas) == 0 {
break
}
for _, area := range nareas { for _, area := range nareas {
c1.X = area.X1 + x c1.X = area.X1 + x
@ -129,14 +126,23 @@ func (btc *BaseTileCreator) CreateTile(x, z int16, i, j int) (bool, error) {
c2.X = area.X2 + x c2.X = area.X2 + x
c2.Z = area.Z2 + z c2.Z = area.Z2 + z
query := Cuboid{P1: c1, P2: c2} query := Cuboid{P1: c1, P2: c2}
if err := btc.client.QueryCuboid(query, drawBlock); err != nil { var count int
var err error
if count, err = btc.client.QueryCuboid(query, btc.drawBlock); err != nil {
return false, err return false, err
} }
if err := btc.yOrder.Drain(btc.colors); err != nil { allCount += count
if err = btc.yOrder.Drain(btc.colors); err != nil {
log.Printf("WARN: rendering block failed: %s\n", err) log.Printf("WARN: rendering block failed: %s\n", err)
} }
} }
oareas, nareas = nareas, oareas[0:0] if allCount > 0 {
xareas := btc.renderer.UncoveredAreas(oareas, nareas)
if len(xareas) == 0 {
break
}
nareas, oareas = xareas, nareas[:0]
}
} }
path := filepath.Join(btc.baseDir, strconv.Itoa(i), strconv.Itoa(j)+".png") path := filepath.Join(btc.baseDir, strconv.Itoa(i), strconv.Itoa(j)+".png")

View File

@ -144,7 +144,7 @@ func (client *RedisClient) readBulkString(data *[]byte) (size int, err error) {
return return
} }
func (client *RedisClient) QueryCuboid(cuboid Cuboid, fn func(*Block)) (err error) { func (client *RedisClient) QueryCuboid(cuboid Cuboid, fn func(*Block)) (count int, err error) {
p1 := CoordToPlain(cuboid.P1) p1 := CoordToPlain(cuboid.P1)
p2 := CoordToPlain(cuboid.P2) p2 := CoordToPlain(cuboid.P2)
if err = client.writeHSpatial(p1, p2); err != nil { if err = client.writeHSpatial(p1, p2); err != nil {
@ -157,7 +157,7 @@ func (client *RedisClient) QueryCuboid(cuboid Cuboid, fn func(*Block)) (err erro
key int64 key int64
) )
for { for ; ; count++ {
if size, err = client.readBulkString(&data); err != nil { if size, err = client.readBulkString(&data); err != nil {
return return
} }