Added a meaningful comment to the method of the base tile creator which creates the backgound task.

This commit is contained in:
Sascha L. Teichmann 2017-04-15 13:08:19 +02:00
parent 6a1356f0eb
commit 8badf4aaca

View File

@ -52,14 +52,13 @@ var BackgroundColor = color.RGBA{R: 0xff, G: 0xff, B: 0xff, A: 0xff}
type BaseTileUpdateFunc func(x, y int, hash []byte) bool type BaseTileUpdateFunc func(x, y int, hash []byte) bool
type BaseTileCreator struct { type BaseTileCreator struct {
client *RedisClient client *RedisClient
colors *Colors colors *Colors
renderer *Renderer renderer *Renderer
yOrder *YOrder yOrder *YOrder
yMin int16 yMin int16
yMax int16 yMax int16
baseDir string baseDir string
//update BaseTileUpdateFunc
emptyImage []byte emptyImage []byte
bg color.RGBA bg color.RGBA
} }
@ -71,7 +70,7 @@ func NewBaseTileCreator(
yMin, yMax int16, yMin, yMax int16,
transparent bool, transparent bool,
baseDir string) *BaseTileCreator { baseDir string) *BaseTileCreator {
//update BaseTileUpdateFunc) *BaseTileCreator {
renderer := NewRenderer(tileWidth, tileHeight, transparent) renderer := NewRenderer(tileWidth, tileHeight, transparent)
yMin, yMax = Order16(yMin, yMax) yMin, yMax = Order16(yMin, yMax)
btc := &BaseTileCreator{ btc := &BaseTileCreator{
@ -83,7 +82,6 @@ func NewBaseTileCreator(
yMax: yMax, yMax: yMax,
baseDir: baseDir, baseDir: baseDir,
} }
//update: update}
btc.yOrder = NewYOrder(btc.renderBlock, yOrderCapacity) btc.yOrder = NewYOrder(btc.renderBlock, yOrderCapacity)
return btc return btc
} }
@ -168,6 +166,9 @@ func (btc *BaseTileCreator) blankImage() []byte {
return btc.emptyImage return btc.emptyImage
} }
// WriteFunc returns a function intended to be run in background so
// the creation of the next tile with this creator can be done
// concurrently.
func (btc *BaseTileCreator) WriteFunc(i, j int, update BaseTileUpdateFunc) func() (bool, error) { func (btc *BaseTileCreator) WriteFunc(i, j int, update BaseTileUpdateFunc) func() (bool, error) {
path := filepath.Join(btc.baseDir, strconv.Itoa(i), strconv.Itoa(j)+".png") path := filepath.Join(btc.baseDir, strconv.Itoa(i), strconv.Itoa(j)+".png")