mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 15:29:42 +02:00
split code that sends edits via avatar-mixer out of queueEditEntityMessage
This commit is contained in:
parent
1e849956c9
commit
4b13fd969e
3 changed files with 51 additions and 32 deletions
|
@ -183,7 +183,6 @@ void Avatar::updateAvatarEntities() {
|
||||||
// - setAvatarEntityData saves the bytes and sets _avatarEntityDataChanged = true
|
// - setAvatarEntityData saves the bytes and sets _avatarEntityDataChanged = true
|
||||||
// - (My)Avatar::simulate notices _avatarEntityDataChanged and here we are...
|
// - (My)Avatar::simulate notices _avatarEntityDataChanged and here we are...
|
||||||
|
|
||||||
const static quint64 refreshTime = 3 * USECS_PER_SECOND;
|
|
||||||
if (!_avatarEntityDataChanged) {
|
if (!_avatarEntityDataChanged) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,51 @@ void EntityEditPacketSender::adjustEditPacketForClockSkew(PacketType type, QByte
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EntityEditPacketSender::queueEditAvatarEntityMessage(PacketType type,
|
||||||
|
EntityTreePointer entityTree,
|
||||||
|
EntityItemID entityItemID,
|
||||||
|
const EntityItemProperties& properties) {
|
||||||
|
if (!_shouldSend) {
|
||||||
|
return; // bail early
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(properties.getClientOnly());
|
||||||
|
|
||||||
|
// this is an avatar-based entity. update our avatar-data rather than sending to the entity-server
|
||||||
|
assert(_myAvatar);
|
||||||
|
|
||||||
|
if (!entityTree) {
|
||||||
|
qDebug() << "EntityEditPacketSender::queueEditEntityMessage null entityTree.";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
EntityItemPointer entity = entityTree->findEntityByEntityItemID(entityItemID);
|
||||||
|
if (!entity) {
|
||||||
|
qDebug() << "EntityEditPacketSender::queueEditEntityMessage can't find entity.";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// the properties that get serialized into the avatar identity packet should be the entire set
|
||||||
|
// rather than just the ones being edited.
|
||||||
|
entity->setProperties(properties);
|
||||||
|
EntityItemProperties entityProperties = entity->getProperties();
|
||||||
|
|
||||||
|
QScriptValue scriptProperties = EntityItemNonDefaultPropertiesToScriptValue(&_scriptEngine, entityProperties);
|
||||||
|
QVariant variantProperties = scriptProperties.toVariant();
|
||||||
|
QJsonDocument jsonProperties = QJsonDocument::fromVariant(variantProperties);
|
||||||
|
|
||||||
|
// the ID of the parent/avatar changes from session to session. use a special UUID to indicate the avatar
|
||||||
|
QJsonObject jsonObject = jsonProperties.object();
|
||||||
|
if (QUuid(jsonObject["parentID"].toString()) == _myAvatar->getID()) {
|
||||||
|
jsonObject["parentID"] = AVATAR_SELF_ID.toString();
|
||||||
|
}
|
||||||
|
jsonProperties = QJsonDocument(jsonObject);
|
||||||
|
|
||||||
|
QByteArray binaryProperties = jsonProperties.toBinaryData();
|
||||||
|
_myAvatar->updateAvatarEntity(entityItemID, binaryProperties);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void EntityEditPacketSender::queueEditEntityMessage(PacketType type,
|
void EntityEditPacketSender::queueEditEntityMessage(PacketType type,
|
||||||
EntityTreePointer entityTree,
|
EntityTreePointer entityTree,
|
||||||
EntityItemID entityItemID,
|
EntityItemID entityItemID,
|
||||||
|
@ -43,38 +88,9 @@ void EntityEditPacketSender::queueEditEntityMessage(PacketType type,
|
||||||
if (!_shouldSend) {
|
if (!_shouldSend) {
|
||||||
return; // bail early
|
return; // bail early
|
||||||
}
|
}
|
||||||
|
|
||||||
if (properties.getClientOnly()) {
|
if (properties.getClientOnly()) {
|
||||||
// this is an avatar-based entity. update our avatar-data rather than sending to the entity-server
|
queueEditAvatarEntityMessage(type, entityTree, entityItemID, properties);
|
||||||
assert(_myAvatar);
|
|
||||||
|
|
||||||
if (!entityTree) {
|
|
||||||
qDebug() << "EntityEditPacketSender::queueEditEntityMessage null entityTree.";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
EntityItemPointer entity = entityTree->findEntityByEntityItemID(entityItemID);
|
|
||||||
if (!entity) {
|
|
||||||
qDebug() << "EntityEditPacketSender::queueEditEntityMessage can't find entity.";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// the properties that get serialized into the avatar identity packet should be the entire set
|
|
||||||
// rather than just the ones being edited.
|
|
||||||
entity->setProperties(properties);
|
|
||||||
EntityItemProperties entityProperties = entity->getProperties();
|
|
||||||
|
|
||||||
QScriptValue scriptProperties = EntityItemNonDefaultPropertiesToScriptValue(&_scriptEngine, entityProperties);
|
|
||||||
QVariant variantProperties = scriptProperties.toVariant();
|
|
||||||
QJsonDocument jsonProperties = QJsonDocument::fromVariant(variantProperties);
|
|
||||||
|
|
||||||
// the ID of the parent/avatar changes from session to session. use a special UUID to indicate the avatar
|
|
||||||
QJsonObject jsonObject = jsonProperties.object();
|
|
||||||
if (QUuid(jsonObject["parentID"].toString()) == _myAvatar->getID()) {
|
|
||||||
jsonObject["parentID"] = AVATAR_SELF_ID.toString();
|
|
||||||
}
|
|
||||||
jsonProperties = QJsonDocument(jsonObject);
|
|
||||||
|
|
||||||
QByteArray binaryProperties = jsonProperties.toBinaryData();
|
|
||||||
_myAvatar->updateAvatarEntity(entityItemID, binaryProperties);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,10 @@ public:
|
||||||
AvatarData* getMyAvatar() { return _myAvatar; }
|
AvatarData* getMyAvatar() { return _myAvatar; }
|
||||||
void clearAvatarEntity(QUuid entityID) { assert(_myAvatar); _myAvatar->clearAvatarEntity(entityID); }
|
void clearAvatarEntity(QUuid entityID) { assert(_myAvatar); _myAvatar->clearAvatarEntity(entityID); }
|
||||||
|
|
||||||
|
void queueEditAvatarEntityMessage(PacketType type, EntityTreePointer entityTree,
|
||||||
|
EntityItemID entityItemID, const EntityItemProperties& properties);
|
||||||
|
|
||||||
|
|
||||||
/// Queues an array of several voxel edit messages. Will potentially send a pending multi-command packet. Determines
|
/// Queues an array of several voxel edit messages. Will potentially send a pending multi-command packet. Determines
|
||||||
/// which voxel-server node or nodes the packet should be sent to. Can be called even before voxel servers are known, in
|
/// which voxel-server node or nodes the packet should be sent to. Can be called even before voxel servers are known, in
|
||||||
/// which case up to MaxPendingMessages will be buffered and processed when voxel servers are known.
|
/// which case up to MaxPendingMessages will be buffered and processed when voxel servers are known.
|
||||||
|
|
Loading…
Reference in a new issue