-
Notifications
You must be signed in to change notification settings - Fork 41
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
[Feature Request] Region
wrapper
#79
Comments
I like the idea. The main thing holding me back is what the interface should look like. A We could provide higher level interfaces than getting a block, for example iterate over every chunk in a dimension, or iterate every block. The implementations would then iterate efficiently, eg region at a time. Do you have any use cases in mind, and we can see what a higher level interface than Edit: A good start would probably be a Dimension abstraction that allows you to iterate over regions, and have regions allow you to iterate over chunks (which the RegionFileLoader and Region sort of already implement), and have chunks allow iterating over blocks. |
I dont have any very specific use case in mind. I simple once planed to do some world analysis. Do you have any plans for adding a block placing | chaning API? Any other specific thoughts for a iteration API? |
I have no plans to implement it myself right now, very happy for someone else to tackle it. :) A A mutating iterator would have to read from the file then write to the file, which might be a bit tricky as these things can fail. Ideally there would be a way to signal removing a chunk entirely as well. For mutating a region I think something like this is reasonable, which is possible now: fn do_something(ChunkData) -> Option<ChunkData>;
let region = todo!();
let chunks = region.iter().map(|chunk| { do_something(chunk) }).filter(Option::is_some).collect();
// write a brand new region file with `chunks`. If all of that is figured out, extending similar logic to an entire dimension and world sounds good. In the more distant future (not now), a dimension level 'window2d' API would be great for the rendering. This would iterate a chunk and allow access to the chunks around it. It would automatically take care of loading the up-to 4 region files and chunks to do so. |
what do you think about some sort of backing step, wich unifies the data structure of all chunks. Something similar to what the this would have a performance penalty at the creation of the chunk. But would simplify working with it and possibly even increase the performance if a lot of reads happen. thinking forward this could also simplify adding a new "format" and if writing chunks to files is added would make it easy updating an old chunk to a new fileformat. |
Sorry I'm not sure I understand what you're suggesting. What do you mean by a backing step? Can you give an example? |
very simplified it could look like this. struct MinecraftChunk {
blocks: Vec<Block>,
status: String,
}
let minecraft_chunk = current_minecraft_chunk.into_minecraft_chunk();
let minecraft_chunk = pre18_minecraft_chunk.into_minecraft_chunk();
let minecraft_chunk = pre13_minecraft_chunk.into_minecraft_chunk();
let block = minecraft_chunk.block_at(0,0,0); with baking in this case i mean the action of e.g. creation a vec of Blocks out of the chunk version specific data. the |
Ah I see, like a chunk data format entirely internal to fastanvil, so we only have to implement methods once. Having to match on the enum all the time is annoying, so it's a good idea. I think keeping sections and block palettes makes sense, though. The internal format would probably look very similar to 1.19's now. One major issue here, is that if people are expecting to be able to mutate these chunks we're going to need to be able to go from this internal format to the modern format (and ideally older formats if possible). The existing chunk types are not designed to be written back to disk. They only capture information relevant to rendering a world. For example, they do not capture entities at all, so serializing the An internal data format like this would need to capture all information if it wants to be able to write this data back. At the moment fastanvil leaves that it up to the user of the library to provide a suitable chunk type. Fastanvil providing a type that supports serializing back into a world would be nice. If fastanvil were to support this I think it would make sense as part of its own submodule, maybe a I'd say it's a lot of work! |
would you say it does make sence setting the foundation for such a change though some sort of this would not replace the current Chunk system instead just adding yet another layer ontop. (which looking at the already very complex / deeph structure maby sound scary....) futher there could be a |
I think creating a It's tricky to implement That could then provide an |
sounds good! you said that you would keep the sections and block palettes. In which way would it then be diffrent to the we could simplify the any other stucture changes? at the end of the day the deserialization would work the same as with the |
You're right, it probably wouldn't be much different to the I don't recall why I made the section tower have a As you say the block data can be vec of indicies. Since a section is 16^3, a Yeah, so I'm picturing |
after implemanting the most basic i would image the creation api to be simular to the api of the "normal" one question would be if we should pre create all chunks when the the first way would be very simple to multithread. but allways has a big performace impackt on first creation. what do you think? |
Regions can theoretically get pretty large in filesize, with a compressed chunk being up to 1 MiB, and 1024 of them per region, so storing it all in memory could be quite a pain (and not necessarily any faster overall). I think it would be nice for
It mixes One potential issue here is |
In which way would you say an API like the one requested in #17 should be implemented? would you say a Dimension wide manager | wrapper should implement such API. This Dimension-manager should then cach already created chunks or would you say chunk chaching should be add to the |
I think I would say to simply not implement #17. A Dimension or World struct would allow getting regions, which allows getting chunks, which allows getting blocks. I think chunk caching should be left to the user of the library. The caching you would want would probably depend on your use case. The |
It would be very useful to have some sort of abstraction above a whole dimension (collection of all regions). Which then enables the usage of things like #17 and the possibility to set blocks.
This could go as far as managing all 3 Minecraft-Dimension (Overworld, Nether, End) at the same time. Something like a
World
.What are your thoughts on such abstractions?
The text was updated successfully, but these errors were encountered: