godot_voxel/server/load_all_blocks_data_task.cpp

59 lines
1.8 KiB
C++
Raw Normal View History

#include "load_all_blocks_data_task.h"
2022-04-09 15:00:34 +01:00
#include "../util/log.h"
2022-02-02 21:03:09 +00:00
#include "../util/profiling.h"
#include "voxel_server.h"
namespace zylann::voxel {
void LoadAllBlocksDataTask::run(zylann::ThreadedTaskContext ctx) {
2022-02-02 21:03:09 +00:00
VOXEL_PROFILE_SCOPE();
CRASH_COND(stream_dependency == nullptr);
Ref<VoxelStream> stream = stream_dependency->stream;
CRASH_COND(stream.is_null());
stream->load_all_blocks(_result);
2022-04-09 15:00:34 +01:00
ZN_PRINT_VERBOSE(format("Loaded {} blocks for volume {}", _result.blocks.size(), volume_id));
2022-02-02 21:03:09 +00:00
}
int LoadAllBlocksDataTask::get_priority() {
2022-02-02 21:03:09 +00:00
return 0;
}
bool LoadAllBlocksDataTask::is_cancelled() {
2022-02-02 21:03:09 +00:00
return !stream_dependency->valid;
}
void LoadAllBlocksDataTask::apply_result() {
if (VoxelServer::get_singleton().is_volume_valid(volume_id)) {
2022-02-02 21:03:09 +00:00
// TODO Comparing pointer may not be guaranteed
// The request response must match the dependency it would have been requested with.
// If it doesn't match, we are no longer interested in the result.
if (stream_dependency->valid) {
VoxelServer::VolumeCallbacks callbacks = VoxelServer::get_singleton().get_volume_callbacks(volume_id);
2022-02-02 21:03:09 +00:00
ERR_FAIL_COND(callbacks.data_output_callback == nullptr);
for (auto it = _result.blocks.begin(); it != _result.blocks.end(); ++it) {
VoxelStream::FullLoadingResult::Block &rb = *it;
VoxelServer::BlockDataOutput o;
o.voxels = rb.voxels;
o.instances = std::move(rb.instances_data);
o.position = rb.position;
o.lod = rb.lod;
o.dropped = false;
o.max_lod_hint = false;
o.initial_load = true;
callbacks.data_output_callback(callbacks.data, o);
}
}
} else {
// This can happen if the user removes the volume while requests are still about to return
2022-04-06 23:26:54 +01:00
ZN_PRINT_VERBOSE("Stream data request response came back but volume wasn't found");
2022-02-02 21:03:09 +00:00
}
}
} // namespace zylann::voxel