Started with db abstraction in seeder.

This commit is contained in:
Sascha L. Teichmann 2022-02-27 21:02:16 +01:00
parent 481cf6e517
commit 34d01762f0
4 changed files with 18 additions and 22 deletions

View File

@ -10,7 +10,6 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"strconv" "strconv"
"strings"
"sync" "sync"
"bitbucket.org/s_l_teichmann/mtsatellite/common" "bitbucket.org/s_l_teichmann/mtsatellite/common"
@ -57,7 +56,7 @@ func createTiles(
} }
func createBaseLevel( func createBaseLevel(
address string, dbcc dbClientCreator,
xMin, yMin, zMin, xMax, yMax, zMax int, xMin, yMin, zMin, xMax, yMax, zMax int,
transparent bool, transparentDim float32, transparent bool, transparentDim float32,
colorsFile string, bg color.RGBA, outDir string, colorsFile string, bg color.RGBA, outDir string,
@ -79,17 +78,10 @@ func createBaseLevel(
jobs := make(chan blockPos) jobs := make(chan blockPos)
var done sync.WaitGroup var done sync.WaitGroup
var proto string
if strings.ContainsRune(address, '/') {
proto = "unix"
} else {
proto = "tcp"
}
for i := 0; i < numWorkers; i++ { for i := 0; i < numWorkers; i++ {
var client *common.RedisClient var client common.DBClient
if client, err = common.NewRedisClient(proto, address); err != nil { if client, err = dbcc(); err != nil {
return return
} }
done.Add(1) done.Add(1)

View File

@ -6,9 +6,7 @@ package main
import ( import (
"flag" "flag"
"fmt"
"log" "log"
"strings"
"bitbucket.org/s_l_teichmann/mtsatellite/common" "bitbucket.org/s_l_teichmann/mtsatellite/common"
) )
@ -70,16 +68,12 @@ func main() {
bg := common.ParseColorDefault(bgColor, common.BackgroundColor) bg := common.ParseColorDefault(bgColor, common.BackgroundColor)
dbcc := createDBClientCreator(host, port)
if !skipBaseLevel { if !skipBaseLevel {
td := common.Clamp32f(float32(transparentDim/100.0), 0.0, 1.0) td := common.Clamp32f(float32(transparentDim/100.0), 0.0, 1.0)
var address string
if strings.ContainsRune(host, '/') {
address = host
} else {
address = fmt.Sprintf("%s:%d", host, port)
}
if err := createBaseLevel( if err := createBaseLevel(
address, dbcc,
xMin, yMin, zMin, xMax, yMax, zMax, xMin, yMin, zMin, xMax, yMax, zMax,
transparent, td, transparent, td,
colorsFile, bg, colorsFile, bg,

View File

@ -52,7 +52,7 @@ 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 DBClient
colors *Colors colors *Colors
renderer *Renderer renderer *Renderer
yOrder *YOrder yOrder *YOrder
@ -64,7 +64,7 @@ type BaseTileCreator struct {
} }
func NewBaseTileCreator( func NewBaseTileCreator(
client *RedisClient, client DBClient,
colors *Colors, colors *Colors,
bg color.RGBA, bg color.RGBA,
yMin, yMax int16, yMin, yMax int16,

10
common/dbclient.go Normal file
View File

@ -0,0 +1,10 @@
package common
// Copyright 2022 by Sascha L. Teichmann
// Use of this source code is governed by the MIT license
// that can be found in the LICENSE file.
type DBClient interface {
QueryCuboid(cuboid Cuboid, fn func(*Block) *Block) (count int, err error)
Close() error
}