cmd/mtredisalize/leveldb.go

This commit is contained in:
Sascha L. Teichmann 2024-01-06 16:12:19 +01:00
parent 5442fab97d
commit 7f69467f26
7 changed files with 27 additions and 24 deletions

View File

@ -44,7 +44,8 @@ func NewRedisParser(reader *bufio.Reader,
} }
func (rp *RedisParser) Parse() { func (rp *RedisParser) Parse() {
for line := rp.nextLine(); line != nil && rp.dispatch(line); line = rp.nextLine() { for line := rp.nextLine(); line != nil && rp.dispatch(line); {
line = rp.nextLine()
} }
} }

View File

@ -196,7 +196,7 @@ func (ss *SQLiteSession) txStmt(stmt *sql.Stmt) *sql.Stmt {
return stmt return stmt
} }
func (ss *SQLiteSession) Del(hash, key []byte) (success bool, err error) { func (ss *SQLiteSession) Del(_, key []byte) (success bool, err error) {
var pos int64 var pos int64
if pos, err = ss.backend.decoder(key); err != nil { if pos, err = ss.backend.decoder(key); err != nil {
return return
@ -226,7 +226,7 @@ func (ss *SQLiteSession) Del(hash, key []byte) (success bool, err error) {
return return
} }
func (ss *SQLiteSession) Fetch(hash, key []byte) (data []byte, err error) { func (ss *SQLiteSession) Fetch(_, key []byte) (data []byte, err error) {
var pos int64 var pos int64
if pos, err = ss.backend.decoder(key); err != nil { if pos, err = ss.backend.decoder(key); err != nil {
return return
@ -248,7 +248,7 @@ func (ss *SQLiteSession) InTransaction() bool {
return ss.tx != nil return ss.tx != nil
} }
func (ss *SQLiteSession) Store(hash, key, value []byte) (exists bool, err error) { func (ss *SQLiteSession) Store(_, key, value []byte) (exists bool, err error) {
var pos int64 var pos int64
if pos, err = ss.backend.decoder(key); err != nil { if pos, err = ss.backend.decoder(key); err != nil {
return return
@ -322,7 +322,7 @@ func (ss *SQLiteSession) CommitTransaction() error {
} }
func (ss *SQLiteSession) AllKeys( func (ss *SQLiteSession) AllKeys(
hash []byte, _ []byte,
done <-chan struct{}) (<-chan []byte, int, error) { done <-chan struct{}) (<-chan []byte, int, error) {
globalLock.RLock() globalLock.RLock()
@ -373,7 +373,7 @@ func (ss *SQLiteSession) AllKeys(
} }
func (ss *SQLiteSession) SpatialQuery( func (ss *SQLiteSession) SpatialQuery(
hash, first, second []byte, _, first, second []byte,
done <-chan struct{}) (<-chan Block, error) { done <-chan struct{}) (<-chan Block, error) {
if ss.backend.interleaved { if ss.backend.interleaved {

View File

@ -177,7 +177,7 @@ func (ps *players) initConnection(wsf *websocketForwarder, c *connection) {
wsf.singleSend(c, &plsMsg{Pls: ps.current()}) wsf.singleSend(c, &plsMsg{Pls: ps.current()})
} }
func (ps *players) ServeHTTP(rw http.ResponseWriter, r *http.Request) { func (ps *players) ServeHTTP(rw http.ResponseWriter, _ *http.Request) {
rw.Header().Set("Content-Type", "application/json") rw.Header().Set("Content-Type", "application/json")
pls := ps.current() pls := ps.current()
encoder := json.NewEncoder(rw) encoder := json.NewEncoder(rw)

View File

@ -37,7 +37,7 @@ func areasContain(areas []Area, x, z int16) bool {
// to newAreas which ist return. // to newAreas which ist return.
// This is useful to spatial query only blocks from db // This is useful to spatial query only blocks from db
// that are not below already rendered blocks. // that are not below already rendered blocks.
func (area Area) recalculate(r *Renderer, nareas []Area) []Area { func (a Area) recalculate(r *Renderer, nareas []Area) []Area {
yM := r.yMin yM := r.yMin
const ex = 1 const ex = 1
@ -45,28 +45,28 @@ func (area Area) recalculate(r *Renderer, nareas []Area) []Area {
nas := len(nareas) nas := len(nareas)
for z := area.Z1; z <= area.Z2; z++ { for z := a.Z1; z <= a.Z2; z++ {
row := z * int16(r.width) row := z * int16(r.width)
for x := area.X1; x <= area.X2; x++ { for x := a.X1; x <= a.X2; x++ {
// Uncovered and not in list of new areas? // Uncovered and not in list of new areas?
if yM[row+x] > math.MinInt32 || areasContain(nareas[nas:], x, z) { if yM[row+x] > math.MinInt32 || areasContain(nareas[nas:], x, z) {
continue continue
} }
a := Area{X1: x, Z1: z, X2: x, Z2: z} ar := Area{X1: x, Z1: z, X2: x, Z2: z}
// Try to extend the area in x and/or z till no further extension is possible. // Try to extend the area in x and/or z till no further extension is possible.
ext: ext:
for extend := ex | ez; extend != 0; { for extend := ex | ez; extend != 0; {
// If we extending in both directions a the current area // If we extending in both directions a the current area
// is higher than wide we gain more block if extend // is higher than wide we gain more block if extend
// in the x direction first. // in the x direction first.
if (extend == ex|ez && a.higher()) || extend&ex == ex { // check x if (extend == ex|ez && ar.higher()) || extend&ex == ex { // check x
nx := a.X2 + 1 nx := ar.X2 + 1
if nx > area.X2 { // reached border of area if nx > a.X2 { // reached border of area
extend &= ^ex extend &= ^ex
continue continue
} }
// Check column right of the current area if its fully free. // Check column right of the current area if its fully free.
for nz := a.Z1; nz <= a.Z2; nz++ { for nz := ar.Z1; nz <= ar.Z2; nz++ {
if yM[nz*int16(r.width)+nx] > math.MinInt32 || if yM[nz*int16(r.width)+nx] > math.MinInt32 ||
areasContain(nareas[nas:], nx, nz) { areasContain(nareas[nas:], nx, nz) {
extend &= ^ex extend &= ^ex
@ -74,16 +74,16 @@ func (area Area) recalculate(r *Renderer, nareas []Area) []Area {
} }
} }
// free -> extend // free -> extend
a.X2 = nx ar.X2 = nx
} else if extend&ez == ez { // check z } else if extend&ez == ez { // check z
nz := a.Z2 + 1 nz := ar.Z2 + 1
if nz > area.Z2 { if nz > a.Z2 {
extend &= ^ez extend &= ^ez
continue continue
} }
// Check line right below the current area if its free. // Check line right below the current area if its free.
row2 := nz * int16(r.width) row2 := nz * int16(r.width)
for nx := a.X1; nx <= a.X2; nx++ { for nx := ar.X1; nx <= ar.X2; nx++ {
if yM[row2+nx] > math.MinInt32 || if yM[row2+nx] > math.MinInt32 ||
areasContain(nareas[nas:], nx, nz) { areasContain(nareas[nas:], nx, nz) {
extend &= ^ez extend &= ^ez
@ -91,11 +91,11 @@ func (area Area) recalculate(r *Renderer, nareas []Area) []Area {
} }
} }
// free -> extend // free -> extend
a.Z2 = nz ar.Z2 = nz
} }
} }
// At this point the area is extended to max. // At this point the area is extended to max.
nareas = append(nareas, a) nareas = append(nareas, ar)
} }
} }
return nareas return nareas

View File

@ -109,7 +109,8 @@ func BlendColor(c1, c2 color.RGBA, a float32) color.RGBA {
func (colors *Colors) BlendColors(span *Span, col color.RGBA, pos int32) color.RGBA { func (colors *Colors) BlendColors(span *Span, col color.RGBA, pos int32) color.RGBA {
curr := span curr := span
// Ignore colors below pos. // Ignore colors below pos.
for ; curr != nil && pos >= curr.To; curr = curr.Next { for curr != nil && pos >= curr.To {
curr = curr.Next
} }
if curr == nil { if curr == nil {
return col return col

View File

@ -8,7 +8,7 @@ import (
"context" "context"
"database/sql" "database/sql"
_ "github.com/jackc/pgx/v4/stdlib" _ "github.com/jackc/pgx/v4/stdlib" // link PostgreSQL driver
) )
const queryCuboidSQL = ` const queryCuboidSQL = `

View File

@ -137,7 +137,8 @@ func (s *Span) Len() int {
} }
func (s *Span) Top() int32 { func (s *Span) Top() int32 {
for ; s.Next != nil; s = s.Next { for s.Next != nil {
s = s.Next
} }
return s.To return s.To
} }