Showing the changes to libraries/entities/src/EntityScriptingInterface.cpp (1 of 4 files). Show all
Unified · Split
| @@ -178,6 +178,8 @@ EntityItemProperties convertLocationFromScriptSemantics(const EntityItemProperti · 177 unmodified lines | |||
| 178 | 178 | ||
| 179 | 179 | ||
| 180 | QUuid EntityScriptingInterface::addEntity(const EntityItemProperties& properties, bool clientOnly) { | 180 | QUuid EntityScriptingInterface::addEntity(const EntityItemProperties& properties, bool clientOnly) { |
| 181 | PROFILE_RANGE(script_entities, __FUNCTION__); | ||
| 182 | |||
| 181 | _activityTracking.addedEntityCount++; | 183 | _activityTracking.addedEntityCount++; |
| 182 | 184 | ||
| 183 | EntityItemProperties propertiesWithSimID = convertLocationFromScriptSemantics(properties); | 185 | EntityItemProperties propertiesWithSimID = convertLocationFromScriptSemantics(properties); |
| @@ -270,6 +272,8 @@ EntityItemProperties EntityScriptingInterface::getEntityProperties(QUuid identit · 86 unmodified lines | |||
| 270 | } | 272 | } |
| 271 | 273 | ||
| 272 | EntityItemProperties EntityScriptingInterface::getEntityProperties(QUuid identity, EntityPropertyFlags desiredProperties) { | 274 | EntityItemProperties EntityScriptingInterface::getEntityProperties(QUuid identity, EntityPropertyFlags desiredProperties) { |
| 275 | PROFILE_RANGE(script_entities, __FUNCTION__); | ||
| 276 | |||
| 273 | EntityItemProperties results; | 277 | EntityItemProperties results; |
| 274 | if (_entityTree) { | 278 | if (_entityTree) { |
| 275 | _entityTree->withReadLock([&] { | 279 | _entityTree->withReadLock([&] { |
| @@ -316,6 +320,8 @@ EntityItemProperties EntityScriptingInterface::getEntityProperties(QUuid identit · 40 unmodified lines | |||
| 316 | } | 320 | } |
| 317 | 321 | ||
| 318 | QUuid EntityScriptingInterface::editEntity(QUuid id, const EntityItemProperties& scriptSideProperties) { | 322 | QUuid EntityScriptingInterface::editEntity(QUuid id, const EntityItemProperties& scriptSideProperties) { |
| 323 | PROFILE_RANGE(script_entities, __FUNCTION__); | ||
| 324 | |||
| 319 | _activityTracking.editedEntityCount++; | 325 | _activityTracking.editedEntityCount++; |
| 320 | 326 | ||
| 321 | EntityItemProperties properties = scriptSideProperties; | 327 | EntityItemProperties properties = scriptSideProperties; |
| @@ -467,6 +473,8 @@ QUuid EntityScriptingInterface::editEntity(QUuid id, const EntityItemProperties& · 145 unmodified lines | |||
| 467 | } | 473 | } |
| 468 | 474 | ||
| 469 | void EntityScriptingInterface::deleteEntity(QUuid id) { | 475 | void EntityScriptingInterface::deleteEntity(QUuid id) { |
| 476 | PROFILE_RANGE(script_entities, __FUNCTION__); | ||
| 477 | |||
| 470 | _activityTracking.deletedEntityCount++; | 478 | _activityTracking.deletedEntityCount++; |
| 471 | 479 | ||
| 472 | EntityItemID entityID(id); | 480 | EntityItemID entityID(id); |
| @@ -522,6 +530,8 @@ void EntityScriptingInterface::setEntitiesScriptEngine(EntitiesScriptEngineProvi · 49 unmodified lines | |||
| 522 | } | 530 | } |
| 523 | 531 | ||
| 524 | void EntityScriptingInterface::callEntityMethod(QUuid id, const QString& method, const QStringList& params) { | 532 | void EntityScriptingInterface::callEntityMethod(QUuid id, const QString& method, const QStringList& params) { |
| 533 | PROFILE_RANGE(script_entities, __FUNCTION__); | ||
| 534 | |||
| 525 | std::lock_guard<std::recursive_mutex> lock(_entitiesScriptEngineLock); | 535 | std::lock_guard<std::recursive_mutex> lock(_entitiesScriptEngineLock); |
| 526 | if (_entitiesScriptEngine) { | 536 | if (_entitiesScriptEngine) { |
| 527 | EntityItemID entityID{ id }; | 537 | EntityItemID entityID{ id }; |
| @@ -530,6 +540,8 @@ void EntityScriptingInterface::callEntityMethod(QUuid id, const QString& method, · 2 unmodified lines | |||
| 530 | } | 540 | } |
| 531 | 541 | ||
| 532 | QUuid EntityScriptingInterface::findClosestEntity(const glm::vec3& center, float radius) const { | 542 | QUuid EntityScriptingInterface::findClosestEntity(const glm::vec3& center, float radius) const { |
| 543 | PROFILE_RANGE(script_entities, __FUNCTION__); | ||
| 544 | |||
| 533 | EntityItemID result; | 545 | EntityItemID result; |
| 534 | if (_entityTree) { | 546 | if (_entityTree) { |
| 535 | EntityItemPointer closestEntity; | 547 | EntityItemPointer closestEntity; |
| @@ -553,6 +565,8 @@ void EntityScriptingInterface::dumpTree() const { · 17 unmodified lines | |||
| 553 | } | 565 | } |
| 554 | 566 | ||
| 555 | QVector<QUuid> EntityScriptingInterface::findEntities(const glm::vec3& center, float radius) const { | 567 | QVector<QUuid> EntityScriptingInterface::findEntities(const glm::vec3& center, float radius) const { |
| 568 | PROFILE_RANGE(script_entities, __FUNCTION__); | ||
| 569 | |||
| 556 | QVector<QUuid> result; | 570 | QVector<QUuid> result; |
| 557 | if (_entityTree) { | 571 | if (_entityTree) { |
| 558 | QVector<EntityItemPointer> entities; | 572 | QVector<EntityItemPointer> entities; |
| @@ -568,6 +582,8 @@ QVector<QUuid> EntityScriptingInterface::findEntities(const glm::vec3& center, f · 9 unmodified lines | |||
| 568 | } | 582 | } |
| 569 | 583 | ||
| 570 | QVector<QUuid> EntityScriptingInterface::findEntitiesInBox(const glm::vec3& corner, const glm::vec3& dimensions) const { | 584 | QVector<QUuid> EntityScriptingInterface::findEntitiesInBox(const glm::vec3& corner, const glm::vec3& dimensions) const { |
| 585 | PROFILE_RANGE(script_entities, __FUNCTION__); | ||
| 586 | |||
| 571 | QVector<QUuid> result; | 587 | QVector<QUuid> result; |
| 572 | if (_entityTree) { | 588 | if (_entityTree) { |
| 573 | QVector<EntityItemPointer> entities; | 589 | QVector<EntityItemPointer> entities; |
| @@ -584,6 +600,8 @@ QVector<QUuid> EntityScriptingInterface::findEntitiesInBox(const glm::vec3& corn · 10 unmodified lines | |||
| 584 | } | 600 | } |
| 585 | 601 | ||
| 586 | QVector<QUuid> EntityScriptingInterface::findEntitiesInFrustum(QVariantMap frustum) const { | 602 | QVector<QUuid> EntityScriptingInterface::findEntitiesInFrustum(QVariantMap frustum) const { |
| 603 | PROFILE_RANGE(script_entities, __FUNCTION__); | ||
| 604 | |||
| 587 | QVector<QUuid> result; | 605 | QVector<QUuid> result; |
| 588 | 606 | ||
| 589 | const QString POSITION_PROPERTY = "position"; | 607 | const QString POSITION_PROPERTY = "position"; |
| @@ -627,6 +645,7 @@ QVector<QUuid> EntityScriptingInterface::findEntitiesInFrustum(QVariantMap frust · 37 unmodified lines | |||
| 627 | 645 | ||
| 628 | RayToEntityIntersectionResult EntityScriptingInterface::findRayIntersection(const PickRay& ray, bool precisionPicking, | 646 | RayToEntityIntersectionResult EntityScriptingInterface::findRayIntersection(const PickRay& ray, bool precisionPicking, |
| 629 | const QScriptValue& entityIdsToInclude, const QScriptValue& entityIdsToDiscard, bool visibleOnly, bool collidableOnly) { | 647 | const QScriptValue& entityIdsToInclude, const QScriptValue& entityIdsToDiscard, bool visibleOnly, bool collidableOnly) { |
| 648 | PROFILE_RANGE(script_entities, __FUNCTION__); | ||
| 630 | 649 | ||
| 631 | QVector<EntityItemID> entitiesToInclude = qVectorEntityItemIDFromScriptValue(entityIdsToInclude); | 650 | QVector<EntityItemID> entitiesToInclude = qVectorEntityItemIDFromScriptValue(entityIdsToInclude); |
| 632 | QVector<EntityItemID> entitiesToDiscard = qVectorEntityItemIDFromScriptValue(entityIdsToDiscard); | 651 | QVector<EntityItemID> entitiesToDiscard = qVectorEntityItemIDFromScriptValue(entityIdsToDiscard); |
| @@ -734,6 +753,8 @@ RayToEntityIntersectionResult::RayToEntityIntersectionResult() : · 101 unmodified lines | |||
| 734 | } | 753 | } |
| 735 | 754 | ||
| 736 | QScriptValue RayToEntityIntersectionResultToScriptValue(QScriptEngine* engine, const RayToEntityIntersectionResult& value) { | 755 | QScriptValue RayToEntityIntersectionResultToScriptValue(QScriptEngine* engine, const RayToEntityIntersectionResult& value) { |
| 756 | PROFILE_RANGE(script_entities, __FUNCTION__); | ||
| 757 | |||
| 737 | QScriptValue obj = engine->newObject(); | 758 | QScriptValue obj = engine->newObject(); |
| 738 | obj.setProperty("intersects", value.intersects); | 759 | obj.setProperty("intersects", value.intersects); |
| 739 | obj.setProperty("accurate", value.accurate); | 760 | obj.setProperty("accurate", value.accurate); |
| @@ -781,6 +802,8 @@ QScriptValue RayToEntityIntersectionResultToScriptValue(QScriptEngine* engine, c · 41 unmodified lines | |||
| 781 | } | 802 | } |
| 782 | 803 | ||
| 783 | void RayToEntityIntersectionResultFromScriptValue(const QScriptValue& object, RayToEntityIntersectionResult& value) { | 804 | void RayToEntityIntersectionResultFromScriptValue(const QScriptValue& object, RayToEntityIntersectionResult& value) { |
| 805 | PROFILE_RANGE(script_entities, __FUNCTION__); | ||
| 806 | |||
| 784 | value.intersects = object.property("intersects").toVariant().toBool(); | 807 | value.intersects = object.property("intersects").toVariant().toBool(); |
| 785 | value.accurate = object.property("accurate").toVariant().toBool(); | 808 | value.accurate = object.property("accurate").toVariant().toBool(); |
| 786 | QScriptValue entityIDValue = object.property("entityID"); | 809 | QScriptValue entityIDValue = object.property("entityID"); |
| @@ -818,6 +841,8 @@ void RayToEntityIntersectionResultFromScriptValue(const QScriptValue& object, Ra · 31 unmodified lines | |||
| 818 | 841 | ||
| 819 | bool EntityScriptingInterface::setVoxels(QUuid entityID, | 842 | bool EntityScriptingInterface::setVoxels(QUuid entityID, |
| 820 | std::function<bool(PolyVoxEntityItem&)> actor) { | 843 | std::function<bool(PolyVoxEntityItem&)> actor) { |
| 844 | PROFILE_RANGE(script_entities, __FUNCTION__); | ||
| 845 | |||
| 821 | if (!_entityTree) { | 846 | if (!_entityTree) { |
| 822 | return false; | 847 | return false; |
| 823 | } | 848 | } |
| @@ -842,6 +867,8 @@ bool EntityScriptingInterface::setVoxels(QUuid entityID, · 18 unmodified lines | |||
| 842 | } | 867 | } |
| 843 | 868 | ||
| 844 | bool EntityScriptingInterface::setPoints(QUuid entityID, std::function<bool(LineEntityItem&)> actor) { | 869 | bool EntityScriptingInterface::setPoints(QUuid entityID, std::function<bool(LineEntityItem&)> actor) { |
| 870 | PROFILE_RANGE(script_entities, __FUNCTION__); | ||
| 871 | |||
| 845 | if (!_entityTree) { | 872 | if (!_entityTree) { |
| 846 | return false; | 873 | return false; |
| 847 | } | 874 | } |
| @@ -881,18 +908,24 @@ bool EntityScriptingInterface::setPoints(QUuid entityID, std::function<bool(Line · 33 unmodified lines | |||
| 881 | 908 | ||
| 882 | 909 | ||
| 883 | bool EntityScriptingInterface::setVoxelSphere(QUuid entityID, const glm::vec3& center, float radius, int value) { | 910 | bool EntityScriptingInterface::setVoxelSphere(QUuid entityID, const glm::vec3& center, float radius, int value) { |
| 911 | PROFILE_RANGE(script_entities, __FUNCTION__); | ||
| 912 | |||
| 884 | return setVoxels(entityID, [center, radius, value](PolyVoxEntityItem& polyVoxEntity) { | 913 | return setVoxels(entityID, [center, radius, value](PolyVoxEntityItem& polyVoxEntity) { |
| 885 | return polyVoxEntity.setSphere(center, radius, value); | 914 | return polyVoxEntity.setSphere(center, radius, value); |
| 886 | }); | 915 | }); |
| 887 | } | 916 | } |
| 888 | 917 | ||
| 889 | bool EntityScriptingInterface::setVoxel(QUuid entityID, const glm::vec3& position, int value) { | 918 | bool EntityScriptingInterface::setVoxel(QUuid entityID, const glm::vec3& position, int value) { |
| 919 | PROFILE_RANGE(script_entities, __FUNCTION__); | ||
| 920 | |||
| 890 | return setVoxels(entityID, [position, value](PolyVoxEntityItem& polyVoxEntity) { | 921 | return setVoxels(entityID, [position, value](PolyVoxEntityItem& polyVoxEntity) { |
| 891 | return polyVoxEntity.setVoxelInVolume(position, value); | 922 | return polyVoxEntity.setVoxelInVolume(position, value); |
| 892 | }); | 923 | }); |
| 893 | } | 924 | } |
| 894 | 925 | ||
| 895 | bool EntityScriptingInterface::setAllVoxels(QUuid entityID, int value) { | 926 | bool EntityScriptingInterface::setAllVoxels(QUuid entityID, int value) { |
| 927 | PROFILE_RANGE(script_entities, __FUNCTION__); | ||
| 928 | |||
| 896 | return setVoxels(entityID, [value](PolyVoxEntityItem& polyVoxEntity) { | 929 | return setVoxels(entityID, [value](PolyVoxEntityItem& polyVoxEntity) { |
| 897 | return polyVoxEntity.setAll(value); | 930 | return polyVoxEntity.setAll(value); |
| 898 | }); | 931 | }); |
| @@ -900,12 +933,16 @@ bool EntityScriptingInterface::setAllVoxels(QUuid entityID, int value) { · 1 unmodified line | |||
| 900 | 933 | ||
| 901 | bool EntityScriptingInterface::setVoxelsInCuboid(QUuid entityID, const glm::vec3& lowPosition, | 934 | bool EntityScriptingInterface::setVoxelsInCuboid(QUuid entityID, const glm::vec3& lowPosition, |
| 902 | const glm::vec3& cuboidSize, int value) { | 935 | const glm::vec3& cuboidSize, int value) { |
| 936 | PROFILE_RANGE(script_entities, __FUNCTION__); | ||
| 937 | |||
| 903 | return setVoxels(entityID, [lowPosition, cuboidSize, value](PolyVoxEntityItem& polyVoxEntity) { | 938 | return setVoxels(entityID, [lowPosition, cuboidSize, value](PolyVoxEntityItem& polyVoxEntity) { |
| 904 | return polyVoxEntity.setCuboid(lowPosition, cuboidSize, value); | 939 | return polyVoxEntity.setCuboid(lowPosition, cuboidSize, value); |
| 905 | }); | 940 | }); |
| 906 | } | 941 | } |
| 907 | 942 | ||
| 908 | bool EntityScriptingInterface::setAllPoints(QUuid entityID, const QVector<glm::vec3>& points) { | 943 | bool EntityScriptingInterface::setAllPoints(QUuid entityID, const QVector<glm::vec3>& points) { |
| 944 | PROFILE_RANGE(script_entities, __FUNCTION__); | ||
| 945 | |||
| 909 | EntityItemPointer entity = static_cast<EntityItemPointer>(_entityTree->findEntityByEntityItemID(entityID)); | 946 | EntityItemPointer entity = static_cast<EntityItemPointer>(_entityTree->findEntityByEntityItemID(entityID)); |
| 910 | if (!entity) { | 947 | if (!entity) { |
| 911 | qCDebug(entities) << "EntityScriptingInterface::setPoints no entity with ID" << entityID; | 948 | qCDebug(entities) << "EntityScriptingInterface::setPoints no entity with ID" << entityID; |
| @@ -924,6 +961,8 @@ bool EntityScriptingInterface::setAllPoints(QUuid entityID, const QVector<glm::v · 12 unmodified lines | |||
| 924 | } | 961 | } |
| 925 | 962 | ||
| 926 | bool EntityScriptingInterface::appendPoint(QUuid entityID, const glm::vec3& point) { | 963 | bool EntityScriptingInterface::appendPoint(QUuid entityID, const glm::vec3& point) { |
| 964 | PROFILE_RANGE(script_entities, __FUNCTION__); | ||
| 965 | |||
| 927 | EntityItemPointer entity = static_cast<EntityItemPointer>(_entityTree->findEntityByEntityItemID(entityID)); | 966 | EntityItemPointer entity = static_cast<EntityItemPointer>(_entityTree->findEntityByEntityItemID(entityID)); |
| 928 | if (!entity) { | 967 | if (!entity) { |
| 929 | qCDebug(entities) << "EntityScriptingInterface::setPoints no entity with ID" << entityID; | 968 | qCDebug(entities) << "EntityScriptingInterface::setPoints no entity with ID" << entityID; |
| @@ -999,6 +1038,8 @@ bool EntityScriptingInterface::actionWorker(const QUuid& entityID, · 69 unmodified lines | |||
| 999 | QUuid EntityScriptingInterface::addAction(const QString& actionTypeString, | 1038 | QUuid EntityScriptingInterface::addAction(const QString& actionTypeString, |
| 1000 | const QUuid& entityID, | 1039 | const QUuid& entityID, |
| 1001 | const QVariantMap& arguments) { | 1040 | const QVariantMap& arguments) { |
| 1041 | PROFILE_RANGE(script_entities, __FUNCTION__); | ||
| 1042 | |||
| 1002 | QUuid actionID = QUuid::createUuid(); | 1043 | QUuid actionID = QUuid::createUuid(); |
| 1003 | auto actionFactory = DependencyManager::get<EntityActionFactoryInterface>(); | 1044 | auto actionFactory = DependencyManager::get<EntityActionFactoryInterface>(); |
| 1004 | bool success = false; | 1045 | bool success = false; |
| @@ -1030,6 +1071,8 @@ QUuid EntityScriptingInterface::addAction(const QString& actionTypeString, · 25 unmodified lines | |||
| 1030 | 1071 | ||
| 1031 | 1072 | ||
| 1032 | bool EntityScriptingInterface::updateAction(const QUuid& entityID, const QUuid& actionID, const QVariantMap& arguments) { | 1073 | bool EntityScriptingInterface::updateAction(const QUuid& entityID, const QUuid& actionID, const QVariantMap& arguments) { |
| 1074 | PROFILE_RANGE(script_entities, __FUNCTION__); | ||
| 1075 | |||
| 1033 | return actionWorker(entityID, [&](EntitySimulationPointer simulation, EntityItemPointer entity) { | 1076 | return actionWorker(entityID, [&](EntitySimulationPointer simulation, EntityItemPointer entity) { |
| 1034 | bool success = entity->updateAction(simulation, actionID, arguments); | 1077 | bool success = entity->updateAction(simulation, actionID, arguments); |
| 1035 | if (success) { | 1078 | if (success) { |
| @@ -1040,6 +1083,8 @@ bool EntityScriptingInterface::updateAction(const QUuid& entityID, const QUuid& · 4 unmodified lines | |||
| 1040 | } | 1083 | } |
| 1041 | 1084 | ||
| 1042 | bool EntityScriptingInterface::deleteAction(const QUuid& entityID, const QUuid& actionID) { | 1085 | bool EntityScriptingInterface::deleteAction(const QUuid& entityID, const QUuid& actionID) { |
| 1086 | PROFILE_RANGE(script_entities, __FUNCTION__); | ||
| 1087 | |||
| 1043 | bool success = false; | 1088 | bool success = false; |
| 1044 | actionWorker(entityID, [&](EntitySimulationPointer simulation, EntityItemPointer entity) { | 1089 | actionWorker(entityID, [&](EntitySimulationPointer simulation, EntityItemPointer entity) { |
| 1045 | success = entity->removeAction(simulation, actionID); | 1090 | success = entity->removeAction(simulation, actionID); |
| @@ -1053,6 +1098,8 @@ bool EntityScriptingInterface::deleteAction(const QUuid& entityID, const QUuid& · 7 unmodified lines | |||
| 1053 | } | 1098 | } |
| 1054 | 1099 | ||
| 1055 | QVector<QUuid> EntityScriptingInterface::getActionIDs(const QUuid& entityID) { | 1100 | QVector<QUuid> EntityScriptingInterface::getActionIDs(const QUuid& entityID) { |
| 1101 | PROFILE_RANGE(script_entities, __FUNCTION__); | ||
| 1102 | |||
| 1056 | QVector<QUuid> result; | 1103 | QVector<QUuid> result; |
| 1057 | actionWorker(entityID, [&](EntitySimulationPointer simulation, EntityItemPointer entity) { | 1104 | actionWorker(entityID, [&](EntitySimulationPointer simulation, EntityItemPointer entity) { |
| 1058 | QList<QUuid> actionIDs = entity->getActionIDs(); | 1105 | QList<QUuid> actionIDs = entity->getActionIDs(); |
| @@ -1063,6 +1110,8 @@ QVector<QUuid> EntityScriptingInterface::getActionIDs(const QUuid& entityID) { · 4 unmodified lines | |||
| 1063 | } | 1110 | } |
| 1064 | 1111 | ||
| 1065 | QVariantMap EntityScriptingInterface::getActionArguments(const QUuid& entityID, const QUuid& actionID) { | 1112 | QVariantMap EntityScriptingInterface::getActionArguments(const QUuid& entityID, const QUuid& actionID) { |
| 1113 | PROFILE_RANGE(script_entities, __FUNCTION__); | ||
| 1114 | |||
| 1066 | QVariantMap result; | 1115 | QVariantMap result; |
| 1067 | actionWorker(entityID, [&](EntitySimulationPointer simulation, EntityItemPointer entity) { | 1116 | actionWorker(entityID, [&](EntitySimulationPointer simulation, EntityItemPointer entity) { |
| 1068 | result = entity->getActionArguments(actionID); | 1117 | result = entity->getActionArguments(actionID); |