Schedule source chunk features globally
This commit is contained in:
parent
11440f556c
commit
ea66091f85
4 changed files with 125 additions and 0 deletions
21
internal/world/feature_scheduler.go
Normal file
21
internal/world/feature_scheduler.go
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
package world
|
||||
|
||||
// decorationSource is a source chunk whose feature pass may inspect or write a
|
||||
// target chunk. Vanilla FEATURES has a one-chunk block-state write radius.
|
||||
type decorationSource struct {
|
||||
X, Z int32
|
||||
}
|
||||
|
||||
// decorationSources returns source chunks in deterministic X-major/Z-minor
|
||||
// order. Replaying all nine against one mutable 3x3 terrain region makes target
|
||||
// output independent of cache request order while preserving each source's own
|
||||
// decoration seed and placement origin.
|
||||
func decorationSources(targetX, targetZ int32) []decorationSource {
|
||||
sources := make([]decorationSource, 0, 9)
|
||||
for sourceX := targetX - 1; sourceX <= targetX+1; sourceX++ {
|
||||
for sourceZ := targetZ - 1; sourceZ <= targetZ+1; sourceZ++ {
|
||||
sources = append(sources, decorationSource{X: sourceX, Z: sourceZ})
|
||||
}
|
||||
}
|
||||
return sources
|
||||
}
|
||||
27
internal/world/feature_scheduler_test.go
Normal file
27
internal/world/feature_scheduler_test.go
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
package world
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestDecorationSourcesCoverVanillaFeatureWriteRadius(t *testing.T) {
|
||||
got := decorationSources(4, -7)
|
||||
want := []decorationSource{
|
||||
{3, -8}, {3, -7}, {3, -6},
|
||||
{4, -8}, {4, -7}, {4, -6},
|
||||
{5, -8}, {5, -7}, {5, -6},
|
||||
}
|
||||
if !reflect.DeepEqual(got, want) {
|
||||
t.Fatalf("sources = %v, want %v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDecorationSourcesAreRequestOrderIndependent(t *testing.T) {
|
||||
first := decorationSources(-2, 9)
|
||||
_ = decorationSources(100, -100)
|
||||
second := decorationSources(-2, 9)
|
||||
if !reflect.DeepEqual(first, second) {
|
||||
t.Fatalf("sources changed after unrelated request: %v != %v", first, second)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue