refactor storage format and bpe handling; add redirecting bpe support and utility function for next largest number

This commit is contained in:
adman
2026-05-06 16:48:39 +02:00
parent be6d2fb461
commit 600842a679
3 changed files with 26 additions and 21 deletions
+1
View File
@@ -42,6 +42,7 @@ func MakeBiomeFormat(version string) StorageFormat {
func MakeBlockFormat(version string) StorageFormat {
directBpe := uint8(math.Ceil(math.Log2(float64(len(data.BlocksForVersion(version))))))
return StorageFormat{
RedirectingBpes: []uint8{1, 2, 3},
AvailableBpes: []uint8{0, 4, 5, 6, 7, 8, directBpe},
BiggestDirect: true,
Len: BlocksPerChunkSection,
+10 -15
View File
@@ -6,9 +6,12 @@ import (
"io"
"math"
"slices"
"github.com/admin-else/strom/util"
)
type StorageFormat struct {
RedirectingBpes []uint8 // block bpe 1 2 3 redirect to 4
AvailableBpes []uint8
BiggestDirect bool
Len int32
@@ -33,24 +36,16 @@ func (r StorageFormat) Import(data []uint64, bpe uint8, palette []int32) (s *Sto
s.resize(bpe)
if !slices.Contains(r.AvailableBpes, bpe) {
var newBpe uint8
for _, newBpe = range r.AvailableBpes {
if bpe <= newBpe {
break
if !slices.Contains(r.RedirectingBpes, bpe) {
err = NoAvailableBpeErr
return
}
}
var tmps *Storage
tmps, err = StorageFormat{
AvailableBpes: []uint8{bpe},
BiggestDirect: false,
Len: r.Len,
}.ImportDataDirect(data)
if err != nil {
var found bool
bpe, found = util.GetNextLargestNumberSlice(bpe, r.AvailableBpes)
if !found {
err = NoAvailableBpeErr
return
}
tmps.resize(newBpe)
data = tmps.data
bpe = newBpe
}
if bpe == 0 && len(palette) != 1 {
err = Bpe0PalletMustBeLenOneErr
+9
View File
@@ -85,3 +85,12 @@ func SliceRange[T Numeric](s, e T) (ret []T) {
func IsLastElement[T comparable](s []T, e T) bool {
return len(s) > 0 && s[len(s)-1] == e
}
func GetNextLargestNumberSlice[T Numeric](a T, s []T) (ret T, found bool) {
for _, v := range s {
if v > a {
return v, true
}
}
return
}