2019-05-25 08:07:38 -07:00
|
|
|
#ifndef VOXEL_STREAM_H
|
|
|
|
#define VOXEL_STREAM_H
|
2017-01-01 17:15:57 -08:00
|
|
|
|
2021-01-17 09:18:05 -08:00
|
|
|
#include "../generators/voxel_generator.h"
|
2020-01-26 14:34:26 -08:00
|
|
|
#include "voxel_block_request.h"
|
2019-04-23 17:29:47 -07:00
|
|
|
#include <core/resource.h>
|
2017-01-01 17:15:57 -08:00
|
|
|
|
2020-01-26 14:34:26 -08:00
|
|
|
// Provides access to a source of paged voxel data, which may load and save.
|
2021-01-17 09:18:05 -08:00
|
|
|
// This is intented for files, so it may run in a single background thread and gets requests in batches.
|
|
|
|
// Must be implemented in a thread-safe way.
|
|
|
|
//
|
|
|
|
// If you are looking for a more specialized API to generate voxels with more threads, use VoxelGenerator.
|
|
|
|
//
|
2019-05-25 08:07:38 -07:00
|
|
|
class VoxelStream : public Resource {
|
|
|
|
GDCLASS(VoxelStream, Resource)
|
2017-01-01 17:15:57 -08:00
|
|
|
public:
|
2019-08-18 15:13:12 -07:00
|
|
|
VoxelStream();
|
2021-01-17 09:18:05 -08:00
|
|
|
~VoxelStream();
|
|
|
|
|
|
|
|
enum Result {
|
|
|
|
// Something went wrong, the request should be aborted
|
|
|
|
RESULT_ERROR,
|
|
|
|
// The block could not be found in the stream. The requester may fallback on the generator.
|
|
|
|
RESULT_BLOCK_NOT_FOUND,
|
|
|
|
// The block was found, so the requester won't use the generator.
|
|
|
|
RESULT_BLOCK_FOUND,
|
|
|
|
|
|
|
|
_RESULT_COUNT
|
|
|
|
};
|
2019-08-18 15:13:12 -07:00
|
|
|
|
2020-08-10 11:03:01 -07:00
|
|
|
// TODO Rename load_block()
|
2020-01-21 12:00:29 -08:00
|
|
|
// Queries a block of voxels beginning at the given world-space voxel position and LOD.
|
|
|
|
// If you use LOD, the result at a given coordinate must always remain the same regardless of it.
|
|
|
|
// In other words, voxels values must solely depend on their coordinates or fixed parameters.
|
2021-01-17 09:18:05 -08:00
|
|
|
virtual Result emerge_block(Ref<VoxelBuffer> out_buffer, Vector3i origin_in_voxels, int lod);
|
2020-01-21 12:00:29 -08:00
|
|
|
|
2021-01-17 09:18:05 -08:00
|
|
|
// TODO Rename save_block()
|
2019-04-29 13:57:39 -07:00
|
|
|
virtual void immerge_block(Ref<VoxelBuffer> buffer, Vector3i origin_in_voxels, int lod);
|
2017-01-01 17:15:57 -08:00
|
|
|
|
2019-08-16 12:56:07 -07:00
|
|
|
// Note: vector is passed by ref for performance. Don't reorder it.
|
2021-01-17 09:18:05 -08:00
|
|
|
virtual void emerge_blocks(Vector<VoxelBlockRequest> &p_blocks, Vector<Result> &out_results);
|
2020-01-21 12:00:29 -08:00
|
|
|
|
|
|
|
// Returns multiple blocks of voxels to the stream.
|
|
|
|
// This function is recommended if you save to files, because you can batch their access.
|
2021-01-17 09:18:05 -08:00
|
|
|
virtual void immerge_blocks(const Vector<VoxelBlockRequest> &p_blocks);
|
2019-08-14 12:34:06 -07:00
|
|
|
|
2020-07-11 10:05:26 -07:00
|
|
|
// Declares the format expected from this stream
|
2020-02-14 11:12:13 -08:00
|
|
|
virtual int get_used_channels_mask() const;
|
|
|
|
|
2021-01-17 09:18:05 -08:00
|
|
|
// Gets which block size this stream will provide, as a power of two.
|
|
|
|
// File streams are likely to impose a specific block size,
|
|
|
|
// and changing it can be very expensive so the API is usually specific too
|
|
|
|
virtual int get_block_size_po2() const;
|
|
|
|
|
|
|
|
// Gets at how many levels of details blocks can be queried.
|
|
|
|
virtual int get_lod_count() const;
|
|
|
|
|
|
|
|
// Should generated blocks be saved immediately? If not, they will be saved only when modified.
|
|
|
|
void set_save_generator_output(bool enabled);
|
|
|
|
bool get_save_generator_output() const;
|
2020-08-14 12:33:09 -07:00
|
|
|
|
2021-01-17 09:18:05 -08:00
|
|
|
private:
|
2017-01-01 17:15:57 -08:00
|
|
|
static void _bind_methods();
|
|
|
|
|
2021-01-17 09:18:05 -08:00
|
|
|
void _b_emerge_block(Ref<VoxelBuffer> out_buffer, Vector3 origin_in_voxels, int lod);
|
|
|
|
void _b_immerge_block(Ref<VoxelBuffer> buffer, Vector3 origin_in_voxels, int lod);
|
|
|
|
int _b_get_used_channels_mask() const;
|
|
|
|
Vector3 _b_get_block_size() const;
|
|
|
|
|
|
|
|
struct Parameters {
|
|
|
|
bool save_generator_output = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
Parameters _parameters;
|
|
|
|
RWLock *_parameters_lock = nullptr;
|
2017-01-01 17:15:57 -08:00
|
|
|
};
|
|
|
|
|
2021-01-17 09:18:05 -08:00
|
|
|
VARIANT_ENUM_CAST(VoxelStream::Result);
|
|
|
|
|
2019-05-25 08:16:03 -07:00
|
|
|
#endif // VOXEL_STREAM_H
|