CLenaing the interface of Item::Status to be more explicit

This commit is contained in:
Sam Gateau 2015-07-06 12:23:57 -07:00
parent 2bbffff22f
commit e63be58251
3 changed files with 63 additions and 28 deletions

View file

@ -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++;

View file

@ -10,6 +10,8 @@
//
#include "Scene.h"
#include <numeric>
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<unsigned short>::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<unsigned short>::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);

View file

@ -20,7 +20,6 @@
#include <queue>
#include <set>
#include <vector>
#include <numeric>
#include <AABox.h>
#include <RenderArgs.h>
@ -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<unsigned short>::max() -1) * 0.5f * (1.0f + std::max(std::min(x, 1.0f), -1.0f)); }
void setY(float y) { _y = (std::numeric_limits<unsigned short>::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<Value()> 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<Status> 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;