mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 10:13:15 +02:00
Fix voxel deadlock and improve performance
This commit is contained in:
parent
4790b167f8
commit
e14a41c3e0
1 changed files with 30 additions and 9 deletions
|
@ -198,13 +198,17 @@ bool isEdged(PolyVoxEntityItem::PolyVoxSurfaceStyle surfaceStyle) {
|
||||||
|
|
||||||
void RenderablePolyVoxEntityItem::setVoxelData(const QByteArray& voxelData) {
|
void RenderablePolyVoxEntityItem::setVoxelData(const QByteArray& voxelData) {
|
||||||
// accept compressed voxel information from the entity-server
|
// accept compressed voxel information from the entity-server
|
||||||
|
bool is_updated = false;
|
||||||
withWriteLock([&] {
|
withWriteLock([&] {
|
||||||
if (_voxelData != voxelData) {
|
if (_voxelData != voxelData) {
|
||||||
_voxelData = voxelData;
|
_voxelData = voxelData;
|
||||||
_voxelDataDirty = true;
|
_voxelDataDirty = true;
|
||||||
startUpdates();
|
is_updated = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
if (is_updated) {
|
||||||
|
startUpdates();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderablePolyVoxEntityItem::setVoxelSurfaceStyle(PolyVoxSurfaceStyle voxelSurfaceStyle) {
|
void RenderablePolyVoxEntityItem::setVoxelSurfaceStyle(PolyVoxSurfaceStyle voxelSurfaceStyle) {
|
||||||
|
@ -249,6 +253,9 @@ bool RenderablePolyVoxEntityItem::setVoxel(const ivec3& v, uint8_t toValue) {
|
||||||
withWriteLock([&] {
|
withWriteLock([&] {
|
||||||
result = setVoxelInternal(v, toValue);
|
result = setVoxelInternal(v, toValue);
|
||||||
});
|
});
|
||||||
|
if (result) {
|
||||||
|
startUpdates();
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -294,10 +301,12 @@ bool RenderablePolyVoxEntityItem::setAll(uint8_t toValue) {
|
||||||
result |= setVoxelInternal(v, toValue);
|
result |= setVoxelInternal(v, toValue);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
if (result) {
|
||||||
|
startUpdates();
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool RenderablePolyVoxEntityItem::setCuboid(const glm::vec3& lowPosition, const glm::vec3& cuboidSize, int toValue) {
|
bool RenderablePolyVoxEntityItem::setCuboid(const glm::vec3& lowPosition, const glm::vec3& cuboidSize, int toValue) {
|
||||||
bool result = false;
|
bool result = false;
|
||||||
if (_locked) {
|
if (_locked) {
|
||||||
|
@ -316,11 +325,12 @@ bool RenderablePolyVoxEntityItem::setCuboid(const glm::vec3& lowPosition, const
|
||||||
result |= setVoxelInternal(v, toValue);
|
result |= setVoxelInternal(v, toValue);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
if (result) {
|
||||||
|
startUpdates();
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool RenderablePolyVoxEntityItem::setVoxelInVolume(const vec3& position, uint8_t toValue) {
|
bool RenderablePolyVoxEntityItem::setVoxelInVolume(const vec3& position, uint8_t toValue) {
|
||||||
if (_locked) {
|
if (_locked) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -350,6 +360,9 @@ bool RenderablePolyVoxEntityItem::setSphereInVolume(const vec3& center, float ra
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
if (result) {
|
||||||
|
startUpdates();
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -407,6 +420,9 @@ bool RenderablePolyVoxEntityItem::setSphere(const vec3& centerWorldCoords, float
|
||||||
// }
|
// }
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
if (result) {
|
||||||
|
startUpdates();
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -452,6 +468,9 @@ bool RenderablePolyVoxEntityItem::setCapsule(const vec3& startWorldCoords, const
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
if (result) {
|
||||||
|
startUpdates();
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -718,7 +737,7 @@ void RenderablePolyVoxEntityItem::changeUpdates(bool value) {
|
||||||
EntitySimulationPointer simulation = entityTree->getSimulation();
|
EntitySimulationPointer simulation = entityTree->getSimulation();
|
||||||
if (simulation) {
|
if (simulation) {
|
||||||
_updateNeeded = value;
|
_updateNeeded = value;
|
||||||
_flags |= Simulation::DIRTY_UPDATEABLE;
|
markDirtyFlags(Simulation::DIRTY_UPDATEABLE);
|
||||||
simulation->changeEntity(getThisPointer());
|
simulation->changeEntity(getThisPointer());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -964,6 +983,7 @@ void RenderablePolyVoxEntityItem::setVoxelMarkNeighbors(int x, int y, int z, uin
|
||||||
|
|
||||||
bool RenderablePolyVoxEntityItem::setVoxelInternal(const ivec3& v, uint8_t toValue) {
|
bool RenderablePolyVoxEntityItem::setVoxelInternal(const ivec3& v, uint8_t toValue) {
|
||||||
// set a voxel without recompressing the voxel data. This assumes that the caller has write-locked the entity.
|
// set a voxel without recompressing the voxel data. This assumes that the caller has write-locked the entity.
|
||||||
|
// TODO: could be made much more performant by moving startUpdates() to another function
|
||||||
bool result = updateOnCount(v, toValue);
|
bool result = updateOnCount(v, toValue);
|
||||||
if (result) {
|
if (result) {
|
||||||
if (isEdged()) {
|
if (isEdged()) {
|
||||||
|
@ -972,9 +992,7 @@ bool RenderablePolyVoxEntityItem::setVoxelInternal(const ivec3& v, uint8_t toVal
|
||||||
setVoxelMarkNeighbors(v.x, v.y, v.z, toValue);
|
setVoxelMarkNeighbors(v.x, v.y, v.z, toValue);
|
||||||
}
|
}
|
||||||
_volDataDirty = true;
|
_volDataDirty = true;
|
||||||
startUpdates();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1049,7 +1067,7 @@ void RenderablePolyVoxEntityItem::setVoxelsFromData(QByteArray uncompressedData,
|
||||||
quint16 voxelXSize, quint16 voxelYSize, quint16 voxelZSize) {
|
quint16 voxelXSize, quint16 voxelYSize, quint16 voxelZSize) {
|
||||||
// this accepts the payload from uncompressVolumeData
|
// this accepts the payload from uncompressVolumeData
|
||||||
ivec3 low{ 0 };
|
ivec3 low{ 0 };
|
||||||
int index = 0;
|
bool result = false;
|
||||||
|
|
||||||
withWriteLock([&] {
|
withWriteLock([&] {
|
||||||
if (isEdged()) {
|
if (isEdged()) {
|
||||||
|
@ -1057,11 +1075,14 @@ void RenderablePolyVoxEntityItem::setVoxelsFromData(QByteArray uncompressedData,
|
||||||
}
|
}
|
||||||
loop3(ivec3(0), ivec3(voxelXSize, voxelYSize, voxelZSize), [&](const ivec3& v) {
|
loop3(ivec3(0), ivec3(voxelXSize, voxelYSize, voxelZSize), [&](const ivec3& v) {
|
||||||
int uncompressedIndex = (v.z * (voxelYSize) * (voxelXSize)) + (v.y * (voxelZSize)) + v.x;
|
int uncompressedIndex = (v.z * (voxelYSize) * (voxelXSize)) + (v.y * (voxelZSize)) + v.x;
|
||||||
setVoxelInternal(v, uncompressedData[uncompressedIndex]);
|
result |= setVoxelInternal(v, uncompressedData[uncompressedIndex]);
|
||||||
});
|
});
|
||||||
|
|
||||||
_state = PolyVoxState::UncompressingFinished;
|
_state = PolyVoxState::UncompressingFinished;
|
||||||
});
|
});
|
||||||
|
if (result) {
|
||||||
|
startUpdates();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderablePolyVoxEntityItem::compressVolumeDataAndSendEditPacket() {
|
void RenderablePolyVoxEntityItem::compressVolumeDataAndSendEditPacket() {
|
||||||
|
|
Loading…
Reference in a new issue