Showing the changes to libraries/entities/src/EntityScriptingInterface.cpp (1 of 27 files). Show all
Unified · Split
| @@ -470,7 +470,7 @@ void synchronizeEditedGrabProperties(EntityItemProperties& properties, const QSt · 469 unmodified lines | |||
| 470 | } | 470 | } |
| 471 | 471 | ||
| 472 | 472 | ||
| 473 | QUuid EntityScriptingInterface::addEntity(const EntityItemProperties& properties, bool clientOnly) { | 473 | QUuid EntityScriptingInterface::addEntity(const EntityItemProperties& properties, const QString& entityHostTypeString) { |
| 474 | PROFILE_RANGE(script_entities, __FUNCTION__); | 474 | PROFILE_RANGE(script_entities, __FUNCTION__); |
| 475 | 475 | ||
| 476 | _activityTracking.addedEntityCount++; | 476 | _activityTracking.addedEntityCount++; |
| @@ -479,9 +479,13 @@ QUuid EntityScriptingInterface::addEntity(const EntityItemProperties& properties · 2 unmodified lines | |||
| 479 | const auto sessionID = nodeList->getSessionUUID(); | 479 | const auto sessionID = nodeList->getSessionUUID(); |
| 480 | 480 | ||
| 481 | EntityItemProperties propertiesWithSimID = properties; | 481 | EntityItemProperties propertiesWithSimID = properties; |
| 482 | if (clientOnly) { | 482 | propertiesWithSimID.setEntityHostTypeFromString(entityHostTypeString); |
| 483 | propertiesWithSimID.setClientOnly(clientOnly); | 483 | if (propertiesWithSimID.getEntityHostType() == entity::HostType::AVATAR) { |
| 484 | propertiesWithSimID.setOwningAvatarID(sessionID); | 484 | propertiesWithSimID.setOwningAvatarID(sessionID); |
| 485 | } else if (propertiesWithSimID.getEntityHostType() == entity::HostType::LOCAL) { | ||
| 486 | // For now, local entities are always collisionless | ||
| 487 | // TODO: create a separate, local physics simulation that just handles local entities (and MyAvatar?) | ||
| 488 | propertiesWithSimID.setCollisionless(true); | ||
| 485 | } | 489 | } |
| 486 | 490 | ||
| 487 | propertiesWithSimID.setLastEditedBy(sessionID); | 491 | propertiesWithSimID.setLastEditedBy(sessionID); |
| @@ -570,8 +574,11 @@ QUuid EntityScriptingInterface::cloneEntity(QUuid entityIDToClone) { · 82 unmodified lines | |||
| 570 | bool cloneAvatarEntity = properties.getCloneAvatarEntity(); | 574 | bool cloneAvatarEntity = properties.getCloneAvatarEntity(); |
| 571 | properties.convertToCloneProperties(entityIDToClone); | 575 | properties.convertToCloneProperties(entityIDToClone); |
| 572 | 576 | ||
| 573 | if (cloneAvatarEntity) { | 577 | if (properties.getEntityHostType() == entity::HostType::LOCAL) { |
| 574 | return addEntity(properties, true); | 578 | // Local entities are only cloned locally |
| 579 | return addEntity(properties, "local"); | ||
| 580 | } else if (cloneAvatarEntity) { | ||
| 581 | return addEntity(properties, "avatar"); | ||
| 575 | } else { | 582 | } else { |
| 576 | // setLastEdited timestamp to 0 to ensure this entity gets updated with the properties | 583 | // setLastEdited timestamp to 0 to ensure this entity gets updated with the properties |
| 577 | // from the server-created entity, don't change this unless you know what you are doing | 584 | // from the server-created entity, don't change this unless you know what you are doing |
| @@ -683,6 +690,10 @@ QScriptValue EntityScriptingInterface::getMultipleEntityPropertiesInternal(QScri · 105 unmodified lines | |||
| 683 | psuedoPropertyFlags.set(EntityPsuedoPropertyFlag::ClientOnly); | 690 | psuedoPropertyFlags.set(EntityPsuedoPropertyFlag::ClientOnly); |
| 684 | } else if (extendedPropertyString == "owningAvatarID") { | 691 | } else if (extendedPropertyString == "owningAvatarID") { |
| 685 | psuedoPropertyFlags.set(EntityPsuedoPropertyFlag::OwningAvatarID); | 692 | psuedoPropertyFlags.set(EntityPsuedoPropertyFlag::OwningAvatarID); |
| 693 | } else if (extendedPropertyString == "avatarEntity") { | ||
| 694 | psuedoPropertyFlags.set(EntityPsuedoPropertyFlag::AvatarEntity); | ||
| 695 | } else if (extendedPropertyString == "localEntity") { | ||
| 696 | psuedoPropertyFlags.set(EntityPsuedoPropertyFlag::LocalEntity); | ||
| 686 | } else if (extendedPropertyString == "faceCamera") { | 697 | } else if (extendedPropertyString == "faceCamera") { |
| 687 | psuedoPropertyFlags.set(EntityPsuedoPropertyFlag::FaceCamera); | 698 | psuedoPropertyFlags.set(EntityPsuedoPropertyFlag::FaceCamera); |
| 688 | } else if (extendedPropertyString == "isFacingAvatar") { | 699 | } else if (extendedPropertyString == "isFacingAvatar") { |
| @@ -790,7 +801,7 @@ QUuid EntityScriptingInterface::editEntity(QUuid id, const EntityItemProperties& · 101 unmodified lines | |||
| 790 | return; | 801 | return; |
| 791 | } | 802 | } |
| 792 | 803 | ||
| 793 | if (entity->getClientOnly() && entity->getOwningAvatarID() != sessionID) { | 804 | if (entity->isAvatarEntity() && entity->getOwningAvatarID() != sessionID) { |
| 794 | // don't edit other avatar's avatarEntities | 805 | // don't edit other avatar's avatarEntities |
| 795 | properties = EntityItemProperties(); | 806 | properties = EntityItemProperties(); |
| 796 | return; | 807 | return; |
| @@ -833,7 +844,11 @@ QUuid EntityScriptingInterface::editEntity(QUuid id, const EntityItemProperties& · 36 unmodified lines | |||
| 833 | } | 844 | } |
| 834 | 845 | ||
| 835 | // set these to make EntityItemProperties::getScalesWithParent() work correctly | 846 | // set these to make EntityItemProperties::getScalesWithParent() work correctly |
| 836 | properties.setClientOnly(entity->getClientOnly()); | 847 | entity::HostType entityHostType = entity->getEntityHostType(); |
| 848 | properties.setEntityHostType(entityHostType); | ||
| 849 | if (entityHostType == entity::HostType::LOCAL) { | ||
| 850 | properties.setCollisionless(true); | ||
| 851 | } | ||
| 837 | properties.setOwningAvatarID(entity->getOwningAvatarID()); | 852 | properties.setOwningAvatarID(entity->getOwningAvatarID()); |
| 838 | 853 | ||
| 839 | properties.setActionData(entity->getDynamicData()); | 854 | properties.setActionData(entity->getDynamicData()); |
| @@ -960,7 +975,7 @@ void EntityScriptingInterface::deleteEntity(QUuid id) { · 120 unmodified lines | |||
| 960 | 975 | ||
| 961 | auto nodeList = DependencyManager::get<NodeList>(); | 976 | auto nodeList = DependencyManager::get<NodeList>(); |
| 962 | const QUuid myNodeID = nodeList->getSessionUUID(); | 977 | const QUuid myNodeID = nodeList->getSessionUUID(); |
| 963 | if (entity->getClientOnly() && entity->getOwningAvatarID() != myNodeID) { | 978 | if (entity->isAvatarEntity() && entity->getOwningAvatarID() != myNodeID) { |
| 964 | // don't delete other avatar's avatarEntities | 979 | // don't delete other avatar's avatarEntities |
| 965 | shouldSendDeleteToServer = false; | 980 | shouldSendDeleteToServer = false; |
| 966 | return; | 981 | return; |
| @@ -970,11 +985,11 @@ void EntityScriptingInterface::deleteEntity(QUuid id) { · 3 unmodified lines | |||
| 970 | shouldSendDeleteToServer = false; | 985 | shouldSendDeleteToServer = false; |
| 971 | } else { | 986 | } else { |
| 972 | // only delete local entities, server entities will round trip through the server filters | 987 | // only delete local entities, server entities will round trip through the server filters |
| 973 | if (entity->getClientOnly() || _entityTree->isServerlessMode()) { | 988 | if (entity->isAvatarEntity() || _entityTree->isServerlessMode()) { |
| 974 | shouldSendDeleteToServer = false; | 989 | shouldSendDeleteToServer = false; |
| 975 | _entityTree->deleteEntity(entityID); | 990 | _entityTree->deleteEntity(entityID); |
| 976 | 991 | ||
| 977 | if (entity->getClientOnly() && getEntityPacketSender()->getMyAvatar()) { | 992 | if (entity->isAvatarEntity() && getEntityPacketSender()->getMyAvatar()) { |
| 978 | getEntityPacketSender()->getMyAvatar()->clearAvatarEntity(entityID, false); | 993 | getEntityPacketSender()->getMyAvatar()->clearAvatarEntity(entityID, false); |
| 979 | } | 994 | } |
| 980 | } | 995 | } |
| @@ -1641,14 +1656,14 @@ bool EntityScriptingInterface::actionWorker(const QUuid& entityID, · 660 unmodified lines | |||
| 1641 | return; | 1656 | return; |
| 1642 | } | 1657 | } |
| 1643 | 1658 | ||
| 1644 | if (entity->getClientOnly() && entity->getOwningAvatarID() != myNodeID) { | 1659 | if (entity->isAvatarEntity() && entity->getOwningAvatarID() != myNodeID) { |
| 1645 | return; | 1660 | return; |
| 1646 | } | 1661 | } |
| 1647 | 1662 | ||
| 1648 | doTransmit = actor(simulation, entity); | 1663 | doTransmit = actor(simulation, entity); |
| 1649 | _entityTree->entityChanged(entity); | 1664 | _entityTree->entityChanged(entity); |
| 1650 | if (doTransmit) { | 1665 | if (doTransmit) { |
| 1651 | properties.setClientOnly(entity->getClientOnly()); | 1666 | properties.setEntityHostType(entity->getEntityHostType()); |
| 1652 | properties.setOwningAvatarID(entity->getOwningAvatarID()); | 1667 | properties.setOwningAvatarID(entity->getOwningAvatarID()); |
| 1653 | } | 1668 | } |
| 1654 | }); | 1669 | }); |