Added methods to trigger saves manually
This commit is contained in:
parent
eef3818d29
commit
ec6bc00562
@ -1343,7 +1343,6 @@ struct ScheduleSaveAction {
|
||||
} // namespace
|
||||
|
||||
void VoxelLodTerrain::immerge_block(Vector3i block_pos, int lod_index) {
|
||||
|
||||
VOXEL_PROFILE_SCOPE(profile_immerge_block);
|
||||
|
||||
ERR_FAIL_COND(lod_index >= get_lod_count());
|
||||
@ -1364,7 +1363,6 @@ void VoxelLodTerrain::immerge_block(Vector3i block_pos, int lod_index) {
|
||||
}
|
||||
|
||||
void VoxelLodTerrain::save_all_modified_blocks(bool with_copy) {
|
||||
|
||||
ERR_FAIL_COND(_stream_thread == nullptr);
|
||||
|
||||
flush_pending_lod_edits();
|
||||
@ -1386,12 +1384,10 @@ void VoxelLodTerrain::add_transition_update(VoxelBlock *block) {
|
||||
}
|
||||
|
||||
void VoxelLodTerrain::add_transition_updates_around(Vector3i block_pos, int lod_index) {
|
||||
|
||||
Lod &lod = _lods[lod_index];
|
||||
CRASH_COND(lod.map.is_null());
|
||||
|
||||
for (int dir = 0; dir < Cube::SIDE_COUNT; ++dir) {
|
||||
|
||||
Vector3i npos = block_pos + Cube::g_side_normals[dir];
|
||||
VoxelBlock *nblock = lod.map->get_block(npos);
|
||||
|
||||
@ -1404,9 +1400,7 @@ void VoxelLodTerrain::add_transition_updates_around(Vector3i block_pos, int lod_
|
||||
}
|
||||
|
||||
void VoxelLodTerrain::process_transition_updates() {
|
||||
|
||||
for (unsigned int i = 0; i < _blocks_pending_transition_update.size(); ++i) {
|
||||
|
||||
VoxelBlock *block = _blocks_pending_transition_update[i];
|
||||
CRASH_COND(block == nullptr);
|
||||
|
||||
@ -1421,7 +1415,6 @@ void VoxelLodTerrain::process_transition_updates() {
|
||||
}
|
||||
|
||||
uint8_t VoxelLodTerrain::get_transition_mask(Vector3i block_pos, int lod_index) const {
|
||||
|
||||
uint8_t transition_mask = 0;
|
||||
|
||||
if (lod_index + 1 >= (int)_lods.size()) {
|
||||
@ -1507,7 +1500,6 @@ uint8_t VoxelLodTerrain::get_transition_mask(Vector3i block_pos, int lod_index)
|
||||
}
|
||||
|
||||
Dictionary VoxelLodTerrain::get_statistics() const {
|
||||
|
||||
Dictionary d;
|
||||
d["stream"] = VoxelDataLoader::Mgr::to_dictionary(_stats.stream);
|
||||
d["updater"] = VoxelMeshUpdater::Mgr::to_dictionary(_stats.updater);
|
||||
@ -1528,10 +1520,13 @@ Dictionary VoxelLodTerrain::get_statistics() const {
|
||||
return d;
|
||||
}
|
||||
|
||||
void VoxelLodTerrain::_b_save_modified_blocks() {
|
||||
save_all_modified_blocks(true);
|
||||
}
|
||||
|
||||
// DEBUG LAND
|
||||
|
||||
Array VoxelLodTerrain::debug_raycast_block(Vector3 world_origin, Vector3 world_direction) const {
|
||||
|
||||
Vector3 pos = world_origin;
|
||||
Vector3 dir = world_direction;
|
||||
float max_distance = 256;
|
||||
@ -1559,7 +1554,6 @@ Array VoxelLodTerrain::debug_raycast_block(Vector3 world_origin, Vector3 world_d
|
||||
}
|
||||
|
||||
Dictionary VoxelLodTerrain::debug_get_block_info(Vector3 fbpos, int lod_index) const {
|
||||
|
||||
Dictionary d;
|
||||
ERR_FAIL_COND_V(lod_index < 0, d);
|
||||
ERR_FAIL_COND_V(lod_index >= get_lod_count(), d);
|
||||
@ -1601,12 +1595,10 @@ Array VoxelLodTerrain::debug_get_octrees() const {
|
||||
}
|
||||
|
||||
Array VoxelLodTerrain::_b_debug_print_sdf_top_down(Vector3 center, Vector3 extents) const {
|
||||
|
||||
Array image_array;
|
||||
image_array.resize(get_lod_count());
|
||||
|
||||
for (int lod_index = 0; lod_index < get_lod_count(); ++lod_index) {
|
||||
|
||||
const Rect3i world_box = Rect3i::from_center_extents(Vector3i(center) >> lod_index, Vector3i(extents) >> lod_index);
|
||||
|
||||
if (world_box.size.volume() == 0) {
|
||||
@ -1634,7 +1626,6 @@ Array VoxelLodTerrain::_b_debug_print_sdf_top_down(Vector3 center, Vector3 exten
|
||||
}
|
||||
|
||||
void VoxelLodTerrain::_bind_methods() {
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_stream", "stream"), &VoxelLodTerrain::set_stream);
|
||||
ClassDB::bind_method(D_METHOD("get_stream"), &VoxelLodTerrain::get_stream);
|
||||
|
||||
@ -1665,11 +1656,11 @@ void VoxelLodTerrain::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("voxel_to_block_position", "lod_index"), &VoxelLodTerrain::voxel_to_block_position);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_voxel_tool"), &VoxelLodTerrain::get_voxel_tool);
|
||||
ClassDB::bind_method(D_METHOD("save_modified_blocks"), &VoxelLodTerrain::_b_save_modified_blocks);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("debug_raycast_block", "origin", "dir"), &VoxelLodTerrain::debug_raycast_block);
|
||||
ClassDB::bind_method(D_METHOD("debug_get_block_info", "block_pos", "lod"), &VoxelLodTerrain::debug_get_block_info);
|
||||
ClassDB::bind_method(D_METHOD("debug_get_octrees"), &VoxelLodTerrain::debug_get_octrees);
|
||||
ClassDB::bind_method(D_METHOD("debug_save_all_modified_blocks"), &VoxelLodTerrain::_b_save_all_modified_blocks);
|
||||
ClassDB::bind_method(D_METHOD("debug_print_sdf_top_down", "center", "extents"), &VoxelLodTerrain::_b_debug_print_sdf_top_down);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("_on_stream_params_changed"), &VoxelLodTerrain::_on_stream_params_changed);
|
||||
@ -1683,7 +1674,3 @@ void VoxelLodTerrain::_bind_methods() {
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "generate_collisions"), "set_generate_collisions", "get_generate_collisions");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_lod_count"), "set_collision_lod_count", "get_collision_lod_count");
|
||||
}
|
||||
|
||||
void VoxelLodTerrain::_b_save_all_modified_blocks() {
|
||||
save_all_modified_blocks(true);
|
||||
}
|
||||
|
@ -116,7 +116,7 @@ private:
|
||||
void process_transition_updates();
|
||||
uint8_t get_transition_mask(Vector3i block_pos, int lod_index) const;
|
||||
|
||||
void _b_save_all_modified_blocks();
|
||||
void _b_save_modified_blocks();
|
||||
Array _b_debug_print_sdf_top_down(Vector3 center, Vector3 extents) const;
|
||||
|
||||
struct OctreeItem {
|
||||
|
@ -294,7 +294,6 @@ void VoxelTerrain::make_block_dirty(Vector3i bpos) {
|
||||
|
||||
namespace {
|
||||
struct ScheduleSaveAction {
|
||||
|
||||
std::vector<VoxelDataLoader::InputBlock> &blocks_to_save;
|
||||
bool with_copy;
|
||||
|
||||
@ -313,7 +312,6 @@ struct ScheduleSaveAction {
|
||||
} // namespace
|
||||
|
||||
void VoxelTerrain::immerge_block(Vector3i bpos) {
|
||||
|
||||
ERR_FAIL_COND(_map.is_null());
|
||||
|
||||
// Note: no need to copy the block because it gets removed from the map anyways
|
||||
@ -326,7 +324,6 @@ void VoxelTerrain::immerge_block(Vector3i bpos) {
|
||||
}
|
||||
|
||||
void VoxelTerrain::save_all_modified_blocks(bool with_copy) {
|
||||
|
||||
ERR_FAIL_COND(_stream_thread == nullptr);
|
||||
|
||||
// That may cause a stutter, so should be used when the player won't notice
|
||||
@ -431,12 +428,10 @@ void VoxelTerrain::start_streamer() {
|
||||
}
|
||||
|
||||
void VoxelTerrain::stop_streamer() {
|
||||
|
||||
if (_stream_thread) {
|
||||
memdelete(_stream_thread);
|
||||
_stream_thread = nullptr;
|
||||
}
|
||||
|
||||
_loading_blocks.clear();
|
||||
_blocks_pending_load.clear();
|
||||
}
|
||||
@ -709,7 +704,6 @@ void VoxelTerrain::get_viewer_pos_and_direction(Vector3 &out_pos, Vector3 &out_d
|
||||
}
|
||||
|
||||
void VoxelTerrain::send_block_data_requests() {
|
||||
|
||||
ERR_FAIL_COND(_stream_thread == nullptr);
|
||||
|
||||
VoxelDataLoader::Input input;
|
||||
@ -1091,8 +1085,27 @@ Vector3 VoxelTerrain::_b_block_to_voxel(Vector3 pos) {
|
||||
return Vector3i(_map->block_to_voxel(pos)).to_vec3();
|
||||
}
|
||||
|
||||
void VoxelTerrain::_bind_methods() {
|
||||
void VoxelTerrain::_b_save_modified_blocks() {
|
||||
save_all_modified_blocks(true);
|
||||
}
|
||||
|
||||
// Explicitely ask to save a block if it was modified
|
||||
void VoxelTerrain::_b_save_block(Vector3 p_block_pos) {
|
||||
ERR_FAIL_COND(_map.is_null());
|
||||
|
||||
const Vector3i block_pos(p_block_pos);
|
||||
|
||||
VoxelBlock *block = _map->get_block(block_pos);
|
||||
ERR_FAIL_COND(block == nullptr);
|
||||
|
||||
if (!block->is_modified()) {
|
||||
return;
|
||||
}
|
||||
|
||||
ScheduleSaveAction{ _blocks_to_save, false }(block);
|
||||
}
|
||||
|
||||
void VoxelTerrain::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_stream", "stream"), &VoxelTerrain::set_stream);
|
||||
ClassDB::bind_method(D_METHOD("get_stream"), &VoxelTerrain::get_stream);
|
||||
|
||||
@ -1117,6 +1130,9 @@ void VoxelTerrain::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_statistics"), &VoxelTerrain::get_statistics);
|
||||
ClassDB::bind_method(D_METHOD("get_voxel_tool"), &VoxelTerrain::get_voxel_tool);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("save_modified_blocks"), &VoxelTerrain::_b_save_modified_blocks);
|
||||
ClassDB::bind_method(D_METHOD("save_block"), &VoxelTerrain::_b_save_block);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("_on_stream_params_changed"), &VoxelTerrain::_on_stream_params_changed);
|
||||
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "stream", PROPERTY_HINT_RESOURCE_TYPE, "VoxelStream"), "set_stream", "get_stream");
|
||||
|
@ -101,6 +101,8 @@ private:
|
||||
Vector3 _b_voxel_to_block(Vector3 pos);
|
||||
Vector3 _b_block_to_voxel(Vector3 pos);
|
||||
//void _force_load_blocks_binding(Vector3 center, Vector3 extents) { force_load_blocks(center, extents); }
|
||||
void _b_save_modified_blocks();
|
||||
void _b_save_block(Vector3 p_block_pos);
|
||||
|
||||
// Voxel storage
|
||||
Ref<VoxelMap> _map;
|
||||
|
Loading…
x
Reference in New Issue
Block a user