本文整理汇总了C++中EntityTreePointer::withWriteLock方法的典型用法代码示例。如果您正苦于以下问题:C++ EntityTreePointer::withWriteLock方法的具体用法?C++ EntityTreePointer::withWriteLock怎么用?C++ EntityTreePointer::withWriteLock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EntityTreePointer
的用法示例。
在下文中一共展示了EntityTreePointer::withWriteLock方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: removeDeadAvatarEntities
void AvatarManager::removeDeadAvatarEntities(const SetOfEntities& deadEntities) {
auto treeRenderer = DependencyManager::get<EntityTreeRenderer>();
EntityTreePointer entityTree = treeRenderer ? treeRenderer->getTree() : nullptr;
for (auto entity : deadEntities) {
QUuid entityOwnerID = entity->getOwningAvatarID();
AvatarSharedPointer avatar = getAvatarBySessionID(entityOwnerID);
const bool REQUIRES_REMOVAL_FROM_TREE = false;
if (avatar) {
avatar->clearAvatarEntity(entity->getID(), REQUIRES_REMOVAL_FROM_TREE);
}
if (entityTree && entity->isMyAvatarEntity()) {
entityTree->withWriteLock([&] {
// We only need to delete the direct children (rather than the descendants) because
// when the child is deleted, it will take care of its own children. If the child
// is also an avatar-entity, we'll end up back here. If it's not, the entity-server
// will take care of it in the usual way.
entity->forEachChild([&](SpatiallyNestablePointer child) {
EntityItemPointer childEntity = std::dynamic_pointer_cast<EntityItem>(child);
if (childEntity) {
entityTree->deleteEntity(childEntity->getID(), true, true);
if (avatar) {
avatar->clearAvatarEntity(childEntity->getID(), REQUIRES_REMOVAL_FROM_TREE);
}
}
});
});
}
}
}
示例2: addAvatarEntities
void addAvatarEntities(const QVariantList& avatarEntities) {
auto nodeList = DependencyManager::get<NodeList>();
const QUuid myNodeID = nodeList->getSessionUUID();
EntityTreePointer entityTree = DependencyManager::get<EntityTreeRenderer>()->getTree();
if (!entityTree) {
return;
}
EntitySimulationPointer entitySimulation = entityTree->getSimulation();
PhysicalEntitySimulationPointer physicalEntitySimulation = std::static_pointer_cast<PhysicalEntitySimulation>(entitySimulation);
EntityEditPacketSender* entityPacketSender = physicalEntitySimulation->getPacketSender();
QScriptEngine scriptEngine;
for (int index = 0; index < avatarEntities.count(); index++) {
const QVariantMap& avatarEntityProperties = avatarEntities.at(index).toMap();
QVariant variantProperties = avatarEntityProperties["properties"];
QVariantMap asMap = variantProperties.toMap();
QScriptValue scriptProperties = variantMapToScriptValue(asMap, scriptEngine);
EntityItemProperties entityProperties;
EntityItemPropertiesFromScriptValueHonorReadOnly(scriptProperties, entityProperties);
entityProperties.setParentID(myNodeID);
entityProperties.setClientOnly(true);
entityProperties.setOwningAvatarID(myNodeID);
entityProperties.setSimulationOwner(myNodeID, AVATAR_ENTITY_SIMULATION_PRIORITY);
entityProperties.markAllChanged();
EntityItemID id = EntityItemID(QUuid::createUuid());
bool success = true;
entityTree->withWriteLock([&] {
EntityItemPointer entity = entityTree->addEntity(id, entityProperties);
if (entity) {
if (entityProperties.queryAACubeRelatedPropertyChanged()) {
// due to parenting, the server may not know where something is in world-space, so include the bounding cube.
bool success;
AACube queryAACube = entity->getQueryAACube(success);
if (success) {
entityProperties.setQueryAACube(queryAACube);
}
}
entity->setLastBroadcast(usecTimestampNow());
// since we're creating this object we will immediately volunteer to own its simulation
entity->flagForOwnershipBid(VOLUNTEER_SIMULATION_PRIORITY);
entityProperties.setLastEdited(entity->getLastEdited());
} else {
qCDebug(entities) << "AvatarEntitiesBookmark failed to add new Entity to local Octree";
success = false;
}
});
if (success) {
entityPacketSender->queueEditEntityMessage(PacketType::EntityAdd, entityTree, id, entityProperties);
}
}
}