mirror of
https://github.com/lubosz/overte.git
synced 2025-04-07 15:22:09 +02:00
cleanup
This commit is contained in:
parent
aa82ad8855
commit
a3d86a0242
4 changed files with 41 additions and 33 deletions
|
@ -245,7 +245,7 @@ void EntityEditFilters::scriptRequestFinished(EntityItemID entityID) {
|
|||
entitiesObject.setProperty("ADD_FILTER_TYPE", EntityTree::FilterType::Add);
|
||||
entitiesObject.setProperty("EDIT_FILTER_TYPE", EntityTree::FilterType::Edit);
|
||||
entitiesObject.setProperty("PHYSICS_FILTER_TYPE", EntityTree::FilterType::Physics);
|
||||
entitiesObject.setProperty("ERASE_FILTER_TYPE", EntityTree::FilterType::Erase);
|
||||
entitiesObject.setProperty("DELETE_FILTER_TYPE", EntityTree::FilterType::Delete);
|
||||
global.setProperty("Entities", entitiesObject);
|
||||
filterData.filterFn = global.property("filter");
|
||||
if (!filterData.filterFn.isFunction()) {
|
||||
|
|
|
@ -1850,6 +1850,37 @@ void EntityTree::forgetEntitiesDeletedBefore(quint64 sinceTime) {
|
|||
}
|
||||
|
||||
|
||||
bool EntityTree::shouldEraseEntity(EntityItemID entityID, const SharedNodePointer& sourceNode) {
|
||||
EntityItemPointer existingEntity;
|
||||
|
||||
auto startLookup = usecTimestampNow();
|
||||
existingEntity = findEntityByEntityItemID(entityID);
|
||||
auto endLookup = usecTimestampNow();
|
||||
_totalLookupTime += endLookup - startLookup;
|
||||
|
||||
auto startFilter = usecTimestampNow();
|
||||
FilterType filterType = FilterType::Delete;
|
||||
EntityItemProperties dummyProperties;
|
||||
bool wasChanged = false;
|
||||
|
||||
bool allowed = (sourceNode->isAllowedEditor()) || filterProperties(existingEntity, dummyProperties, dummyProperties, wasChanged, filterType);
|
||||
auto endFilter = usecTimestampNow();
|
||||
|
||||
_totalFilterTime += endFilter - startFilter;
|
||||
|
||||
if (allowed) {
|
||||
if (wantEditLogging() || wantTerseEditLogging()) {
|
||||
qCDebug(entities) << "User [" << sourceNode->getUUID() << "] deleting entity. ID:" << entityID;
|
||||
}
|
||||
}
|
||||
else if (wantEditLogging() || wantTerseEditLogging()) {
|
||||
qCDebug(entities) << "User [" << sourceNode->getUUID() << "] attempted to deleteentity. ID:" << entityID << " Filter rejected erase.";
|
||||
}
|
||||
|
||||
return allowed;
|
||||
}
|
||||
|
||||
|
||||
// TODO: consider consolidating processEraseMessageDetails() and processEraseMessage()
|
||||
int EntityTree::processEraseMessage(ReceivedMessage& message, const SharedNodePointer& sourceNode) {
|
||||
#ifdef EXTRA_ERASE_DEBUGGING
|
||||
|
@ -1877,12 +1908,10 @@ int EntityTree::processEraseMessage(ReceivedMessage& message, const SharedNodePo
|
|||
#endif
|
||||
|
||||
EntityItemID entityItemID(entityID);
|
||||
entityItemIDsToDelete << entityItemID;
|
||||
|
||||
if (wantEditLogging() || wantTerseEditLogging()) {
|
||||
qCDebug(entities) << "User [" << sourceNode->getUUID() << "] deleting entity. ID:" << entityItemID;
|
||||
if (shouldEraseEntity(entityID, sourceNode)) {
|
||||
entityItemIDsToDelete << entityItemID;
|
||||
}
|
||||
|
||||
}
|
||||
deleteEntities(entityItemIDsToDelete, true, true);
|
||||
}
|
||||
|
@ -1929,33 +1958,10 @@ int EntityTree::processEraseMessageDetails(const QByteArray& dataByteArray, cons
|
|||
|
||||
EntityItemID entityItemID(entityID);
|
||||
|
||||
EntityItemPointer existingEntity;
|
||||
|
||||
auto startLookup = usecTimestampNow();
|
||||
existingEntity = findEntityByEntityItemID(entityItemID);
|
||||
auto endLookup = usecTimestampNow();
|
||||
_totalLookupTime += endLookup - startLookup;
|
||||
|
||||
auto startFilter = usecTimestampNow();
|
||||
FilterType filterType = FilterType::Erase;
|
||||
EntityItemProperties dummyProperties;
|
||||
bool wasChanged = false;
|
||||
|
||||
bool allowed = (sourceNode->isAllowedEditor()) || filterProperties(existingEntity, dummyProperties, dummyProperties, wasChanged, filterType);
|
||||
auto endFilter = usecTimestampNow();
|
||||
|
||||
_totalFilterTime += endFilter - startFilter;
|
||||
|
||||
if (allowed) {
|
||||
if (shouldEraseEntity(entityID, sourceNode)) {
|
||||
entityItemIDsToDelete << entityItemID;
|
||||
if (wantEditLogging() || wantTerseEditLogging()) {
|
||||
qCDebug(entities) << "User [" << sourceNode->getUUID() << "] deleting entity. ID:" << entityItemID;
|
||||
}
|
||||
} else if (wantEditLogging() || wantTerseEditLogging()) {
|
||||
qCDebug(entities) << "User [" << sourceNode->getUUID() << "] attempted to deleteentity. ID:" << entityItemID << " Filter rejected erase.";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
deleteEntities(entityItemIDsToDelete, true, true);
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ public:
|
|||
Add,
|
||||
Edit,
|
||||
Physics,
|
||||
Erase
|
||||
Delete
|
||||
};
|
||||
EntityTree(bool shouldReaverage = false);
|
||||
virtual ~EntityTree();
|
||||
|
@ -194,6 +194,8 @@ public:
|
|||
|
||||
int processEraseMessage(ReceivedMessage& message, const SharedNodePointer& sourceNode);
|
||||
int processEraseMessageDetails(const QByteArray& buffer, const SharedNodePointer& sourceNode);
|
||||
bool shouldEraseEntity(EntityItemID entityID, const SharedNodePointer& sourceNode);
|
||||
|
||||
|
||||
EntityTreeElementPointer getContainingElement(const EntityItemID& entityItemID) /*const*/;
|
||||
void addEntityMapEntry(EntityItemPointer entity);
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
//
|
||||
// prevent-erase-in-zone-example.js
|
||||
// prevent-delete-in-zone-example.js
|
||||
//
|
||||
//
|
||||
// Created by Brad Hefta-Gaub to use Entities on Jan. 25, 2018
|
||||
// Copyright 2018 High Fidelity, Inc.
|
||||
//
|
||||
// This sample entity edit filter script will keep prevent any entity inside the zone from being erased.
|
||||
// This sample entity edit filter script will keep prevent any entity inside the zone from being deleted.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
|
@ -13,7 +13,7 @@
|
|||
|
||||
function filter(properties, type, originalProperties, zoneProperties) {
|
||||
|
||||
if (type == Entities.ERASE_FILTER_TYPE) {
|
||||
if (type == Entities.DELETE_FILTER_TYPE) {
|
||||
return false;
|
||||
}
|
||||
return properties;
|
Loading…
Reference in a new issue