2019-08-17 19:43:08 +01:00
|
|
|
#ifndef VOXEL_STREAM_BLOCK_FILES_H
|
|
|
|
#define VOXEL_STREAM_BLOCK_FILES_H
|
2019-05-28 00:40:09 +01:00
|
|
|
|
2022-02-12 23:37:02 +00:00
|
|
|
#include "../storage/voxel_buffer_internal.h"
|
2020-02-09 17:07:53 +00:00
|
|
|
#include "file_utils.h"
|
2021-02-01 22:25:25 +00:00
|
|
|
#include "voxel_stream.h"
|
2019-05-28 00:40:09 +01:00
|
|
|
|
|
|
|
class FileAccess;
|
|
|
|
|
2022-01-09 22:13:10 +00:00
|
|
|
namespace zylann::voxel {
|
|
|
|
|
2019-05-28 00:40:09 +01:00
|
|
|
// Loads and saves blocks to the filesystem, under a directory.
|
|
|
|
// Each block gets its own file, which may produce a lot of them, but it makes it simple to implement.
|
2021-01-16 13:34:45 +00:00
|
|
|
// This is a naive implementation and may be very slow in practice, so maybe it will be removed in the future.
|
2021-02-01 22:25:25 +00:00
|
|
|
class VoxelStreamBlockFiles : public VoxelStream {
|
|
|
|
GDCLASS(VoxelStreamBlockFiles, VoxelStream)
|
2019-05-28 00:40:09 +01:00
|
|
|
public:
|
2019-08-17 19:43:08 +01:00
|
|
|
VoxelStreamBlockFiles();
|
2019-05-28 00:40:09 +01:00
|
|
|
|
2022-02-12 23:37:02 +00:00
|
|
|
void load_voxel_block(VoxelStream::VoxelQueryData &q) override;
|
|
|
|
void save_voxel_block(VoxelStream::VoxelQueryData &q) override;
|
2019-05-28 00:40:09 +01:00
|
|
|
|
2021-09-18 01:44:33 +01:00
|
|
|
int get_used_channels_mask() const override;
|
|
|
|
|
2019-05-28 00:40:09 +01:00
|
|
|
String get_directory() const;
|
|
|
|
void set_directory(String dirpath);
|
|
|
|
|
2019-08-24 01:44:27 +01:00
|
|
|
int get_block_size_po2() const override;
|
|
|
|
|
2019-05-28 00:40:09 +01:00
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
private:
|
2022-01-09 22:13:10 +00:00
|
|
|
FileResult save_meta();
|
|
|
|
FileResult load_meta();
|
|
|
|
FileResult load_or_create_meta();
|
2019-05-28 00:40:09 +01:00
|
|
|
String get_block_file_path(const Vector3i &block_pos, unsigned int lod) const;
|
|
|
|
Vector3i get_block_position(const Vector3i &origin_in_voxels) const;
|
|
|
|
|
|
|
|
String _directory_path;
|
|
|
|
|
|
|
|
struct Meta {
|
|
|
|
uint8_t version = -1;
|
|
|
|
uint8_t lod_count = 0;
|
2019-08-24 01:44:27 +01:00
|
|
|
uint8_t block_size_po2 = 0; // How many voxels in a block
|
2022-01-09 22:13:10 +00:00
|
|
|
FixedArray<VoxelBufferInternal::Depth, VoxelBufferInternal::MAX_CHANNELS> channel_depths;
|
2019-05-28 00:40:09 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
Meta _meta;
|
2019-08-24 01:44:27 +01:00
|
|
|
bool _meta_loaded = false;
|
|
|
|
bool _meta_saved = false;
|
2019-05-28 00:40:09 +01:00
|
|
|
};
|
|
|
|
|
2022-01-09 22:13:10 +00:00
|
|
|
} // namespace zylann::voxel
|
|
|
|
|
2019-08-17 19:43:08 +01:00
|
|
|
#endif // VOXEL_STREAM_BLOCK_FILES_H
|