VoxelBlockSerializer¶
Inherits: RefCounted
Description:¶
Low-level utility to save and load the data within a VoxelBuffer. This can be useful to send data over the network, or to store it in a file.
To store into a file allocating a PackedByteArray:
# `voxels` is an existing `VoxelBuffer`
var data := VoxelBlockSerializer.serialize_to_byte_array(voxels, true)
file.store_32(len(data))
file.store_buffer(data)
To read it back:
var size := file.get_32()
var data := file.get_buffer(size)
VoxelBlockSerializer.deserialize_from_byte_array(data, voxels, true)
To store into a file by re-using a StreamPeerBuffer:
# Note, buffer can be re-used if you do this often
var stream_peer_buffer := StreamPeerBuffer.new()
var written_size = VoxelBlockSerializer.serialize_to_stream_peer(stream_peer_buffer, voxels, true)
file.store_32(written_size)
file.store_buffer(stream_peer_buffer.data_array)
To read it back:
var size := file.get_32()
var stream_peer_buffer := StreamPeerBuffer.new()
# Unfortunately Godot will always allocate memory with this API, can't avoid that
stream_peer_buffer.data_array = file.get_buffer(size)
VoxelBlockSerializer.deserialize_from_stream_peer(stream_peer_buffer, voxels, size, true)
Methods:¶
Return | Signature |
---|---|
void | deserialize_from_byte_array ( PackedByteArray bytes, VoxelBuffer voxel_buffer, bool decompress ) static |
void | deserialize_from_stream_peer ( StreamPeer peer, VoxelBuffer voxel_buffer, int size, bool decompress ) static |
PackedByteArray | serialize_to_byte_array ( VoxelBuffer voxel_buffer, bool compress ) static |
int | serialize_to_stream_peer ( StreamPeer peer, VoxelBuffer voxel_buffer, bool compress ) static |
Method Descriptions¶
- void deserialize_from_byte_array( PackedByteArray bytes, VoxelBuffer voxel_buffer, bool decompress )
Reads the data of a VoxelBuffer from a PackedByteArray.
- void deserialize_from_stream_peer( StreamPeer peer, VoxelBuffer voxel_buffer, int size, bool decompress )
Reads the data of a VoxelBuffer from a StreamPeer. You must provide the number of bytes to read.
- PackedByteArray serialize_to_byte_array( VoxelBuffer voxel_buffer, bool compress )
Stores the data of a VoxelBuffer into a PackedByteArray.
- int serialize_to_stream_peer( StreamPeer peer, VoxelBuffer voxel_buffer, bool compress )
Stores the data of a VoxelBuffer into a StreamPeer. Returns the number of written bytes.
Generated on Sep 12, 2023