diff --git a/assignment-client/src/Agent.cpp b/assignment-client/src/Agent.cpp index 639e9f924b..e06aed86fc 100644 --- a/assignment-client/src/Agent.cpp +++ b/assignment-client/src/Agent.cpp @@ -368,11 +368,7 @@ void Agent::executeScript() { // setup an Avatar for the script to use auto scriptedAvatar = DependencyManager::get(); - scriptedAvatar->setID(getSessionUUID()); - - connect(_scriptEngine.data(), SIGNAL(update(float)), - scriptedAvatar.data(), SLOT(update(float)), Qt::ConnectionType::QueuedConnection); scriptedAvatar->setForceFaceTrackerConnected(true); // call model URL setters with empty URLs so our avatar, if user, will have the default models @@ -504,8 +500,6 @@ void Agent::executeScript() { DependencyManager::set(_entityViewer.getTree()); - _avatarAudioTimer.start(); - // Agents should run at 45hz static const int AVATAR_DATA_HZ = 45; static const int AVATAR_DATA_IN_MSECS = MSECS_PER_SECOND / AVATAR_DATA_HZ; @@ -530,7 +524,8 @@ void Agent::executeScript() { } avatarDataTimer->stop(); - _avatarAudioTimer.stop(); + + setIsAvatar(false); // will stop timers for sending identity packets } setFinished(true); @@ -582,28 +577,33 @@ void Agent::setIsAvatar(bool isAvatar) { } _isAvatar = isAvatar; - if (_isAvatar && !_avatarIdentityTimer) { - // set up the avatar timers - _avatarIdentityTimer = new QTimer(this); - _avatarQueryTimer = new QTimer(this); + auto scriptableAvatar = DependencyManager::get(); + if (_isAvatar) { + if (!_avatarIdentityTimer) { + // set up the avatar timers + _avatarIdentityTimer = new QTimer(this); + _avatarQueryTimer = new QTimer(this); - // connect our slot - connect(_avatarIdentityTimer, &QTimer::timeout, this, &Agent::sendAvatarIdentityPacket); - connect(_avatarQueryTimer, &QTimer::timeout, this, &Agent::queryAvatars); + // connect our slot + connect(_avatarIdentityTimer, &QTimer::timeout, this, &Agent::sendAvatarIdentityPacket); + connect(_avatarQueryTimer, &QTimer::timeout, this, &Agent::queryAvatars); - static const int AVATAR_IDENTITY_PACKET_SEND_INTERVAL_MSECS = 1000; - static const int AVATAR_VIEW_PACKET_SEND_INTERVAL_MSECS = 1000; + static const int AVATAR_IDENTITY_PACKET_SEND_INTERVAL_MSECS = 1000; + static const int AVATAR_VIEW_PACKET_SEND_INTERVAL_MSECS = 1000; - // start the timers - _avatarIdentityTimer->start(AVATAR_IDENTITY_PACKET_SEND_INTERVAL_MSECS); // FIXME - we shouldn't really need to constantly send identity packets - _avatarQueryTimer->start(AVATAR_VIEW_PACKET_SEND_INTERVAL_MSECS); + // start the timers + _avatarIdentityTimer->start(AVATAR_IDENTITY_PACKET_SEND_INTERVAL_MSECS); // FIXME - we shouldn't really need to constantly send identity packets + _avatarQueryTimer->start(AVATAR_VIEW_PACKET_SEND_INTERVAL_MSECS); - // tell the avatarAudioTimer to start ticking - QMetaObject::invokeMethod(&_avatarAudioTimer, "start"); - } + connect(_scriptEngine.data(), &ScriptEngine::update, + scriptableAvatar.data(), &ScriptableAvatar::update, Qt::QueuedConnection); - if (!_isAvatar) { + // tell the avatarAudioTimer to start ticking + QMetaObject::invokeMethod(&_avatarAudioTimer, "start"); + } + _entityEditSender.setMyAvatar(scriptableAvatar.data()); + } else { if (_avatarIdentityTimer) { _avatarIdentityTimer->stop(); delete _avatarIdentityTimer; @@ -630,14 +630,14 @@ void Agent::setIsAvatar(bool isAvatar) { packet->writePrimitive(KillAvatarReason::NoReason); nodeList->sendPacket(std::move(packet), *node); }); + + disconnect(_scriptEngine.data(), &ScriptEngine::update, + scriptableAvatar.data(), &ScriptableAvatar::update); + + QMetaObject::invokeMethod(&_avatarAudioTimer, "stop"); } - QMetaObject::invokeMethod(&_avatarAudioTimer, "stop"); - _entityEditSender.setMyAvatar(nullptr); - } else { - auto scriptableAvatar = DependencyManager::get(); - _entityEditSender.setMyAvatar(scriptableAvatar.data()); } } @@ -864,8 +864,6 @@ void Agent::processAgentAvatarAudio() { } void Agent::aboutToFinish() { - setIsAvatar(false);// will stop timers for sending identity packets - // our entity tree is going to go away so tell that to the EntityScriptingInterface DependencyManager::get()->setEntityTree(nullptr); diff --git a/assignment-client/src/avatars/AvatarMixerSlave.cpp b/assignment-client/src/avatars/AvatarMixerSlave.cpp index b6ec006c39..f3f47dff74 100644 --- a/assignment-client/src/avatars/AvatarMixerSlave.cpp +++ b/assignment-client/src/avatars/AvatarMixerSlave.cpp @@ -380,6 +380,11 @@ void AvatarMixerSlave::broadcastAvatarDataToAgent(const SharedNodePointer& node) if (lastSeqToReceiver == lastSeqFromSender && lastSeqToReceiver != 0) { ++numAvatarsHeldBack; shouldIgnore = true; + } else if (lastSeqFromSender == 0) { + // We have have not yet recieved any data about this avatar. Ignore it for now + // This is important for Agent scripts that are not avatar + // so that they don't appear to be an avatar at the origin + shouldIgnore = true; } else if (lastSeqFromSender - lastSeqToReceiver > 1) { // this is a skip - we still send the packet but capture the presence of the skip so we see it happening ++numAvatarsWithSkippedFrames; diff --git a/assignment-client/src/avatars/ScriptableAvatar.h b/assignment-client/src/avatars/ScriptableAvatar.h index 52beba72a1..578bd84a8f 100644 --- a/assignment-client/src/avatars/ScriptableAvatar.h +++ b/assignment-client/src/avatars/ScriptableAvatar.h @@ -164,7 +164,7 @@ public: void setHasAudioEnabledFaceMovement(bool hasAudioEnabledFaceMovement); bool getHasAudioEnabledFaceMovement() const override { return _headData->getHasAudioEnabledFaceMovement(); } -private slots: +public slots: void update(float deltatime); private: