Fix terrain streaming and surface spawning

This commit is contained in:
Master290 2026-07-21 11:11:19 +03:00
parent f0279cdb65
commit 2b07d6be20
17 changed files with 424 additions and 111 deletions

View file

@ -32,6 +32,10 @@ type Config struct {
// MaxCachedChunks bounds the in-memory chunk+frame cache (LRU). 0 means
// unbounded (use only for tests/flat worlds). At ~200KiB/chunk, 1024 ≈ 200MB.
MaxCachedChunks int
// MaxViewDistance caps the client-requested chunk radius. Generation is much
// more expensive than vanilla's pregenerated worlds, so the server owns the
// upper bound instead of accepting the client's render distance verbatim.
MaxViewDistance int
}
// DefaultConfig returns sensible defaults matching vanilla expectations.
@ -51,6 +55,7 @@ func DefaultConfig() Config {
// MaxCachedChunks keeps the live cache near 200MB at the default; the
// streamer's pre-gen ring and player view distance comfortably fit.
MaxCachedChunks: 1024,
MaxViewDistance: 2,
}
}
@ -143,6 +148,9 @@ func validateConfig(cfg Config) error {
if cfg.MaxCachedChunks < 0 {
return fmt.Errorf("server: max cached chunks must not be negative")
}
if cfg.MaxViewDistance < 2 || cfg.MaxViewDistance > 16 {
return fmt.Errorf("server: max view distance must be between 2 and 16")
}
return nil
}