From 32cf669d8bc8466c81439fe42edfd025f70b24a5 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 18 Jun 2015 17:51:41 -0700 Subject: [PATCH] moving toward sending actions over wire --- interface/src/avatar/Avatar.cpp | 4 +- libraries/entities/src/EntityItem.cpp | 45 ++++++++++++++----- libraries/entities/src/EntityItem.h | 2 + .../entities/src/EntityItemProperties.cpp | 8 +++- libraries/entities/src/EntityItemProperties.h | 6 ++- libraries/entities/src/EntityPropertyFlags.h | 8 ++-- libraries/physics/src/ObjectActionSpring.cpp | 2 +- 7 files changed, 57 insertions(+), 18 deletions(-) diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index 731c69979e..be110cbc03 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -692,9 +692,9 @@ Transform Avatar::calculateDisplayNameTransform(const ViewFrustum& frustum, floa const float DESIRED_HIGHT_ON_SCREEN = 20; // In pixels (this is double on retinas) // Projected point are between -1.0f and 1.0f, hence 0.5f * windowSizeY - double pixelHeight = 0.5f * windowSizeY * glm::abs((p1.y / p1.w) - (p0.y / p0.w)); // + float pixelHeight = 0.5f * windowSizeY * glm::abs((p1.y / p1.w) - (p0.y / p0.w)); // // Handles pixel density (especially for macs retina displays) - double devicePixelRatio = qApp->getDevicePixelRatio() * qApp->getRenderResolutionScale(); // pixels / unit + float devicePixelRatio = (float)qApp->getDevicePixelRatio() * qApp->getRenderResolutionScale(); // pixels / unit // Compute correct scale to apply float scale = DESIRED_HIGHT_ON_SCREEN / (fontSize * pixelHeight) * devicePixelRatio; diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index da5f96f503..c804abca32 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -252,6 +252,7 @@ OctreeElement::AppendState EntityItem::appendEntityData(OctreePacketData* packet APPEND_ENTITY_PROPERTY(PROP_COLLISION_SOUND_URL, getCollisionSoundURL()); APPEND_ENTITY_PROPERTY(PROP_HREF, getHref()); APPEND_ENTITY_PROPERTY(PROP_DESCRIPTION, getDescription()); + APPEND_ENTITY_PROPERTY(PROP_ACTION_DATA, getActionData()); appendSubclassData(packetData, params, entityTreeElementExtraEncodeData, @@ -401,7 +402,7 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef qCDebug(entities) << " lastEdited =" << lastEdited; qCDebug(entities) << " ago=" << editedAgo << "seconds - " << agoAsString; #endif - + quint64 lastEditedFromBuffer = 0; quint64 lastEditedFromBufferAdjusted = 0; @@ -448,7 +449,7 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef ignoreServerPacket = true; } } - + if (ignoreServerPacket) { overwriteLocalData = false; #ifdef WANT_DEBUG @@ -465,8 +466,8 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef _lastEdited = lastEditedFromBufferAdjusted; _lastEditedFromRemote = now; _lastEditedFromRemoteInRemoteTime = lastEditedFromBuffer; - - // TODO: only send this notification if something ACTUALLY changed (hint, we haven't yet parsed + + // TODO: only send this notification if something ACTUALLY changed (hint, we haven't yet parsed // the properties out of the bitstream (see below)) somethingChangedNotification(); // notify derived classes that something has changed } @@ -486,7 +487,7 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef encodedUpdateDelta = updateDeltaCoder; // determine true length dataAt += encodedUpdateDelta.size(); bytesRead += encodedUpdateDelta.size(); - + // Newer bitstreams will have a last simulated and a last updated value quint64 lastSimulatedFromBufferAdjusted = now; if (args.bitstreamVersion >= VERSION_ENTITIES_HAS_LAST_SIMULATED_TIME) { @@ -509,7 +510,7 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef dataAt += encodedSimulatedDelta.size(); bytesRead += encodedSimulatedDelta.size(); } - + #ifdef WANT_DEBUG if (overwriteLocalData) { qCDebug(entities) << "EntityItem::readEntityDataFromBuffer()... changed entity:" << getEntityItemID(); @@ -518,7 +519,7 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef qCDebug(entities) << " getLastUpdated:" << debugTime(getLastUpdated(), now); } #endif - + // Property Flags QByteArray encodedPropertyFlags = originalDataBuffer.mid(bytesRead); // maximum possible size @@ -567,7 +568,7 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef if (args.bitstreamVersion >= VERSION_ENTITIES_HAVE_ACCELERATION) { // we always accept the server's notion of simulatorID, so we fake overwriteLocalData as true - // before we try to READ_ENTITY_PROPERTY it + // before we try to READ_ENTITY_PROPERTY it bool temp = overwriteLocalData; overwriteLocalData = true; READ_ENTITY_PROPERTY(PROP_SIMULATOR_ID, QUuid, updateSimulatorID); @@ -583,12 +584,15 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef READ_ENTITY_PROPERTY(PROP_HREF, QString, setHref); READ_ENTITY_PROPERTY(PROP_DESCRIPTION, QString, setDescription); - bytesRead += readEntitySubclassDataFromBuffer(dataAt, (bytesLeftToRead - bytesRead), args, propertyFlags, overwriteLocalData); + READ_ENTITY_PROPERTY(PROP_ACTION_DATA, QByteArray, setActionData); + + bytesRead += readEntitySubclassDataFromBuffer(dataAt, (bytesLeftToRead - bytesRead), args, + propertyFlags, overwriteLocalData); //////////////////////////////////// // WARNING: Do not add stream content here after the subclass. Always add it before the subclass // - // NOTE: we had a bad version of the stream that we added stream data after the subclass. We can attempt to recover + // NOTE: we had a bad version of the stream that we added stream data after the subclass. We can attempt to recover // by doing this parsing here... but it's not likely going to fully recover the content. // // TODO: Remove this conde once we've sufficiently migrated content past this damaged version @@ -1392,3 +1396,24 @@ void EntityItem::clearActions(EntitySimulation* simulation) { action->removeFromSimulation(simulation); } } + +void EntityItem::setActionData(QByteArray actionData) { + +} + + +const QByteArray EntityItem::getActionData() const { + QVector serializedActions; + QHash::const_iterator i = _objectActions.begin(); + while (i != _objectActions.end()) { + const QUuid id = i.key(); + EntityActionPointer action = _objectActions[id]; + QByteArray bytesForAction = action->serialize(); + serializedActions << bytesForAction; + } + + QByteArray result; + QDataStream ds(&result, QIODevice::WriteOnly); + ds << serializedActions; + return result; +} diff --git a/libraries/entities/src/EntityItem.h b/libraries/entities/src/EntityItem.h index 73f9127361..b96a14c2cf 100644 --- a/libraries/entities/src/EntityItem.h +++ b/libraries/entities/src/EntityItem.h @@ -379,6 +379,8 @@ public: bool updateAction(EntitySimulation* simulation, const QUuid& actionID, const QVariantMap& arguments); bool removeAction(EntitySimulation* simulation, const QUuid& actionID); void clearActions(EntitySimulation* simulation); + void setActionData(QByteArray actionData); + const QByteArray getActionData() const; protected: diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index cbb3b1dc31..6b4235e595 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -98,7 +98,7 @@ CONSTRUCT_PROPERTY(backgroundMode, BACKGROUND_MODE_INHERIT), CONSTRUCT_PROPERTY(sourceUrl, ""), CONSTRUCT_PROPERTY(lineWidth, LineEntityItem::DEFAULT_LINE_WIDTH), CONSTRUCT_PROPERTY(linePoints, QVector()), - +CONSTRUCT_PROPERTY(actionData, QByteArray()), _id(UNKNOWN_ENTITY_ID), _idSet(false), @@ -349,6 +349,7 @@ EntityPropertyFlags EntityItemProperties::getChangedProperties() const { CHECK_PROPERTY_CHANGE(PROP_LINE_POINTS, linePoints); CHECK_PROPERTY_CHANGE(PROP_HREF, href); CHECK_PROPERTY_CHANGE(PROP_DESCRIPTION, description); + CHECK_PROPERTY_CHANGE(PROP_ACTION_DATA, actionData); changedProperties += _stage.getChangedProperties(); changedProperties += _atmosphere.getChangedProperties(); @@ -444,6 +445,7 @@ QScriptValue EntityItemProperties::copyToScriptValue(QScriptEngine* engine, bool COPY_PROPERTY_TO_QSCRIPTVALUE(linePoints); COPY_PROPERTY_TO_QSCRIPTVALUE(href); COPY_PROPERTY_TO_QSCRIPTVALUE(description); + COPY_PROPERTY_TO_QSCRIPTVALUE(actionData); // Sitting properties support if (!skipDefaults) { @@ -555,6 +557,7 @@ void EntityItemProperties::copyFromScriptValue(const QScriptValue& object, bool COPY_PROPERTY_FROM_QSCRIPTVALUE(linePoints, qVectorVec3, setLinePoints); COPY_PROPERTY_FROM_QSCRIPTVALUE(href, QString, setHref); COPY_PROPERTY_FROM_QSCRIPTVALUE(description, QString, setDescription); + COPY_PROPERTY_FROM_QSCRIPTVALUE(actionData, QByteArray, setActionData); if (!honorReadOnly) { @@ -804,6 +807,7 @@ bool EntityItemProperties::encodeEntityEditPacket(PacketType command, EntityItem APPEND_ENTITY_PROPERTY(PROP_MARKETPLACE_ID, properties.getMarketplaceID()); APPEND_ENTITY_PROPERTY(PROP_NAME, properties.getName()); APPEND_ENTITY_PROPERTY(PROP_COLLISION_SOUND_URL, properties.getCollisionSoundURL()); + APPEND_ENTITY_PROPERTY(PROP_ACTION_DATA, properties.getActionData()); } if (propertyCount > 0) { int endOfEntityItemData = packetData->getUncompressedByteOffset(); @@ -1051,6 +1055,7 @@ bool EntityItemProperties::decodeEntityEditPacket(const unsigned char* data, int READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_MARKETPLACE_ID, QString, setMarketplaceID); READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_NAME, QString, setName); READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_COLLISION_SOUND_URL, QString, setCollisionSoundURL); + READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_ACTION_DATA, QByteArray, setActionData); return valid; } @@ -1162,6 +1167,7 @@ void EntityItemProperties::markAllChanged() { _hrefChanged = true; _descriptionChanged = true; + _actionDataChanged = true; } /// The maximum bounding cube for the entity, independent of it's rotation. diff --git a/libraries/entities/src/EntityItemProperties.h b/libraries/entities/src/EntityItemProperties.h index 068bc98f7e..9285ba8a1d 100644 --- a/libraries/entities/src/EntityItemProperties.h +++ b/libraries/entities/src/EntityItemProperties.h @@ -150,6 +150,7 @@ public: DEFINE_PROPERTY_REF(LINE_POINTS, LinePoints, linePoints, QVector); DEFINE_PROPERTY_REF(PROP_HREF, Href, href, QString); DEFINE_PROPERTY_REF(PROP_DESCRIPTION, Description, description, QString); + DEFINE_PROPERTY_REF(PROP_ACTION_DATA, ActionData, actionData, QByteArray); static QString getBackgroundModeString(BackgroundMode mode); @@ -202,6 +203,8 @@ public: bool hasTerseUpdateChanges() const; + void setActionDataDirty() { _actionDataChanged = true; } + private: QUuid _id; bool _idSet; @@ -299,7 +302,8 @@ inline QDebug operator<<(QDebug debug, const EntityItemProperties& properties) { DEBUG_PROPERTY_IF_CHANGED(debug, properties, VoxelSurfaceStyle, voxelSurfaceStyle, ""); DEBUG_PROPERTY_IF_CHANGED(debug, properties, Href, href, ""); DEBUG_PROPERTY_IF_CHANGED(debug, properties, Description, description, ""); - + DEBUG_PROPERTY_IF_CHANGED(debug, properties, ActionData, actionData, ""); + properties.getStage().debugDump(); properties.getAtmosphere().debugDump(); properties.getSkybox().debugDump(); diff --git a/libraries/entities/src/EntityPropertyFlags.h b/libraries/entities/src/EntityPropertyFlags.h index f1ebdb8a1f..e5af56c322 100644 --- a/libraries/entities/src/EntityPropertyFlags.h +++ b/libraries/entities/src/EntityPropertyFlags.h @@ -86,7 +86,7 @@ enum EntityPropertyList { // available to all entities PROP_LOCKED, - + PROP_TEXTURES, // used by Model entities PROP_ANIMATION_SETTINGS, // used by Model entities PROP_USER_DATA, // all entities @@ -100,7 +100,7 @@ enum EntityPropertyList { PROP_EMIT_STRENGTH, PROP_LOCAL_GRAVITY, PROP_PARTICLE_RADIUS, - + PROP_COMPOUND_SHAPE_URL, // used by Model + zones entities PROP_MARKETPLACE_ID, // all entities PROP_ACCELERATION, // all entities @@ -121,7 +121,9 @@ enum EntityPropertyList { // used by hyperlinks PROP_HREF, PROP_DESCRIPTION, - + + PROP_ACTION_DATA, + //////////////////////////////////////////////////////////////////////////////////////////////////// // ATTENTION: add new properties ABOVE this line PROP_AFTER_LAST_ITEM, diff --git a/libraries/physics/src/ObjectActionSpring.cpp b/libraries/physics/src/ObjectActionSpring.cpp index 5efdd29f09..be23423c2f 100644 --- a/libraries/physics/src/ObjectActionSpring.cpp +++ b/libraries/physics/src/ObjectActionSpring.cpp @@ -108,7 +108,7 @@ bool ObjectActionSpring::updateArguments(QVariantMap arguments) { EntityActionInterface::extractFloatArgument("spring action", arguments, "angularTimeScale", rscOk, false); if (!ptOk && !rtOk) { - qDebug() << "spring action requires either targetPosition or targetRotation argument"; + qDebug() << "spring action requires at least one of targetPosition or targetRotation argument"; return false; }