forked from df-mc/dragonfly
-
Notifications
You must be signed in to change notification settings - Fork 6
Add block network hash conversion helpers #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
577a54c
Add block network hash conversion helpers
HashimTheArab 7555d77
Add hashed subchunk encoding helper
HashimTheArab 2de5b48
Avoid cloning full chunks for hash encoding
HashimTheArab d3a42ef
Fix chunk decoder comment formatting
HashimTheArab a683785
Test unmapped block hash preservation
HashimTheArab 014e92f
Add runtime cache chunk compaction
HashimTheArab 083ef3b
test: focus chunk coverage on runtime compaction
HashimTheArab 536885c
test: remove runtime compaction coverage
HashimTheArab File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| package chunk | ||
|
|
||
| import "slices" | ||
|
|
||
| // ConvertBlockNetworkHashesToRuntimeIDs converts block palette values from network hashes to registry runtime IDs. | ||
| // Unknown hashes are preserved unchanged. | ||
| func (chunk *Chunk) ConvertBlockNetworkHashesToRuntimeIDs() { | ||
| if chunk == nil { | ||
| return | ||
| } | ||
| for _, sub := range chunk.sub { | ||
| sub.ConvertBlockNetworkHashesToRuntimeIDs(chunk.br) | ||
| } | ||
| } | ||
|
|
||
| // ConvertBlockNetworkHashesToRuntimeIDs converts block palette values from network hashes to registry runtime IDs. | ||
| // Unknown hashes are preserved unchanged. | ||
| func (sub *SubChunk) ConvertBlockNetworkHashesToRuntimeIDs(br BlockRegistry) { | ||
| if sub == nil || br == nil { | ||
| return | ||
| } | ||
| for _, storage := range sub.storages { | ||
| if storage == nil { | ||
| continue | ||
| } | ||
| storage.palette.Replace(func(runtimeID uint32) uint32 { | ||
| if converted, ok := br.HashToRuntimeID(runtimeID); ok { | ||
| return converted | ||
| } | ||
| return runtimeID | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| // EncodeWithBlockNetworkHashes encodes c for the network with block palette runtime IDs converted to network hashes. | ||
| // The chunk is cloned before conversion, so the source chunk remains in registry runtime-ID form. Unknown runtime IDs | ||
| // are preserved unchanged. | ||
| func EncodeWithBlockNetworkHashes(c *Chunk) SerialisedData { | ||
| if c == nil { | ||
| return SerialisedData{} | ||
| } | ||
| networkChunk := c.Clone() | ||
| for _, sub := range networkChunk.sub { | ||
| sub.convertRuntimeIDsToBlockNetworkHashes(c.br) | ||
| } | ||
| return Encode(networkChunk, NetworkEncoding) | ||
| } | ||
|
|
||
| // EncodeSubChunkWithBlockNetworkHashes encodes one sub-chunk for the network with block palette runtime IDs converted | ||
| // to network hashes. The chunk is cloned before conversion, so the source chunk remains unchanged. | ||
| func EncodeSubChunkWithBlockNetworkHashes(c *Chunk, index int) []byte { | ||
| if c == nil || index < 0 || index >= len(c.sub) { | ||
| return nil | ||
| } | ||
| networkChunk := *c | ||
| networkChunk.sub = slices.Clone(c.sub) | ||
| networkChunk.sub[index] = c.sub[index].Clone() | ||
| networkChunk.sub[index].convertRuntimeIDsToBlockNetworkHashes(c.br) | ||
| return EncodeSubChunk(&networkChunk, NetworkEncoding, index) | ||
| } | ||
|
|
||
| func (sub *SubChunk) convertRuntimeIDsToBlockNetworkHashes(br BlockRegistry) { | ||
| if sub == nil || br == nil { | ||
| return | ||
| } | ||
| for _, storage := range sub.storages { | ||
| if storage == nil { | ||
| continue | ||
| } | ||
| storage.palette.Replace(func(runtimeID uint32) uint32 { | ||
| if hash, ok := br.RuntimeIDToHash(runtimeID); ok { | ||
| return hash | ||
| } | ||
| return runtimeID | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗄️ Data Integrity & Integration | 🔴 Critical | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: oomph-ac/dragonfly
Length of output: 5286
🏁 Script executed:
Repository: oomph-ac/dragonfly
Length of output: 16135
🏁 Script executed:
Repository: oomph-ac/dragonfly
Length of output: 7739
🏁 Script executed:
Repository: oomph-ac/dragonfly
Length of output: 11297
Sync
Palette.sizewhen shrinking storage.compactForRuntimeCache()callsresize(size)without updatingstorage.palette.size, so the palette can keep a wider capacity than the packed indices. A laterPalette.Addmay then skip the grow resize and write an index that no longer fitsindexMask, corrupting live chunk data. Update the palette size here or insideresize().🤖 Prompt for AI Agents