2019-05-25 08:07:38 -07:00
|
|
|
#ifndef VOXEL_STREAM_H
|
|
|
|
#define VOXEL_STREAM_H
|
2017-01-01 17:15:57 -08:00
|
|
|
|
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.
|
2019-05-19 10:27:49 -07:00
|
|
|
// Must be implemented in a multi-thread-safe way.
|
2020-01-26 14:34:26 -08:00
|
|
|
// If you are looking for a more specialized API to generate voxels, 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-16 16:46:24 -07:00
|
|
|
struct Stats {
|
2019-08-18 08:10:40 -07:00
|
|
|
int file_openings = 0;
|
|
|
|
int time_spent_opening_files = 0;
|
2019-08-16 16:46:24 -07:00
|
|
|
};
|
|
|
|
|
2019-08-18 15:13:12 -07:00
|
|
|
VoxelStream();
|
|
|
|
|
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.
|
2019-04-29 13:57:39 -07:00
|
|
|
virtual void emerge_block(Ref<VoxelBuffer> out_buffer, Vector3i origin_in_voxels, int lod);
|
2020-01-21 12:00:29 -08:00
|
|
|
|
2020-08-10 11:03:01 -07:00
|
|
|
// TODO Rename unload_block(), or 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.
|
2020-01-26 14:34:26 -08:00
|
|
|
virtual void emerge_blocks(Vector<VoxelBlockRequest> &p_blocks);
|
2020-01-21 12:00:29 -08:00
|
|
|
|
|
|
|
// Returns multiple blocks of voxels to the stream.
|
|
|
|
// Generators usually don't implement it.
|
|
|
|
// This function is recommended if you save to files, because you can batch their access.
|
2020-01-26 14:34:26 -08:00
|
|
|
virtual void immerge_blocks(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;
|
|
|
|
|
2020-08-11 12:29:27 -07:00
|
|
|
// If the stream is thread-safe, the same instance will be used by the streamer across all threads.
|
|
|
|
// If the stream is not thread-safe:
|
|
|
|
// - If it is cloneable, the streamer will duplicate the instance for each thread.
|
|
|
|
// - If it isn't, the streamer will be limited to a single thread.
|
2019-05-27 16:40:09 -07:00
|
|
|
virtual bool is_thread_safe() const;
|
|
|
|
virtual bool is_cloneable() const;
|
|
|
|
|
2019-08-25 09:40:19 -07:00
|
|
|
Stats get_statistics() const;
|
2019-08-16 16:46:24 -07:00
|
|
|
|
2020-08-14 12:33:09 -07:00
|
|
|
virtual bool has_script() const;
|
|
|
|
|
2017-01-01 17:15:57 -08:00
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
2019-04-29 13:57:39 -07:00
|
|
|
void _emerge_block(Ref<VoxelBuffer> out_buffer, Vector3 origin_in_voxels, int lod);
|
|
|
|
void _immerge_block(Ref<VoxelBuffer> buffer, Vector3 origin_in_voxels, int lod);
|
2020-02-14 11:12:13 -08:00
|
|
|
int _get_used_channels_mask() const;
|
2019-08-16 16:46:24 -07:00
|
|
|
|
|
|
|
Stats _stats;
|
2017-01-01 17:15:57 -08:00
|
|
|
};
|
|
|
|
|
2019-05-25 08:16:03 -07:00
|
|
|
#endif // VOXEL_STREAM_H
|