From 34d01762f079119d0d5275b6f2fd46d648af1bc1 Mon Sep 17 00:00:00 2001 From: "Sascha L. Teichmann" Date: Sun, 27 Feb 2022 21:02:16 +0100 Subject: [PATCH] Started with db abstraction in seeder. --- cmd/mtseeder/baselevel.go | 14 +++----------- cmd/mtseeder/main.go | 12 +++--------- common/basetilecreator.go | 4 ++-- common/dbclient.go | 10 ++++++++++ 4 files changed, 18 insertions(+), 22 deletions(-) create mode 100644 common/dbclient.go diff --git a/cmd/mtseeder/baselevel.go b/cmd/mtseeder/baselevel.go index 72b0c74..65250c6 100644 --- a/cmd/mtseeder/baselevel.go +++ b/cmd/mtseeder/baselevel.go @@ -10,7 +10,6 @@ import ( "os" "path/filepath" "strconv" - "strings" "sync" "bitbucket.org/s_l_teichmann/mtsatellite/common" @@ -57,7 +56,7 @@ func createTiles( } func createBaseLevel( - address string, + dbcc dbClientCreator, xMin, yMin, zMin, xMax, yMax, zMax int, transparent bool, transparentDim float32, colorsFile string, bg color.RGBA, outDir string, @@ -79,17 +78,10 @@ func createBaseLevel( jobs := make(chan blockPos) var done sync.WaitGroup - var proto string - if strings.ContainsRune(address, '/') { - proto = "unix" - } else { - proto = "tcp" - } - 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 } done.Add(1) diff --git a/cmd/mtseeder/main.go b/cmd/mtseeder/main.go index 8af83df..4b5edc2 100644 --- a/cmd/mtseeder/main.go +++ b/cmd/mtseeder/main.go @@ -6,9 +6,7 @@ package main import ( "flag" - "fmt" "log" - "strings" "bitbucket.org/s_l_teichmann/mtsatellite/common" ) @@ -70,16 +68,12 @@ func main() { bg := common.ParseColorDefault(bgColor, common.BackgroundColor) + dbcc := createDBClientCreator(host, port) + if !skipBaseLevel { 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( - address, + dbcc, xMin, yMin, zMin, xMax, yMax, zMax, transparent, td, colorsFile, bg, diff --git a/common/basetilecreator.go b/common/basetilecreator.go index 264ee6c..b6719a4 100644 --- a/common/basetilecreator.go +++ b/common/basetilecreator.go @@ -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 BaseTileCreator struct { - client *RedisClient + client DBClient colors *Colors renderer *Renderer yOrder *YOrder @@ -64,7 +64,7 @@ type BaseTileCreator struct { } func NewBaseTileCreator( - client *RedisClient, + client DBClient, colors *Colors, bg color.RGBA, yMin, yMax int16, diff --git a/common/dbclient.go b/common/dbclient.go new file mode 100644 index 0000000..7d05236 --- /dev/null +++ b/common/dbclient.go @@ -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 +}