mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 11:48:09 +02:00
Merge pull request #2086 from PhilipRosedale/master
Add stochastic falloff for sending other avatar’s data
This commit is contained in:
commit
17e4426b50
1 changed files with 23 additions and 13 deletions
|
@ -61,26 +61,36 @@ void broadcastAvatarData() {
|
||||||
// reset packet pointers for this node
|
// reset packet pointers for this node
|
||||||
mixedAvatarByteArray.resize(numPacketHeaderBytes);
|
mixedAvatarByteArray.resize(numPacketHeaderBytes);
|
||||||
|
|
||||||
|
AvatarMixerClientData* myData = reinterpret_cast<AvatarMixerClientData*>(node->getLinkedData());
|
||||||
|
glm::vec3 myPosition = myData->getPosition();
|
||||||
|
|
||||||
// this is an AGENT we have received head data from
|
// this is an AGENT we have received head data from
|
||||||
// send back a packet with other active node data to this node
|
// send back a packet with other active node data to this node
|
||||||
foreach (const SharedNodePointer& otherNode, nodeList->getNodeHash()) {
|
foreach (const SharedNodePointer& otherNode, nodeList->getNodeHash()) {
|
||||||
if (otherNode->getLinkedData() && otherNode->getUUID() != node->getUUID()) {
|
if (otherNode->getLinkedData() && otherNode->getUUID() != node->getUUID()) {
|
||||||
|
|
||||||
QByteArray avatarByteArray;
|
AvatarMixerClientData* otherNodeData = reinterpret_cast<AvatarMixerClientData*>(otherNode->getLinkedData());
|
||||||
avatarByteArray.append(otherNode->getUUID().toRfc4122());
|
glm::vec3 otherPosition = otherNodeData->getPosition();
|
||||||
|
float distanceToAvatar = glm::length(myPosition - otherPosition);
|
||||||
AvatarMixerClientData* nodeData = reinterpret_cast<AvatarMixerClientData*>(otherNode->getLinkedData());
|
// The full rate distance is the distance at which EVERY update will be sent for this avatar
|
||||||
avatarByteArray.append(nodeData->toByteArray());
|
// at a distance of twice the full rate distance, there will be a 50% chance of sending this avatar's update
|
||||||
|
const float FULL_RATE_DISTANCE = 2.f;
|
||||||
if (avatarByteArray.size() + mixedAvatarByteArray.size() > MAX_PACKET_SIZE) {
|
// Decide whether to send this avatar's data based on it's distance from us
|
||||||
nodeList->writeDatagram(mixedAvatarByteArray, node);
|
if ((distanceToAvatar == 0.f) || (randFloat() < FULL_RATE_DISTANCE / distanceToAvatar)) {
|
||||||
|
QByteArray avatarByteArray;
|
||||||
|
avatarByteArray.append(otherNode->getUUID().toRfc4122());
|
||||||
|
avatarByteArray.append(otherNodeData->toByteArray());
|
||||||
|
|
||||||
// reset the packet
|
if (avatarByteArray.size() + mixedAvatarByteArray.size() > MAX_PACKET_SIZE) {
|
||||||
mixedAvatarByteArray.resize(numPacketHeaderBytes);
|
nodeList->writeDatagram(mixedAvatarByteArray, node);
|
||||||
|
|
||||||
|
// reset the packet
|
||||||
|
mixedAvatarByteArray.resize(numPacketHeaderBytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
// copy the avatar into the mixedAvatarByteArray packet
|
||||||
|
mixedAvatarByteArray.append(avatarByteArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
// copy the avatar into the mixedAvatarByteArray packet
|
|
||||||
mixedAvatarByteArray.append(avatarByteArray);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue