This commit is contained in:
Andrew Meadows 2018-12-07 14:43:44 -08:00
parent fe2ee68b79
commit 6c81e8845b
7 changed files with 44 additions and 39 deletions

View file

@ -1303,6 +1303,10 @@ void MyAvatar::saveData() {
} }
void MyAvatar::saveAvatarEntityDataToSettings() { void MyAvatar::saveAvatarEntityDataToSettings() {
if (!_entitiesToSaveToSettings.empty()) {
// TODO: save these to settings.
_entitiesToSaveToSettings.clear();
}
// save new settings // save new settings
uint32_t numEntities = _avatarEntityStrings.size(); uint32_t numEntities = _avatarEntityStrings.size();
_avatarEntityCountSetting.set(numEntities); _avatarEntityCountSetting.set(numEntities);
@ -1429,17 +1433,28 @@ void MyAvatar::setEnableInverseKinematics(bool isEnabled) {
_skeletonModel->getRig().setEnableInverseKinematics(isEnabled); _skeletonModel->getRig().setEnableInverseKinematics(isEnabled);
} }
void MyAvatar::updateAvatarEntity(const QUuid& entityID, const QString& entityPropertiesString) { void MyAvatar::storeAvatarEntityDataPayload(const QUuid& entityID, const QByteArray& payload) {
/* TODO: implement this so JS can add/update (and delete?) AvatarEntitieskj:w AvatarData::storeAvatarEntityDataPayload(entityID, payload);
// convert string to properties _entitiesToSaveToSettings.insert(entityID);
// NOTE: this path from EntityItemProperties JSON string to EntityItemProperties is NOT efficient }
EntityItemProperties properties;
properties.copyFromJSONString(scriptEngine, entityPropertiesString);
/* TODO: verify we don't need this
void MyAvatar::updateAvatarEntity(const QUuid& entityID, const QString& entityPropertiesString) {
auto entityTreeRenderer = qApp->getEntities(); auto entityTreeRenderer = qApp->getEntities();
EntityTreePointer entityTree = entityTreeRenderer ? entityTreeRenderer->getTree() : nullptr; EntityTreePointer entityTree = entityTreeRenderer ? entityTreeRenderer->getTree() : nullptr;
EntityItemPointer entity; EntityItemPointer entity;
if (entityTree) { if (entityTree) {
return;
}
// convert string to properties
EntityItemProperties properties;
{
// NOTE: this path from EntityItemProperties JSON string to EntityItemProperties is NOT efficient
QScriptEngine scriptEngine;
properties.copyFromJSONString(scriptEngine, entityPropertiesString);
}
entityTree->withWriteLock([&] {
entity = entityTree->findEntityByID(entityID); entity = entityTree->findEntityByID(entityID);
if (!entity) { if (!entity) {
entity = entityTree->addEntity(entityID, properties); entity = entityTree->addEntity(entityID, properties);
@ -1450,25 +1465,25 @@ void MyAvatar::updateAvatarEntity(const QUuid& entityID, const QString& entityPr
} }
// TODO: remember this entity and its properties, so we can save to settings // TODO: remember this entity and its properties, so we can save to settings
} else { } else {
// TODO: propagate changes to entity entityTree->updateEntity(entityID, properties);
// TODO: and remember these changes so we can save to settings
} }
} if (entity) {
// build update packet for later
OctreePacketData packetData(false, AvatarTraits::MAXIMUM_TRAIT_SIZE);
EncodeBitstreamParams params;
EntityTreeElementExtraEncodeDataPointer extra { nullptr };
OctreeElement::AppendState appendState = entity->appendEntityData(&packetData, params, extra);
if (appendState == OctreeElement::COMPLETED) {
QByteArray tempArray = QByteArray::fromRawData((const char*)packetData.getUncompressedData(), packetData.getUncompressedSize());
storeAvatarEntityDataPayload(entity->getID(), tempArray);
properties = entity->getProperties();
_entitiesToSaveToSettings.insert(entityID);
}
OctreePacketData packetData(false, AvatarTraits::MAXIMUM_TRAIT_SIZE); }
EncodeBitstreamParams params; });
EntityTreeElementExtraEncodeDataPointer extra { nullptr };
OctreeElement::AppendState appendState = entity->appendEntityData(&packetData, params, extra);
if (appendState != OctreeElement::COMPLETED) {
// this entity's data is too big
return;
}
QByteArray tempArray = QByteArray::fromRawData((const char*)packetData.getUncompressedData(), packetData.getUncompressedSize());
storeAvatarEntityDataPayload(entity->getID(), tempArray);
*/
} }
*/
void MyAvatar::updateAvatarEntities() { void MyAvatar::updateAvatarEntities() {
// TODO: modify this info for MyAvatar // TODO: modify this info for MyAvatar

View file

@ -1407,7 +1407,7 @@ public slots:
*/ */
bool getEnableMeshVisible() const override; bool getEnableMeshVisible() const override;
void updateAvatarEntity(const QUuid& entityID, const QString& entityPropertiesString) override; void storeAvatarEntityDataPayload(const QUuid& entityID, const QByteArray& payload) override;
/**jsdoc /**jsdoc
* Set whether or not your avatar mesh is visible. * Set whether or not your avatar mesh is visible.
@ -1948,6 +1948,7 @@ private:
std::vector<Setting::Handle<QString>> _avatarEntityDataSettings; std::vector<Setting::Handle<QString>> _avatarEntityDataSettings;
std::map<QUuid, QString> _avatarEntityStrings; std::map<QUuid, QString> _avatarEntityStrings;
std::map<QUuid, QString> _avatarEntityProperties; std::map<QUuid, QString> _avatarEntityProperties;
std::set<QUuid> _entitiesToSaveToSettings;
}; };
QScriptValue audioListenModeToScriptValue(QScriptEngine* engine, const AudioListenerMode& audioListenerMode); QScriptValue audioListenModeToScriptValue(QScriptEngine* engine, const AudioListenerMode& audioListenerMode);

View file

@ -2777,7 +2777,7 @@ void AvatarData::storeAvatarEntityDataPayload(const QUuid& entityID, const QByte
} }
void AvatarData::updateAvatarEntity(const QUuid& entityID, const QString& entityPropertiesString) { void AvatarData::updateAvatarEntity(const QUuid& entityID, const QString& entityPropertiesString) {
// TODO: implement this as API exposed to JS // TODO: implement this to expose AvatarEntity to JS
} }
void AvatarData::clearAvatarEntity(const QUuid& entityID, bool requiresRemovalFromTree) { void AvatarData::clearAvatarEntity(const QUuid& entityID, bool requiresRemovalFromTree) {

View file

@ -952,14 +952,14 @@ public:
// FIXME: Can this name be improved? Can it be deprecated? // FIXME: Can this name be improved? Can it be deprecated?
Q_INVOKABLE virtual void setAttachmentsVariant(const QVariantList& variant); Q_INVOKABLE virtual void setAttachmentsVariant(const QVariantList& variant);
void storeAvatarEntityDataPayload(const QUuid& entityID, const QByteArray& payload); virtual void storeAvatarEntityDataPayload(const QUuid& entityID, const QByteArray& payload);
/**jsdoc /**jsdoc
* @function MyAvatar.updateAvatarEntity * @function MyAvatar.updateAvatarEntity
* @param {Uuid} entityID * @param {Uuid} entityID
* @param {string} entityData * @param {string} entityData
*/ */
Q_INVOKABLE void updateAvatarEntity(const QUuid& entityID, const QString& entityPropertiesString); Q_INVOKABLE virtual void updateAvatarEntity(const QUuid& entityID, const QString& entityPropertiesString);
/**jsdoc /**jsdoc
* @function MyAvatar.clearAvatarEntity * @function MyAvatar.clearAvatarEntity

View file

@ -69,8 +69,8 @@ void EntityEditPacketSender::queueEditAvatarEntityMessage(EntityTreePointer enti
return; return;
} }
packetData.shrinkByteArrays(); QByteArray tempArray = QByteArray::fromRawData((const char*)packetData.getUncompressedData(), packetData.getUncompressedSize());
_myAvatar->storeAvatarEntityDataPayload(entity->getID(), packetData.getUncompressedByteArray()); _myAvatar->storeAvatarEntityDataPayload(entityItemID, tempArray);
} }
void EntityEditPacketSender::queueEditEntityMessage(PacketType type, void EntityEditPacketSender::queueEditEntityMessage(PacketType type,

View file

@ -654,15 +654,6 @@ void OctreePacketData::loadFinalizedContent(const unsigned char* data, int lengt
} }
} }
void OctreePacketData::shrinkByteArrays() {
_uncompressedByteArray.resize(_bytesInUse);
_compressedByteArray.resize(_compressedBytes);
// if you call this method then you are expected to be done packing to raw pointers
// and you just want the ByteArrays
// therefore we reset
reset();
}
void OctreePacketData::debugContent() { void OctreePacketData::debugContent() {
qCDebug(octree, "OctreePacketData::debugContent()... COMPRESSED DATA.... size=%d",_compressedBytes); qCDebug(octree, "OctreePacketData::debugContent()... COMPRESSED DATA.... size=%d",_compressedBytes);
int perline=0; int perline=0;

View file

@ -245,8 +245,6 @@ public:
int getBytesAvailable() { return _bytesAvailable; } int getBytesAvailable() { return _bytesAvailable; }
void shrinkByteArrays();
/// displays contents for debugging /// displays contents for debugging
void debugContent(); void debugContent();
void debugBytes(); void debugBytes();