2019-08-17 10:15:16 -07:00
|
|
|
#ifndef VOXEL_BLOCK_SERIALIZER_H
|
|
|
|
#define VOXEL_BLOCK_SERIALIZER_H
|
|
|
|
|
|
|
|
#include <core/io/file_access_memory.h>
|
2020-07-25 13:56:23 -07:00
|
|
|
#include <core/reference.h>
|
2019-08-17 10:15:16 -07:00
|
|
|
#include <vector>
|
|
|
|
|
2020-07-25 13:56:23 -07:00
|
|
|
class StreamPeer;
|
2021-09-25 20:14:50 -07:00
|
|
|
class VoxelBufferInternal;
|
2019-08-17 10:15:16 -07:00
|
|
|
|
2020-07-25 13:56:23 -07:00
|
|
|
class VoxelBlockSerializerInternal {
|
|
|
|
// Had to be named differently to not conflict with the wrapper for Godot script API
|
2019-08-17 10:15:16 -07:00
|
|
|
public:
|
2021-01-29 17:36:37 -08:00
|
|
|
struct SerializeResult {
|
|
|
|
const std::vector<uint8_t> &data;
|
|
|
|
bool success;
|
|
|
|
|
|
|
|
inline SerializeResult(const std::vector<uint8_t> &p_data, bool p_success) :
|
|
|
|
data(p_data), success(p_success) {}
|
|
|
|
};
|
|
|
|
|
2021-09-25 20:14:50 -07:00
|
|
|
SerializeResult serialize(const VoxelBufferInternal &voxel_buffer);
|
|
|
|
bool deserialize(const std::vector<uint8_t> &p_data, VoxelBufferInternal &out_voxel_buffer);
|
2019-08-17 10:15:16 -07:00
|
|
|
|
2021-09-25 20:14:50 -07:00
|
|
|
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(FileAccess *f, unsigned int size_to_read, VoxelBufferInternal &out_voxel_buffer);
|
2019-08-17 10:15:16 -07:00
|
|
|
|
2021-09-25 20:14:50 -07:00
|
|
|
int serialize(Ref<StreamPeer> peer, VoxelBufferInternal &voxel_buffer, bool compress);
|
|
|
|
void deserialize(Ref<StreamPeer> peer, VoxelBufferInternal &voxel_buffer, int size, bool decompress);
|
2020-07-25 13:56:23 -07:00
|
|
|
|
2019-08-17 10:15:16 -07:00
|
|
|
private:
|
2021-01-29 17:36:37 -08:00
|
|
|
// Make thread-locals?
|
2019-08-17 10:15:16 -07:00
|
|
|
std::vector<uint8_t> _data;
|
|
|
|
std::vector<uint8_t> _compressed_data;
|
2020-08-10 11:03:01 -07:00
|
|
|
std::vector<uint8_t> _metadata_tmp;
|
2019-08-17 10:15:16 -07:00
|
|
|
FileAccessMemory _file_access_memory;
|
|
|
|
};
|
|
|
|
|
2021-09-25 20:14:50 -07:00
|
|
|
class VoxelBuffer;
|
|
|
|
|
2020-07-25 13:56:23 -07:00
|
|
|
class VoxelBlockSerializer : public Reference {
|
|
|
|
GDCLASS(VoxelBlockSerializer, Reference)
|
|
|
|
public:
|
|
|
|
int serialize(Ref<StreamPeer> peer, Ref<VoxelBuffer> voxel_buffer, bool compress);
|
|
|
|
void deserialize(Ref<StreamPeer> peer, Ref<VoxelBuffer> voxel_buffer, int size, bool decompress);
|
|
|
|
|
|
|
|
private:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
VoxelBlockSerializerInternal _serializer;
|
|
|
|
};
|
|
|
|
|
2019-08-17 10:15:16 -07:00
|
|
|
#endif // VOXEL_BLOCK_SERIALIZER_H
|