From 4414c91f1e8d44128af51a1d414f39e209af4349 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Thu, 23 Jan 2014 18:05:04 -0800 Subject: [PATCH] Working on streaming edits. --- interface/src/MetavoxelSystem.cpp | 13 +++++++------ interface/src/MetavoxelSystem.h | 2 +- interface/src/ui/MetavoxelEditor.cpp | 2 +- libraries/metavoxels/src/Bitstream.cpp | 18 ++++++++++++++++++ libraries/metavoxels/src/Bitstream.h | 4 ++++ libraries/metavoxels/src/MetavoxelData.cpp | 3 +++ libraries/metavoxels/src/MetavoxelData.h | 3 +++ libraries/metavoxels/src/MetavoxelMessages.h | 13 +++++++++++++ 8 files changed, 50 insertions(+), 8 deletions(-) diff --git a/interface/src/MetavoxelSystem.cpp b/interface/src/MetavoxelSystem.cpp index 258db6da00..cf0c29ff15 100644 --- a/interface/src/MetavoxelSystem.cpp +++ b/interface/src/MetavoxelSystem.cpp @@ -48,13 +48,12 @@ void MetavoxelSystem::processData(const QByteArray& data, const HifiSockAddr& se void MetavoxelSystem::simulate(float deltaTime) { // simulate the clients - foreach (MetavoxelClient* client, _clients) { - client->simulate(deltaTime); - } - _points.clear(); _data.guide(_pointVisitor); - + foreach (MetavoxelClient* client, _clients) { + client->simulate(deltaTime, _pointVisitor); + } + _buffer.bind(); int bytes = _points.size() * sizeof(Point); if (_buffer.size() < bytes) { @@ -188,11 +187,13 @@ MetavoxelClient::MetavoxelClient(const HifiSockAddr& address) : _receiveRecords.append(record); } -void MetavoxelClient::simulate(float deltaTime) { +void MetavoxelClient::simulate(float deltaTime, MetavoxelVisitor& visitor) { Bitstream& out = _sequencer.startPacket(); ClientStateMessage state = { Application::getInstance()->getCamera()->getPosition() }; out << QVariant::fromValue(state); _sequencer.endPacket(); + + _data->guide(visitor); } void MetavoxelClient::receivedData(const QByteArray& data, const HifiSockAddr& sender) { diff --git a/interface/src/MetavoxelSystem.h b/interface/src/MetavoxelSystem.h index 708b4d0839..7692f0d30d 100644 --- a/interface/src/MetavoxelSystem.h +++ b/interface/src/MetavoxelSystem.h @@ -90,7 +90,7 @@ public: const QUuid& getSessionID() const { return _sessionID; } - void simulate(float deltaTime); + void simulate(float deltaTime, MetavoxelVisitor& visitor); void receivedData(const QByteArray& data, const HifiSockAddr& sender); diff --git a/interface/src/ui/MetavoxelEditor.cpp b/interface/src/ui/MetavoxelEditor.cpp index d3e4494ac9..71fcffdd08 100644 --- a/interface/src/ui/MetavoxelEditor.cpp +++ b/interface/src/ui/MetavoxelEditor.cpp @@ -375,7 +375,7 @@ bool Applier::visit(MetavoxelInfo& info) { return false; // entirely contained } if (info.size <= _granularity) { - if (volume > 0.5f) { + if (volume >= 0.5f) { info.outputValues[0] = _value; } return false; // reached granularity limit; take best guess diff --git a/libraries/metavoxels/src/Bitstream.cpp b/libraries/metavoxels/src/Bitstream.cpp index e1ab79c974..77273fea9c 100644 --- a/libraries/metavoxels/src/Bitstream.cpp +++ b/libraries/metavoxels/src/Bitstream.cpp @@ -237,6 +237,24 @@ Bitstream& Bitstream::operator>>(QVariant& value) { return *this; } +Bitstream& Bitstream::operator<<(const AttributeValue& value) { + _attributeStreamer << value.getAttribute(); + if (value.getAttribute()) { + value.getAttribute()->write(*this, value.getValue(), true); + } + return *this; +} + +Bitstream& Bitstream::operator>>(AttributeValue& value) { + AttributePointer attribute; + _attributeStreamer >> attribute; + if (attribute) { + void* value; + attribute->read(*this, value, true); + } + return *this; +} + Bitstream& Bitstream::operator<<(const QObject* object) { if (!object) { _metaObjectStreamer << NULL; diff --git a/libraries/metavoxels/src/Bitstream.h b/libraries/metavoxels/src/Bitstream.h index 09c14d63e6..c8793f9673 100644 --- a/libraries/metavoxels/src/Bitstream.h +++ b/libraries/metavoxels/src/Bitstream.h @@ -23,6 +23,7 @@ struct QMetaObject; class QObject; class Attribute; +class AttributeValue; class Bitstream; class TypeStreamer; @@ -231,6 +232,9 @@ public: Bitstream& operator<<(const QVariant& value); Bitstream& operator>>(QVariant& value); + Bitstream& operator<<(const AttributeValue& value); + Bitstream& operator>>(AttributeValue& value); + template Bitstream& operator<<(const QList& list); template Bitstream& operator>>(QList& list); diff --git a/libraries/metavoxels/src/MetavoxelData.cpp b/libraries/metavoxels/src/MetavoxelData.cpp index ffbe5b4ff8..a88c5cd922 100644 --- a/libraries/metavoxels/src/MetavoxelData.cpp +++ b/libraries/metavoxels/src/MetavoxelData.cpp @@ -334,6 +334,9 @@ MetavoxelVisitor::MetavoxelVisitor(const QVector& inputs, cons _outputs(outputs) { } +MetavoxelVisitor::~MetavoxelVisitor() { +} + PolymorphicData* DefaultMetavoxelGuide::clone() const { return new DefaultMetavoxelGuide(); } diff --git a/libraries/metavoxels/src/MetavoxelData.h b/libraries/metavoxels/src/MetavoxelData.h index a25e0bc9a8..8628958052 100644 --- a/libraries/metavoxels/src/MetavoxelData.h +++ b/libraries/metavoxels/src/MetavoxelData.h @@ -124,6 +124,7 @@ class MetavoxelVisitor { public: MetavoxelVisitor(const QVector& inputs, const QVector& outputs); + virtual ~MetavoxelVisitor(); /// Returns a reference to the list of input attributes desired. const QVector& getInputs() const { return _inputs; } @@ -142,6 +143,8 @@ protected: QVector _outputs; }; +typedef QSharedPointer MetavoxelVisitorPointer; + /// Interface for objects that guide metavoxel visitors. class MetavoxelGuide : public PolymorphicData { public: diff --git a/libraries/metavoxels/src/MetavoxelMessages.h b/libraries/metavoxels/src/MetavoxelMessages.h index 3951e16d22..e3550acaa5 100644 --- a/libraries/metavoxels/src/MetavoxelMessages.h +++ b/libraries/metavoxels/src/MetavoxelMessages.h @@ -29,4 +29,17 @@ class MetavoxelDeltaMessage { DECLARE_STREAMABLE_METATYPE(MetavoxelDeltaMessage) +/// A simple streamable edit. +class MetavoxelEdit { + STREAMABLE + +public: + + glm::vec3 minimum; + glm::vec3 maximum; + float granularity; +}; + +DECLARE_STREAMABLE_METATYPE(MetavoxelEdit) + #endif /* defined(__interface__MetavoxelMessages__) */