uuid keys for overlays appears to work

This commit is contained in:
Seth Alves 2017-02-16 21:22:23 -08:00
parent c1e41311fc
commit 05c135b9d8
8 changed files with 43 additions and 64 deletions

View file

@ -529,7 +529,7 @@ bool setupEssentials(int& argc, char** argv) {
// to take care of highlighting keyboard focused items, rather than
// continuing to overburden Application.cpp
std::shared_ptr<Cube3DOverlay> _keyboardFocusHighlight{ nullptr };
OverlayID _keyboardFocusHighlightID{ -1 };
OverlayID _keyboardFocusHighlightID{ UNKNOWN_OVERLAY_ID };
// FIXME hack access to the internal share context for the Chromium helper
@ -1683,9 +1683,9 @@ void Application::cleanupBeforeQuit() {
_applicationStateDevice.reset();
{
if (_keyboardFocusHighlightID) {
if (_keyboardFocusHighlightID != UNKNOWN_OVERLAY_ID) {
getOverlays().deleteOverlay(_keyboardFocusHighlightID);
_keyboardFocusHighlightID = UNKNOWN_OVERLAY_ID;
_keyboardFocusHighlightID = UNKNOWN_OVERLAY_ID;
}
_keyboardFocusHighlight = nullptr;
}
@ -3072,7 +3072,7 @@ void Application::mouseMoveEvent(QMouseEvent* event) {
buttons, event->modifiers());
if (compositor.getReticleVisible() || !isHMDMode() || !compositor.getReticleOverDesktop() ||
getOverlays().getOverlayAtPoint(glm::vec2(transformedPos.x(), transformedPos.y()))) {
getOverlays().getOverlayAtPoint(glm::vec2(transformedPos.x(), transformedPos.y())) != UNKNOWN_OVERLAY_ID) {
getOverlays().mouseMoveEvent(&mappedEvent);
getEntities()->mouseMoveEvent(&mappedEvent);
}
@ -4091,7 +4091,7 @@ void Application::rotationModeChanged() const {
void Application::setKeyboardFocusHighlight(const glm::vec3& position, const glm::quat& rotation, const glm::vec3& dimensions) {
// Create focus
if (_keyboardFocusHighlightID == UNKNOWN_OVERLAY_ID || !getOverlays().isAddedOverlay(_keyboardFocusHighlightID)) {
if (_keyboardFocusHighlightID == UNKNOWN_OVERLAY_ID || !getOverlays().isAddedOverlay(_keyboardFocusHighlightID)) {
_keyboardFocusHighlight = std::make_shared<Cube3DOverlay>();
_keyboardFocusHighlight->setAlpha(1.0f);
_keyboardFocusHighlight->setBorderSize(1.0f);

View file

@ -193,7 +193,7 @@ DdeFaceTracker::DdeFaceTracker(const QHostAddress& host, quint16 serverPort, qui
_calibrationCount(0),
_calibrationValues(),
_calibrationBillboard(NULL),
_calibrationBillboardID(0),
_calibrationBillboardID(UNKNOWN_OVERLAY_ID),
_calibrationMessage(QString()),
_isCalibrated(false)
{

View file

@ -23,6 +23,9 @@ public:
Base3DOverlay();
Base3DOverlay(const Base3DOverlay* base3DOverlay);
virtual OverlayID getOverlayID() const override { return OverlayID(getID().toString()); }
void setOverlayID(OverlayID overlayID) override { setID(overlayID); }
// getters
virtual bool is3D() const override { return true; }

View file

@ -189,7 +189,7 @@ float Overlay::updatePulse() {
_pulseDirection *= -1.0f;
}
_pulse += pulseDelta;
return _pulse;
}
@ -205,11 +205,11 @@ void Overlay::removeFromScene(Overlay::Pointer overlay, std::shared_ptr<render::
}
QScriptValue OverlayIDtoScriptValue(QScriptEngine* engine, const OverlayID& id) {
return QScriptValue(id.id);
return quuidToScriptValue(engine, id);
}
void OverlayIDfromScriptValue(const QScriptValue &object, OverlayID& id) {
id = object.toUInt32();
quuidFromScriptValue(object, id);
}
QVector<OverlayID> qVectorOverlayIDFromScriptValue(const QScriptValue& array) {
@ -220,9 +220,7 @@ QVector<OverlayID> qVectorOverlayIDFromScriptValue(const QScriptValue& array) {
int length = array.property("length").toInteger();
newVector.reserve(length);
for (int i = 0; i < length; i++) {
OverlayID id;
OverlayIDfromScriptValue(array.property(i), id);
newVector << id;
newVector << OverlayID(array.property(i).toString());
}
return newVector;
}

View file

@ -15,22 +15,11 @@
#include <SharedUtil.h> // for xColor
#include <render/Scene.h>
class OverlayID {
class OverlayID : public QUuid {
public:
OverlayID() {}
OverlayID(int value) { id = value; }
OverlayID& operator=(const OverlayID& other) { id = other.id; return *this; }
OverlayID& operator++() { id++; return *this; }
// OverlayID& operator=(unsigned int value) { id = value; return *this; }
bool operator==(const OverlayID& other) const { return id == other.id; }
bool operator!=(const OverlayID& other) const { return id != other.id; }
// bool operator<(const OverlayID& other) const { return id < other.id; }
// bool operator>(const OverlayID& other) const { return id > other.id; }
operator bool() const { return id != 0; }
unsigned int id;
OverlayID() : QUuid() {}
OverlayID(QString v) : QUuid(v) {}
OverlayID(QUuid v) : QUuid(v) {}
};
class Overlay : public QObject {
@ -50,8 +39,8 @@ public:
Overlay(const Overlay* overlay);
~Overlay();
OverlayID getOverlayID() { return _overlayID; }
void setOverlayID(OverlayID overlayID) { _overlayID = overlayID; }
virtual OverlayID getOverlayID() const { return _overlayID; }
virtual void setOverlayID(OverlayID overlayID) { _overlayID = overlayID; }
virtual void update(float deltatime) {}
virtual void render(RenderArgs* args) = 0;
@ -107,8 +96,6 @@ protected:
render::ItemID _renderItemID{ render::Item::INVALID_ITEM_ID };
OverlayID _overlayID; // what Overlays.cpp knows this instance as
bool _isLoaded;
float _alpha;
@ -125,10 +112,13 @@ protected:
xColor _color;
bool _visible; // should the overlay be drawn at all
Anchor _anchor;
private:
OverlayID _overlayID; // only used for non-3d overlays
};
namespace render {
template <> const ItemKey payloadGetKey(const Overlay::Pointer& overlay);
template <> const ItemKey payloadGetKey(const Overlay::Pointer& overlay);
template <> const Item::Bound payloadGetBound(const Overlay::Pointer& overlay);
template <> int payloadGetLayer(const Overlay::Pointer& overlay);
template <> void payloadRender(const Overlay::Pointer& overlay, RenderArgs* args);
@ -141,5 +131,5 @@ QScriptValue OverlayIDtoScriptValue(QScriptEngine* engine, const OverlayID& id);
void OverlayIDfromScriptValue(const QScriptValue &object, OverlayID& id);
QVector<OverlayID> qVectorOverlayIDFromScriptValue(const QScriptValue& array);
#endif // hifi_Overlay_h

View file

@ -89,7 +89,7 @@ QVariant OverlayPanel::getProperty(const QString &property) {
if (property == "children") {
QVariantList array;
for (int i = 0; i < _children.length(); i++) {
array.append(OverlayIDtoScriptValue(nullptr, _children[i]));
array.append(OverlayIDtoScriptValue(nullptr, _children[i]).toVariant());
}
return array;
}

View file

@ -39,9 +39,6 @@
Q_LOGGING_CATEGORY(trace_render_overlays, "trace.render.overlays")
Overlays::Overlays() :
_nextOverlayID(1) {}
void Overlays::cleanupAllOverlays() {
{
QWriteLocker lock(&_lock);
@ -188,14 +185,13 @@ OverlayID Overlays::addOverlay(const QString& type, const QVariant& properties)
thisOverlay->setProperties(properties.toMap());
return addOverlay(thisOverlay);
}
return 0;
return UNKNOWN_OVERLAY_ID;
}
OverlayID Overlays::addOverlay(Overlay::Pointer overlay) {
QWriteLocker lock(&_lock);
OverlayID thisID = _nextOverlayID;
OverlayID thisID = OverlayID(QUuid::createUuid());
overlay->setOverlayID(thisID);
++_nextOverlayID;
if (overlay->is3D()) {
_overlaysWorld[thisID] = overlay;
@ -220,9 +216,9 @@ OverlayID Overlays::cloneOverlay(OverlayID id) {
attachable->getParentPanel()->addChild(cloneId);
}
return cloneId;
}
return 0; // Not found
}
return UNKNOWN_OVERLAY_ID; // Not found
}
bool Overlays::editOverlay(OverlayID id, const QVariant& properties) {
@ -242,13 +238,7 @@ bool Overlays::editOverlays(const QVariant& propertiesById) {
bool success = true;
QWriteLocker lock(&_lock);
for (const auto& key : map.keys()) {
bool convertSuccess;
OverlayID id = key.toUInt(&convertSuccess);
if (!convertSuccess) {
success = false;
continue;
}
OverlayID id = OverlayID(key);
Overlay::Pointer thisOverlay = getOverlay(id);
if (!thisOverlay) {
success = false;
@ -310,7 +300,7 @@ OverlayID Overlays::getParentPanel(OverlayID childId) const {
} else if (_panels.contains(childId)) {
return _panels.key(getPanel(childId)->getParentPanel());
}
return 0;
return UNKNOWN_OVERLAY_ID;
}
void Overlays::setParentPanel(OverlayID childId, OverlayID panelId) {
@ -347,7 +337,7 @@ OverlayID Overlays::getOverlayAtPoint(const glm::vec2& point) {
glm::vec2 pointCopy = point;
QReadLocker lock(&_lock);
if (!_enabled) {
return 0;
return UNKNOWN_OVERLAY_ID;
}
QMapIterator<OverlayID, Overlay::Pointer> i(_overlaysHUD);
i.toBack();
@ -378,7 +368,7 @@ OverlayID Overlays::getOverlayAtPoint(const glm::vec2& point) {
}
}
return 0; // not found
return UNKNOWN_OVERLAY_ID; // not found
}
OverlayPropertyResult Overlays::getProperty(OverlayID id, const QString& property) {
@ -447,14 +437,14 @@ RayToOverlayIntersectionResult Overlays::findRayIntersection(const PickRay& ray,
return result;
}
RayToOverlayIntersectionResult::RayToOverlayIntersectionResult() :
intersects(false),
overlayID(-1),
RayToOverlayIntersectionResult::RayToOverlayIntersectionResult() :
intersects(false),
overlayID(UNKNOWN_OVERLAY_ID),
distance(0),
face(),
intersection(),
extraInfo()
{
{
}
QScriptValue RayToOverlayIntersectionResultToScriptValue(QScriptEngine* engine, const RayToOverlayIntersectionResult& value) {
@ -463,7 +453,7 @@ QScriptValue RayToOverlayIntersectionResultToScriptValue(QScriptEngine* engine,
obj.setProperty("overlayID", OverlayIDtoScriptValue(engine, value.overlayID));
obj.setProperty("distance", value.distance);
QString faceName = "";
QString faceName = "";
// handle BoxFace
switch (value.face) {
case MIN_X_FACE:
@ -499,7 +489,7 @@ QScriptValue RayToOverlayIntersectionResultToScriptValue(QScriptEngine* engine,
void RayToOverlayIntersectionResultFromScriptValue(const QScriptValue& objectVar, RayToOverlayIntersectionResult& value) {
QVariantMap object = objectVar.toVariant().toMap();
value.intersects = object["intersects"].toBool();
value.overlayID = object["overlayID"].toInt();
value.overlayID = OverlayID(QUuid(object["overlayID"].toString()));
value.distance = object["distance"].toFloat();
QString faceName = object["face"].toString();
@ -556,8 +546,7 @@ QSizeF Overlays::textSize(OverlayID id, const QString& text) const {
OverlayID Overlays::addPanel(OverlayPanel::Pointer panel) {
QWriteLocker lock(&_lock);
OverlayID thisID = _nextOverlayID;
++_nextOverlayID;
OverlayID thisID = QUuid::createUuid();
_panels[thisID] = panel;
return thisID;

View file

@ -77,7 +77,7 @@ void RayToOverlayIntersectionResultFromScriptValue(const QScriptValue& object, R
* @namespace Overlays
*/
const OverlayID UNKNOWN_OVERLAY_ID = 0;
const OverlayID UNKNOWN_OVERLAY_ID = OverlayID();
class Overlays : public QObject {
Q_OBJECT
@ -85,7 +85,7 @@ class Overlays : public QObject {
Q_PROPERTY(OverlayID keyboardFocusOverlay READ getKeyboardFocusOverlay WRITE setKeyboardFocusOverlay)
public:
Overlays();
Overlays() {};
void init();
void update(float deltatime);
@ -305,7 +305,6 @@ private:
QMap<OverlayID, Overlay::Pointer> _overlaysWorld;
QMap<OverlayID, OverlayPanel::Pointer> _panels;
QList<Overlay::Pointer> _overlaysToDelete;
OverlayID _nextOverlayID;
QReadWriteLock _lock;
QReadWriteLock _deleteLock;