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 | 474 | PROFILE_RANGE(script_entities, __FUNCTION__); |
| 475 | 475 | |
| 476 | 476 | _activityTracking.addedEntityCount++; |
| @@ -479,9 +479,13 @@ QUuid EntityScriptingInterface::addEntity(const EntityItemProperties& properties · 2 unmodified lines | ||
| 479 | 479 | const auto sessionID = nodeList->getSessionUUID(); |
| 480 | 480 | |
| 481 | 481 | EntityItemProperties propertiesWithSimID = properties; |
| 482 | − if (clientOnly) { | |
| 483 | − propertiesWithSimID.setClientOnly(clientOnly); | |
| 482 | + propertiesWithSimID.setEntityHostTypeFromString(entityHostTypeString); | |
| 483 | + if (propertiesWithSimID.getEntityHostType() == entity::HostType::AVATAR) { | |
| 484 | 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 | 491 | propertiesWithSimID.setLastEditedBy(sessionID); |
| @@ -570,8 +574,11 @@ QUuid EntityScriptingInterface::cloneEntity(QUuid entityIDToClone) { · 82 unmodified lines | ||
| 570 | 574 | bool cloneAvatarEntity = properties.getCloneAvatarEntity(); |
| 571 | 575 | properties.convertToCloneProperties(entityIDToClone); |
| 572 | 576 | |
| 573 | − if (cloneAvatarEntity) { | |
| 574 | − return addEntity(properties, true); | |
| 577 | + if (properties.getEntityHostType() == entity::HostType::LOCAL) { | |
| 578 | + // Local entities are only cloned locally | |
| 579 | + return addEntity(properties, "local"); | |
| 580 | + } else if (cloneAvatarEntity) { | |
| 581 | + return addEntity(properties, "avatar"); | |
| 575 | 582 | } else { |
| 576 | 583 | // setLastEdited timestamp to 0 to ensure this entity gets updated with the properties |
| 577 | 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 | 690 | psuedoPropertyFlags.set(EntityPsuedoPropertyFlag::ClientOnly); |
| 684 | 691 | } else if (extendedPropertyString == "owningAvatarID") { |
| 685 | 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 | 697 | } else if (extendedPropertyString == "faceCamera") { |
| 687 | 698 | psuedoPropertyFlags.set(EntityPsuedoPropertyFlag::FaceCamera); |
| 688 | 699 | } else if (extendedPropertyString == "isFacingAvatar") { |
| @@ -790,7 +801,7 @@ QUuid EntityScriptingInterface::editEntity(QUuid id, const EntityItemProperties& · 101 unmodified lines | ||
| 790 | 801 | return; |
| 791 | 802 | } |
| 792 | 803 | |
| 793 | − if (entity->getClientOnly() && entity->getOwningAvatarID() != sessionID) { | |
| 804 | + if (entity->isAvatarEntity() && entity->getOwningAvatarID() != sessionID) { | |
| 794 | 805 | // don't edit other avatar's avatarEntities |
| 795 | 806 | properties = EntityItemProperties(); |
| 796 | 807 | return; |
| @@ -833,7 +844,11 @@ QUuid EntityScriptingInterface::editEntity(QUuid id, const EntityItemProperties& · 36 unmodified lines | ||
| 833 | 844 | } |
| 834 | 845 | |
| 835 | 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 | 852 | properties.setOwningAvatarID(entity->getOwningAvatarID()); |
| 838 | 853 | |
| 839 | 854 | properties.setActionData(entity->getDynamicData()); |
| @@ -960,7 +975,7 @@ void EntityScriptingInterface::deleteEntity(QUuid id) { · 120 unmodified lines | ||
| 960 | 975 | |
| 961 | 976 | auto nodeList = DependencyManager::get<NodeList>(); |
| 962 | 977 | const QUuid myNodeID = nodeList->getSessionUUID(); |
| 963 | − if (entity->getClientOnly() && entity->getOwningAvatarID() != myNodeID) { | |
| 978 | + if (entity->isAvatarEntity() && entity->getOwningAvatarID() != myNodeID) { | |
| 964 | 979 | // don't delete other avatar's avatarEntities |
| 965 | 980 | shouldSendDeleteToServer = false; |
| 966 | 981 | return; |
| @@ -970,11 +985,11 @@ void EntityScriptingInterface::deleteEntity(QUuid id) { · 3 unmodified lines | ||
| 970 | 985 | shouldSendDeleteToServer = false; |
| 971 | 986 | } else { |
| 972 | 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 | 989 | shouldSendDeleteToServer = false; |
| 975 | 990 | _entityTree->deleteEntity(entityID); |
| 976 | 991 | |
| 977 | − if (entity->getClientOnly() && getEntityPacketSender()->getMyAvatar()) { | |
| 992 | + if (entity->isAvatarEntity() && getEntityPacketSender()->getMyAvatar()) { | |
| 978 | 993 | getEntityPacketSender()->getMyAvatar()->clearAvatarEntity(entityID, false); |
| 979 | 994 | } |
| 980 | 995 | } |
| @@ -1641,14 +1656,14 @@ bool EntityScriptingInterface::actionWorker(const QUuid& entityID, · 660 unmodified lines | ||
| 1641 | 1656 | return; |
| 1642 | 1657 | } |
| 1643 | 1658 | |
| 1644 | − if (entity->getClientOnly() && entity->getOwningAvatarID() != myNodeID) { | |
| 1659 | + if (entity->isAvatarEntity() && entity->getOwningAvatarID() != myNodeID) { | |
| 1645 | 1660 | return; |
| 1646 | 1661 | } |
| 1647 | 1662 | |
| 1648 | 1663 | doTransmit = actor(simulation, entity); |
| 1649 | 1664 | _entityTree->entityChanged(entity); |
| 1650 | 1665 | if (doTransmit) { |
| 1651 | − properties.setClientOnly(entity->getClientOnly()); | |
| 1666 | + properties.setEntityHostType(entity->getEntityHostType()); | |
| 1652 | 1667 | properties.setOwningAvatarID(entity->getOwningAvatarID()); |
| 1653 | 1668 | } |
| 1654 | 1669 | }); |