Showing the changes to libraries/entities/src/EntityScriptingInterface.cpp (1 of 452 files). Show all
Unified · Split
| @@ -32,7 +32,7 @@ EntityScriptingInterface::EntityScriptingInterface() : · 31 unmodified lines | ||
| 32 | 32 | connect(nodeList.data(), &NodeList::canRezChanged, this, &EntityScriptingInterface::canRezChanged); |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | −void EntityScriptingInterface::queueEntityMessage(PacketType packetType, | |
| 35 | +void EntityScriptingInterface::queueEntityMessage(PacketType::Value packetType, | |
| 36 | 36 | EntityItemID entityID, const EntityItemProperties& properties) { |
| 37 | 37 | getEntityPacketSender()->queueEditEntityMessage(packetType, entityID, properties); |
| 38 | 38 | } |
| @@ -93,7 +93,7 @@ QUuid EntityScriptingInterface::addEntity(const EntityItemProperties& properties · 54 unmodified lines | ||
| 93 | 93 | |
| 94 | 94 | // queue the packet |
| 95 | 95 | if (success) { |
| 96 | − queueEntityMessage(PacketTypeEntityAdd, id, propertiesWithSimID); | |
| 96 | + queueEntityMessage(PacketType::EntityAdd, id, propertiesWithSimID); | |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | return id; |
| @@ -118,6 +118,7 @@ EntityItemProperties EntityScriptingInterface::getEntityProperties(QUuid identit · 18 unmodified lines | ||
| 118 | 118 | results.setSittingPoints(geometry->sittingPoints); |
| 119 | 119 | Extents meshExtents = geometry->getUnscaledMeshExtents(); |
| 120 | 120 | results.setNaturalDimensions(meshExtents.maximum - meshExtents.minimum); |
| 121 | + results.calculateNaturalPosition(meshExtents.minimum, meshExtents.maximum); | |
| 121 | 122 | } |
| 122 | 123 | } |
| 123 | 124 | |
| @@ -175,13 +176,13 @@ QUuid EntityScriptingInterface::editEntity(QUuid id, EntityItemProperties proper · 51 unmodified lines | ||
| 175 | 176 | entity->setLastBroadcast(usecTimestampNow()); |
| 176 | 177 | } |
| 177 | 178 | _entityTree->unlock(); |
| 178 | − queueEntityMessage(PacketTypeEntityEdit, entityID, properties); | |
| 179 | + queueEntityMessage(PacketType::EntityEdit, entityID, properties); | |
| 179 | 180 | return id; |
| 180 | 181 | } |
| 181 | 182 | return QUuid(); |
| 182 | 183 | } |
| 183 | 184 | |
| 184 | − queueEntityMessage(PacketTypeEntityEdit, entityID, properties); | |
| 185 | + queueEntityMessage(PacketType::EntityEdit, entityID, properties); | |
| 185 | 186 | return id; |
| 186 | 187 | } |
| 187 | 188 | |
| @@ -419,7 +420,7 @@ bool EntityScriptingInterface::setVoxels(QUuid entityID, · 231 unmodified lines | ||
| 419 | 420 | return false; |
| 420 | 421 | } |
| 421 | 422 | |
| 422 | − EntityItemPointer entity = static_cast<EntityItemPointer>(_entityTree->findEntityByEntityItemID(entityID)); | |
| 423 | + EntityItemPointer entity = _entityTree->findEntityByEntityItemID(entityID); | |
| 423 | 424 | if (!entity) { |
| 424 | 425 | qCDebug(entities) << "EntityScriptingInterface::setVoxelSphere no entity with ID" << entityID; |
| 425 | 426 | return false; |
| @@ -432,7 +433,7 @@ bool EntityScriptingInterface::setVoxels(QUuid entityID, · 6 unmodified lines | ||
| 432 | 433 | |
| 433 | 434 | auto now = usecTimestampNow(); |
| 434 | 435 | |
| 435 | − PolyVoxEntityItem* polyVoxEntity = static_cast<PolyVoxEntityItem*>(entity.get()); | |
| 436 | + auto polyVoxEntity = std::dynamic_pointer_cast<PolyVoxEntityItem>(entity); | |
| 436 | 437 | _entityTree->lockForWrite(); |
| 437 | 438 | actor(*polyVoxEntity); |
| 438 | 439 | entity->setLastEdited(now); |
| @@ -446,18 +447,29 @@ bool EntityScriptingInterface::setVoxels(QUuid entityID, · 7 unmodified lines | ||
| 446 | 447 | properties.setVoxelDataDirty(); |
| 447 | 448 | properties.setLastEdited(now); |
| 448 | 449 | |
| 449 | − queueEntityMessage(PacketTypeEntityEdit, entityID, properties); | |
| 450 | + queueEntityMessage(PacketType::EntityEdit, entityID, properties); | |
| 450 | 451 | return true; |
| 451 | 452 | } |
| 452 | 453 | |
| 453 | −bool EntityScriptingInterface::setPoints(EntityItemPointer entity, std::function<bool(LineEntityItem&)> actor) { | |
| 454 | +bool EntityScriptingInterface::setPoints(QUuid entityID, std::function<bool(LineEntityItem&)> actor) { | |
| 454 | 455 | if (!_entityTree) { |
| 455 | 456 | return false; |
| 456 | 457 | } |
| 457 | 458 | |
| 459 | + EntityItemPointer entity = static_cast<EntityItemPointer>(_entityTree->findEntityByEntityItemID(entityID)); | |
| 460 | + if (!entity) { | |
| 461 | + qCDebug(entities) << "EntityScriptingInterface::setPoints no entity with ID" << entityID; | |
| 462 | + } | |
| 463 | + | |
| 464 | + EntityTypes::EntityType entityType = entity->getType(); | |
| 465 | + | |
| 466 | + if (entityType != EntityTypes::Line) { | |
| 467 | + return false; | |
| 468 | + } | |
| 469 | + | |
| 458 | 470 | auto now = usecTimestampNow(); |
| 459 | 471 | |
| 460 | − LineEntityItem* lineEntity = static_cast<LineEntityItem*>(entity.get()); | |
| 472 | + auto lineEntity = std::static_pointer_cast<LineEntityItem>(entity); | |
| 461 | 473 | _entityTree->lockForWrite(); |
| 462 | 474 | bool success = actor(*lineEntity); |
| 463 | 475 | entity->setLastEdited(now); |
| @@ -472,30 +484,44 @@ bool EntityScriptingInterface::setPoints(EntityItemPointer entity, std::function · 8 unmodified lines | ||
| 472 | 484 | properties.setLastEdited(now); |
| 473 | 485 | |
| 474 | 486 | |
| 475 | − queueEntityMessage(PacketTypeEntityEdit, entity->getID(), properties); | |
| 487 | + queueEntityMessage(PacketType::EntityEdit, entityID, properties); | |
| 476 | 488 | return success; |
| 477 | 489 | } |
| 478 | 490 | |
| 479 | −bool EntityScriptingInterface::setPoints(EntityItemPointer entity, std::function<bool(PolyLineEntityItem&)> actor) { | |
| 491 | +bool EntityScriptingInterface::setPoints(QUuid entityID, std::function<bool(PolyLineEntityItem&)> actor) { | |
| 480 | 492 | if (!_entityTree) { |
| 481 | 493 | return false; |
| 482 | 494 | } |
| 483 | − | |
| 495 | + | |
| 496 | + EntityItemPointer entity = static_cast<EntityItemPointer>(_entityTree->findEntityByEntityItemID(entityID)); | |
| 497 | + if (!entity) { | |
| 498 | + qCDebug(entities) << "EntityScriptingInterface::setPoints no entity with ID" << entityID; | |
| 499 | + } | |
| 500 | + | |
| 501 | + EntityTypes::EntityType entityType = entity->getType(); | |
| 502 | + | |
| 503 | + if (entityType != EntityTypes::Line) { | |
| 504 | + return false; | |
| 505 | + } | |
| 506 | + | |
| 484 | 507 | auto now = usecTimestampNow(); |
| 485 | − PolyLineEntityItem* PolyLineEntity = static_cast<PolyLineEntityItem*>(entity.get()); | |
| 508 | + | |
| 509 | + auto polyLineEntity = std::static_pointer_cast<PolyLineEntityItem>(entity); | |
| 486 | 510 | _entityTree->lockForWrite(); |
| 487 | − bool success = actor(*PolyLineEntity); | |
| 511 | + bool success = actor(*polyLineEntity); | |
| 488 | 512 | entity->setLastEdited(now); |
| 489 | 513 | entity->setLastBroadcast(now); |
| 490 | 514 | _entityTree->unlock(); |
| 491 | − | |
| 515 | + | |
| 492 | 516 | _entityTree->lockForRead(); |
| 493 | 517 | EntityItemProperties properties = entity->getProperties(); |
| 494 | 518 | _entityTree->unlock(); |
| 495 | − | |
| 519 | + | |
| 496 | 520 | properties.setLinePointsDirty(); |
| 497 | 521 | properties.setLastEdited(now); |
| 498 | − queueEntityMessage(PacketTypeEntityEdit, entity->getID(), properties); | |
| 522 | + | |
| 523 | + | |
| 524 | + queueEntityMessage(PacketType::EntityEdit, entityID, properties); | |
| 499 | 525 | return success; |
| 500 | 526 | } |
| 501 | 527 | |
| @@ -526,14 +552,14 @@ bool EntityScriptingInterface::setAllPoints(QUuid entityID, const QVector<glm::v · 24 unmodified lines | ||
| 526 | 552 | EntityTypes::EntityType entityType = entity->getType(); |
| 527 | 553 | |
| 528 | 554 | if (entityType == EntityTypes::Line) { |
| 529 | − return setPoints(entity, [points](LineEntityItem& lineEntity) -> bool | |
| 555 | + return setPoints(entityID, [points](LineEntityItem& lineEntity) -> bool | |
| 530 | 556 | { |
| 531 | 557 | return lineEntity.setLinePoints(points); |
| 532 | 558 | }); |
| 533 | 559 | } |
| 534 | 560 | |
| 535 | 561 | if (entityType == EntityTypes::PolyLine) { |
| 536 | − return setPoints(entity, [points](PolyLineEntityItem& PolyLineEntity) -> bool | |
| 562 | + return setPoints(entityID, [points](PolyLineEntityItem& PolyLineEntity) -> bool | |
| 537 | 563 | { |
| 538 | 564 | return PolyLineEntity.setLinePoints(points); |
| 539 | 565 | }); |
| @@ -551,14 +577,14 @@ bool EntityScriptingInterface::appendPoint(QUuid entityID, const glm::vec3& poin · 11 unmodified lines | ||
| 551 | 577 | EntityTypes::EntityType entityType = entity->getType(); |
| 552 | 578 | |
| 553 | 579 | if (entityType == EntityTypes::Line) { |
| 554 | − return setPoints(entity, [point](LineEntityItem& lineEntity) -> bool | |
| 580 | + return setPoints(entityID, [point](LineEntityItem& lineEntity) -> bool | |
| 555 | 581 | { |
| 556 | 582 | return lineEntity.appendPoint(point); |
| 557 | 583 | }); |
| 558 | 584 | } |
| 559 | 585 | |
| 560 | 586 | if (entityType == EntityTypes::PolyLine) { |
| 561 | − return setPoints(entity, [point](PolyLineEntityItem& PolyLineEntity) -> bool | |
| 587 | + return setPoints(entityID, [point](PolyLineEntityItem& PolyLineEntity) -> bool | |
| 562 | 588 | { |
| 563 | 589 | return PolyLineEntity.appendPoint(point); |
| 564 | 590 | }); |
| @@ -603,7 +629,7 @@ bool EntityScriptingInterface::actionWorker(const QUuid& entityID, · 38 unmodified lines | ||
| 603 | 629 | properties.setActionDataDirty(); |
| 604 | 630 | auto now = usecTimestampNow(); |
| 605 | 631 | properties.setLastEdited(now); |
| 606 | − queueEntityMessage(PacketTypeEntityEdit, entityID, properties); | |
| 632 | + queueEntityMessage(PacketType::EntityEdit, entityID, properties); | |
| 607 | 633 | |
| 608 | 634 | return success; |
| 609 | 635 | } |