Use span instead of requiring a vector
This commit is contained in:
parent
16b7445d1d
commit
33b66153dc
@ -631,7 +631,7 @@ void VoxelStreamSQLite::emerge_blocks(Span<VoxelBlockRequest> p_blocks, Vector<R
|
||||
if (res == RESULT_BLOCK_FOUND) {
|
||||
VoxelBlockRequest &wr = p_blocks[ri];
|
||||
// TODO Not sure if we should actually expect non-null. There can be legit not found blocks.
|
||||
_voxel_block_serializer.decompress_and_deserialize(_temp_block_data, wr.voxel_buffer);
|
||||
_voxel_block_serializer.decompress_and_deserialize(to_span_const(_temp_block_data), wr.voxel_buffer);
|
||||
}
|
||||
|
||||
out_results.write[i] = res;
|
||||
|
@ -264,7 +264,7 @@ VoxelBlockSerializerInternal::SerializeResult VoxelBlockSerializerInternal::seri
|
||||
return SerializeResult(_data, true);
|
||||
}
|
||||
|
||||
bool VoxelBlockSerializerInternal::deserialize(const std::vector<uint8_t> &p_data,
|
||||
bool VoxelBlockSerializerInternal::deserialize(Span<const uint8_t> p_data,
|
||||
VoxelBufferInternal &out_voxel_buffer) {
|
||||
//
|
||||
VOXEL_PROFILE_SCOPE();
|
||||
@ -384,13 +384,13 @@ VoxelBlockSerializerInternal::SerializeResult VoxelBlockSerializerInternal::seri
|
||||
}
|
||||
|
||||
bool VoxelBlockSerializerInternal::decompress_and_deserialize(
|
||||
const std::vector<uint8_t> &p_data, VoxelBufferInternal &out_voxel_buffer) {
|
||||
Span<const uint8_t> p_data, VoxelBufferInternal &out_voxel_buffer) {
|
||||
VOXEL_PROFILE_SCOPE();
|
||||
|
||||
const bool res = VoxelCompressedData::decompress(Span<const uint8_t>(p_data.data(), 0, p_data.size()), _data);
|
||||
const bool res = VoxelCompressedData::decompress(p_data, _data);
|
||||
ERR_FAIL_COND_V(!res, false);
|
||||
|
||||
return deserialize(_data, out_voxel_buffer);
|
||||
return deserialize(to_span_const(_data), out_voxel_buffer);
|
||||
}
|
||||
|
||||
bool VoxelBlockSerializerInternal::decompress_and_deserialize(
|
||||
@ -408,7 +408,7 @@ bool VoxelBlockSerializerInternal::decompress_and_deserialize(
|
||||
const unsigned int read_size = f->get_buffer(_compressed_data.data(), size_to_read);
|
||||
ERR_FAIL_COND_V(read_size != size_to_read, false);
|
||||
|
||||
return decompress_and_deserialize(_compressed_data, out_voxel_buffer);
|
||||
return decompress_and_deserialize(to_span_const(_compressed_data), out_voxel_buffer);
|
||||
}
|
||||
|
||||
int VoxelBlockSerializerInternal::serialize(Ref<StreamPeer> peer, VoxelBufferInternal &voxel_buffer, bool compress) {
|
||||
@ -432,14 +432,14 @@ void VoxelBlockSerializerInternal::deserialize(
|
||||
_compressed_data.resize(size);
|
||||
const Error err = peer->get_data(_compressed_data.data(), _compressed_data.size());
|
||||
ERR_FAIL_COND(err != OK);
|
||||
bool success = decompress_and_deserialize(_compressed_data, voxel_buffer);
|
||||
bool success = decompress_and_deserialize(to_span_const(_compressed_data), voxel_buffer);
|
||||
ERR_FAIL_COND(!success);
|
||||
|
||||
} else {
|
||||
_data.resize(size);
|
||||
const Error err = peer->get_data(_data.data(), _data.size());
|
||||
ERR_FAIL_COND(err != OK);
|
||||
deserialize(_data, voxel_buffer);
|
||||
deserialize(to_span_const(_data), voxel_buffer);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,8 @@
|
||||
#ifndef VOXEL_BLOCK_SERIALIZER_H
|
||||
#define VOXEL_BLOCK_SERIALIZER_H
|
||||
|
||||
#include "../util/span.h"
|
||||
|
||||
#include <core/io/file_access_memory.h>
|
||||
#include <core/reference.h>
|
||||
#include <vector>
|
||||
@ -20,10 +22,10 @@ public:
|
||||
};
|
||||
|
||||
SerializeResult serialize(const VoxelBufferInternal &voxel_buffer);
|
||||
bool deserialize(const std::vector<uint8_t> &p_data, VoxelBufferInternal &out_voxel_buffer);
|
||||
bool deserialize(Span<const uint8_t> p_data, VoxelBufferInternal &out_voxel_buffer);
|
||||
|
||||
SerializeResult serialize_and_compress(const VoxelBufferInternal &voxel_buffer);
|
||||
bool decompress_and_deserialize(const std::vector<uint8_t> &p_data, VoxelBufferInternal &out_voxel_buffer);
|
||||
bool decompress_and_deserialize(Span<const uint8_t> p_data, VoxelBufferInternal &out_voxel_buffer);
|
||||
bool decompress_and_deserialize(FileAccess *f, unsigned int size_to_read, VoxelBufferInternal &out_voxel_buffer);
|
||||
|
||||
int serialize(Ref<StreamPeer> peer, VoxelBufferInternal &voxel_buffer, bool compress);
|
||||
|
Loading…
x
Reference in New Issue
Block a user