godot_voxel/terrain/voxel_data_loader.h
Marc Gilleron e9d431360b Fix case where a block gets saved but is requested for loading very shortly after
When a block gets saved, a thread event comes back to confirm it,
but that event can be mistaken for a loading event because nothing was
explicitely checking for it. It worked so far because the "loading blocks"
check was luckily taking "care" of it, except in that edge case.
2020-02-04 15:37:52 +01:00

47 lines
1.1 KiB
C++

#ifndef VOXEL_DATA_LOADER_H
#define VOXEL_DATA_LOADER_H
#include "block_thread_manager.h"
class VoxelStream;
class VoxelBuffer;
class VoxelDataLoader {
public:
struct InputBlockData {
Ref<VoxelBuffer> voxels_to_save;
};
enum RequestType {
TYPE_NOT_INITIALIZED = 0, // For error detection
TYPE_SAVE,
TYPE_LOAD
};
struct OutputBlockData {
RequestType type;
Ref<VoxelBuffer> voxels_loaded;
};
typedef VoxelBlockThreadManager<InputBlockData, OutputBlockData> Mgr;
typedef Mgr::InputBlock InputBlock;
typedef Mgr::OutputBlock OutputBlock;
typedef Mgr::Input Input;
typedef Mgr::Output Output;
typedef Mgr::Stats Stats;
VoxelDataLoader(unsigned int thread_count, Ref<VoxelStream> stream, unsigned int block_size_pow2);
~VoxelDataLoader();
void push(const Input &input) { _mgr->push(input); }
void pop(Output &output) { _mgr->pop(output); }
private:
void process_blocks_thread_func(const ArraySlice<InputBlock> inputs, ArraySlice<OutputBlock> outputs, Ref<VoxelStream> stream, Mgr::ProcessorStats &stats);
Mgr *_mgr = nullptr;
int _block_size_pow2 = 0;
};
#endif // VOXEL_DATA_LOADER_H