History

merge from upstream

Seth Alves committed 9 years ago

Commit e8a9ff82 parents 9881dd2 546f324463 files · +21986 −6894Browse files

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

Unified · Split

libraries/entities/src/EntityScriptingInterface.cpp+121−59
@@ -27,6 +27,7 @@ · 26 unmodified lines
2727 #include "ZoneEntityItem.h"
2828 #include "WebEntityItem.h"
2929 #include <EntityScriptClient.h>
30+#include <Profile.h>
3031
3132
3233 EntityScriptingInterface::EntityScriptingInterface(bool bidOnSimulationOwnership) :
@@ -178,6 +179,8 @@ EntityItemProperties convertLocationFromScriptSemantics(const EntityItemProperti · 145 unmodified lines
178179
179180
180181 QUuid EntityScriptingInterface::addEntity(const EntityItemProperties& properties, bool clientOnly) {
182+ PROFILE_RANGE(script_entities, __FUNCTION__);
183+
181184 _activityTracking.addedEntityCount++;
182185
183186 EntityItemProperties propertiesWithSimID = convertLocationFromScriptSemantics(properties);
@@ -259,6 +262,8 @@ EntityItemProperties EntityScriptingInterface::getEntityProperties(QUuid identit · 75 unmodified lines
259262 }
260263
261264 EntityItemProperties EntityScriptingInterface::getEntityProperties(QUuid identity, EntityPropertyFlags desiredProperties) {
265+ PROFILE_RANGE(script_entities, __FUNCTION__);
266+
262267 EntityItemProperties results;
263268 if (_entityTree) {
264269 _entityTree->withReadLock([&] {
@@ -280,7 +285,7 @@ EntityItemProperties EntityScriptingInterface::getEntityProperties(QUuid identit · 15 unmodified lines
280285 desiredProperties = entity->getEntityProperties(params);
281286 desiredProperties.setHasProperty(PROP_LOCAL_POSITION);
282287 desiredProperties.setHasProperty(PROP_LOCAL_ROTATION);
283− }
288+ }
284289
285290 results = entity->getProperties(desiredProperties);
286291
@@ -305,6 +310,8 @@ EntityItemProperties EntityScriptingInterface::getEntityProperties(QUuid identit · 18 unmodified lines
305310 }
306311
307312 QUuid EntityScriptingInterface::editEntity(QUuid id, const EntityItemProperties& scriptSideProperties) {
313+ PROFILE_RANGE(script_entities, __FUNCTION__);
314+
308315 _activityTracking.editedEntityCount++;
309316
310317 EntityItemProperties properties = scriptSideProperties;
@@ -456,6 +463,8 @@ QUuid EntityScriptingInterface::editEntity(QUuid id, const EntityItemProperties& · 145 unmodified lines
456463 }
457464
458465 void EntityScriptingInterface::deleteEntity(QUuid id) {
466+ PROFILE_RANGE(script_entities, __FUNCTION__);
467+
459468 _activityTracking.deletedEntityCount++;
460469
461470 EntityItemID entityID(id);
@@ -511,6 +520,8 @@ void EntityScriptingInterface::setEntitiesScriptEngine(EntitiesScriptEngineProvi · 49 unmodified lines
511520 }
512521
513522 void EntityScriptingInterface::callEntityMethod(QUuid id, const QString& method, const QStringList& params) {
523+ PROFILE_RANGE(script_entities, __FUNCTION__);
524+
514525 std::lock_guard<std::recursive_mutex> lock(_entitiesScriptEngineLock);
515526 if (_entitiesScriptEngine) {
516527 EntityItemID entityID{ id };
@@ -519,6 +530,8 @@ void EntityScriptingInterface::callEntityMethod(QUuid id, const QString& method, · 2 unmodified lines
519530 }
520531
521532 QUuid EntityScriptingInterface::findClosestEntity(const glm::vec3& center, float radius) const {
533+ PROFILE_RANGE(script_entities, __FUNCTION__);
534+
522535 EntityItemID result;
523536 if (_entityTree) {
524537 EntityItemPointer closestEntity;
@@ -542,6 +555,8 @@ void EntityScriptingInterface::dumpTree() const { · 17 unmodified lines
542555 }
543556
544557 QVector<QUuid> EntityScriptingInterface::findEntities(const glm::vec3& center, float radius) const {
558+ PROFILE_RANGE(script_entities, __FUNCTION__);
559+
545560 QVector<QUuid> result;
546561 if (_entityTree) {
547562 QVector<EntityItemPointer> entities;
@@ -557,6 +572,8 @@ QVector<QUuid> EntityScriptingInterface::findEntities(const glm::vec3& center, f · 9 unmodified lines
557572 }
558573
559574 QVector<QUuid> EntityScriptingInterface::findEntitiesInBox(const glm::vec3& corner, const glm::vec3& dimensions) const {
575+ PROFILE_RANGE(script_entities, __FUNCTION__);
576+
560577 QVector<QUuid> result;
561578 if (_entityTree) {
562579 QVector<EntityItemPointer> entities;
@@ -573,6 +590,8 @@ QVector<QUuid> EntityScriptingInterface::findEntitiesInBox(const glm::vec3& corn · 10 unmodified lines
573590 }
574591
575592 QVector<QUuid> EntityScriptingInterface::findEntitiesInFrustum(QVariantMap frustum) const {
593+ PROFILE_RANGE(script_entities, __FUNCTION__);
594+
576595 QVector<QUuid> result;
577596
578597 const QString POSITION_PROPERTY = "position";
@@ -616,6 +635,7 @@ QVector<QUuid> EntityScriptingInterface::findEntitiesInFrustum(QVariantMap frust · 37 unmodified lines
616635
617636 RayToEntityIntersectionResult EntityScriptingInterface::findRayIntersection(const PickRay& ray, bool precisionPicking,
618637 const QScriptValue& entityIdsToInclude, const QScriptValue& entityIdsToDiscard, bool visibleOnly, bool collidableOnly) {
638+ PROFILE_RANGE(script_entities, __FUNCTION__);
619639
620640 QVector<EntityItemID> entitiesToInclude = qVectorEntityItemIDFromScriptValue(entityIdsToInclude);
621641 QVector<EntityItemID> entitiesToDiscard = qVectorEntityItemIDFromScriptValue(entityIdsToDiscard);
@@ -664,22 +684,8 @@ bool EntityScriptingInterface::getServerScriptStatus(QUuid entityID, QScriptValu · 42 unmodified lines
664684 auto client = DependencyManager::get<EntityScriptClient>();
665685 auto request = client->createScriptStatusRequest(entityID);
666686 connect(request, &GetScriptStatusRequest::finished, callback.engine(), [callback](GetScriptStatusRequest* request) mutable {
667− QString statusString;
668− switch (request->getStatus()) {
669− case RUNNING:
670− statusString = "running";
671− break;
672− case ERROR_LOADING_SCRIPT:
673− statusString = "error_loading_script";
674− break;
675− case ERROR_RUNNING_SCRIPT:
676− statusString = "error_running_script";
677− break;
678− default:
679− statusString = "";
680− break;
681− }
682− QScriptValueList args { request->getResponseReceived(), request->getIsRunning(), statusString, request->getErrorInfo() };
687+ QString statusString = EntityScriptStatus_::valueToKey(request->getStatus());;
688+ QScriptValueList args { request->getResponseReceived(), request->getIsRunning(), statusString.toLower(), request->getErrorInfo() };
683689 callback.call(QScriptValue(), args);
684690 request->deleteLater();
685691 });
@@ -723,6 +729,8 @@ RayToEntityIntersectionResult::RayToEntityIntersectionResult() : · 37 unmodified lines
723729 }
724730
725731 QScriptValue RayToEntityIntersectionResultToScriptValue(QScriptEngine* engine, const RayToEntityIntersectionResult& value) {
732+ PROFILE_RANGE(script_entities, __FUNCTION__);
733+
726734 QScriptValue obj = engine->newObject();
727735 obj.setProperty("intersects", value.intersects);
728736 obj.setProperty("accurate", value.accurate);
@@ -770,6 +778,8 @@ QScriptValue RayToEntityIntersectionResultToScriptValue(QScriptEngine* engine, c · 41 unmodified lines
770778 }
771779
772780 void RayToEntityIntersectionResultFromScriptValue(const QScriptValue& object, RayToEntityIntersectionResult& value) {
781+ PROFILE_RANGE(script_entities, __FUNCTION__);
782+
773783 value.intersects = object.property("intersects").toVariant().toBool();
774784 value.accurate = object.property("accurate").toVariant().toBool();
775785 QScriptValue entityIDValue = object.property("entityID");
@@ -806,13 +816,15 @@ void RayToEntityIntersectionResultFromScriptValue(const QScriptValue& object, Ra · 30 unmodified lines
806816 }
807817
808818 bool EntityScriptingInterface::polyVoxWorker(QUuid entityID, std::function<bool(PolyVoxEntityItem&)> actor) {
819+ PROFILE_RANGE(script_entities, __FUNCTION__);
820+
809821 if (!_entityTree) {
810822 return false;
811823 }
812824
813825 EntityItemPointer entity = _entityTree->findEntityByEntityItemID(entityID);
814826 if (!entity) {
815− qCDebug(entities) << "EntityScriptingInterface::setVoxelSphere no entity with ID" << entityID;
827+ qCDebug(entities) << "EntityScriptingInterface::setVoxels no entity with ID" << entityID;
816828 return false;
817829 }
818830
@@ -830,6 +842,8 @@ bool EntityScriptingInterface::polyVoxWorker(QUuid entityID, std::function<bool( · 11 unmodified lines
830842 }
831843
832844 bool EntityScriptingInterface::setPoints(QUuid entityID, std::function<bool(LineEntityItem&)> actor) {
845+ PROFILE_RANGE(script_entities, __FUNCTION__);
846+
833847 if (!_entityTree) {
834848 return false;
835849 }
@@ -869,18 +883,41 @@ bool EntityScriptingInterface::setPoints(QUuid entityID, std::function<bool(Line · 33 unmodified lines
869883
870884
871885 bool EntityScriptingInterface::setVoxelSphere(QUuid entityID, const glm::vec3& center, float radius, int value) {
886+ PROFILE_RANGE(script_entities, __FUNCTION__);
872887 return polyVoxWorker(entityID, [center, radius, value](PolyVoxEntityItem& polyVoxEntity) {
873888 return polyVoxEntity.setSphere(center, radius, value);
874889 });
875890 }
876891
877892 bool EntityScriptingInterface::setVoxel(QUuid entityID, const glm::vec3& position, int value) {
893+ PROFILE_RANGE(script_entities, __FUNCTION__);
894+
878895 return polyVoxWorker(entityID, [position, value](PolyVoxEntityItem& polyVoxEntity) {
896+ return polyVoxEntity.setSphere(center, radius, value);
897+ });
898+}
899+
900+bool EntityScriptingInterface::setVoxelCapsule(QUuid entityID,
901+ const glm::vec3& start, const glm::vec3& end,
902+ float radius, int value) {
903+ PROFILE_RANGE(script_entities, __FUNCTION__);
904+
905+ return setVoxels(entityID, [start, end, radius, value](PolyVoxEntityItem& polyVoxEntity) {
906+ return polyVoxEntity.setCapsule(start, end, radius, value);
907+ });
908+}
909+
910+bool EntityScriptingInterface::setVoxel(QUuid entityID, const glm::vec3& position, int value) {
911+ PROFILE_RANGE(script_entities, __FUNCTION__);
912+
913+ return setVoxels(entityID, [position, value](PolyVoxEntityItem& polyVoxEntity) {
879914 return polyVoxEntity.setVoxelInVolume(position, value);
880915 });
881916 }
882917
883918 bool EntityScriptingInterface::setAllVoxels(QUuid entityID, int value) {
919+ PROFILE_RANGE(script_entities, __FUNCTION__);
920+
884921 return polyVoxWorker(entityID, [value](PolyVoxEntityItem& polyVoxEntity) {
885922 return polyVoxEntity.setAll(value);
886923 });
@@ -888,12 +925,16 @@ bool EntityScriptingInterface::setAllVoxels(QUuid entityID, int value) { · 1 unmodified line
888925
889926 bool EntityScriptingInterface::setVoxelsInCuboid(QUuid entityID, const glm::vec3& lowPosition,
890927 const glm::vec3& cuboidSize, int value) {
928+ PROFILE_RANGE(script_entities, __FUNCTION__);
929+
891930 return polyVoxWorker(entityID, [lowPosition, cuboidSize, value](PolyVoxEntityItem& polyVoxEntity) {
892931 return polyVoxEntity.setCuboid(lowPosition, cuboidSize, value);
893932 });
894933 }
895934
896935 void EntityScriptingInterface::voxelsToMesh(QUuid entityID, QScriptValue callback) {
936+ PROFILE_RANGE(script_entities, __FUNCTION__);
937+
897938 polyVoxWorker(entityID, [callback](PolyVoxEntityItem& polyVoxEntity) mutable {
898939 QScriptValue mesh;
899940 polyVoxEntity.getMeshAsScriptValue(callback.engine(), mesh);
@@ -904,6 +945,8 @@ void EntityScriptingInterface::voxelsToMesh(QUuid entityID, QScriptValue callbac · 4 unmodified lines
904945 }
905946
906947 bool EntityScriptingInterface::setAllPoints(QUuid entityID, const QVector<glm::vec3>& points) {
948+ PROFILE_RANGE(script_entities, __FUNCTION__);
949+
907950 EntityItemPointer entity = static_cast<EntityItemPointer>(_entityTree->findEntityByEntityItemID(entityID));
908951 if (!entity) {
909952 qCDebug(entities) << "EntityScriptingInterface::setPoints no entity with ID" << entityID;
@@ -922,6 +965,8 @@ bool EntityScriptingInterface::setAllPoints(QUuid entityID, const QVector<glm::v · 12 unmodified lines
922965 }
923966
924967 bool EntityScriptingInterface::appendPoint(QUuid entityID, const glm::vec3& point) {
968+ PROFILE_RANGE(script_entities, __FUNCTION__);
969+
925970 EntityItemPointer entity = static_cast<EntityItemPointer>(_entityTree->findEntityByEntityItemID(entityID));
926971 if (!entity) {
927972 qCDebug(entities) << "EntityScriptingInterface::setPoints no entity with ID" << entityID;
@@ -997,29 +1042,31 @@ bool EntityScriptingInterface::actionWorker(const QUuid& entityID, · 69 unmodified lines
9971042 QUuid EntityScriptingInterface::addAction(const QString& actionTypeString,
9981043 const QUuid& entityID,
9991044 const QVariantMap& arguments) {
1045+ PROFILE_RANGE(script_entities, __FUNCTION__);
1046+
10001047 QUuid actionID = QUuid::createUuid();
10011048 auto actionFactory = DependencyManager::get<EntityActionFactoryInterface>();
10021049 bool success = false;
10031050 actionWorker(entityID, [&](EntitySimulationPointer simulation, EntityItemPointer entity) {
1004− // create this action even if the entity doesn't have physics info. it will often be the
1005− // case that a script adds an action immediately after an object is created, and the physicsInfo
1006− // is computed asynchronously.
1007− // if (!entity->getPhysicsInfo()) {
1008− // return false;
1009− // }
1010− EntityActionType actionType = EntityActionInterface::actionTypeFromString(actionTypeString);
1011− if (actionType == ACTION_TYPE_NONE) {
1012− return false;
1013− }
1014− EntityActionPointer action = actionFactory->factory(actionType, actionID, entity, arguments);
1015− if (!action) {
1016− return false;
1017− }
1018− action->setIsMine(true);
1019− success = entity->addAction(simulation, action);
1020− entity->grabSimulationOwnership();
1021− return false; // Physics will cause a packet to be sent, so don't send from here.
1022− });
1051+ // create this action even if the entity doesn't have physics info. it will often be the
1052+ // case that a script adds an action immediately after an object is created, and the physicsInfo
1053+ // is computed asynchronously.
1054+ // if (!entity->getPhysicsInfo()) {
1055+ // return false;
1056+ // }
1057+ EntityActionType actionType = EntityActionInterface::actionTypeFromString(actionTypeString);
1058+ if (actionType == ACTION_TYPE_NONE) {
1059+ return false;
1060+ }
1061+ EntityActionPointer action = actionFactory->factory(actionType, actionID, entity, arguments);
1062+ if (!action) {
1063+ return false;
1064+ }
1065+ action->setIsMine(true);
1066+ success = entity->addAction(simulation, action);
1067+ entity->grabSimulationOwnership();
1068+ return false; // Physics will cause a packet to be sent, so don't send from here.
1069+ });
10231070 if (success) {
10241071 return actionID;
10251072 }
@@ -1028,44 +1075,52 @@ QUuid EntityScriptingInterface::addAction(const QString& actionTypeString, · 2 unmodified lines
10281075
10291076
10301077 bool EntityScriptingInterface::updateAction(const QUuid& entityID, const QUuid& actionID, const QVariantMap& arguments) {
1078+ PROFILE_RANGE(script_entities, __FUNCTION__);
1079+
10311080 return actionWorker(entityID, [&](EntitySimulationPointer simulation, EntityItemPointer entity) {
1032− bool success = entity->updateAction(simulation, actionID, arguments);
1033− if (success) {
1034− entity->grabSimulationOwnership();
1035− }
1036− return success;
1037− });
1081+ bool success = entity->updateAction(simulation, actionID, arguments);
1082+ if (success) {
1083+ entity->grabSimulationOwnership();
1084+ }
1085+ return success;
1086+ });
10381087 }
10391088
10401089 bool EntityScriptingInterface::deleteAction(const QUuid& entityID, const QUuid& actionID) {
1090+ PROFILE_RANGE(script_entities, __FUNCTION__);
1091+
10411092 bool success = false;
10421093 actionWorker(entityID, [&](EntitySimulationPointer simulation, EntityItemPointer entity) {
1043− success = entity->removeAction(simulation, actionID);
1044− if (success) {
1045− // reduce from grab to poke
1046− entity->pokeSimulationOwnership();
1047− }
1048− return false; // Physics will cause a packet to be sent, so don't send from here.
1049− });
1094+ success = entity->removeAction(simulation, actionID);
1095+ if (success) {
1096+ // reduce from grab to poke
1097+ entity->pokeSimulationOwnership();
1098+ }
1099+ return false; // Physics will cause a packet to be sent, so don't send from here.
1100+ });
10501101 return success;
10511102 }
10521103
10531104 QVector<QUuid> EntityScriptingInterface::getActionIDs(const QUuid& entityID) {
1105+ PROFILE_RANGE(script_entities, __FUNCTION__);
1106+
10541107 QVector<QUuid> result;
10551108 actionWorker(entityID, [&](EntitySimulationPointer simulation, EntityItemPointer entity) {
1056− QList<QUuid> actionIDs = entity->getActionIDs();
1057− result = QVector<QUuid>::fromList(actionIDs);
1058− return false; // don't send an edit packet
1059− });
1109+ QList<QUuid> actionIDs = entity->getActionIDs();
1110+ result = QVector<QUuid>::fromList(actionIDs);
1111+ return false; // don't send an edit packet
1112+ });
10601113 return result;
10611114 }
10621115
10631116 QVariantMap EntityScriptingInterface::getActionArguments(const QUuid& entityID, const QUuid& actionID) {
1117+ PROFILE_RANGE(script_entities, __FUNCTION__);
1118+
10641119 QVariantMap result;
10651120 actionWorker(entityID, [&](EntitySimulationPointer simulation, EntityItemPointer entity) {
1066− result = entity->getActionArguments(actionID);
1067− return false; // don't send an edit packet
1068− });
1121+ result = entity->getActionArguments(actionID);
1122+ return false; // don't send an edit packet
1123+ });
10691124 return result;
10701125 }
10711126
@@ -1392,8 +1447,7 @@ QVector<QUuid> EntityScriptingInterface::getChildrenIDsOfJoint(const QUuid& pare · 320 unmodified lines
13921447 return;
13931448 }
13941449 parent->forEachChild([&](SpatiallyNestablePointer child) {
1395− if (child->getParentJointIndex() == jointIndex &&
1396− child->getNestableType() != NestableType::Overlay) {
1450+ if (child->getParentJointIndex() == jointIndex) {
13971451 result.push_back(child->getID());
13981452 }
13991453 });
@@ -1497,3 +1551,11 @@ QObject* EntityScriptingInterface::getWebViewRoot(const QUuid& entityID) { · 97 unmodified lines
14971551 return nullptr;
14981552 }
14991553 }
1554+
1555+// TODO move this someplace that makes more sense...
1556+bool EntityScriptingInterface::AABoxIntersectsCapsule(const glm::vec3& low, const glm::vec3& dimensions,
1557+ const glm::vec3& start, const glm::vec3& end, float radius) {
1558+ glm::vec3 penetration;
1559+ AABox aaBox(low, dimensions);
1560+ return aaBox.findCapsulePenetration(start, end, radius, penetration);
1561+}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t