mirror of
https://github.com/lubosz/overte.git
synced 2025-04-19 16:44:04 +02:00
Before merging upstream
This commit is contained in:
parent
f40d390cc9
commit
fb68c09941
5 changed files with 34 additions and 16 deletions
|
@ -11,6 +11,7 @@
|
|||
|
||||
#include "Base3DOverlay.h"
|
||||
|
||||
#include "Application.h"
|
||||
#include <RegisteredMetaTypes.h>
|
||||
#include <SharedUtil.h>
|
||||
|
||||
|
@ -42,11 +43,14 @@ Base3DOverlay::Base3DOverlay(const Base3DOverlay* base3DOverlay) :
|
|||
void Base3DOverlay::setProperties(const QVariantMap& properties) {
|
||||
Overlay::setProperties(properties);
|
||||
|
||||
bool needRenderItemUpdate = false;
|
||||
|
||||
auto drawInFront = properties["drawInFront"];
|
||||
|
||||
if (drawInFront.isValid()) {
|
||||
bool value = drawInFront.toBool();
|
||||
setDrawInFront(value);
|
||||
needRenderItemUpdate = true;
|
||||
}
|
||||
|
||||
auto position = properties["position"];
|
||||
|
@ -60,16 +64,19 @@ void Base3DOverlay::setProperties(const QVariantMap& properties) {
|
|||
}
|
||||
if (position.isValid()) {
|
||||
setPosition(vec3FromVariant(position));
|
||||
needRenderItemUpdate = true;
|
||||
}
|
||||
|
||||
if (properties["lineWidth"].isValid()) {
|
||||
setLineWidth(properties["lineWidth"].toFloat());
|
||||
needRenderItemUpdate = true;
|
||||
}
|
||||
|
||||
auto rotation = properties["rotation"];
|
||||
|
||||
if (rotation.isValid()) {
|
||||
setRotation(quatFromVariant(rotation));
|
||||
needRenderItemUpdate = true;
|
||||
}
|
||||
|
||||
if (properties["isSolid"].isValid()) {
|
||||
|
@ -100,6 +107,18 @@ void Base3DOverlay::setProperties(const QVariantMap& properties) {
|
|||
if (properties["ignoreRayIntersection"].isValid()) {
|
||||
setIgnoreRayIntersection(properties["ignoreRayIntersection"].toBool());
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (needRenderItemUpdate) {
|
||||
auto itemID = getRenderItemID();
|
||||
if (render::Item::isValidID(itemID)) {
|
||||
render::ScenePointer scene = qApp->getMain3DScene();
|
||||
render::PendingChanges pendingChanges;
|
||||
pendingChanges.updateItem(itemID);
|
||||
scene->enqueuePendingChanges(pendingChanges);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QVariant Base3DOverlay::getProperty(const QString& property) {
|
||||
|
|
|
@ -233,19 +233,6 @@ bool Overlays::editOverlay(unsigned int id, const QVariant& properties) {
|
|||
if (thisOverlay) {
|
||||
thisOverlay->setProperties(properties.toMap());
|
||||
|
||||
if (thisOverlay->is3D()) {
|
||||
auto itemID = thisOverlay->getRenderItemID();
|
||||
if (render::Item::isValidID(itemID)) {
|
||||
render::ScenePointer scene = qApp->getMain3DScene();
|
||||
const render::Item& item = scene->getItem(itemID);
|
||||
if (item.getKey() != render::payloadGetKey(thisOverlay)) {
|
||||
render::PendingChanges pendingChanges;
|
||||
pendingChanges.updateItem(itemID);
|
||||
scene->enqueuePendingChanges(pendingChanges);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -48,6 +48,10 @@ ItemID Scene::allocateID() {
|
|||
return _IDAllocator.fetch_add(1);
|
||||
}
|
||||
|
||||
bool Scene::isAllocatedID(const ItemID& id) {
|
||||
return Item::isValidID(id) && (id < _numAllocatedItems.load());
|
||||
}
|
||||
|
||||
/// Enqueue change batch to the scene
|
||||
void Scene::enqueuePendingChanges(const PendingChanges& pendingChanges) {
|
||||
_changeQueueMutex.lock();
|
||||
|
@ -83,6 +87,9 @@ void Scene::processPendingChangesQueue() {
|
|||
updateItems(consolidatedPendingChanges._updatedItems, consolidatedPendingChanges._updateFunctors);
|
||||
removeItems(consolidatedPendingChanges._removedItems);
|
||||
|
||||
// Update the numItemsAtomic counter AFTER the pending changes went through
|
||||
_numAllocatedItems.exchange(maxID);
|
||||
|
||||
// ready to go back to rendering activities
|
||||
_itemsMutex.unlock();
|
||||
}
|
||||
|
|
|
@ -60,6 +60,9 @@ public:
|
|||
// This call is thread safe, can be called from anywhere to allocate a new ID
|
||||
ItemID allocateID();
|
||||
|
||||
// Check that the ID is valid and allocated for this scene, this a threadsafe call
|
||||
bool isAllocatedID(const ItemID& id);
|
||||
|
||||
// Enqueue change batch to the scene
|
||||
void enqueuePendingChanges(const PendingChanges& pendingChanges);
|
||||
|
||||
|
@ -81,6 +84,8 @@ public:
|
|||
protected:
|
||||
// Thread safe elements that can be accessed from anywhere
|
||||
std::atomic<unsigned int> _IDAllocator{ 1 }; // first valid itemID will be One
|
||||
std::atomic<unsigned int> _numAllocatedItems{ 1 }; // num of allocated items, matching the _items.size()
|
||||
|
||||
std::mutex _changeQueueMutex;
|
||||
PendingChangesQueue _changeQueue;
|
||||
|
||||
|
|
|
@ -402,9 +402,9 @@ namespace render {
|
|||
// Clamp a position expressed in a depth space to make sure it is in the valid space for that Depth
|
||||
glm::vec3 clampRelPosToTreeRange(const glm::vec3& pos) const {
|
||||
return glm::vec3(
|
||||
std::min(std::max(pos.x, 0.0f), _size),
|
||||
std::min(std::max(pos.y, 0.0f), _size),
|
||||
std::min(std::max(pos.z, 0.0f), _size));
|
||||
std::min(std::max(pos.x, 1.0f), _size - 1.0f),
|
||||
std::min(std::max(pos.y, 1.0f), _size - 1.0f),
|
||||
std::min(std::max(pos.z, 1.0f), _size - 1.0f));
|
||||
}
|
||||
Coord3 evalCoord(const glm::vec3& pos, Depth depth = Octree::METRIC_COORD_DEPTH) const {
|
||||
auto npos = clampRelPosToTreeRange((pos - getOrigin()));
|
||||
|
|
Loading…
Reference in a new issue