From 3c01433e12ebfaed4df2dbf46b5297426fd46f2c Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Wed, 15 Aug 2018 10:20:58 -0700 Subject: [PATCH] stub for avatars changing workload regions --- interface/src/avatar/AvatarManager.cpp | 8 +++++-- interface/src/avatar/AvatarManager.h | 12 ++++++---- interface/src/avatar/OtherAvatar.h | 4 ++++ interface/src/workload/PhysicsBoundary.cpp | 24 ++++++++++++++++--- interface/src/workload/PhysicsBoundary.h | 3 --- .../src/EntityTreeRenderer.cpp | 3 ++- 6 files changed, 40 insertions(+), 14 deletions(-) diff --git a/interface/src/avatar/AvatarManager.cpp b/interface/src/avatar/AvatarManager.cpp index 551847324a..06c259f907 100644 --- a/interface/src/avatar/AvatarManager.cpp +++ b/interface/src/avatar/AvatarManager.cpp @@ -44,7 +44,6 @@ #include "InterfaceLogging.h" #include "Menu.h" #include "MyAvatar.h" -#include "OtherAvatar.h" #include "SceneScriptingInterface.h" // 50 times per second - target is 45hz, but this helps account for any small deviations @@ -91,7 +90,8 @@ AvatarSharedPointer AvatarManager::addAvatar(const QUuid& sessionUUID, const QWe otherAvatar->setSpaceIndex(spaceIndex); workload::Sphere sphere(otherAvatar->getWorldPosition(), otherAvatar->getBoundingRadius()); workload::Transaction transaction; - transaction.reset(spaceIndex, sphere, workload::Owner(otherAvatar)); + SpatiallyNestablePointer nestable = std::static_pointer_cast(otherAvatar); + transaction.reset(spaceIndex, sphere, workload::Owner(nestable)); _space->enqueueTransaction(transaction); } return avatar; @@ -393,6 +393,10 @@ AvatarSharedPointer AvatarManager::newSharedAvatar() { return AvatarSharedPointer(new OtherAvatar(qApp->thread()), [](OtherAvatar* ptr) { ptr->deleteLater(); }); } +void AvatarManager::handleSpaceChange(OtherAvatarPointer avatar) { + // WORKLOAD_AVATARS_BOOKMARK: implement this +} + void AvatarManager::handleRemovedAvatar(const AvatarSharedPointer& removedAvatar, KillAvatarReason removalReason) { auto avatar = std::static_pointer_cast(removedAvatar); { diff --git a/interface/src/avatar/AvatarManager.h b/interface/src/avatar/AvatarManager.h index 316e247aa0..bbf13d25c4 100644 --- a/interface/src/avatar/AvatarManager.h +++ b/interface/src/avatar/AvatarManager.h @@ -27,6 +27,7 @@ #include "AvatarMotionState.h" #include "MyAvatar.h" +#include "OtherAvatar.h" /**jsdoc * The AvatarManager API has properties and methods which manage Avatars within the same domain. @@ -94,6 +95,7 @@ public: void getObjectsToRemoveFromPhysics(VectorOfMotionStates& motionStates); void getObjectsToAddToPhysics(VectorOfMotionStates& motionStates); void getObjectsToChange(VectorOfMotionStates& motionStates); + void handleChangedMotionStates(const VectorOfMotionStates& motionStates); void handleCollisionEvents(const CollisionEvents& collisionEvents); @@ -104,23 +106,21 @@ public: * @returns {number} */ Q_INVOKABLE float getAvatarDataRate(const QUuid& sessionID, const QString& rateName = QString("")) const; - + /**jsdoc * @function AvatarManager.getAvatarUpdateRate * @param {Uuid} sessionID * @param {string} [rateName=""] * @returns {number} */ - Q_INVOKABLE float getAvatarUpdateRate(const QUuid& sessionID, const QString& rateName = QString("")) const; - + /**jsdoc * @function AvatarManager.getAvatarSimulationRate * @param {Uuid} sessionID * @param {string} [rateName=""] * @returns {number} */ - Q_INVOKABLE float getAvatarSimulationRate(const QUuid& sessionID, const QString& rateName = QString("")) const; /**jsdoc @@ -155,7 +155,7 @@ public: */ // TODO: remove this HACK once we settle on optimal default sort coefficients Q_INVOKABLE float getAvatarSortCoefficient(const QString& name); - + /**jsdoc * @function AvatarManager.setAvatarSortCoefficient * @param {string} name @@ -185,6 +185,8 @@ public slots: */ void updateAvatarRenderStatus(bool shouldRenderAvatars); + void handleSpaceChange(OtherAvatarPointer avatar); + protected: AvatarSharedPointer addAvatar(const QUuid& sessionUUID, const QWeakPointer& mixerWeakPointer) override; diff --git a/interface/src/avatar/OtherAvatar.h b/interface/src/avatar/OtherAvatar.h index 27a5b29353..dcd54332c6 100644 --- a/interface/src/avatar/OtherAvatar.h +++ b/interface/src/avatar/OtherAvatar.h @@ -9,6 +9,8 @@ #ifndef hifi_OtherAvatar_h #define hifi_OtherAvatar_h +#include + #include #include "ui/overlays/Overlays.h" #include "ui/overlays/Sphere3DOverlay.h" @@ -36,4 +38,6 @@ protected: int32_t _spaceIndex { -1 }; }; +using OtherAvatarPointer = std::shared_ptr; + #endif // hifi_OtherAvatar_h diff --git a/interface/src/workload/PhysicsBoundary.cpp b/interface/src/workload/PhysicsBoundary.cpp index 927121ac04..d1de9ad6b2 100644 --- a/interface/src/workload/PhysicsBoundary.cpp +++ b/interface/src/workload/PhysicsBoundary.cpp @@ -10,9 +10,13 @@ #include "PhysicsBoundary.h" +#include +#include #include #include +#include "avatar/AvatarManager.h" +#include "avatar/OtherAvatar.h" #include "workload/GameWorkload.h" void PhysicsBoundary::run(const workload::WorkloadContextPointer& context, const Inputs& inputs) { @@ -22,12 +26,26 @@ void PhysicsBoundary::run(const workload::WorkloadContextPointer& context, const } GameWorkloadContext* gameContext = static_cast(context.get()); PhysicalEntitySimulationPointer simulation = gameContext->_simulation; + auto avatarManager = DependencyManager::get(); const auto& regionChanges = inputs.get0(); for (uint32_t i = 0; i < (uint32_t)regionChanges.size(); ++i) { const workload::Space::Change& change = regionChanges[i]; - auto entity = space->getOwner(change.proxyId).get(); - if (entity) { - simulation->changeEntity(entity); + auto nestable = space->getOwner(change.proxyId).get(); + if (nestable) { + switch (nestable->getNestableType()) { + case NestableType::Entity: { + EntityItemPointer entity = std::static_pointer_cast(nestable); + simulation->changeEntity(entity); + } + break; + case NestableType::Avatar: { + auto avatar = std::static_pointer_cast(nestable); + avatarManager->handleSpaceChange(avatar); + } + break; + default: + break; + } } } } diff --git a/interface/src/workload/PhysicsBoundary.h b/interface/src/workload/PhysicsBoundary.h index c316fa5686..e4d0411104 100644 --- a/interface/src/workload/PhysicsBoundary.h +++ b/interface/src/workload/PhysicsBoundary.h @@ -10,12 +10,9 @@ #ifndef hifi_PhysicsGatekeeper_h #define hifi_PhysicsGatekeeper_h -#include #include #include -#include "PhysicalEntitySimulation.h" - class PhysicsBoundary { public: using Config = workload::Job::Config; diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.cpp b/libraries/entities-renderer/src/EntityTreeRenderer.cpp index 34d8dbbaef..c3c4095251 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.cpp +++ b/libraries/entities-renderer/src/EntityTreeRenderer.cpp @@ -295,7 +295,8 @@ void EntityTreeRenderer::addPendingEntities(const render::ScenePointer& scene, r auto spaceIndex = _space->allocateID(); workload::Sphere sphere(entity->getWorldPosition(), entity->getBoundingRadius()); workload::Transaction transaction; - transaction.reset(spaceIndex, sphere, workload::Owner(entity)); + SpatiallyNestablePointer nestable = std::static_pointer_cast(entity); + transaction.reset(spaceIndex, sphere, workload::Owner(nestable)); _space->enqueueTransaction(transaction); entity->setSpaceIndex(spaceIndex); connect(entity.get(), &EntityItem::spaceUpdate, this, &EntityTreeRenderer::handleSpaceUpdate, Qt::QueuedConnection);