Fix logic in zone-checking code, other clean-up

This commit is contained in:
Simon Walton 2019-11-26 13:32:50 -08:00
parent 6b371ec388
commit 8b2fc968f6
2 changed files with 27 additions and 17 deletions

View file

@ -100,7 +100,7 @@ struct FindContainingZone {
bool isInScreenshareZone { false };
float priorityZoneVolume { std::numeric_limits<float>::max() };
float screenshareZoneVolume { priorityZoneVolume };
EntityItemID id{};
EntityItemID screenshareZoneid{};
static bool operation(const OctreeElementPointer& element, void* extraData) {
auto findContainingZone = static_cast<FindContainingZone*>(extraData);
@ -109,17 +109,19 @@ struct FindContainingZone {
entityTreeElement->forEachEntity([&findContainingZone](EntityItemPointer item) {
if (item->getType() == EntityTypes::Zone && item->contains(findContainingZone->position)) {
auto zoneItem = static_pointer_cast<ZoneEntityItem>(item);
if (zoneItem->getAvatarPriority() != COMPONENT_MODE_INHERIT) {
float volume = zoneItem->getVolumeEstimate();
if (volume < findContainingZone->priorityZoneVolume) { // Smaller volume wins
findContainingZone->isInPriorityZone = zoneItem->getAvatarPriority() == COMPONENT_MODE_ENABLED;
findContainingZone->priorityZoneVolume = volume;
}
if (volume < findContainingZone->screenshareZoneVolume) {
findContainingZone->isInScreenshareZone = zoneItem->getScreenshare() == COMPONENT_MODE_ENABLED;
auto avatarPriorityProperty = zoneItem->getAvatarPriority();
auto screenshareProperty = zoneItem->getScreenshare();
float volume = zoneItem->getVolumeEstimate();
if (avatarPriorityProperty != COMPONENT_MODE_INHERIT
&& volume < findContainingZone->priorityZoneVolume) { // Smaller volume wins
findContainingZone->isInPriorityZone = avatarPriorityProperty == COMPONENT_MODE_ENABLED;
findContainingZone->priorityZoneVolume = volume;
}
if (screenshareProperty != COMPONENT_MODE_INHERIT
&& volume < findContainingZone->screenshareZoneVolume) {
findContainingZone->isInScreenshareZone = screenshareProperty == COMPONENT_MODE_ENABLED;
findContainingZone->screenshareZoneVolume = volume;
findContainingZone->id = zoneItem->getEntityItemID();
}
findContainingZone->screenshareZoneid = zoneItem->getEntityItemID();
}
}
});
@ -162,12 +164,16 @@ int AvatarMixerClientData::parseData(ReceivedMessage& message, const SlaveShared
if (currentlyHasPriority != _avatar->getHasPriority()) {
_avatar->setHasPriority(currentlyHasPriority);
}
if (findContainingZone.isInScreenshareZone) {
auto nodeList = DependencyManager::get<NodeList>();
auto packet = NLPacket::create(PacketType::AvatarZonePresence, 2 * NUM_BYTES_RFC4122_UUID, true);
packet->write(_avatar->getSessionUUID().toRfc4122());
packet->write(findContainingZone.id.toRfc4122());
nodeList->sendPacket(std::move(packet), nodeList->getDomainSockAddr());
bool isInScreenshareZone = findContainingZone.isInScreenshareZone;
if (isInScreenshareZone != _avatar->isInScreenshareZone()) {
_avatar->setInScreenshareZone(isInScreenshareZone);
if (isInScreenshareZone) {
auto nodeList = DependencyManager::get<NodeList>();
auto packet = NLPacket::create(PacketType::AvatarZonePresence, 2 * NUM_BYTES_RFC4122_UUID, true);
packet->write(_avatar->getSessionUUID().toRfc4122());
packet->write(findContainingZone.screenshareZoneid.toRfc4122());
nodeList->sendPacket(std::move(packet), nodeList->getDomainSockAddr());
}
}
_avatar->setNeedsHeroCheck(false);
}

View file

@ -43,6 +43,9 @@ public:
};
Q_ENUM(VerifyState)
bool isInScreenshareZone() const { return _inScreenshareZone; }
void setInScreenshareZone(bool value = true) { _inScreenshareZone = value; }
private:
bool _needsHeroCheck { false };
static const char* stateToName(VerifyState state);
@ -65,6 +68,7 @@ private:
int _numberChallenges { 0 };
bool _certifyFailed { false };
bool _needsIdentityUpdate { false };
bool _inScreenshareZone { false };
bool generateFSTHash();
bool validateFSTHash(const QString& publicKey) const;