world: publish decorated region batches

This commit is contained in:
Daniar Mannanov 2026-08-25 03:59:29 +03:00
parent d8b5d0f79b
commit c4be38acdd
10 changed files with 471 additions and 25 deletions

View file

@ -114,18 +114,20 @@ func New(cfg Config) (*Server, error) {
if err := validateConfig(cfg); err != nil {
return nil, err
}
gen := world.NewVanillaGenerator(cfg.WorldSeed)
gen, batchGen := world.NewVanillaRegionGenerators(cfg.WorldSeed)
em := world.NewEntityManager()
if cfg.WorldDir == "" {
return newServerState(cfg,
world.NewCacheWithLimit(int32(cfg.CompressionThreshold), gen, nil, cfg.MaxCachedChunks), nil, em), nil
chunks := world.NewCacheWithLimit(int32(cfg.CompressionThreshold), gen, nil, cfg.MaxCachedChunks)
chunks.SetBatchGenerator(batchGen)
return newServerState(cfg, chunks, nil, em), nil
}
store, err := world.NewStoreForSeed(cfg.WorldDir, cfg.WorldSeed)
if err != nil {
return nil, err
}
return newServerState(cfg,
world.NewCacheWithLimit(int32(cfg.CompressionThreshold), gen, store, cfg.MaxCachedChunks), store, em), nil
chunks := world.NewCacheWithLimit(int32(cfg.CompressionThreshold), gen, store, cfg.MaxCachedChunks)
chunks.SetBatchGenerator(batchGen)
return newServerState(cfg, chunks, store, em), nil
}
// NewWithCache constructs a server around an existing cache. It is useful for

View file

@ -1,6 +1,7 @@
package server
import (
"context"
"errors"
"sync"
"sync/atomic"
@ -128,3 +129,24 @@ func TestServerRejectsNegativeCacheLimit(t *testing.T) {
t.Fatal("negative cache limit was accepted")
}
}
func TestNewUsesProductionBatchGenerator(t *testing.T) {
cfg := DefaultConfig()
cfg.WorldDir = ""
cfg.WorldSeed = 12345
cfg.MaxCachedChunks = 64
srv, err := New(cfg)
if err != nil {
t.Fatal(err)
}
if err := srv.Chunks().PreloadErrContext(context.Background(), 0, 0); err != nil {
t.Fatal(err)
}
for cx := int32(-1); cx <= 1; cx++ {
for cz := int32(-1); cz <= 1; cz++ {
if !srv.Chunks().IsChunkLoaded(cx, cz) {
t.Fatalf("production batch did not publish neighbor (%d,%d)", cx, cz)
}
}
}
}