mirror of
https://github.com/Relintai/godot_voxel.git
synced 2024-11-19 02:47:18 +01:00
Fix VoxelBuffer channel initialized with wrong value when allocated
This commit is contained in:
parent
869b921ce8
commit
9108bfe0f6
@ -19,9 +19,10 @@ void VoxelBuffer::create(int sx, int sy, int sz) {
|
|||||||
for (unsigned int i = 0; i < MAX_CHANNELS; ++i) {
|
for (unsigned int i = 0; i < MAX_CHANNELS; ++i) {
|
||||||
Channel &channel = _channels[i];
|
Channel &channel = _channels[i];
|
||||||
if (channel.data) {
|
if (channel.data) {
|
||||||
|
// Channel already contained data
|
||||||
// TODO Optimize with realloc
|
// TODO Optimize with realloc
|
||||||
delete_channel(i);
|
delete_channel(i);
|
||||||
create_channel(i, new_size);
|
create_channel(i, new_size, channel.defval);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_size = new_size;
|
_size = new_size;
|
||||||
@ -71,7 +72,8 @@ void VoxelBuffer::set_voxel(int value, int x, int y, int z, unsigned int channel
|
|||||||
|
|
||||||
if (channel.data == NULL) {
|
if (channel.data == NULL) {
|
||||||
if (channel.defval != value) {
|
if (channel.defval != value) {
|
||||||
create_channel(channel_index, _size);
|
// Allocate channel with same initial values as defval
|
||||||
|
create_channel(channel_index, _size, channel.defval);
|
||||||
channel.data[index(x, y, z)] = value;
|
channel.data[index(x, y, z)] = value;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -90,7 +92,7 @@ void VoxelBuffer::try_set_voxel(int x, int y, int z, int value, unsigned int cha
|
|||||||
|
|
||||||
if (channel.data == NULL) {
|
if (channel.data == NULL) {
|
||||||
if (channel.defval != value) {
|
if (channel.defval != value) {
|
||||||
create_channel(channel_index, _size);
|
create_channel(channel_index, _size, channel.defval);
|
||||||
channel.data[index(x, y, z)] = value;
|
channel.data[index(x, y, z)] = value;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -142,7 +144,7 @@ void VoxelBuffer::fill_area(int defval, Vector3i min, Vector3i max, unsigned int
|
|||||||
if (channel.defval == defval) {
|
if (channel.defval == defval) {
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
create_channel(channel_index, _size);
|
create_channel(channel_index, _size, channel.defval);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -227,7 +229,7 @@ void VoxelBuffer::copy_from(const VoxelBuffer &other, Vector3i src_min, Vector3i
|
|||||||
} else {
|
} else {
|
||||||
if (other_channel.data) {
|
if (other_channel.data) {
|
||||||
if (channel.data == NULL) {
|
if (channel.data == NULL) {
|
||||||
create_channel(channel_index, _size);
|
create_channel(channel_index, _size, channel.defval);
|
||||||
}
|
}
|
||||||
// Copy row by row
|
// Copy row by row
|
||||||
Vector3i pos;
|
Vector3i pos;
|
||||||
@ -241,7 +243,7 @@ void VoxelBuffer::copy_from(const VoxelBuffer &other, Vector3i src_min, Vector3i
|
|||||||
}
|
}
|
||||||
} else if (channel.defval != other_channel.defval) {
|
} else if (channel.defval != other_channel.defval) {
|
||||||
if (channel.data == NULL) {
|
if (channel.data == NULL) {
|
||||||
create_channel(channel_index, _size);
|
create_channel(channel_index, _size, channel.defval);
|
||||||
}
|
}
|
||||||
// Set row by row
|
// Set row by row
|
||||||
Vector3i pos;
|
Vector3i pos;
|
||||||
|
@ -98,7 +98,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void create_channel_noinit(int i, Vector3i size);
|
void create_channel_noinit(int i, Vector3i size);
|
||||||
void create_channel(int i, Vector3i size, uint8_t defval = 0);
|
void create_channel(int i, Vector3i size, uint8_t defval);
|
||||||
void delete_channel(int i);
|
void delete_channel(int i);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
Loading…
Reference in New Issue
Block a user