mirror of
https://bitbucket.org/s_l_teichmann/mtsatellite
synced 2024-12-23 08:40:18 +01:00
Started with db abstraction in seeder.
This commit is contained in:
parent
481cf6e517
commit
34d01762f0
@ -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)
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
10
common/dbclient.go
Normal file
10
common/dbclient.go
Normal 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
|
||||
}
|
Loading…
Reference in New Issue
Block a user