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
62}62}
63 63
64void bidForSimulationOwnership(EntityItemProperties& properties) {64void 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
66 // in the outgoing properties. The EntityServer may accept the bid or might not.66 // in the outgoing properties. The EntityServer may accept the bid or might not.
67 auto nodeList = DependencyManager::get<NodeList>();67 auto nodeList = DependencyManager::get<NodeList>();
68 const QUuid myNodeID = nodeList->getSessionUUID();68 const QUuid myNodeID = nodeList->getSessionUUID();
@@ -113,7 +113,7 @@ EntityItemProperties EntityScriptingInterface::getEntityProperties(QUuid identit · 44 unmodified lines
113 if (entity) {113 if (entity) {
114 results = entity->getProperties();114 results = entity->getProperties();
115 115
116 // TODO: improve sitting points and naturalDimensions in the future, 116 // TODO: improve sitting points and naturalDimensions in the future,
117 // for now we've included the old sitting points model behavior for entity types that are models117 // for now we've included the old sitting points model behavior for entity types that are models
118 // we've also added this hack for setting natural dimensions of models118 // we've also added this hack for setting natural dimensions of models
119 if (entity->getType() == EntityTypes::Model) {119 if (entity->getType() == EntityTypes::Model) {
@@ -149,15 +149,15 @@ QUuid EntityScriptingInterface::editEntity(QUuid id, EntityItemProperties proper · 29 unmodified lines
149 if (properties.hasTerseUpdateChanges()) {149 if (properties.hasTerseUpdateChanges()) {
150 auto nodeList = DependencyManager::get<NodeList>();150 auto nodeList = DependencyManager::get<NodeList>();
151 const QUuid myNodeID = nodeList->getSessionUUID();151 const QUuid myNodeID = nodeList->getSessionUUID();
152 152
153 if (entity->getSimulatorID() == myNodeID) {153 if (entity->getSimulatorID() == myNodeID) {
154 // we think we already own the simulation, so make sure to send ALL TerseUpdate properties154 // we think we already own the simulation, so make sure to send ALL TerseUpdate properties
155 entity->getAllTerseUpdateProperties(properties);155 entity->getAllTerseUpdateProperties(properties);
156 // TODO: if we knew that ONLY TerseUpdate properties have changed in properties AND the object 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 157 // is dynamic AND it is active in the physics simulation then we could chose to NOT queue an update
158 // and instead let the physics simulation decide when to send a terse update. This would remove158 // and instead let the physics simulation decide when to send a terse update. This would remove
159 // the "slide-no-rotate" glitch (and typical a double-update) that we see during the "poke rolling159 // 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
161 // proxy toward the true physical position" feature to hide the final glitches in the remote watcher's161 // proxy toward the true physical position" feature to hide the final glitches in the remote watcher's
162 // simulation.162 // simulation.
163 }163 }
@@ -204,7 +204,7 @@ void EntityScriptingInterface::deleteEntity(QUuid id) { · 40 unmodified lines
204}204}
205 205
206QUuid EntityScriptingInterface::findClosestEntity(const glm::vec3& center, float radius) const {206QUuid EntityScriptingInterface::findClosestEntity(const glm::vec3& center, float radius) const {
207 EntityItemID result; 207 EntityItemID result;
208 if (_entityTree) {208 if (_entityTree) {
209 _entityTree->lockForRead();209 _entityTree->lockForRead();
210 EntityItemPointer closestEntity = _entityTree->findClosestEntity(center, radius);210 EntityItemPointer closestEntity = _entityTree->findClosestEntity(center, radius);
@@ -264,8 +264,8 @@ RayToEntityIntersectionResult EntityScriptingInterface::findRayIntersectionBlock · 53 unmodified lines
264 return findRayIntersectionWorker(ray, Octree::Lock, precisionPicking);264 return findRayIntersectionWorker(ray, Octree::Lock, precisionPicking);
265}265}
266 266
267RayToEntityIntersectionResult EntityScriptingInterface::findRayIntersectionWorker(const PickRay& ray, 267RayToEntityIntersectionResult EntityScriptingInterface::findRayIntersectionWorker(const PickRay& ray,
268 Octree::lockType lockType, 268 Octree::lockType lockType,
269 bool precisionPicking) {269 bool precisionPicking) {
270 270
271 271
@@ -273,8 +273,8 @@ RayToEntityIntersectionResult EntityScriptingInterface::findRayIntersectionWorke · 1 unmodified line
273 if (_entityTree) {273 if (_entityTree) {
274 OctreeElement* element;274 OctreeElement* element;
275 EntityItemPointer intersectedEntity = NULL;275 EntityItemPointer intersectedEntity = NULL;
276 result.intersects = _entityTree->findRayIntersection(ray.origin, ray.direction, element, result.distance, result.face, 276 result.intersects = _entityTree->findRayIntersection(ray.origin, ray.direction, element, result.distance, result.face,
277 (void**)&intersectedEntity, lockType, &result.accurate, 277 (void**)&intersectedEntity, lockType, &result.accurate,
278 precisionPicking);278 precisionPicking);
279 if (result.intersects && intersectedEntity) {279 if (result.intersects && intersectedEntity) {
280 result.entityID = intersectedEntity->getEntityItemID();280 result.entityID = intersectedEntity->getEntityItemID();
@@ -318,15 +318,15 @@ bool EntityScriptingInterface::getSendPhysicsUpdates() const { · 37 unmodified lines
318}318}
319 319
320 320
321RayToEntityIntersectionResult::RayToEntityIntersectionResult() : 321RayToEntityIntersectionResult::RayToEntityIntersectionResult() :
322 intersects(false), 322 intersects(false),
323 accurate(true), // assume it's accurate323 accurate(true), // assume it's accurate
324 entityID(),324 entityID(),
325 properties(),325 properties(),
326 distance(0),326 distance(0),
327 face(),327 face(),
328 entity(NULL)328 entity(NULL)
329{ 329{
330}330}
331 331
332QScriptValue RayToEntityIntersectionResultToScriptValue(QScriptEngine* engine, const RayToEntityIntersectionResult& value) {332QScriptValue RayToEntityIntersectionResultToScriptValue(QScriptEngine* engine, const RayToEntityIntersectionResult& value) {
@@ -341,7 +341,7 @@ QScriptValue RayToEntityIntersectionResultToScriptValue(QScriptEngine* engine, c · 8 unmodified lines
341 341
342 obj.setProperty("distance", value.distance);342 obj.setProperty("distance", value.distance);
343 343
344 QString faceName = ""; 344 QString faceName = "";
345 // handle BoxFace345 // handle BoxFace
346 switch (value.face) {346 switch (value.face) {
347 case MIN_X_FACE:347 case MIN_X_FACE:
@@ -446,35 +446,35 @@ bool EntityScriptingInterface::setPoints(QUuid entityID, std::function<bool(Line · 98 unmodified lines
446 if (!_entityTree) {446 if (!_entityTree) {
447 return false;447 return false;
448 }448 }
449 449
450 EntityItemPointer entity = static_cast<EntityItemPointer>(_entityTree->findEntityByEntityItemID(entityID));450 EntityItemPointer entity = static_cast<EntityItemPointer>(_entityTree->findEntityByEntityItemID(entityID));
451 if (!entity) {451 if (!entity) {
452 qCDebug(entities) << "EntityScriptingInterface::setPoints no entity with ID" << entityID;452 qCDebug(entities) << "EntityScriptingInterface::setPoints no entity with ID" << entityID;
453 }453 }
454 454
455 EntityTypes::EntityType entityType = entity->getType();455 EntityTypes::EntityType entityType = entity->getType();
456 456
457 if (entityType != EntityTypes::Line) {457 if (entityType != EntityTypes::Line) {
458 return false;458 return false;
459 }459 }
460 460
461 auto now = usecTimestampNow();461 auto now = usecTimestampNow();
462 462
463 LineEntityItem* lineEntity = static_cast<LineEntityItem*>(entity.get());463 LineEntityItem* lineEntity = static_cast<LineEntityItem*>(entity.get());
464 _entityTree->lockForWrite();464 _entityTree->lockForWrite();
465 bool success = actor(*lineEntity);465 bool success = actor(*lineEntity);
466 entity->setLastEdited(now);466 entity->setLastEdited(now);
467 entity->setLastBroadcast(now);467 entity->setLastBroadcast(now);
468 _entityTree->unlock();468 _entityTree->unlock();
469 469
470 _entityTree->lockForRead();470 _entityTree->lockForRead();
471 EntityItemProperties properties = entity->getProperties();471 EntityItemProperties properties = entity->getProperties();
472 _entityTree->unlock();472 _entityTree->unlock();
473 473
474 properties.setLinePointsDirty();474 properties.setLinePointsDirty();
475 properties.setLastEdited(now);475 properties.setLastEdited(now);
476 476
477 477
478 queueEntityMessage(PacketTypeEntityEdit, entityID, properties);478 queueEntityMessage(PacketTypeEntityEdit, entityID, properties);
479 return success;479 return success;
480}480}
@@ -509,7 +509,6 @@ bool EntityScriptingInterface::appendPoint(QUuid entityID, const glm::vec3& poin · 28 unmodified lines
509 {509 {
510 return lineEntity.appendPoint(point);510 return lineEntity.appendPoint(point);
511 });511 });
512
513}512}
514 513
515 514
@@ -585,9 +584,27 @@ bool EntityScriptingInterface::updateAction(const QUuid& entityID, const QUuid& · 69 unmodified lines
585 });584 });
586}585}
587 586
588
589bool EntityScriptingInterface::deleteAction(const QUuid& entityID, const QUuid& actionID) {587bool EntityScriptingInterface::deleteAction(const QUuid& entityID, const QUuid& actionID) {
590 return actionWorker(entityID, [&](EntitySimulation* simulation, EntityItemPointer entity) {588 return actionWorker(entityID, [&](EntitySimulation* simulation, EntityItemPointer entity) {
591 return entity->removeAction(simulation, actionID);589 return entity->removeAction(simulation, actionID);
592 });590 });
593}591}
592
593QVector<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
603QVariantMap 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}