Fix voxel mips saved at wrong positions, caused them to show up often in the air

This commit is contained in:
Marc Gilleron 2021-10-04 01:32:12 +01:00
parent e75ba2eec2
commit 191659ae7c
2 changed files with 8 additions and 5 deletions

View File

@ -56,6 +56,7 @@ Ongoing development - `master`
- `VoxelTerrain`: fixed materials shown under the wrong inspector category
- `VoxelStreamRegionFiles`: fixed errors caused by meta file being sometimes written with wrong depth values
- `VoxelStreamBlockFiles`: fixed warning about channels always shown in the scene tree
- `VoxelStreamSQLite`: fixed blocks above LOD0 being saved at wrong locations, causing them to be reloaded often floating in the air
- Fix some crashes occurring when all PoolVector allocs are in use (Godot 3.x limitation). It will print errors instead, but crashes can still occur inside Godot's code as it's not often checking for this

View File

@ -594,7 +594,7 @@ void VoxelStreamSQLite::emerge_blocks(Span<VoxelBlockRequest> p_blocks, Vector<R
Vector<int> blocks_to_load;
for (unsigned int i = 0; i < p_blocks.size(); ++i) {
VoxelBlockRequest &wr = p_blocks[i];
const Vector3i pos = wr.origin_in_voxels >> bs_po2;
const Vector3i pos = wr.origin_in_voxels >> (bs_po2 + wr.lod);
Ref<VoxelBuffer> vb;
if (_cache.load_voxel_block(pos, wr.lod, wr.voxel_buffer)) {
@ -620,10 +620,12 @@ void VoxelStreamSQLite::emerge_blocks(Span<VoxelBlockRequest> p_blocks, Vector<R
const int ri = blocks_to_load[i];
const VoxelBlockRequest &r = p_blocks[ri];
const unsigned int po2 = bs_po2 + r.lod;
BlockLocation loc;
loc.x = r.origin_in_voxels.x >> bs_po2;
loc.y = r.origin_in_voxels.y >> bs_po2;
loc.z = r.origin_in_voxels.z >> bs_po2;
loc.x = r.origin_in_voxels.x >> po2;
loc.y = r.origin_in_voxels.y >> po2;
loc.z = r.origin_in_voxels.z >> po2;
loc.lod = r.lod;
const Result res = con->load_block(loc, _temp_block_data, VoxelStreamSQLiteInternal::VOXELS);
@ -649,7 +651,7 @@ void VoxelStreamSQLite::immerge_blocks(Span<VoxelBlockRequest> p_blocks) {
// First put in cache
for (unsigned int i = 0; i < p_blocks.size(); ++i) {
VoxelBlockRequest &r = p_blocks[i];
const Vector3i pos = r.origin_in_voxels >> bs_po2;
const Vector3i pos = r.origin_in_voxels >> (bs_po2 + r.lod);
if (!BlockLocation::validate(pos, r.lod)) {
ERR_PRINT(String("Block position {0} is outside of supported range").format(varray(pos.to_vec3())));