Simplified tiles update processing and forwarding.

This commit is contained in:
Sascha L. Teichmann 2016-05-08 22:30:00 +02:00
parent b59f849d73
commit da2a6a82d4
2 changed files with 10 additions and 14 deletions

View File

@ -27,7 +27,7 @@ type connection struct {
} }
type msg struct { type msg struct {
tiles map[xz]bool tiles []xz
pls []*player pls []*player
} }
@ -57,12 +57,8 @@ func (wsf *websocketForwarder) run() {
} }
encMsg := map[string]interface{}{} encMsg := map[string]interface{}{}
if tiles := message.tiles; tiles != nil { if message.tiles != nil {
xzs := make([]xz, 0, len(tiles)) encMsg["tiles"] = message.tiles
for xz := range tiles {
xzs = append(xzs, xz)
}
encMsg["tiles"] = xzs
} }
if message.pls != nil { if message.pls != nil {
@ -101,7 +97,7 @@ func (wsf *websocketForwarder) ServeHTTP(rw http.ResponseWriter, r *http.Request
c.reader() c.reader()
} }
func (wsf *websocketForwarder) BaseTilesUpdated(changes map[xz]bool) { func (wsf *websocketForwarder) BaseTilesUpdated(changes []xz) {
wsf.broadcast <- msg{tiles: changes} wsf.broadcast <- msg{tiles: changes}
} }

View File

@ -25,7 +25,7 @@ import (
) )
type baseTilesUpdates interface { type baseTilesUpdates interface {
BaseTilesUpdated(map[xz]bool) BaseTilesUpdated([]xz)
} }
type tileUpdater struct { type tileUpdater struct {
@ -165,11 +165,11 @@ func extractChanges(changes map[xz]bool) []xzc {
return chs return chs
} }
func activeChanges(changes []xzc) map[xz]bool { func activeChanges(changes []xzc) []xz {
chs := make(map[xz]bool) chs := make([]xz, 0, len(changes))
for i := range changes { for i := range changes {
if !changes[i].canceled { if !changes[i].canceled {
chs[changes[i].xz] = true chs = append(chs, changes[i].xz)
} }
} }
return chs return chs
@ -222,8 +222,8 @@ func (tu *tileUpdater) doUpdates() {
} }
parentJobs := make(map[xz]uint16) parentJobs := make(map[xz]uint16)
for c := range actChs { for i := range actChs {
pxz := c.parent() pxz := actChs[i].parent()
parentJobs[pxz.P] |= pxz.Mask parentJobs[pxz.P] |= pxz.Mask
} }