Showing the changes to libraries/entities/src/EntityScriptingInterface.cpp (1 of 79 files). Show all
Unified · Split
| @@ -50,6 +50,10 @@ EntityScriptingInterface::EntityScriptingInterface(bool bidOnSimulationOwnership · 49 unmodified lines | ||
| 50 | 50 | connect(nodeList.data(), &NodeList::canRezCertifiedChanged, this, &EntityScriptingInterface::canRezCertifiedChanged); |
| 51 | 51 | connect(nodeList.data(), &NodeList::canRezTmpCertifiedChanged, this, &EntityScriptingInterface::canRezTmpCertifiedChanged); |
| 52 | 52 | connect(nodeList.data(), &NodeList::canWriteAssetsChanged, this, &EntityScriptingInterface::canWriteAssetsChanged); |
| 53 | + | |
| 54 | + | |
| 55 | + auto& packetReceiver = nodeList->getPacketReceiver(); | |
| 56 | + packetReceiver.registerListener(PacketType::EntityScriptCallMethod, this, "handleEntityScriptCallMethodPacket"); | |
| 53 | 57 | } |
| 54 | 58 | |
| 55 | 59 | void EntityScriptingInterface::queueEntityMessage(PacketType packetType, |
| @@ -457,7 +461,7 @@ QUuid EntityScriptingInterface::editEntity(QUuid id, const EntityItemProperties& · 401 unmodified lines | ||
| 457 | 461 | // if they've changed. |
| 458 | 462 | entity->forEachDescendant([&](SpatiallyNestablePointer descendant) { |
| 459 | 463 | if (descendant->getNestableType() == NestableType::Entity) { |
| 460 | − if (descendant->checkAndMaybeUpdateQueryAACube()) { | |
| 464 | + if (descendant->updateQueryAACube()) { | |
| 461 | 465 | EntityItemPointer entityDescendant = std::static_pointer_cast<EntityItem>(descendant); |
| 462 | 466 | EntityItemProperties newQueryCubeProperties; |
| 463 | 467 | newQueryCubeProperties.setQueryAACube(descendant->getQueryAACube()); |
| @@ -571,6 +575,48 @@ void EntityScriptingInterface::callEntityServerMethod(QUuid id, const QString& m · 107 unmodified lines | ||
| 571 | 575 | DependencyManager::get<EntityScriptClient>()->callEntityServerMethod(id, method, params); |
| 572 | 576 | } |
| 573 | 577 | |
| 578 | +void EntityScriptingInterface::callEntityClientMethod(QUuid clientSessionID, QUuid entityID, const QString& method, const QStringList& params) { | |
| 579 | + PROFILE_RANGE(script_entities, __FUNCTION__); | |
| 580 | + auto scriptServerServices = DependencyManager::get<EntityScriptServerServices>(); | |
| 581 | + | |
| 582 | + // this won't be available on clients | |
| 583 | + if (scriptServerServices) { | |
| 584 | + scriptServerServices->callEntityClientMethod(clientSessionID, entityID, method, params); | |
| 585 | + } else { | |
| 586 | + qWarning() << "Entities.callEntityClientMethod() not allowed in client"; | |
| 587 | + } | |
| 588 | +} | |
| 589 | + | |
| 590 | + | |
| 591 | +void EntityScriptingInterface::handleEntityScriptCallMethodPacket(QSharedPointer<ReceivedMessage> receivedMessage, SharedNodePointer senderNode) { | |
| 592 | + PROFILE_RANGE(script_entities, __FUNCTION__); | |
| 593 | + | |
| 594 | + auto nodeList = DependencyManager::get<NodeList>(); | |
| 595 | + SharedNodePointer entityScriptServer = nodeList->soloNodeOfType(NodeType::EntityScriptServer); | |
| 596 | + | |
| 597 | + if (entityScriptServer == senderNode) { | |
| 598 | + auto entityID = QUuid::fromRfc4122(receivedMessage->read(NUM_BYTES_RFC4122_UUID)); | |
| 599 | + | |
| 600 | + auto method = receivedMessage->readString(); | |
| 601 | + | |
| 602 | + quint16 paramCount; | |
| 603 | + receivedMessage->readPrimitive(¶mCount); | |
| 604 | + | |
| 605 | + QStringList params; | |
| 606 | + for (int param = 0; param < paramCount; param++) { | |
| 607 | + auto paramString = receivedMessage->readString(); | |
| 608 | + params << paramString; | |
| 609 | + } | |
| 610 | + | |
| 611 | + std::lock_guard<std::recursive_mutex> lock(_entitiesScriptEngineLock); | |
| 612 | + if (_entitiesScriptEngine) { | |
| 613 | + _entitiesScriptEngine->callEntityScriptMethod(entityID, method, params, senderNode->getUUID()); | |
| 614 | + } | |
| 615 | + } | |
| 616 | +} | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 574 | 620 | QUuid EntityScriptingInterface::findClosestEntity(const glm::vec3& center, float radius) const { |
| 575 | 621 | PROFILE_RANGE(script_entities, __FUNCTION__); |
| 576 | 622 | |