mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-04-10 10:34:56 +02:00
Create API call
This commit is contained in:
parent
3d959ca7ee
commit
1fd0d7da94
2 changed files with 27 additions and 9 deletions
|
@ -32,15 +32,15 @@ void AvatarReplicas::addReplica(const QUuid& parentID, AvatarSharedPointer repli
|
|||
replicas.push_back(replica);
|
||||
}
|
||||
|
||||
std::vector<QUuid> AvatarReplicas::getReplicaIDs(const QUuid& parentID, int count) {
|
||||
std::vector<QUuid> AvatarReplicas::getReplicaIDs(const QUuid& parentID) {
|
||||
std::vector<QUuid> ids;
|
||||
if (_replicasMap.find(parentID) != _replicasMap.end()) {
|
||||
auto &replicas = _replicasMap[parentID];
|
||||
for (int i = 0; i < replicas.size(); i++) {
|
||||
ids.push_back(replicas[i]->getID());
|
||||
}
|
||||
} else if (count > 0) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
} else if (_replicaCount > 0) {
|
||||
for (int i = 0; i < _replicaCount; i++) {
|
||||
ids.push_back(QUuid::createUuid());
|
||||
}
|
||||
}
|
||||
|
@ -139,6 +139,19 @@ bool AvatarHashMap::isAvatarInRange(const glm::vec3& position, const float range
|
|||
return false;
|
||||
}
|
||||
|
||||
void AvatarHashMap::setReplicaCount(int count) {
|
||||
_replicas.setReplicaCount(count);
|
||||
auto avatars = getAvatarIdentifiers();
|
||||
for (int i = 0; i < avatars.size(); i++) {
|
||||
KillAvatarReason reason = KillAvatarReason::NoReason;
|
||||
removeAvatar(avatars[i], reason);
|
||||
auto replicaIDs = _replicas.getReplicaIDs(avatars[i]);
|
||||
for (auto id : replicaIDs) {
|
||||
removeAvatar(id, reason);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int AvatarHashMap::numberOfAvatarsInRange(const glm::vec3& position, float rangeMeters) {
|
||||
auto hashCopy = getHashCopy();
|
||||
auto rangeMeters2 = rangeMeters * rangeMeters;
|
||||
|
@ -210,9 +223,6 @@ AvatarSharedPointer AvatarHashMap::parseAvatarData(QSharedPointer<ReceivedMessag
|
|||
|
||||
// make sure this isn't our own avatar data or for a previously ignored node
|
||||
auto nodeList = DependencyManager::get<NodeList>();
|
||||
|
||||
const int REPLICAS_COUNT = 8;
|
||||
|
||||
bool isNewAvatar;
|
||||
if (sessionUUID != _lastOwnerSessionUUID && (!nodeList->isIgnoringNode(sessionUUID) || nodeList->getRequestsDomainListData())) {
|
||||
auto avatar = newOrExistingAvatar(sessionUUID, sendingNode, isNewAvatar);
|
||||
|
@ -220,7 +230,7 @@ AvatarSharedPointer AvatarHashMap::parseAvatarData(QSharedPointer<ReceivedMessag
|
|||
if (isNewAvatar) {
|
||||
QWriteLocker locker(&_hashLock);
|
||||
_pendingAvatars.insert(sessionUUID, { std::chrono::steady_clock::now(), 0, avatar });
|
||||
auto replicaIDs = _replicas.getReplicaIDs(sessionUUID, REPLICAS_COUNT);
|
||||
auto replicaIDs = _replicas.getReplicaIDs(sessionUUID);
|
||||
for (auto replicaID : replicaIDs) {
|
||||
auto replicaAvatar = addAvatar(replicaID, sendingNode);
|
||||
_replicas.addReplica(sessionUUID, replicaAvatar);
|
||||
|
|
|
@ -43,9 +43,9 @@
|
|||
|
||||
class AvatarReplicas {
|
||||
public:
|
||||
AvatarReplicas() {};
|
||||
AvatarReplicas() : _replicaCount(0) {}
|
||||
void addReplica(const QUuid& parentID, AvatarSharedPointer replica);
|
||||
std::vector<QUuid> getReplicaIDs(const QUuid& parentID, int count = 0);
|
||||
std::vector<QUuid> getReplicaIDs(const QUuid& parentID);
|
||||
void parseDataFromBuffer(const QUuid& parentID, const QByteArray& buffer);
|
||||
void processAvatarIdentity(const QUuid& parentID, const QByteArray& identityData, bool& identityChanged, bool& displayNameChanged);
|
||||
void removeReplicas(const QUuid& parentID);
|
||||
|
@ -53,9 +53,11 @@ public:
|
|||
void processDeletedTraitInstance(const QUuid& parentID, AvatarTraits::TraitType traitType, AvatarTraits::TraitInstanceID instanceID);
|
||||
void processTraitInstance(const QUuid& parentID, AvatarTraits::TraitType traitType,
|
||||
AvatarTraits::TraitInstanceID instanceID, QByteArray traitBinaryData);
|
||||
void setReplicaCount(int count) { _replicaCount = count; }
|
||||
|
||||
private:
|
||||
std::map<QUuid, std::vector<AvatarSharedPointer>> _replicasMap;
|
||||
int _replicaCount;
|
||||
};
|
||||
|
||||
|
||||
|
@ -92,6 +94,12 @@ public:
|
|||
// Null/Default-constructed QUuids will return MyAvatar
|
||||
Q_INVOKABLE virtual ScriptAvatarData* getAvatar(QUuid avatarID) { return new ScriptAvatarData(getAvatarBySessionID(avatarID)); }
|
||||
|
||||
/**jsdoc
|
||||
* @function AvatarList.setReplicaCount
|
||||
* @param {number} count // The times an avatar will get replicated
|
||||
*/
|
||||
Q_INVOKABLE void setReplicaCount(int count);
|
||||
|
||||
virtual AvatarSharedPointer getAvatarBySessionID(const QUuid& sessionID) const { return findAvatar(sessionID); }
|
||||
int numberOfAvatarsInRange(const glm::vec3& position, float rangeMeters);
|
||||
|
||||
|
|
Loading…
Reference in a new issue