Rename tasks:

- As verbs for the task they do
- Suffixed with Task instead of Request,
  to avoid confusion with network stuff
This commit is contained in:
Marc Gilleron 2022-02-06 13:45:51 +00:00
parent ba1930769f
commit 320cc7422c
12 changed files with 140 additions and 143 deletions

View File

@ -1,8 +1,8 @@
#include "block_generate_request.h" #include "generate_block_task.h"
#include "../util/godot/funcs.h" #include "../util/godot/funcs.h"
#include "../util/macros.h" #include "../util/macros.h"
#include "../util/profiling.h" #include "../util/profiling.h"
#include "save_block_data_request.h" #include "save_block_data_task.h"
#include "voxel_server.h" #include "voxel_server.h"
namespace zylann::voxel { namespace zylann::voxel {
@ -11,19 +11,19 @@ namespace {
std::atomic_int g_debug_generate_tasks_count; std::atomic_int g_debug_generate_tasks_count;
} }
BlockGenerateRequest::BlockGenerateRequest() { GenerateBlockTask::GenerateBlockTask() {
++g_debug_generate_tasks_count; ++g_debug_generate_tasks_count;
} }
BlockGenerateRequest::~BlockGenerateRequest() { GenerateBlockTask::~GenerateBlockTask() {
--g_debug_generate_tasks_count; --g_debug_generate_tasks_count;
} }
int BlockGenerateRequest::debug_get_running_count() { int GenerateBlockTask::debug_get_running_count() {
return g_debug_generate_tasks_count; return g_debug_generate_tasks_count;
} }
void BlockGenerateRequest::run(zylann::ThreadedTaskContext ctx) { void GenerateBlockTask::run(zylann::ThreadedTaskContext ctx) {
VOXEL_PROFILE_SCOPE(); VOXEL_PROFILE_SCOPE();
CRASH_COND(stream_dependency == nullptr); CRASH_COND(stream_dependency == nullptr);
@ -57,28 +57,28 @@ void BlockGenerateRequest::run(zylann::ThreadedTaskContext ctx) {
// No instances, generators are not designed to produce them at this stage yet. // No instances, generators are not designed to produce them at this stage yet.
// No priority data, saving doesnt need sorting // No priority data, saving doesnt need sorting
SaveBlockDataRequest *save_request = SaveBlockDataTask *save_task =
memnew(SaveBlockDataRequest(volume_id, position, lod, block_size, voxels_copy, stream_dependency)); memnew(SaveBlockDataTask(volume_id, position, lod, block_size, voxels_copy, stream_dependency));
VoxelServer::get_singleton()->push_async_task(save_request); VoxelServer::get_singleton()->push_async_task(save_task);
} }
} }
has_run = true; has_run = true;
} }
int BlockGenerateRequest::get_priority() { int GenerateBlockTask::get_priority() {
float closest_viewer_distance_sq; float closest_viewer_distance_sq;
const int p = priority_dependency.evaluate(lod, &closest_viewer_distance_sq); const int p = priority_dependency.evaluate(lod, &closest_viewer_distance_sq);
too_far = drop_beyond_max_distance && closest_viewer_distance_sq > priority_dependency.drop_distance_squared; too_far = drop_beyond_max_distance && closest_viewer_distance_sq > priority_dependency.drop_distance_squared;
return p; return p;
} }
bool BlockGenerateRequest::is_cancelled() { bool GenerateBlockTask::is_cancelled() {
return !stream_dependency->valid || too_far; // || stream_dependency->stream->get_fallback_generator().is_null(); return !stream_dependency->valid || too_far; // || stream_dependency->stream->get_fallback_generator().is_null();
} }
void BlockGenerateRequest::apply_result() { void GenerateBlockTask::apply_result() {
bool aborted = true; bool aborted = true;
if (VoxelServer::get_singleton()->is_volume_valid(volume_id)) { if (VoxelServer::get_singleton()->is_volume_valid(volume_id)) {

View File

@ -1,5 +1,5 @@
#ifndef BLOCK_GENERATE_REQUEST_H #ifndef GENERATE_BLOCK_TASK_H
#define BLOCK_GENERATE_REQUEST_H #define GENERATE_BLOCK_TASK_H
#include "../util/tasks/async_dependency_tracker.h" #include "../util/tasks/async_dependency_tracker.h"
#include "../util/tasks/threaded_task.h" #include "../util/tasks/threaded_task.h"
@ -8,10 +8,10 @@
namespace zylann::voxel { namespace zylann::voxel {
class BlockGenerateRequest : public IThreadedTask { class GenerateBlockTask : public IThreadedTask {
public: public:
BlockGenerateRequest(); GenerateBlockTask();
~BlockGenerateRequest(); ~GenerateBlockTask();
void run(ThreadedTaskContext ctx) override; void run(ThreadedTaskContext ctx) override;
int get_priority() override; int get_priority() override;
@ -36,4 +36,4 @@ public:
} // namespace zylann::voxel } // namespace zylann::voxel
#endif // BLOCK_GENERATE_REQUEST_H #endif // GENERATE_BLOCK_TASK_H

View File

@ -1,11 +1,11 @@
#include "all_blocks_data_request.h" #include "load_all_blocks_data_task.h"
#include "../util/macros.h" #include "../util/macros.h"
#include "../util/profiling.h" #include "../util/profiling.h"
#include "voxel_server.h" #include "voxel_server.h"
namespace zylann::voxel { namespace zylann::voxel {
void AllBlocksDataRequest::run(zylann::ThreadedTaskContext ctx) { void LoadAllBlocksDataTask::run(zylann::ThreadedTaskContext ctx) {
VOXEL_PROFILE_SCOPE(); VOXEL_PROFILE_SCOPE();
CRASH_COND(stream_dependency == nullptr); CRASH_COND(stream_dependency == nullptr);
@ -17,15 +17,15 @@ void AllBlocksDataRequest::run(zylann::ThreadedTaskContext ctx) {
PRINT_VERBOSE(String("Loaded {0} blocks for volume {1}").format(varray(_result.blocks.size(), volume_id))); PRINT_VERBOSE(String("Loaded {0} blocks for volume {1}").format(varray(_result.blocks.size(), volume_id)));
} }
int AllBlocksDataRequest::get_priority() { int LoadAllBlocksDataTask::get_priority() {
return 0; return 0;
} }
bool AllBlocksDataRequest::is_cancelled() { bool LoadAllBlocksDataTask::is_cancelled() {
return !stream_dependency->valid; return !stream_dependency->valid;
} }
void AllBlocksDataRequest::apply_result() { void LoadAllBlocksDataTask::apply_result() {
if (VoxelServer::get_singleton()->is_volume_valid(volume_id)) { if (VoxelServer::get_singleton()->is_volume_valid(volume_id)) {
// TODO Comparing pointer may not be guaranteed // TODO Comparing pointer may not be guaranteed
// The request response must match the dependency it would have been requested with. // The request response must match the dependency it would have been requested with.

View File

@ -1,5 +1,5 @@
#ifndef ALL_BLOCKS_DATA_REQUEST_H #ifndef LOAD_ALL_BLOCKS_DATA_TASK_H
#define ALL_BLOCKS_DATA_REQUEST_H #define LOAD_ALL_BLOCKS_DATA_TASK_H
#include "../streams/voxel_stream.h" #include "../streams/voxel_stream.h"
#include "../util/tasks/threaded_task.h" #include "../util/tasks/threaded_task.h"
@ -8,7 +8,7 @@
namespace zylann::voxel { namespace zylann::voxel {
class AllBlocksDataRequest : public IThreadedTask { class LoadAllBlocksDataTask : public IThreadedTask {
public: public:
void run(ThreadedTaskContext ctx) override; void run(ThreadedTaskContext ctx) override;
int get_priority() override; int get_priority() override;
@ -24,4 +24,4 @@ private:
} // namespace zylann::voxel } // namespace zylann::voxel
#endif // ALL_BLOCKS_DATA_REQUEST_H #endif // LOAD_ALL_BLOCKS_DATA_TASK_H

View File

@ -1,8 +1,8 @@
#include "load_block_data_request.h" #include "load_block_data_task.h"
#include "../util/godot/funcs.h" #include "../util/godot/funcs.h"
#include "../util/macros.h" #include "../util/macros.h"
#include "../util/profiling.h" #include "../util/profiling.h"
#include "block_generate_request.h" #include "generate_block_task.h"
#include "voxel_server.h" #include "voxel_server.h"
namespace zylann::voxel { namespace zylann::voxel {
@ -11,8 +11,8 @@ namespace {
std::atomic_int g_debug_load_block_tasks_count; std::atomic_int g_debug_load_block_tasks_count;
} }
LoadBlockDataRequest::LoadBlockDataRequest(uint32_t p_volume_id, Vector3i p_block_pos, uint8_t p_lod, LoadBlockDataTask::LoadBlockDataTask(uint32_t p_volume_id, Vector3i p_block_pos, uint8_t p_lod, uint8_t p_block_size,
uint8_t p_block_size, bool p_request_instances, std::shared_ptr<StreamingDependency> p_stream_dependency, bool p_request_instances, std::shared_ptr<StreamingDependency> p_stream_dependency,
PriorityDependency p_priority_dependency) : PriorityDependency p_priority_dependency) :
_priority_dependency(p_priority_dependency), _priority_dependency(p_priority_dependency),
_position(p_block_pos), _position(p_block_pos),
@ -26,15 +26,15 @@ LoadBlockDataRequest::LoadBlockDataRequest(uint32_t p_volume_id, Vector3i p_bloc
++g_debug_load_block_tasks_count; ++g_debug_load_block_tasks_count;
} }
LoadBlockDataRequest::~LoadBlockDataRequest() { LoadBlockDataTask::~LoadBlockDataTask() {
--g_debug_load_block_tasks_count; --g_debug_load_block_tasks_count;
} }
int LoadBlockDataRequest::debug_get_running_count() { int LoadBlockDataTask::debug_get_running_count() {
return g_debug_load_block_tasks_count; return g_debug_load_block_tasks_count;
} }
void LoadBlockDataRequest::run(zylann::ThreadedTaskContext ctx) { void LoadBlockDataTask::run(zylann::ThreadedTaskContext ctx) {
VOXEL_PROFILE_SCOPE(); VOXEL_PROFILE_SCOPE();
CRASH_COND(_stream_dependency == nullptr); CRASH_COND(_stream_dependency == nullptr);
@ -62,16 +62,16 @@ void LoadBlockDataRequest::run(zylann::ThreadedTaskContext ctx) {
Ref<VoxelGenerator> generator = _stream_dependency->generator; Ref<VoxelGenerator> generator = _stream_dependency->generator;
if (generator.is_valid()) { if (generator.is_valid()) {
BlockGenerateRequest *r = memnew(BlockGenerateRequest); GenerateBlockTask *task = memnew(GenerateBlockTask);
r->voxels = _voxels; task->voxels = _voxels;
r->volume_id = _volume_id; task->volume_id = _volume_id;
r->position = _position; task->position = _position;
r->lod = _lod; task->lod = _lod;
r->block_size = _block_size; task->block_size = _block_size;
r->stream_dependency = _stream_dependency; task->stream_dependency = _stream_dependency;
r->priority_dependency = _priority_dependency; task->priority_dependency = _priority_dependency;
VoxelServer::get_singleton()->push_async_task(r); VoxelServer::get_singleton()->push_async_task(task);
_fallback_on_generator = true; _fallback_on_generator = true;
} else { } else {
@ -105,18 +105,18 @@ void LoadBlockDataRequest::run(zylann::ThreadedTaskContext ctx) {
_has_run = true; _has_run = true;
} }
int LoadBlockDataRequest::get_priority() { int LoadBlockDataTask::get_priority() {
float closest_viewer_distance_sq; float closest_viewer_distance_sq;
const int p = _priority_dependency.evaluate(_lod, &closest_viewer_distance_sq); const int p = _priority_dependency.evaluate(_lod, &closest_viewer_distance_sq);
_too_far = closest_viewer_distance_sq > _priority_dependency.drop_distance_squared; _too_far = closest_viewer_distance_sq > _priority_dependency.drop_distance_squared;
return p; return p;
} }
bool LoadBlockDataRequest::is_cancelled() { bool LoadBlockDataTask::is_cancelled() {
return !_stream_dependency->valid || _too_far; return !_stream_dependency->valid || _too_far;
} }
void LoadBlockDataRequest::apply_result() { void LoadBlockDataTask::apply_result() {
if (VoxelServer::get_singleton()->is_volume_valid(_volume_id)) { if (VoxelServer::get_singleton()->is_volume_valid(_volume_id)) {
// TODO Comparing pointer may not be guaranteed // TODO Comparing pointer may not be guaranteed
// The request response must match the dependency it would have been requested with. // The request response must match the dependency it would have been requested with.

View File

@ -1,5 +1,5 @@
#ifndef LOAD_BLOCK_DATA_REQUEST_H #ifndef LOAD_BLOCK_DATA_TASK_H
#define LOAD_BLOCK_DATA_REQUEST_H #define LOAD_BLOCK_DATA_TASK_H
#include "../util/tasks/threaded_task.h" #include "../util/tasks/threaded_task.h"
#include "priority_dependency.h" #include "priority_dependency.h"
@ -7,13 +7,13 @@
namespace zylann::voxel { namespace zylann::voxel {
class LoadBlockDataRequest : public IThreadedTask { class LoadBlockDataTask : public IThreadedTask {
public: public:
LoadBlockDataRequest(uint32_t p_volume_id, Vector3i p_block_pos, uint8_t p_lod, uint8_t p_block_size, LoadBlockDataTask(uint32_t p_volume_id, Vector3i p_block_pos, uint8_t p_lod, uint8_t p_block_size,
bool p_request_instances, std::shared_ptr<StreamingDependency> p_stream_dependency, bool p_request_instances, std::shared_ptr<StreamingDependency> p_stream_dependency,
PriorityDependency p_priority_dependency); PriorityDependency p_priority_dependency);
~LoadBlockDataRequest(); ~LoadBlockDataTask();
void run(ThreadedTaskContext ctx) override; void run(ThreadedTaskContext ctx) override;
int get_priority() override; int get_priority() override;
@ -41,4 +41,4 @@ private:
} // namespace zylann::voxel } // namespace zylann::voxel
#endif // LOAD_BLOCK_DATA_REQUEST_H #endif // LOAD_BLOCK_DATA_TASK_H

View File

@ -1,4 +1,4 @@
#include "block_mesh_request.h" #include "mesh_block_task.h"
#include "../util/macros.h" #include "../util/macros.h"
#include "../util/profiling.h" #include "../util/profiling.h"
#include "voxel_server.h" #include "voxel_server.h"
@ -137,19 +137,19 @@ namespace {
std::atomic_int g_debug_mesh_tasks_count; std::atomic_int g_debug_mesh_tasks_count;
} //namespace } //namespace
BlockMeshRequest::BlockMeshRequest() { MeshBlockTask::MeshBlockTask() {
++g_debug_mesh_tasks_count; ++g_debug_mesh_tasks_count;
} }
BlockMeshRequest::~BlockMeshRequest() { MeshBlockTask::~MeshBlockTask() {
--g_debug_mesh_tasks_count; --g_debug_mesh_tasks_count;
} }
int BlockMeshRequest::debug_get_running_count() { int MeshBlockTask::debug_get_running_count() {
return g_debug_mesh_tasks_count; return g_debug_mesh_tasks_count;
} }
void BlockMeshRequest::run(zylann::ThreadedTaskContext ctx) { void MeshBlockTask::run(zylann::ThreadedTaskContext ctx) {
VOXEL_PROFILE_SCOPE(); VOXEL_PROFILE_SCOPE();
CRASH_COND(meshing_dependency == nullptr); CRASH_COND(meshing_dependency == nullptr);
@ -169,18 +169,18 @@ void BlockMeshRequest::run(zylann::ThreadedTaskContext ctx) {
_has_run = true; _has_run = true;
} }
int BlockMeshRequest::get_priority() { int MeshBlockTask::get_priority() {
float closest_viewer_distance_sq; float closest_viewer_distance_sq;
const int p = priority_dependency.evaluate(lod, &closest_viewer_distance_sq); const int p = priority_dependency.evaluate(lod, &closest_viewer_distance_sq);
_too_far = closest_viewer_distance_sq > priority_dependency.drop_distance_squared; _too_far = closest_viewer_distance_sq > priority_dependency.drop_distance_squared;
return p; return p;
} }
bool BlockMeshRequest::is_cancelled() { bool MeshBlockTask::is_cancelled() {
return !meshing_dependency->valid || _too_far; return !meshing_dependency->valid || _too_far;
} }
void BlockMeshRequest::apply_result() { void MeshBlockTask::apply_result() {
if (VoxelServer::get_singleton()->is_volume_valid(volume_id)) { if (VoxelServer::get_singleton()->is_volume_valid(volume_id)) {
// The request response must match the dependency it would have been requested with. // 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 it doesn't match, we are no longer interested in the result.

View File

@ -1,5 +1,5 @@
#ifndef VOXEL_BLOCK_MESH_REQUEST_H #ifndef VOXEL_MESH_BLOCK_TASK_H
#define VOXEL_BLOCK_MESH_REQUEST_H #define VOXEL_MESH_BLOCK_TASK_H
#include "../constants/voxel_constants.h" #include "../constants/voxel_constants.h"
#include "../generators/voxel_generator.h" #include "../generators/voxel_generator.h"
@ -11,7 +11,7 @@
namespace zylann::voxel { namespace zylann::voxel {
// Asynchronous task generating a mesh from voxel blocks and their neighbors, in a particular volume // Asynchronous task generating a mesh from voxel blocks and their neighbors, in a particular volume
class BlockMeshRequest : public IThreadedTask { class MeshBlockTask : public IThreadedTask {
public: public:
struct MeshingDependency { struct MeshingDependency {
Ref<VoxelMesher> mesher; Ref<VoxelMesher> mesher;
@ -19,8 +19,8 @@ public:
bool valid = true; bool valid = true;
}; };
BlockMeshRequest(); MeshBlockTask();
~BlockMeshRequest(); ~MeshBlockTask();
void run(ThreadedTaskContext ctx) override; void run(ThreadedTaskContext ctx) override;
int get_priority() override; int get_priority() override;
@ -49,4 +49,4 @@ private:
} // namespace zylann::voxel } // namespace zylann::voxel
#endif // VOXEL_BLOCK_MESH_REQUEST_H #endif // VOXEL_MESH_BLOCK_TASK_H

View File

@ -1,8 +1,8 @@
#include "save_block_data_request.h" #include "save_block_data_task.h"
#include "../util/godot/funcs.h" #include "../util/godot/funcs.h"
#include "../util/macros.h" #include "../util/macros.h"
#include "../util/profiling.h" #include "../util/profiling.h"
#include "block_generate_request.h" #include "generate_block_task.h"
#include "voxel_server.h" #include "voxel_server.h"
namespace zylann::voxel { namespace zylann::voxel {
@ -11,9 +11,8 @@ namespace {
std::atomic_int g_debug_save_block_tasks_count; std::atomic_int g_debug_save_block_tasks_count;
} }
SaveBlockDataRequest::SaveBlockDataRequest(uint32_t p_volume_id, Vector3i p_block_pos, uint8_t p_lod, SaveBlockDataTask::SaveBlockDataTask(uint32_t p_volume_id, Vector3i p_block_pos, uint8_t p_lod, uint8_t p_block_size,
uint8_t p_block_size, std::shared_ptr<VoxelBufferInternal> p_voxels, std::shared_ptr<VoxelBufferInternal> p_voxels, std::shared_ptr<StreamingDependency> p_stream_dependency) :
std::shared_ptr<StreamingDependency> p_stream_dependency) :
_voxels(p_voxels), _voxels(p_voxels),
_position(p_block_pos), _position(p_block_pos),
_volume_id(p_volume_id), _volume_id(p_volume_id),
@ -26,9 +25,8 @@ SaveBlockDataRequest::SaveBlockDataRequest(uint32_t p_volume_id, Vector3i p_bloc
++g_debug_save_block_tasks_count; ++g_debug_save_block_tasks_count;
} }
SaveBlockDataRequest::SaveBlockDataRequest(uint32_t p_volume_id, Vector3i p_block_pos, uint8_t p_lod, SaveBlockDataTask::SaveBlockDataTask(uint32_t p_volume_id, Vector3i p_block_pos, uint8_t p_lod, uint8_t p_block_size,
uint8_t p_block_size, std::unique_ptr<InstanceBlockData> p_instances, std::unique_ptr<InstanceBlockData> p_instances, std::shared_ptr<StreamingDependency> p_stream_dependency) :
std::shared_ptr<StreamingDependency> p_stream_dependency) :
_instances(std::move(p_instances)), _instances(std::move(p_instances)),
_position(p_block_pos), _position(p_block_pos),
_volume_id(p_volume_id), _volume_id(p_volume_id),
@ -41,15 +39,15 @@ SaveBlockDataRequest::SaveBlockDataRequest(uint32_t p_volume_id, Vector3i p_bloc
++g_debug_save_block_tasks_count; ++g_debug_save_block_tasks_count;
} }
SaveBlockDataRequest::~SaveBlockDataRequest() { SaveBlockDataTask::~SaveBlockDataTask() {
--g_debug_save_block_tasks_count; --g_debug_save_block_tasks_count;
} }
int SaveBlockDataRequest::debug_get_running_count() { int SaveBlockDataTask::debug_get_running_count() {
return g_debug_save_block_tasks_count; return g_debug_save_block_tasks_count;
} }
void SaveBlockDataRequest::run(zylann::ThreadedTaskContext ctx) { void SaveBlockDataTask::run(zylann::ThreadedTaskContext ctx) {
VOXEL_PROFILE_SCOPE(); VOXEL_PROFILE_SCOPE();
CRASH_COND(_stream_dependency == nullptr); CRASH_COND(_stream_dependency == nullptr);
@ -90,15 +88,15 @@ void SaveBlockDataRequest::run(zylann::ThreadedTaskContext ctx) {
_has_run = true; _has_run = true;
} }
int SaveBlockDataRequest::get_priority() { int SaveBlockDataTask::get_priority() {
return 0; return 0;
} }
bool SaveBlockDataRequest::is_cancelled() { bool SaveBlockDataTask::is_cancelled() {
return false; return false;
} }
void SaveBlockDataRequest::apply_result() { void SaveBlockDataTask::apply_result() {
if (VoxelServer::get_singleton()->is_volume_valid(_volume_id)) { if (VoxelServer::get_singleton()->is_volume_valid(_volume_id)) {
if (_stream_dependency->valid) { if (_stream_dependency->valid) {
VoxelServer::BlockDataOutput o; VoxelServer::BlockDataOutput o;

View File

@ -1,22 +1,22 @@
#ifndef SAVE_BLOCK_DATA_REQUEST_H #ifndef SAVE_BLOCK_DATA_TASK_H
#define SAVE_BLOCK_DATA_REQUEST_H #define SAVE_BLOCK_DATA_TASK_H
#include "../util/tasks/threaded_task.h" #include "../util/tasks/threaded_task.h"
#include "streaming_dependency.h" #include "streaming_dependency.h"
namespace zylann::voxel { namespace zylann::voxel {
class SaveBlockDataRequest : public IThreadedTask { class SaveBlockDataTask : public IThreadedTask {
public: public:
// For saving voxels only // For saving voxels only
SaveBlockDataRequest(uint32_t p_volume_id, Vector3i p_block_pos, uint8_t p_lod, uint8_t p_block_size, SaveBlockDataTask(uint32_t p_volume_id, Vector3i p_block_pos, uint8_t p_lod, uint8_t p_block_size,
std::shared_ptr<VoxelBufferInternal> p_voxels, std::shared_ptr<StreamingDependency> p_stream_dependency); std::shared_ptr<VoxelBufferInternal> p_voxels, std::shared_ptr<StreamingDependency> p_stream_dependency);
// For saving instances only // For saving instances only
SaveBlockDataRequest(uint32_t p_volume_id, Vector3i p_block_pos, uint8_t p_lod, uint8_t p_block_size, SaveBlockDataTask(uint32_t p_volume_id, Vector3i p_block_pos, uint8_t p_lod, uint8_t p_block_size,
std::unique_ptr<InstanceBlockData> p_instances, std::shared_ptr<StreamingDependency> p_stream_dependency); std::unique_ptr<InstanceBlockData> p_instances, std::shared_ptr<StreamingDependency> p_stream_dependency);
~SaveBlockDataRequest(); ~SaveBlockDataTask();
void run(ThreadedTaskContext ctx) override; void run(ThreadedTaskContext ctx) override;
int get_priority() override; int get_priority() override;
@ -40,4 +40,4 @@ private:
} // namespace zylann::voxel } // namespace zylann::voxel
#endif // SAVE_BLOCK_DATA_REQUEST_H #endif // SAVE_BLOCK_DATA_TASK_H

View File

@ -5,10 +5,10 @@
#include "../util/godot/funcs.h" #include "../util/godot/funcs.h"
#include "../util/macros.h" #include "../util/macros.h"
#include "../util/profiling.h" #include "../util/profiling.h"
#include "all_blocks_data_request.h" #include "generate_block_task.h"
#include "block_generate_request.h" #include "load_all_blocks_data_task.h"
#include "load_block_data_request.h" #include "load_block_data_task.h"
#include "save_block_data_request.h" #include "save_block_data_task.h"
#include <core/config/project_settings.h> #include <core/config/project_settings.h>
#include <core/os/memory.h> #include <core/os/memory.h>
@ -101,9 +101,9 @@ VoxelServer::VoxelServer() {
// Init world // Init world
_world.shared_priority_dependency = gd_make_shared<PriorityDependency::ViewersData>(); _world.shared_priority_dependency = gd_make_shared<PriorityDependency::ViewersData>();
PRINT_VERBOSE(String("Size of LoadBlockDataRequest: {0}").format(varray((int)sizeof(LoadBlockDataRequest)))); PRINT_VERBOSE(String("Size of LoadBlockDataTask: {0}").format(varray((int)sizeof(LoadBlockDataTask))));
PRINT_VERBOSE(String("Size of SaveBlockDataRequest: {0}").format(varray((int)sizeof(SaveBlockDataRequest)))); PRINT_VERBOSE(String("Size of SaveBlockDataTask: {0}").format(varray((int)sizeof(SaveBlockDataTask))));
PRINT_VERBOSE(String("Size of BlockMeshRequest: {0}").format(varray((int)sizeof(BlockMeshRequest)))); PRINT_VERBOSE(String("Size of MeshBlockTask: {0}").format(varray((int)sizeof(MeshBlockTask))));
} }
VoxelServer::~VoxelServer() { VoxelServer::~VoxelServer() {
@ -144,7 +144,7 @@ uint32_t VoxelServer::add_volume(VolumeCallbacks callbacks, VolumeType type) {
Volume volume; Volume volume;
volume.type = type; volume.type = type;
volume.callbacks = callbacks; volume.callbacks = callbacks;
volume.meshing_dependency = gd_make_shared<BlockMeshRequest::MeshingDependency>(); volume.meshing_dependency = gd_make_shared<MeshBlockTask::MeshingDependency>();
return _world.volumes.create(volume); return _world.volumes.create(volume);
} }
@ -194,7 +194,7 @@ void VoxelServer::set_volume_generator(uint32_t volume_id, Ref<VoxelGenerator> g
volume.meshing_dependency->valid = false; volume.meshing_dependency->valid = false;
} }
volume.meshing_dependency = gd_make_shared<BlockMeshRequest::MeshingDependency>(); volume.meshing_dependency = gd_make_shared<MeshBlockTask::MeshingDependency>();
volume.meshing_dependency->mesher = volume.mesher; volume.meshing_dependency->mesher = volume.mesher;
volume.meshing_dependency->generator = volume.generator; volume.meshing_dependency->generator = volume.generator;
} }
@ -207,7 +207,7 @@ void VoxelServer::set_volume_mesher(uint32_t volume_id, Ref<VoxelMesher> mesher)
volume.meshing_dependency->valid = false; volume.meshing_dependency->valid = false;
} }
volume.meshing_dependency = gd_make_shared<BlockMeshRequest::MeshingDependency>(); volume.meshing_dependency = gd_make_shared<MeshBlockTask::MeshingDependency>();
volume.meshing_dependency->mesher = volume.mesher; volume.meshing_dependency->mesher = volume.mesher;
volume.meshing_dependency->generator = volume.generator; volume.meshing_dependency->generator = volume.generator;
} }
@ -220,7 +220,7 @@ void VoxelServer::set_volume_octree_lod_distance(uint32_t volume_id, float lod_d
void VoxelServer::invalidate_volume_mesh_requests(uint32_t volume_id) { void VoxelServer::invalidate_volume_mesh_requests(uint32_t volume_id) {
Volume &volume = _world.volumes.get(volume_id); Volume &volume = _world.volumes.get(volume_id);
volume.meshing_dependency->valid = false; volume.meshing_dependency->valid = false;
volume.meshing_dependency = gd_make_shared<BlockMeshRequest::MeshingDependency>(); volume.meshing_dependency = gd_make_shared<MeshBlockTask::MeshingDependency>();
volume.meshing_dependency->mesher = volume.mesher; volume.meshing_dependency->mesher = volume.mesher;
volume.meshing_dependency->generator = volume.generator; volume.meshing_dependency->generator = volume.generator;
} }
@ -271,20 +271,20 @@ void VoxelServer::request_block_mesh(uint32_t volume_id, const BlockMeshInput &i
ERR_FAIL_COND(volume.meshing_dependency->mesher.is_null()); ERR_FAIL_COND(volume.meshing_dependency->mesher.is_null());
ERR_FAIL_COND(volume.data_block_size > 255); ERR_FAIL_COND(volume.data_block_size > 255);
BlockMeshRequest *r = memnew(BlockMeshRequest); MeshBlockTask *task = memnew(MeshBlockTask);
r->volume_id = volume_id; task->volume_id = volume_id;
r->blocks = input.data_blocks; task->blocks = input.data_blocks;
r->blocks_count = input.data_blocks_count; task->blocks_count = input.data_blocks_count;
r->position = input.render_block_position; task->position = input.render_block_position;
r->lod = input.lod; task->lod = input.lod;
r->meshing_dependency = volume.meshing_dependency; task->meshing_dependency = volume.meshing_dependency;
r->data_block_size = volume.data_block_size; task->data_block_size = volume.data_block_size;
init_priority_dependency( init_priority_dependency(
r->priority_dependency, input.render_block_position, input.lod, volume, volume.render_block_size); task->priority_dependency, input.render_block_position, input.lod, volume, volume.render_block_size);
// We'll allocate this quite often. If it becomes a problem, it should be easy to pool. // We'll allocate this quite often. If it becomes a problem, it should be easy to pool.
_general_thread_pool.enqueue(r); _general_thread_pool.enqueue(task);
} }
void VoxelServer::request_block_load(uint32_t volume_id, Vector3i block_pos, int lod, bool request_instances) { void VoxelServer::request_block_load(uint32_t volume_id, Vector3i block_pos, int lod, bool request_instances) {
@ -296,25 +296,25 @@ void VoxelServer::request_block_load(uint32_t volume_id, Vector3i block_pos, int
PriorityDependency priority_dependency; PriorityDependency priority_dependency;
init_priority_dependency(priority_dependency, block_pos, lod, volume, volume.data_block_size); init_priority_dependency(priority_dependency, block_pos, lod, volume, volume.data_block_size);
LoadBlockDataRequest *r = memnew(LoadBlockDataRequest(volume_id, block_pos, lod, volume.data_block_size, LoadBlockDataTask *task = memnew(LoadBlockDataTask(volume_id, block_pos, lod, volume.data_block_size,
request_instances, volume.stream_dependency, priority_dependency)); request_instances, volume.stream_dependency, priority_dependency));
_streaming_thread_pool.enqueue(r); _streaming_thread_pool.enqueue(task);
} else { } else {
// Directly generate the block without checking the stream // Directly generate the block without checking the stream
ERR_FAIL_COND(volume.stream_dependency->generator.is_null()); ERR_FAIL_COND(volume.stream_dependency->generator.is_null());
BlockGenerateRequest *r = memnew(BlockGenerateRequest); GenerateBlockTask *task = memnew(GenerateBlockTask);
r->volume_id = volume_id; task->volume_id = volume_id;
r->position = block_pos; task->position = block_pos;
r->lod = lod; task->lod = lod;
r->block_size = volume.data_block_size; task->block_size = volume.data_block_size;
r->stream_dependency = volume.stream_dependency; task->stream_dependency = volume.stream_dependency;
init_priority_dependency(r->priority_dependency, block_pos, lod, volume, volume.data_block_size); init_priority_dependency(task->priority_dependency, block_pos, lod, volume, volume.data_block_size);
_general_thread_pool.enqueue(r); _general_thread_pool.enqueue(task);
} }
} }
@ -324,18 +324,18 @@ void VoxelServer::request_block_generate(
const Volume &volume = _world.volumes.get(volume_id); const Volume &volume = _world.volumes.get(volume_id);
ERR_FAIL_COND(volume.stream_dependency->generator.is_null()); ERR_FAIL_COND(volume.stream_dependency->generator.is_null());
BlockGenerateRequest *r = memnew(BlockGenerateRequest); GenerateBlockTask *task = memnew(GenerateBlockTask);
r->volume_id = volume_id; task->volume_id = volume_id;
r->position = block_pos; task->position = block_pos;
r->lod = lod; task->lod = lod;
r->block_size = volume.data_block_size; task->block_size = volume.data_block_size;
r->stream_dependency = volume.stream_dependency; task->stream_dependency = volume.stream_dependency;
r->tracker = tracker; task->tracker = tracker;
r->drop_beyond_max_distance = false; task->drop_beyond_max_distance = false;
init_priority_dependency(r->priority_dependency, block_pos, lod, volume, volume.data_block_size); init_priority_dependency(task->priority_dependency, block_pos, lod, volume, volume.data_block_size);
_general_thread_pool.enqueue(r); _general_thread_pool.enqueue(task);
} }
void VoxelServer::request_all_stream_blocks(uint32_t volume_id) { void VoxelServer::request_all_stream_blocks(uint32_t volume_id) {
@ -344,11 +344,11 @@ void VoxelServer::request_all_stream_blocks(uint32_t volume_id) {
ERR_FAIL_COND(volume.stream.is_null()); ERR_FAIL_COND(volume.stream.is_null());
CRASH_COND(volume.stream_dependency == nullptr); CRASH_COND(volume.stream_dependency == nullptr);
AllBlocksDataRequest *r = memnew(AllBlocksDataRequest); LoadAllBlocksDataTask *task = memnew(LoadAllBlocksDataTask);
r->volume_id = volume_id; task->volume_id = volume_id;
r->stream_dependency = volume.stream_dependency; task->stream_dependency = volume.stream_dependency;
_general_thread_pool.enqueue(r); _general_thread_pool.enqueue(task);
} }
void VoxelServer::request_voxel_block_save( void VoxelServer::request_voxel_block_save(
@ -358,12 +358,12 @@ void VoxelServer::request_voxel_block_save(
ERR_FAIL_COND(volume.stream.is_null()); ERR_FAIL_COND(volume.stream.is_null());
CRASH_COND(volume.stream_dependency == nullptr); CRASH_COND(volume.stream_dependency == nullptr);
SaveBlockDataRequest *r = memnew( SaveBlockDataTask *task = memnew(
SaveBlockDataRequest(volume_id, block_pos, lod, volume.data_block_size, voxels, volume.stream_dependency)); SaveBlockDataTask(volume_id, block_pos, lod, volume.data_block_size, voxels, volume.stream_dependency));
// No priority data, saving doesnt need sorting // No priority data, saving doesnt need sorting
_streaming_thread_pool.enqueue(r); _streaming_thread_pool.enqueue(task);
} }
void VoxelServer::request_instance_block_save( void VoxelServer::request_instance_block_save(
@ -372,12 +372,12 @@ void VoxelServer::request_instance_block_save(
ERR_FAIL_COND(volume.stream.is_null()); ERR_FAIL_COND(volume.stream.is_null());
CRASH_COND(volume.stream_dependency == nullptr); CRASH_COND(volume.stream_dependency == nullptr);
SaveBlockDataRequest *r = memnew(SaveBlockDataRequest( SaveBlockDataTask *task = memnew(SaveBlockDataTask(
volume_id, block_pos, lod, volume.data_block_size, std::move(instances), volume.stream_dependency)); volume_id, block_pos, lod, volume.data_block_size, std::move(instances), volume.stream_dependency));
// No priority data, saving doesnt need sorting // No priority data, saving doesnt need sorting
_streaming_thread_pool.enqueue(r); _streaming_thread_pool.enqueue(task);
} }
void VoxelServer::remove_volume(uint32_t volume_id) { void VoxelServer::remove_volume(uint32_t volume_id) {
@ -587,10 +587,9 @@ VoxelServer::Stats VoxelServer::get_stats() const {
Stats s; Stats s;
s.streaming = debug_get_pool_stats(_streaming_thread_pool); s.streaming = debug_get_pool_stats(_streaming_thread_pool);
s.general = debug_get_pool_stats(_general_thread_pool); s.general = debug_get_pool_stats(_general_thread_pool);
s.generation_tasks = BlockGenerateRequest::debug_get_running_count(); s.generation_tasks = GenerateBlockTask::debug_get_running_count();
s.meshing_tasks = BlockMeshRequest::debug_get_running_count(); s.meshing_tasks = GenerateBlockTask::debug_get_running_count();
s.streaming_tasks = s.streaming_tasks = LoadBlockDataTask::debug_get_running_count() + SaveBlockDataTask::debug_get_running_count();
LoadBlockDataRequest::debug_get_running_count() + SaveBlockDataRequest::debug_get_running_count();
s.main_thread_tasks = _time_spread_task_runner.get_pending_count() + _progressive_task_runner.get_pending_count(); s.main_thread_tasks = _time_spread_task_runner.get_pending_count() + _progressive_task_runner.get_pending_count();
return s; return s;
} }

View File

@ -9,7 +9,7 @@
#include "../util/tasks/progressive_task_runner.h" #include "../util/tasks/progressive_task_runner.h"
#include "../util/tasks/threaded_task_runner.h" #include "../util/tasks/threaded_task_runner.h"
#include "../util/tasks/time_spread_task_runner.h" #include "../util/tasks/time_spread_task_runner.h"
#include "block_mesh_request.h" #include "mesh_block_task.h"
#include "streaming_dependency.h" #include "streaming_dependency.h"
#include <memory> #include <memory>
@ -227,7 +227,7 @@ private:
uint32_t data_block_size = 16; uint32_t data_block_size = 16;
float octree_lod_distance = 0; float octree_lod_distance = 0;
std::shared_ptr<StreamingDependency> stream_dependency; std::shared_ptr<StreamingDependency> stream_dependency;
std::shared_ptr<BlockMeshRequest::MeshingDependency> meshing_dependency; std::shared_ptr<MeshBlockTask::MeshingDependency> meshing_dependency;
}; };
struct World { struct World {