mirror of
https://github.com/lubosz/overte.git
synced 2025-04-26 19:15:32 +02:00
WIP commit, socket errors when AvatarIdentity is larger then MTU
This commit is contained in:
parent
b48134e30c
commit
c48fce4f5a
4 changed files with 60 additions and 58 deletions
assignment-client/src/avatars
libraries/avatars/src
|
@ -417,7 +417,9 @@ void AvatarMixer::handleAvatarIdentityPacket(QSharedPointer<ReceivedMessage> mes
|
|||
AvatarData& avatar = nodeData->getAvatar();
|
||||
|
||||
// parse the identity packet and update the change timestamp if appropriate
|
||||
if (avatar.hasIdentityChangedAfterParsing(message->getMessage())) {
|
||||
AvatarData::Identity identity;
|
||||
AvatarData::parseAvatarIdentityPacket(message->getMessage(), identity);
|
||||
if (avatar.processAvatarIdentity(identity)) {
|
||||
QMutexLocker nodeDataLocker(&nodeData->getMutex());
|
||||
nodeData->flagIdentityChange();
|
||||
}
|
||||
|
|
|
@ -612,7 +612,8 @@ int AvatarData::parseDataFromBuffer(const QByteArray& buffer) {
|
|||
// the wrong bones, resulting in a twisted avatar, An un-animated avatar is preferable to this.
|
||||
bool skipJoints = false;
|
||||
if (_networkJointIndexMap.empty()) {
|
||||
skipJoints = true;
|
||||
qCDebug(avatars) << "AJT: parseAvatarDataPacket _networkJointIndexMap.size = " << _networkJointIndexMap.size();
|
||||
skipJoints = false;
|
||||
}
|
||||
|
||||
int bytesOfValidity = (int)ceil((float)numJoints / (float)BITS_IN_BYTE);
|
||||
|
@ -726,7 +727,7 @@ int AvatarData::parseDataFromBuffer(const QByteArray& buffer) {
|
|||
}
|
||||
}
|
||||
}
|
||||
} // numJoints * 12 bytes
|
||||
} // numJoints * 6 bytes
|
||||
|
||||
#ifdef WANT_DEBUG
|
||||
if (numValidJointRotations > 15) {
|
||||
|
@ -981,42 +982,45 @@ void AvatarData::clearJointsData() {
|
|||
}
|
||||
}
|
||||
|
||||
bool AvatarData::hasIdentityChangedAfterParsing(const QByteArray& data) {
|
||||
void AvatarData::parseAvatarIdentityPacket(const QByteArray& data, Identity& identityOut) {
|
||||
QDataStream packetStream(data);
|
||||
packetStream >> identityOut.uuid >> identityOut.skeletonModelURL >> identityOut.attachmentData >> identityOut.displayName >> identityOut.jointIndices;
|
||||
|
||||
// AJT: just got a new networkJointIndicesMap.
|
||||
qCDebug(avatars) << "AJT: receiving identity.jointIndices.size = " << identityOut.jointIndices.size();
|
||||
}
|
||||
|
||||
bool AvatarData::processAvatarIdentity(const Identity& identity) {
|
||||
|
||||
QUuid avatarUUID;
|
||||
QUrl skeletonModelURL;
|
||||
QVector<AttachmentData> attachmentData;
|
||||
QString displayName;
|
||||
QHash <QString, int> networkJointIndices;
|
||||
packetStream >> avatarUUID >> skeletonModelURL >> attachmentData >> displayName >> networkJointIndices;
|
||||
bool hasIdentityChanged = false;
|
||||
|
||||
if (!_jointIndices.empty() && _networkJointIndexMap.empty() && !networkJointIndices.empty()) {
|
||||
qCDebug(avatars) << "AJT: processAvatarIdentity got here!";
|
||||
|
||||
if (!_jointIndices.empty() && _networkJointIndexMap.empty() && !identity.jointIndices.empty()) {
|
||||
// build networkJointIndexMap from _jointIndices and networkJointIndices.
|
||||
_networkJointIndexMap.fill(networkJointIndices.size(), -1);
|
||||
for (auto iter = networkJointIndices.cbegin(); iter != networkJointIndices.end(); ++iter) {
|
||||
_networkJointIndexMap.fill(identity.jointIndices.size(), -1);
|
||||
for (auto iter = identity.jointIndices.cbegin(); iter != identity.jointIndices.end(); ++iter) {
|
||||
int jointIndex = getJointIndex(iter.key());
|
||||
_networkJointIndexMap[iter.value()] = jointIndex;
|
||||
qCDebug(avatars) << "AJT: mapping " << iter.value() << " -> " << jointIndex;
|
||||
}
|
||||
}
|
||||
|
||||
// AJT: just got a new networkJointIndicesMap.
|
||||
qCDebug(avatars) << "AJT: receiving networkJointIndices.size = " << networkJointIndices.size();
|
||||
qCDebug(avatars) << "AJT: processAvatarIdentity got here!";
|
||||
|
||||
if (_firstSkeletonCheck || (skeletonModelURL != _skeletonModelURL)) {
|
||||
setSkeletonModelURL(skeletonModelURL);
|
||||
if (_firstSkeletonCheck || (identity.skeletonModelURL != _skeletonModelURL)) {
|
||||
setSkeletonModelURL(identity.skeletonModelURL);
|
||||
hasIdentityChanged = true;
|
||||
_firstSkeletonCheck = false;
|
||||
}
|
||||
|
||||
if (displayName != _displayName) {
|
||||
setDisplayName(displayName);
|
||||
if (identity.displayName != _displayName) {
|
||||
setDisplayName(identity.displayName);
|
||||
hasIdentityChanged = true;
|
||||
}
|
||||
|
||||
if (attachmentData != _attachmentData) {
|
||||
setAttachmentData(attachmentData);
|
||||
if (identity.attachmentData != _attachmentData) {
|
||||
setAttachmentData(identity.attachmentData);
|
||||
hasIdentityChanged = true;
|
||||
}
|
||||
|
||||
|
@ -1204,6 +1208,8 @@ void AvatarData::sendIdentityPacket() {
|
|||
|
||||
QByteArray identityData = identityByteArray();
|
||||
|
||||
qCDebug(avatars) << "AJT: sendIdentityPacket() size = " << identityData.size();
|
||||
|
||||
auto packetList = NLPacketList::create(PacketType::AvatarIdentity, QByteArray(), true, true);
|
||||
packetList->write(identityData);
|
||||
nodeList->eachMatchingNode(
|
||||
|
@ -1213,6 +1219,8 @@ void AvatarData::sendIdentityPacket() {
|
|||
[&](const SharedNodePointer& node) {
|
||||
nodeList->sendPacketList(std::move(packetList), *node);
|
||||
});
|
||||
|
||||
qCDebug(avatars) << "AJT: sendIdentityPacket() done!";
|
||||
}
|
||||
|
||||
void AvatarData::updateJointMappings() {
|
||||
|
|
|
@ -280,7 +280,19 @@ public:
|
|||
|
||||
const HeadData* getHeadData() const { return _headData; }
|
||||
|
||||
bool hasIdentityChangedAfterParsing(const QByteArray& data);
|
||||
struct Identity {
|
||||
QUuid uuid;
|
||||
QUrl skeletonModelURL;
|
||||
QVector<AttachmentData> attachmentData;
|
||||
QString displayName;
|
||||
QHash<QString, int> jointIndices;
|
||||
};
|
||||
|
||||
static void parseAvatarIdentityPacket(const QByteArray& data, Identity& identityOut);
|
||||
|
||||
// returns true if identity has changed, false otherwise.
|
||||
bool processAvatarIdentity(const Identity& identity);
|
||||
|
||||
QByteArray identityByteArray();
|
||||
|
||||
const QUrl& getSkeletonModelURL() const { return _skeletonModelURL; }
|
||||
|
|
|
@ -50,26 +50,26 @@ AvatarSharedPointer AvatarHashMap::newSharedAvatar() {
|
|||
|
||||
AvatarSharedPointer AvatarHashMap::addAvatar(const QUuid& sessionUUID, const QWeakPointer<Node>& mixerWeakPointer) {
|
||||
qCDebug(avatars) << "Adding avatar with sessionUUID " << sessionUUID << "to AvatarHashMap.";
|
||||
|
||||
|
||||
auto avatar = newSharedAvatar();
|
||||
avatar->setSessionUUID(sessionUUID);
|
||||
avatar->setOwningAvatarMixer(mixerWeakPointer);
|
||||
|
||||
|
||||
_avatarHash.insert(sessionUUID, avatar);
|
||||
emit avatarAddedEvent(sessionUUID);
|
||||
|
||||
|
||||
return avatar;
|
||||
}
|
||||
|
||||
AvatarSharedPointer AvatarHashMap::newOrExistingAvatar(const QUuid& sessionUUID, const QWeakPointer<Node>& mixerWeakPointer) {
|
||||
QWriteLocker locker(&_hashLock);
|
||||
|
||||
|
||||
auto avatar = _avatarHash.value(sessionUUID);
|
||||
|
||||
|
||||
if (!avatar) {
|
||||
avatar = addAvatar(sessionUUID, mixerWeakPointer);
|
||||
}
|
||||
|
||||
|
||||
return avatar;
|
||||
}
|
||||
|
||||
|
@ -86,14 +86,14 @@ void AvatarHashMap::processAvatarDataPacket(QSharedPointer<ReceivedMessage> mess
|
|||
// only add them if mixerWeakPointer points to something (meaning that mixer is still around)
|
||||
while (message->getBytesLeftToRead()) {
|
||||
QUuid sessionUUID = QUuid::fromRfc4122(message->readWithoutCopy(NUM_BYTES_RFC4122_UUID));
|
||||
|
||||
|
||||
int positionBeforeRead = message->getPosition();
|
||||
|
||||
QByteArray byteArray = message->readWithoutCopy(message->getBytesLeftToRead());
|
||||
|
||||
|
||||
if (sessionUUID != _lastOwnerSessionUUID) {
|
||||
auto avatar = newOrExistingAvatar(sessionUUID, sendingNode);
|
||||
|
||||
|
||||
// have the matching (or new) avatar parse the data from the packet
|
||||
int bytesRead = avatar->parseDataFromBuffer(byteArray);
|
||||
message->seek(positionBeforeRead + bytesRead);
|
||||
|
@ -107,33 +107,13 @@ void AvatarHashMap::processAvatarDataPacket(QSharedPointer<ReceivedMessage> mess
|
|||
}
|
||||
|
||||
void AvatarHashMap::processAvatarIdentityPacket(QSharedPointer<ReceivedMessage> message, SharedNodePointer sendingNode) {
|
||||
// setup a data stream to parse the packet
|
||||
QDataStream identityStream(message->getMessage());
|
||||
AvatarData::Identity identity;
|
||||
AvatarData::parseAvatarIdentityPacket(message->getMessage(), identity);
|
||||
|
||||
QUuid sessionUUID;
|
||||
|
||||
while (!identityStream.atEnd()) {
|
||||
// mesh URL for a UUID, find avatar in our list
|
||||
auto avatar = newOrExistingAvatar(identity.uuid, sendingNode);
|
||||
|
||||
QUrl faceMeshURL, skeletonURL;
|
||||
QVector<AttachmentData> attachmentData;
|
||||
QString displayName;
|
||||
identityStream >> sessionUUID >> faceMeshURL >> skeletonURL >> attachmentData >> displayName;
|
||||
|
||||
// mesh URL for a UUID, find avatar in our list
|
||||
auto avatar = newOrExistingAvatar(sessionUUID, sendingNode);
|
||||
|
||||
if (avatar->getSkeletonModelURL().isEmpty() || (avatar->getSkeletonModelURL() != skeletonURL)) {
|
||||
avatar->setSkeletonModelURL(skeletonURL); // Will expand "" to default and so will not continuously fire
|
||||
}
|
||||
|
||||
if (avatar->getAttachmentData() != attachmentData) {
|
||||
avatar->setAttachmentData(attachmentData);
|
||||
}
|
||||
|
||||
if (avatar->getDisplayName() != displayName) {
|
||||
avatar->setDisplayName(displayName);
|
||||
}
|
||||
}
|
||||
avatar->processAvatarIdentity(identity);
|
||||
}
|
||||
|
||||
void AvatarHashMap::processKillAvatar(QSharedPointer<ReceivedMessage> message, SharedNodePointer sendingNode) {
|
||||
|
@ -144,9 +124,9 @@ void AvatarHashMap::processKillAvatar(QSharedPointer<ReceivedMessage> message, S
|
|||
|
||||
void AvatarHashMap::removeAvatar(const QUuid& sessionUUID) {
|
||||
QWriteLocker locker(&_hashLock);
|
||||
|
||||
|
||||
auto removedAvatar = _avatarHash.take(sessionUUID);
|
||||
|
||||
|
||||
if (removedAvatar) {
|
||||
handleRemovedAvatar(removedAvatar);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue