2019-05-20 12:48:58 -07:00
|
|
|
#ifndef VOXEL_DATA_LOADER_H
|
|
|
|
#define VOXEL_DATA_LOADER_H
|
2018-09-24 16:54:07 -07:00
|
|
|
|
2019-05-20 12:48:58 -07:00
|
|
|
#include "block_thread_manager.h"
|
2018-09-24 16:54:07 -07:00
|
|
|
|
2019-05-25 08:07:38 -07:00
|
|
|
class VoxelStream;
|
2018-09-24 16:54:07 -07:00
|
|
|
class VoxelBuffer;
|
|
|
|
|
2019-05-20 12:48:58 -07:00
|
|
|
class VoxelDataLoader {
|
2018-09-24 16:54:07 -07:00
|
|
|
public:
|
2019-05-20 12:48:58 -07:00
|
|
|
struct InputBlockData {
|
|
|
|
Ref<VoxelBuffer> voxels_to_save;
|
2019-04-29 13:57:39 -07:00
|
|
|
};
|
|
|
|
|
2019-06-01 17:59:39 -07:00
|
|
|
enum RequestType {
|
|
|
|
TYPE_SAVE = 0,
|
|
|
|
TYPE_LOAD
|
|
|
|
};
|
|
|
|
|
2019-05-20 12:48:58 -07:00
|
|
|
struct OutputBlockData {
|
2019-06-01 17:59:39 -07:00
|
|
|
RequestType type;
|
2019-05-20 12:48:58 -07:00
|
|
|
Ref<VoxelBuffer> voxels_loaded;
|
2018-09-24 16:54:07 -07:00
|
|
|
};
|
|
|
|
|
2019-05-20 12:48:58 -07:00
|
|
|
struct Processor {
|
|
|
|
void process_block(const InputBlockData &input, OutputBlockData &output, Vector3i block_position, unsigned int lod);
|
2018-09-24 16:54:07 -07:00
|
|
|
|
2019-05-27 17:10:50 -07:00
|
|
|
Ref<VoxelStream> stream;
|
2019-05-20 12:48:58 -07:00
|
|
|
int block_size_pow2 = 0;
|
2018-09-24 16:54:07 -07:00
|
|
|
};
|
|
|
|
|
2019-05-20 12:48:58 -07:00
|
|
|
typedef VoxelBlockThreadManager<InputBlockData, OutputBlockData, Processor> Mgr;
|
|
|
|
typedef Mgr::InputBlock InputBlock;
|
|
|
|
typedef Mgr::OutputBlock OutputBlock;
|
|
|
|
typedef Mgr::Input Input;
|
|
|
|
typedef Mgr::Output Output;
|
|
|
|
typedef Mgr::Stats Stats;
|
2018-09-24 16:54:07 -07:00
|
|
|
|
2019-05-27 17:10:50 -07:00
|
|
|
VoxelDataLoader(int thread_count, Ref<VoxelStream> stream, int block_size_pow2);
|
2019-05-20 12:48:58 -07:00
|
|
|
~VoxelDataLoader();
|
2018-09-24 16:54:07 -07:00
|
|
|
|
2019-05-20 12:48:58 -07:00
|
|
|
void push(const Input &input) { _mgr->push(input); }
|
|
|
|
void pop(Output &output) { _mgr->pop(output); }
|
2019-05-04 17:09:12 -07:00
|
|
|
|
2018-09-24 16:54:07 -07:00
|
|
|
private:
|
2019-05-20 12:48:58 -07:00
|
|
|
Mgr *_mgr = nullptr;
|
2018-09-24 16:54:07 -07:00
|
|
|
};
|
|
|
|
|
2019-05-20 12:48:58 -07:00
|
|
|
#endif // VOXEL_DATA_LOADER_H
|