Removed deadlock from merge

This commit is contained in:
Atlante45 2014-03-03 18:48:11 -08:00
parent 84f8e6ee19
commit de679b20ad
2 changed files with 24 additions and 35 deletions

View file

@ -42,6 +42,7 @@ var clipboard = Overlays.addOverlay("localvoxels", {
}); });
// When our script shuts down, we should clean up all of our overlays // When our script shuts down, we should clean up all of our overlays
function scriptEnding() { function scriptEnding() {
Overlays.deleteOverlay(overlay1); Overlays.deleteOverlay(overlay1);

View file

@ -53,14 +53,11 @@ void LocalVoxels::setVoxelNonDestructive(float x, float y, float z, float scale,
return; return;
} }
if (_tree ) { if (_tree ) {
if (_tree->tryLockForWrite()) { _tree->createVoxel(x / (float)TREE_SCALE,
_tree->createVoxel(x / (float)TREE_SCALE, y / (float)TREE_SCALE,
y / (float)TREE_SCALE, z / (float)TREE_SCALE,
z / (float)TREE_SCALE, scale / (float)TREE_SCALE,
scale / (float)TREE_SCALE, red, green, blue, false);
red, green, blue, false);
_tree->unlock();
}
} }
} }
@ -71,14 +68,11 @@ void LocalVoxels::setVoxel(float x, float y, float z, float scale,
return; return;
} }
if (_tree ) { if (_tree ) {
if (_tree->tryLockForWrite()) { _tree->createVoxel(x / (float)TREE_SCALE,
_tree->createVoxel(x / (float)TREE_SCALE, y / (float)TREE_SCALE,
y / (float)TREE_SCALE, z / (float)TREE_SCALE,
z / (float)TREE_SCALE, scale / (float)TREE_SCALE,
scale / (float)TREE_SCALE, red, green, blue, true);
red, green, blue, true);
_tree->unlock();
}
} }
} }
@ -88,13 +82,10 @@ void LocalVoxels::eraseVoxel(float x, float y, float z, float scale) {
return; return;
} }
if (_tree ) { if (_tree ) {
if (_tree->tryLockForWrite()) { _tree->deleteVoxelAt(x / (float)TREE_SCALE,
_tree->deleteVoxelAt(x / (float)TREE_SCALE,
y / (float)TREE_SCALE, y / (float)TREE_SCALE,
z / (float)TREE_SCALE, z / (float)TREE_SCALE,
scale / (float)TREE_SCALE); scale / (float)TREE_SCALE);
_tree->unlock();
}
} }
} }
@ -127,21 +118,18 @@ void LocalVoxels::pasteFrom(float x, float y, float z, float scale, const QStrin
RayToVoxelIntersectionResult LocalVoxels::findRayIntersection(const PickRay& ray) { RayToVoxelIntersectionResult LocalVoxels::findRayIntersection(const PickRay& ray) {
RayToVoxelIntersectionResult result; RayToVoxelIntersectionResult result;
if (_tree) { if (_tree) {
if (_tree->tryLockForRead()) { OctreeElement* element;
OctreeElement* element; result.intersects = _tree->findRayIntersection(ray.origin, ray.direction, element, result.distance, result.face);
result.intersects = _tree->findRayIntersection(ray.origin, ray.direction, element, result.distance, result.face); if (result.intersects) {
if (result.intersects) { VoxelTreeElement* voxel = (VoxelTreeElement*)element;
VoxelTreeElement* voxel = (VoxelTreeElement*)element; result.voxel.x = voxel->getCorner().x;
result.voxel.x = voxel->getCorner().x; result.voxel.y = voxel->getCorner().y;
result.voxel.y = voxel->getCorner().y; result.voxel.z = voxel->getCorner().z;
result.voxel.z = voxel->getCorner().z; result.voxel.s = voxel->getScale();
result.voxel.s = voxel->getScale(); result.voxel.red = voxel->getColor()[0];
result.voxel.red = voxel->getColor()[0]; result.voxel.green = voxel->getColor()[1];
result.voxel.green = voxel->getColor()[1]; result.voxel.blue = voxel->getColor()[2];
result.voxel.blue = voxel->getColor()[2]; result.intersection = ray.origin + (ray.direction * result.distance);
result.intersection = ray.origin + (ray.direction * result.distance);
}
_tree->unlock();
} }
} }
return result; return result;