History

provide a way for scripts to get information about what actions an entity has and what the arguments of those actions are

Seth Alves committed 11 years ago

Commit 0970f011 parent c0c111615 files · +136 −30Browse files

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

Unified · Split

libraries/entities/src/EntityScriptingInterface.cpp+43−26
@@ -62,7 +62,7 @@ void EntityScriptingInterface::setEntityTree(EntityTree* modelTree) { · 61 unmodified lines
6262 }
6363
6464 void bidForSimulationOwnership(EntityItemProperties& properties) {
65− // We make a bid for simulation ownership by declaring our sessionID as simulation owner
65+ // We make a bid for simulation ownership by declaring our sessionID as simulation owner
6666 // in the outgoing properties. The EntityServer may accept the bid or might not.
6767 auto nodeList = DependencyManager::get<NodeList>();
6868 const QUuid myNodeID = nodeList->getSessionUUID();
@@ -113,7 +113,7 @@ EntityItemProperties EntityScriptingInterface::getEntityProperties(QUuid identit · 44 unmodified lines
113113 if (entity) {
114114 results = entity->getProperties();
115115
116− // TODO: improve sitting points and naturalDimensions in the future,
116+ // TODO: improve sitting points and naturalDimensions in the future,
117117 // for now we've included the old sitting points model behavior for entity types that are models
118118 // we've also added this hack for setting natural dimensions of models
119119 if (entity->getType() == EntityTypes::Model) {
@@ -149,15 +149,15 @@ QUuid EntityScriptingInterface::editEntity(QUuid id, EntityItemProperties proper · 29 unmodified lines
149149 if (properties.hasTerseUpdateChanges()) {
150150 auto nodeList = DependencyManager::get<NodeList>();
151151 const QUuid myNodeID = nodeList->getSessionUUID();
152−
152+
153153 if (entity->getSimulatorID() == myNodeID) {
154154 // we think we already own the simulation, so make sure to send ALL TerseUpdate properties
155155 entity->getAllTerseUpdateProperties(properties);
156− // TODO: if we knew that ONLY TerseUpdate properties have changed in properties AND the object
157− // is dynamic AND it is active in the physics simulation then we could chose to NOT queue an update
156+ // TODO: if we knew that ONLY TerseUpdate properties have changed in properties AND the object
157+ // is dynamic AND it is active in the physics simulation then we could chose to NOT queue an update
158158 // and instead let the physics simulation decide when to send a terse update. This would remove
159159 // the "slide-no-rotate" glitch (and typical a double-update) that we see during the "poke rolling
160− // balls" test. However, even if we solve this problem we still need to provide a "slerp the visible
160+ // balls" test. However, even if we solve this problem we still need to provide a "slerp the visible
161161 // proxy toward the true physical position" feature to hide the final glitches in the remote watcher's
162162 // simulation.
163163 }
@@ -204,7 +204,7 @@ void EntityScriptingInterface::deleteEntity(QUuid id) { · 40 unmodified lines
204204 }
205205
206206 QUuid EntityScriptingInterface::findClosestEntity(const glm::vec3& center, float radius) const {
207− EntityItemID result;
207+ EntityItemID result;
208208 if (_entityTree) {
209209 _entityTree->lockForRead();
210210 EntityItemPointer closestEntity = _entityTree->findClosestEntity(center, radius);
@@ -264,8 +264,8 @@ RayToEntityIntersectionResult EntityScriptingInterface::findRayIntersectionBlock · 53 unmodified lines
264264 return findRayIntersectionWorker(ray, Octree::Lock, precisionPicking);
265265 }
266266
267−RayToEntityIntersectionResult EntityScriptingInterface::findRayIntersectionWorker(const PickRay& ray,
268− Octree::lockType lockType,
267+RayToEntityIntersectionResult EntityScriptingInterface::findRayIntersectionWorker(const PickRay& ray,
268+ Octree::lockType lockType,
269269 bool precisionPicking) {
270270
271271
@@ -273,8 +273,8 @@ RayToEntityIntersectionResult EntityScriptingInterface::findRayIntersectionWorke · 1 unmodified line
273273 if (_entityTree) {
274274 OctreeElement* element;
275275 EntityItemPointer intersectedEntity = NULL;
276− result.intersects = _entityTree->findRayIntersection(ray.origin, ray.direction, element, result.distance, result.face,
277− (void**)&intersectedEntity, lockType, &result.accurate,
276+ result.intersects = _entityTree->findRayIntersection(ray.origin, ray.direction, element, result.distance, result.face,
277+ (void**)&intersectedEntity, lockType, &result.accurate,
278278 precisionPicking);
279279 if (result.intersects && intersectedEntity) {
280280 result.entityID = intersectedEntity->getEntityItemID();
@@ -318,15 +318,15 @@ bool EntityScriptingInterface::getSendPhysicsUpdates() const { · 37 unmodified lines
318318 }
319319
320320
321−RayToEntityIntersectionResult::RayToEntityIntersectionResult() :
322− intersects(false),
321+RayToEntityIntersectionResult::RayToEntityIntersectionResult() :
322+ intersects(false),
323323 accurate(true), // assume it's accurate
324324 entityID(),
325325 properties(),
326326 distance(0),
327327 face(),
328328 entity(NULL)
329−{
329+{
330330 }
331331
332332 QScriptValue RayToEntityIntersectionResultToScriptValue(QScriptEngine* engine, const RayToEntityIntersectionResult& value) {
@@ -341,7 +341,7 @@ QScriptValue RayToEntityIntersectionResultToScriptValue(QScriptEngine* engine, c · 8 unmodified lines
341341
342342 obj.setProperty("distance", value.distance);
343343
344− QString faceName = "";
344+ QString faceName = "";
345345 // handle BoxFace
346346 switch (value.face) {
347347 case MIN_X_FACE:
@@ -446,35 +446,35 @@ bool EntityScriptingInterface::setPoints(QUuid entityID, std::function<bool(Line · 98 unmodified lines
446446 if (!_entityTree) {
447447 return false;
448448 }
449−
449+
450450 EntityItemPointer entity = static_cast<EntityItemPointer>(_entityTree->findEntityByEntityItemID(entityID));
451451 if (!entity) {
452452 qCDebug(entities) << "EntityScriptingInterface::setPoints no entity with ID" << entityID;
453453 }
454−
454+
455455 EntityTypes::EntityType entityType = entity->getType();
456−
456+
457457 if (entityType != EntityTypes::Line) {
458458 return false;
459459 }
460−
460+
461461 auto now = usecTimestampNow();
462−
462+
463463 LineEntityItem* lineEntity = static_cast<LineEntityItem*>(entity.get());
464464 _entityTree->lockForWrite();
465465 bool success = actor(*lineEntity);
466466 entity->setLastEdited(now);
467467 entity->setLastBroadcast(now);
468468 _entityTree->unlock();
469−
469+
470470 _entityTree->lockForRead();
471471 EntityItemProperties properties = entity->getProperties();
472472 _entityTree->unlock();
473−
473+
474474 properties.setLinePointsDirty();
475475 properties.setLastEdited(now);
476−
477−
476+
477+
478478 queueEntityMessage(PacketTypeEntityEdit, entityID, properties);
479479 return success;
480480 }
@@ -509,7 +509,6 @@ bool EntityScriptingInterface::appendPoint(QUuid entityID, const glm::vec3& poin · 28 unmodified lines
509509 {
510510 return lineEntity.appendPoint(point);
511511 });
512−
513512 }
514513
515514
@@ -585,9 +584,27 @@ bool EntityScriptingInterface::updateAction(const QUuid& entityID, const QUuid& · 69 unmodified lines
585584 });
586585 }
587586
588−
589587 bool EntityScriptingInterface::deleteAction(const QUuid& entityID, const QUuid& actionID) {
590588 return actionWorker(entityID, [&](EntitySimulation* simulation, EntityItemPointer entity) {
591589 return entity->removeAction(simulation, actionID);
592590 });
593591 }
592+
593+QVector<QUuid> EntityScriptingInterface::getActionIDs(const QUuid& entityID) {
594+ QVector<QUuid> result;
595+ actionWorker(entityID, [&](EntitySimulation* simulation, EntityItemPointer entity) {
596+ QList<QUuid> actionIDs = entity->getActionIDs();
597+ result = QVector<QUuid>::fromList(actionIDs);
598+ return true;
599+ });
600+ return result;
601+}
602+
603+QVariantMap EntityScriptingInterface::getActionArguments(const QUuid& entityID, const QUuid& actionID) {
604+ QVariantMap result;
605+ actionWorker(entityID, [&](EntitySimulation* simulation, EntityItemPointer entity) {
606+ result = entity->getActionArguments(actionID);
607+ return true;
608+ });
609+ return result;
610+}