History

Merge branch 'master' of https://github.com/highfidelity/hifi into pop_dynamicTestsMaster

Zach Fox committed 9 years ago

Commit 91333cd2 parents 3e13928 815f68079 files · +784 −892Browse files

Showing the changes to libraries/entities/src/EntityScriptingInterface.cpp (1 of 79 files). Show all

Unified · Split

libraries/entities/src/EntityScriptingInterface.cpp+47−1
@@ -50,6 +50,10 @@ EntityScriptingInterface::EntityScriptingInterface(bool bidOnSimulationOwnership · 49 unmodified lines
50 connect(nodeList.data(), &NodeList::canRezCertifiedChanged, this, &EntityScriptingInterface::canRezCertifiedChanged);50 connect(nodeList.data(), &NodeList::canRezCertifiedChanged, this, &EntityScriptingInterface::canRezCertifiedChanged);
51 connect(nodeList.data(), &NodeList::canRezTmpCertifiedChanged, this, &EntityScriptingInterface::canRezTmpCertifiedChanged);51 connect(nodeList.data(), &NodeList::canRezTmpCertifiedChanged, this, &EntityScriptingInterface::canRezTmpCertifiedChanged);
52 connect(nodeList.data(), &NodeList::canWriteAssetsChanged, this, &EntityScriptingInterface::canWriteAssetsChanged);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
55void EntityScriptingInterface::queueEntityMessage(PacketType packetType,59void EntityScriptingInterface::queueEntityMessage(PacketType packetType,
@@ -457,7 +461,7 @@ QUuid EntityScriptingInterface::editEntity(QUuid id, const EntityItemProperties& · 401 unmodified lines
457 // if they've changed.461 // if they've changed.
458 entity->forEachDescendant([&](SpatiallyNestablePointer descendant) {462 entity->forEachDescendant([&](SpatiallyNestablePointer descendant) {
459 if (descendant->getNestableType() == NestableType::Entity) {463 if (descendant->getNestableType() == NestableType::Entity) {
460 if (descendant->checkAndMaybeUpdateQueryAACube()) {464 if (descendant->updateQueryAACube()) {
461 EntityItemPointer entityDescendant = std::static_pointer_cast<EntityItem>(descendant);465 EntityItemPointer entityDescendant = std::static_pointer_cast<EntityItem>(descendant);
462 EntityItemProperties newQueryCubeProperties;466 EntityItemProperties newQueryCubeProperties;
463 newQueryCubeProperties.setQueryAACube(descendant->getQueryAACube());467 newQueryCubeProperties.setQueryAACube(descendant->getQueryAACube());
@@ -571,6 +575,48 @@ void EntityScriptingInterface::callEntityServerMethod(QUuid id, const QString& m · 107 unmodified lines
571 DependencyManager::get<EntityScriptClient>()->callEntityServerMethod(id, method, params);575 DependencyManager::get<EntityScriptClient>()->callEntityServerMethod(id, method, params);
572}576}
573 577
578void 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
591void 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(&paramCount);
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
574QUuid EntityScriptingInterface::findClosestEntity(const glm::vec3& center, float radius) const {620QUuid EntityScriptingInterface::findClosestEntity(const glm::vec3& center, float radius) const {
575 PROFILE_RANGE(script_entities, __FUNCTION__);621 PROFILE_RANGE(script_entities, __FUNCTION__);
576 622