From e63be582518cf024e4cca5d5d313754db7dcfc7b Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Mon, 6 Jul 2015 12:23:57 -0700 Subject: [PATCH] CLenaing the interface of Item::Status to be more explicit --- libraries/render/src/render/DrawStatus.cpp | 2 +- libraries/render/src/render/Scene.cpp | 44 +++++++++++++++++++-- libraries/render/src/render/Scene.h | 45 +++++++++++----------- 3 files changed, 63 insertions(+), 28 deletions(-) diff --git a/libraries/render/src/render/DrawStatus.cpp b/libraries/render/src/render/DrawStatus.cpp index 3c92e8f0b2..27ad0adb72 100644 --- a/libraries/render/src/render/DrawStatus.cpp +++ b/libraries/render/src/render/DrawStatus.cpp @@ -116,7 +116,7 @@ void DrawStatus::run(const SceneContextPointer& sceneContext, const RenderContex (*itemAABox).setBox(item.bounds.getCorner(), 0.1f); } auto& itemScene = scene->getItem(item.id); - (*itemStatus) = itemScene.getStatusCompressedValues(); + (*itemStatus) = itemScene.getStatusPackedValues(); nbItems++; itemAABox++; diff --git a/libraries/render/src/render/Scene.cpp b/libraries/render/src/render/Scene.cpp index 1ed66e4912..dca32a7828 100644 --- a/libraries/render/src/render/Scene.cpp +++ b/libraries/render/src/render/Scene.cpp @@ -10,6 +10,8 @@ // #include "Scene.h" +#include + using namespace render; void ItemBucketMap::insert(const ItemID& id, const ItemKey& key) { @@ -55,16 +57,41 @@ void ItemBucketMap::allocateStandardOpaqueTranparentBuckets() { const Item::Status::Value Item::Status::Value::INVALID = Item::Status::Value(); -void Item::Status::getCompressedValues(glm::ivec4& values) { - for (int i = 0; i < values.length(); i++) { + +void Item::Status::Value::setScale(float scale) { + _scale = (std::numeric_limits::max() -1) * 0.5f * (1.0f + std::max(std::min(scale, 1.0f), -1.0f)); + } + +void Item::Status::Value::setColor(float hue) { + _color = (std::numeric_limits::max() - 1) * 0.5f * (1.0f + std::max(std::min(hue, 1.0f), -1.0f)); +} + +void Item::Status::getPackedValues(glm::ivec4& values) const { + for (unsigned int i = 0; i < values.length(); i++) { if (i < _values.size()) { - values[i] = _values[i]().getRaw(); + values[i] = _values[i]().getPackedData(); } else { - values[i] = Value::INVALID.getRaw(); + values[i] = Value::INVALID.getPackedData(); } } } +void Item::PayloadInterface::addStatusGetter(const Status::Getter& getter) { + if (!_status) { + _status.reset(new Status()); + } + _status->addGetter(getter); +} + +void Item::PayloadInterface::addStatusGetters(const Status::Getters& getters) { + if (!_status) { + _status.reset(new Status()); + } + for (auto& g : getters) { + _status->addGetter(g); + } +} + void Item::resetPayload(const PayloadPointer& payload) { if (!payload) { kill(); @@ -74,6 +101,15 @@ void Item::resetPayload(const PayloadPointer& payload) { } } +glm::ivec4 Item::getStatusPackedValues() const { + glm::ivec4 values(Status::Value::INVALID.getPackedData()); + auto& status = getStatus(); + if (status) { + status->getPackedValues(values); + }; + return values; +} + void PendingChanges::resetItem(ItemID id, const PayloadPointer& payload) { _resetItems.push_back(id); _resetPayloads.push_back(payload); diff --git a/libraries/render/src/render/Scene.h b/libraries/render/src/render/Scene.h index b846c60cfe..4a6265990d 100644 --- a/libraries/render/src/render/Scene.h +++ b/libraries/render/src/render/Scene.h @@ -20,7 +20,6 @@ #include #include #include -#include #include #include @@ -201,18 +200,24 @@ public: // This is Used for monitoring and dynamically adjust the quality class Status { public: - class Value { - unsigned short _x = 0xFFFF; - unsigned short _y = 0xFFFF; - Value() {} - public: - const static Value INVALID; // Invlaid value meanss the status won't show - Value(float x, float y = 1.0f) { setX(x); setY(y); } - void setX(float x) { _x = (std::numeric_limits::max() -1) * 0.5f * (1.0f + std::max(std::min(x, 1.0f), -1.0f)); } - void setY(float y) { _y = (std::numeric_limits::max() - 1) * 0.5f * (1.0f + std::max(std::min(y, 1.0f), -1.0f)); } - - int getRaw() const { return *((const int*) this); } + // Status::Value class is the data used to represent the transient information of a status as a square icon + // The "icon" is a square displayed in the 3D scene over the render::Item AABB center. + // It can be scaled in the range [0, 1] and the color hue can + class Value { + unsigned short _scale = 0xFFFF; + unsigned short _color = 0xFFFF; + public: + const static Value INVALID; // Invalid value meanss the status won't show + + Value() {} + Value(float scale, float hue) { setScale(scale); setColor(hue); } + + void setScale(float scale); + void setColor(float hue); + + // Retreive the Value data tightely packed as an int + int getPackedData() const { return *((const int*) this); } }; typedef std::function Getter; @@ -221,7 +226,8 @@ public: Getters _values; void addGetter(const Getter& getter) { _values.push_back(getter); } - void getCompressedValues(glm::ivec4& values); + + void getPackedValues(glm::ivec4& values) const; }; typedef std::shared_ptr StatusPointer; @@ -247,15 +253,8 @@ public: // Status interface is local to the base class const StatusPointer& getStatus() const { return _status; } - void addStatusGetter(const Status::Getter& getter) { if (!_status) { _status.reset(new Status());} _status->addGetter(getter); } - void addStatusGetters(const Status::Getters& getters) { - if (!_status) { - _status.reset(new Status()); - } - for (auto& g : getters) { - _status->addGetter(g); - } - } + void addStatusGetter(const Status::Getter& getter); + void addStatusGetters(const Status::Getters& getters); protected: StatusPointer _status; @@ -292,7 +291,7 @@ public: // Access the status const StatusPointer& getStatus() const { return _payload->getStatus(); } - glm::ivec4 getStatusCompressedValues() const { glm::ivec4 values(Status::Value::INVALID.getRaw()); auto& status = getStatus(); if (status) { status->getCompressedValues(values); }; return values; } + glm::ivec4 getStatusPackedValues() const; protected: PayloadPointer _payload;