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() {
if (!_entitiesToSaveToSettings.empty()) {
// TODO: save these to settings.
_entitiesToSaveToSettings.clear();
}
// save new settings
uint32_t numEntities = _avatarEntityStrings.size();
_avatarEntityCountSetting.set(numEntities);
@ -1429,17 +1433,28 @@ void MyAvatar::setEnableInverseKinematics(bool isEnabled) {
_skeletonModel->getRig().setEnableInverseKinematics(isEnabled);
}
void MyAvatar::updateAvatarEntity(const QUuid& entityID, const QString& entityPropertiesString) {
/* TODO: implement this so JS can add/update (and delete?) AvatarEntitieskj:w
// convert string to properties
// NOTE: this path from EntityItemProperties JSON string to EntityItemProperties is NOT efficient
EntityItemProperties properties;
properties.copyFromJSONString(scriptEngine, entityPropertiesString);
void MyAvatar::storeAvatarEntityDataPayload(const QUuid& entityID, const QByteArray& payload) {
AvatarData::storeAvatarEntityDataPayload(entityID, payload);
_entitiesToSaveToSettings.insert(entityID);
}
/* TODO: verify we don't need this
void MyAvatar::updateAvatarEntity(const QUuid& entityID, const QString& entityPropertiesString) {
auto entityTreeRenderer = qApp->getEntities();
EntityTreePointer entityTree = entityTreeRenderer ? entityTreeRenderer->getTree() : nullptr;
EntityItemPointer entity;
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);
if (!entity) {
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
} else {
// TODO: propagate changes to entity
// TODO: and remember these changes so we can save to settings
entityTree->updateEntity(entityID, properties);
}
}
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() {
// TODO: modify this info for MyAvatar

View file

@ -1407,7 +1407,7 @@ public slots:
*/
bool getEnableMeshVisible() const override;
void updateAvatarEntity(const QUuid& entityID, const QString& entityPropertiesString) override;
void storeAvatarEntityDataPayload(const QUuid& entityID, const QByteArray& payload) override;
/**jsdoc
* Set whether or not your avatar mesh is visible.
@ -1948,6 +1948,7 @@ private:
std::vector<Setting::Handle<QString>> _avatarEntityDataSettings;
std::map<QUuid, QString> _avatarEntityStrings;
std::map<QUuid, QString> _avatarEntityProperties;
std::set<QUuid> _entitiesToSaveToSettings;
};
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) {
// TODO: implement this as API exposed to JS
// TODO: implement this to expose AvatarEntity to JS
}
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?
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
* @function MyAvatar.updateAvatarEntity
* @param {Uuid} entityID
* @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
* @function MyAvatar.clearAvatarEntity

View file

@ -69,8 +69,8 @@ void EntityEditPacketSender::queueEditAvatarEntityMessage(EntityTreePointer enti
return;
}
packetData.shrinkByteArrays();
_myAvatar->storeAvatarEntityDataPayload(entity->getID(), packetData.getUncompressedByteArray());
QByteArray tempArray = QByteArray::fromRawData((const char*)packetData.getUncompressedData(), packetData.getUncompressedSize());
_myAvatar->storeAvatarEntityDataPayload(entityItemID, tempArray);
}
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() {
qCDebug(octree, "OctreePacketData::debugContent()... COMPRESSED DATA.... size=%d",_compressedBytes);
int perline=0;

View file

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