MetavoxelDataPointer -> MetavoxelData, grid spacing as power of 2.

This commit is contained in:
Andrzej Kapolka 2014-01-26 13:23:10 -08:00
parent 5a095b57cd
commit 1ef6f5f7b3
10 changed files with 43 additions and 69 deletions

View file

@ -18,8 +18,7 @@
const int SEND_INTERVAL = 50;
MetavoxelServer::MetavoxelServer(const unsigned char* dataBuffer, int numBytes) :
ThreadedAssignment(dataBuffer, numBytes),
_data(new MetavoxelData()) {
ThreadedAssignment(dataBuffer, numBytes) {
_sendTimer.setSingleShot(true);
connect(&_sendTimer, SIGNAL(timeout()), SLOT(sendDeltas()));
@ -94,9 +93,10 @@ MetavoxelSession::MetavoxelSession(MetavoxelServer* server, const QUuid& session
connect(&_sequencer, SIGNAL(readyToWrite(const QByteArray&)), SLOT(sendData(const QByteArray&)));
connect(&_sequencer, SIGNAL(readyToRead(Bitstream&)), SLOT(readPacket(Bitstream&)));
connect(&_sequencer, SIGNAL(sendAcknowledged(int)), SLOT(clearSendRecordsBefore(int)));
connect(&_sequencer, SIGNAL(receivedHighPriorityMessage(const QVariant&)), SLOT(handleMessage(const QVariant&)));
// insert the baseline send record
SendRecord record = { 0, MetavoxelDataPointer(new MetavoxelData()) };
SendRecord record = { 0 };
_sendRecords.append(record);
}
@ -114,7 +114,7 @@ void MetavoxelSession::receivedData(const QByteArray& data, const HifiSockAddr&
void MetavoxelSession::sendDelta() {
Bitstream& out = _sequencer.startPacket();
out << QVariant::fromValue(MetavoxelDeltaMessage());
writeDelta(_server->getData(), _sendRecords.first().data, out);
//writeDelta(_server->getData(), _sendRecords.first().data, out);
_sequencer.endPacket();
// record the send
@ -134,25 +134,26 @@ void MetavoxelSession::sendData(const QByteArray& data) {
void MetavoxelSession::readPacket(Bitstream& in) {
QVariant message;
in >> message;
handleMessage(message, in);
handleMessage(message);
}
void MetavoxelSession::clearSendRecordsBefore(int index) {
_sendRecords.erase(_sendRecords.begin(), _sendRecords.begin() + index + 1);
}
void MetavoxelSession::handleMessage(const QVariant& message, Bitstream& in) {
void MetavoxelSession::handleMessage(const QVariant& message) {
int userType = message.userType();
if (userType == ClientStateMessage::Type) {
ClientStateMessage state = message.value<ClientStateMessage>();
_position = state.position;
} else if (userType == MetavoxelDeltaMessage::Type) {
} else if (userType == MetavoxelEdit::Type) {
MetavoxelEdit edit = message.value<MetavoxelEdit>();
qDebug() << "got edit " << edit.granularity;
} else if (userType == QMetaType::QVariantList) {
foreach (const QVariant& element, message.toList()) {
handleMessage(element, in);
handleMessage(element);
}
}
}

View file

@ -30,7 +30,7 @@ public:
MetavoxelServer(const unsigned char* dataBuffer, int numBytes);
const MetavoxelDataPointer& getData() const { return _data; }
const MetavoxelData& getData() const { return _data; }
void removeSession(const QUuid& sessionId);
@ -51,7 +51,7 @@ private:
QHash<QUuid, MetavoxelSession*> _sessions;
MetavoxelDataPointer _data;
MetavoxelData _data;
};
/// Contains the state of a single client session.
@ -76,14 +76,14 @@ private slots:
void clearSendRecordsBefore(int index);
private:
void handleMessage(const QVariant& message);
void handleMessage(const QVariant& message, Bitstream& in);
private:
class SendRecord {
public:
int packetNumber;
MetavoxelDataPointer data;
MetavoxelData data;
};
MetavoxelServer* _server;

View file

@ -54,7 +54,6 @@ void MetavoxelSystem::processData(const QByteArray& data, const HifiSockAddr& se
void MetavoxelSystem::simulate(float deltaTime) {
// simulate the clients
_points.clear();
_data.guide(_pointVisitor);
foreach (MetavoxelClient* client, _clients) {
client->simulate(deltaTime, _pointVisitor);
}
@ -180,8 +179,7 @@ static QByteArray createDatagramHeader(const QUuid& sessionID) {
MetavoxelClient::MetavoxelClient(const HifiSockAddr& address) :
_address(address),
_sessionID(QUuid::createUuid()),
_sequencer(createDatagramHeader(_sessionID)),
_data(new MetavoxelData()) {
_sequencer(createDatagramHeader(_sessionID)) {
connect(&_sequencer, SIGNAL(readyToWrite(const QByteArray&)), SLOT(sendData(const QByteArray&)));
connect(&_sequencer, SIGNAL(readyToRead(Bitstream&)), SLOT(readPacket(Bitstream&)));
@ -197,7 +195,7 @@ void MetavoxelClient::applyEdit(const MetavoxelEdit& edit) {
edit.apply(_data);
// start sending it out
_sequencer.sendHighPriorityMessage(QVariant::fromValue(edit));
// _sequencer.sendHighPriorityMessage(QVariant::fromValue(edit));
}
void MetavoxelClient::simulate(float deltaTime, MetavoxelVisitor& visitor) {
@ -206,7 +204,7 @@ void MetavoxelClient::simulate(float deltaTime, MetavoxelVisitor& visitor) {
out << QVariant::fromValue(state);
_sequencer.endPacket();
_data->guide(visitor);
_data.guide(visitor);
}
void MetavoxelClient::receivedData(const QByteArray& data, const HifiSockAddr& sender) {
@ -238,7 +236,7 @@ void MetavoxelClient::clearReceiveRecordsBefore(int index) {
void MetavoxelClient::handleMessage(const QVariant& message, Bitstream& in) {
int userType = message.userType();
if (userType == MetavoxelDeltaMessage::Type) {
readDelta(_data, _receiveRecords.first().data, in);
// readDelta(_data, _receiveRecords.first().data, in);
} else if (userType == QMetaType::QVariantList) {
foreach (const QVariant& element, message.toList()) {

View file

@ -72,7 +72,6 @@ private:
static ProgramObject _program;
static int _pointScaleLocation;
MetavoxelData _data;
QVector<Point> _points;
PointVisitor _pointVisitor;
QOpenGLBuffer _buffer;
@ -112,7 +111,7 @@ private:
class ReceiveRecord {
public:
int packetNumber;
MetavoxelDataPointer data;
MetavoxelData data;
};
HifiSockAddr _address;
@ -120,7 +119,7 @@ private:
DatagramSequencer _sequencer;
MetavoxelDataPointer _data;
MetavoxelData _data;
QList<ReceiveRecord> _receiveRecords;
};

View file

@ -60,15 +60,16 @@ MetavoxelEditor::MetavoxelEditor() :
_gridPlane->setCurrentIndex(GRID_PLANE_XZ);
formLayout->addRow("Grid Spacing:", _gridSpacing = new QDoubleSpinBox());
_gridSpacing->setValue(0.1);
_gridSpacing->setMinimum(-FLT_MAX);
_gridSpacing->setMaximum(FLT_MAX);
_gridSpacing->setSingleStep(0.01);
_gridSpacing->setPrefix("2^");
_gridSpacing->setValue(-3.0);
connect(_gridSpacing, SIGNAL(valueChanged(double)), SLOT(updateGridPosition()));
formLayout->addRow("Grid Position:", _gridPosition = new QDoubleSpinBox());
_gridPosition->setSingleStep(0.1);
_gridPosition->setMinimum(-FLT_MAX);
_gridPosition->setMaximum(FLT_MAX);
updateGridPosition();
_value = new QGroupBox();
_value->setTitle("Value");
@ -119,7 +120,7 @@ bool MetavoxelEditor::eventFilter(QObject* watched, QEvent* event) {
float top = base + _height;
glm::quat rotation = getGridRotation();
glm::vec3 start = rotation * glm::vec3(glm::min(_startPosition, _endPosition), glm::min(base, top));
float spacing = _gridSpacing->value();
float spacing = getGridSpacing();
glm::vec3 end = rotation * glm::vec3(glm::max(_startPosition, _endPosition) +
glm::vec2(spacing, spacing), glm::max(base, top));
@ -183,11 +184,9 @@ void MetavoxelEditor::createNewAttribute() {
void MetavoxelEditor::updateGridPosition() {
// make sure our grid position matches our grid spacing
double step = _gridSpacing->value();
if (step > 0.0) {
_gridPosition->setSingleStep(step);
_gridPosition->setValue(step * floor(_gridPosition->value() / step));
}
double step = getGridSpacing();
_gridPosition->setSingleStep(step);
_gridPosition->setValue(step * floor(_gridPosition->value() / step));
}
void MetavoxelEditor::render() {
@ -209,7 +208,7 @@ void MetavoxelEditor::render() {
glm::quat inverseRotation = glm::inverse(rotation);
glm::vec3 rayOrigin = inverseRotation * Application::getInstance()->getMouseRayOrigin();
glm::vec3 rayDirection = inverseRotation * Application::getInstance()->getMouseRayDirection();
float spacing = _gridSpacing->value();
float spacing = getGridSpacing();
float position = _gridPosition->value();
if (_state == RAISING_STATE) {
// find the plane at the mouse position, orthogonal to the plane, facing the eye position
@ -318,6 +317,10 @@ QString MetavoxelEditor::getSelectedAttribute() const {
return selectedItems.isEmpty() ? QString() : selectedItems.first()->text();
}
double MetavoxelEditor::getGridSpacing() const {
return pow(2.0, _gridSpacing->value());
}
glm::quat MetavoxelEditor::getGridRotation() const {
// for simplicity, we handle the other two planes by rotating them onto X/Y and performing computation there
switch (_gridPlane->currentIndex()) {
@ -345,7 +348,7 @@ void MetavoxelEditor::applyValue(const glm::vec3& minimum, const glm::vec3& maxi
return;
}
OwnedAttributeValue value(attribute, attribute->createFromVariant(getValue()));
MetavoxelEdit edit = { minimum, maximum, _gridSpacing->value(), value };
MetavoxelEdit edit = { minimum, maximum, getGridSpacing(), value };
Application::getInstance()->getMetavoxels()->applyEdit(edit);
}

View file

@ -40,6 +40,7 @@ private:
void updateAttributes(const QString& select = QString());
QString getSelectedAttribute() const;
double getGridSpacing() const;
glm::quat getGridRotation() const;
void resetState();
void applyValue(const glm::vec3& minimum, const glm::vec3& maximum);

View file

@ -176,28 +176,6 @@ void MetavoxelData::decrementRootReferenceCounts() {
}
}
void writeDelta(const MetavoxelDataPointer& data, const MetavoxelDataPointer& reference, Bitstream& out) {
if (data == reference) {
out << false;
} else {
out << true;
data->writeDelta(*reference, out);
}
}
void readDelta(MetavoxelDataPointer& data, const MetavoxelDataPointer& reference, Bitstream& in) {
bool changed;
in >> changed;
if (changed) {
data.detach();
data->readDelta(*reference, in);
} else {
data = reference;
}
}
MetavoxelNode::MetavoxelNode(const AttributeValue& attributeValue) : _referenceCount(1) {
_attributeValue = attributeValue.copy();
for (int i = 0; i < CHILD_COUNT; i++) {

View file

@ -10,7 +10,6 @@
#define __interface__MetavoxelData__
#include <QBitArray>
#include <QExplicitlySharedDataPointer>
#include <QHash>
#include <QSharedData>
#include <QScriptString>
@ -28,7 +27,7 @@ class MetavoxelVisitation;
class MetavoxelVisitor;
/// The base metavoxel representation shared between server and client.
class MetavoxelData : public QSharedData {
class MetavoxelData {
public:
MetavoxelData();
@ -56,12 +55,6 @@ private:
QHash<AttributePointer, MetavoxelNode*> _roots;
};
typedef QExplicitlySharedDataPointer<MetavoxelData> MetavoxelDataPointer;
void writeDelta(const MetavoxelDataPointer& data, const MetavoxelDataPointer& reference, Bitstream& out);
void readDelta(MetavoxelDataPointer& data, const MetavoxelDataPointer& reference, Bitstream& in);
/// A single node within a metavoxel layer.
class MetavoxelNode {
public:

View file

@ -6,6 +6,7 @@
// Copyright (c) 2014 High Fidelity, Inc. All rights reserved.
//
#include "MetavoxelData.h"
#include "MetavoxelMessages.h"
class EditVisitor : public MetavoxelVisitor {
@ -47,8 +48,7 @@ bool EditVisitor::visit(MetavoxelInfo& info) {
return true; // subdivide
}
void MetavoxelEdit::apply(MetavoxelDataPointer& data) const {
//data.detach();
void MetavoxelEdit::apply(MetavoxelData& data) const {
EditVisitor visitor(*this);
data->guide(visitor);
data.guide(visitor);
}

View file

@ -11,7 +11,8 @@
#include "AttributeRegistry.h"
#include "Bitstream.h"
#include "MetavoxelData.h"
class MetavoxelData;
/// A message containing the state of a client.
class ClientStateMessage {
@ -42,7 +43,7 @@ public:
STREAM float granularity;
STREAM OwnedAttributeValue value;
void apply(MetavoxelDataPointer& data) const;
void apply(MetavoxelData& data) const;
};
DECLARE_STREAMABLE_METATYPE(MetavoxelEdit)