mirror of
https://github.com/lubosz/overte.git
synced 2025-04-16 09:29:16 +02:00
fixed persist issue, working much better
This commit is contained in:
parent
5ca80803c0
commit
cf780b3b73
7 changed files with 22 additions and 56 deletions
|
@ -72,6 +72,7 @@ OctreePointer EntityServer::createTree() {
|
|||
|
||||
DependencyManager::registerInheritance<SpatialParentFinder, AssignmentParentFinder>();
|
||||
DependencyManager::set<AssignmentParentFinder>(tree);
|
||||
DependencyManager::set<EntityEditFilters>(std::static_pointer_cast<EntityTree>(tree));
|
||||
|
||||
return tree;
|
||||
}
|
||||
|
@ -294,12 +295,12 @@ void EntityServer::readAdditionalConfiguration(const QJsonObject& settingsSectio
|
|||
tree->setEntityScriptSourceWhitelist("");
|
||||
}
|
||||
|
||||
auto entityEditFilters = tree->createEntityEditFilters();
|
||||
auto entityEditFilters = DependencyManager::get<EntityEditFilters>();
|
||||
|
||||
QString filterURL;
|
||||
if (readOptionString("entityEditFilter", settingsSectionObject, filterURL) && !filterURL.isEmpty()) {
|
||||
// connect the filterAdded signal, and block edits until you hear back
|
||||
connect(entityEditFilters, &EntityEditFilters::filterAdded, this, &EntityServer::entityFilterAdded);
|
||||
connect(entityEditFilters.data(), &EntityEditFilters::filterAdded, this, &EntityServer::entityFilterAdded);
|
||||
|
||||
entityEditFilters->rejectAll(true);
|
||||
entityEditFilters->addFilter(EntityItemID(), filterURL);
|
||||
|
|
|
@ -55,9 +55,6 @@ bool EntityEditFilters::filter(glm::vec3& position, EntityItemProperties& proper
|
|||
qCDebug(entities) << zoneID << ",";
|
||||
}
|
||||
|
||||
auto oldProperties = propertiesIn.getDesiredProperties();
|
||||
auto specifiedProperties = propertiesIn.getChangedProperties();
|
||||
propertiesIn.setDesiredProperties(specifiedProperties);
|
||||
for (auto it = zoneIDs.begin(); it != zoneIDs.end(); it++) {
|
||||
qCDebug(entities) << "applying filter for zone" << *it;
|
||||
|
||||
|
@ -70,6 +67,9 @@ bool EntityEditFilters::filter(glm::vec3& position, EntityItemProperties& proper
|
|||
qCDebug(entities) << "pair: " << (qint64) pair << ", engine" << (qint64)engine;
|
||||
if (pair != nullptr && engine != nullptr) {
|
||||
|
||||
auto oldProperties = propertiesIn.getDesiredProperties();
|
||||
auto specifiedProperties = propertiesIn.getChangedProperties();
|
||||
propertiesIn.setDesiredProperties(specifiedProperties);
|
||||
QScriptValue inputValues = propertiesIn.copyToScriptValue(engine, false, true, true);
|
||||
propertiesIn.setDesiredProperties(oldProperties);
|
||||
|
||||
|
@ -122,12 +122,19 @@ void EntityEditFilters::addFilter(EntityItemID& entityID, QString filterURL) {
|
|||
|
||||
QUrl scriptURL(filterURL);
|
||||
|
||||
// setting it to an empty string is same as removing
|
||||
if (filterURL.size() == 0) {
|
||||
removeFilter(entityID);
|
||||
return;
|
||||
}
|
||||
|
||||
// The following should be abstracted out for use in Agent.cpp (and maybe later AvatarMixer.cpp)
|
||||
if (scriptURL.scheme().isEmpty() || (scriptURL.scheme() == URL_SCHEME_FILE)) {
|
||||
qWarning() << "Cannot load script from local filesystem, because assignment may be on a different computer.";
|
||||
scriptRequestFinished(entityID);
|
||||
return;
|
||||
}
|
||||
|
||||
// first remove any existing info for this entity
|
||||
removeFilter(entityID);
|
||||
|
||||
|
@ -143,7 +150,6 @@ void EntityEditFilters::addFilter(EntityItemID& entityID, QString filterURL) {
|
|||
qInfo() << "Requesting script at URL" << qPrintable(scriptRequest->getUrl().toString());
|
||||
scriptRequest->send();
|
||||
qDebug() << "script request sent for entity " << entityID;
|
||||
|
||||
}
|
||||
|
||||
// Copied from ScriptEngine.cpp. We should make this a class method for reuse.
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
|
||||
typedef QPair<QScriptValue, std::function<bool()>> FilterFunctionPair;
|
||||
|
||||
class EntityEditFilters : public QObject {
|
||||
class EntityEditFilters : public QObject, public Dependency {
|
||||
Q_OBJECT
|
||||
public:
|
||||
EntityEditFilters() {};
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include "RegisteredMetaTypes.h"
|
||||
#include "EntityItemID.h"
|
||||
|
||||
int entityItemIDTypeID = qRegisterMetaType<EntityItemID>();
|
||||
|
||||
EntityItemID::EntityItemID() : QUuid()
|
||||
{
|
||||
|
|
|
@ -924,36 +924,12 @@ void EntityTree::fixupTerseEditLogging(EntityItemProperties& properties, QList<Q
|
|||
}
|
||||
}
|
||||
|
||||
void EntityTree::initEntityEditFilterEngine(QScriptEngine* engine, std::function<bool()> entityEditFilterHadUncaughtExceptions) {
|
||||
_entityEditFilterEngine = engine;
|
||||
_entityEditFilterHadUncaughtExceptions = entityEditFilterHadUncaughtExceptions;
|
||||
auto global = _entityEditFilterEngine->globalObject();
|
||||
_entityEditFilterFunction = global.property("filter");
|
||||
if (!_entityEditFilterFunction.isFunction()) {
|
||||
qCDebug(entities) << "Filter function specified but not found. Will reject all edits.";
|
||||
_entityEditFilterEngine = nullptr; // So that we don't try to call it. See filterProperties.
|
||||
}
|
||||
auto entitiesObject = _entityEditFilterEngine->newObject();
|
||||
entitiesObject.setProperty("ADD_FILTER_TYPE", FilterType::Add);
|
||||
entitiesObject.setProperty("EDIT_FILTER_TYPE", FilterType::Edit);
|
||||
entitiesObject.setProperty("PHYSICS_FILTER_TYPE", FilterType::Physics);
|
||||
global.setProperty("Entities", entitiesObject);
|
||||
_hasEntityEditFilter = true;
|
||||
}
|
||||
|
||||
bool EntityTree::filterProperties(EntityItemPointer& existingEntity, EntityItemProperties& propertiesIn, EntityItemProperties& propertiesOut, bool& wasChanged, FilterType filterType) {
|
||||
if (!_entityEditFilterEngine && !_entityEditFilters) {
|
||||
propertiesOut = propertiesIn;
|
||||
wasChanged = false; // not changed
|
||||
if (_hasEntityEditFilter) {
|
||||
qCDebug(entities) << "Rejecting properties because filter has not been set.";
|
||||
return false;
|
||||
}
|
||||
return true; // allowed
|
||||
}
|
||||
bool accepted = true;
|
||||
if (_entityEditFilters) {
|
||||
accepted = _entityEditFilters->filter(existingEntity->getPosition(), propertiesIn, propertiesOut, wasChanged, filterType);
|
||||
auto entityEditFilters = DependencyManager::get<EntityEditFilters>();
|
||||
if (entityEditFilters) {
|
||||
accepted = entityEditFilters->filter(existingEntity->getPosition(), propertiesIn, propertiesOut, wasChanged, filterType);
|
||||
}
|
||||
|
||||
return accepted;
|
||||
|
@ -1749,7 +1725,3 @@ QStringList EntityTree::getJointNames(const QUuid& entityID) const {
|
|||
return entity->getJointNames();
|
||||
}
|
||||
|
||||
EntityEditFilters* EntityTree::createEntityEditFilters() {
|
||||
_entityEditFilters = new EntityEditFilters(getThisPointer());
|
||||
return _entityEditFilters;
|
||||
}
|
||||
|
|
|
@ -272,12 +272,6 @@ public:
|
|||
|
||||
void notifyNewCollisionSoundURL(const QString& newCollisionSoundURL, const EntityItemID& entityID);
|
||||
|
||||
void initEntityEditFilterEngine(QScriptEngine* engine, std::function<bool()> entityEditFilterHadUncaughtExceptions);
|
||||
void setHasEntityFilter(bool hasFilter) { _hasEntityEditFilter = hasFilter; }
|
||||
|
||||
EntityEditFilters* createEntityEditFilters();
|
||||
EntityEditFilters* getEntityEditFilters() { return _entityEditFilters; }
|
||||
|
||||
static const float DEFAULT_MAX_TMP_ENTITY_LIFETIME;
|
||||
|
||||
public slots:
|
||||
|
@ -368,13 +362,7 @@ protected:
|
|||
|
||||
bool filterProperties(EntityItemPointer& existingEntity, EntityItemProperties& propertiesIn, EntityItemProperties& propertiesOut, bool& wasChanged, FilterType filterType);
|
||||
bool _hasEntityEditFilter{ false };
|
||||
QScriptEngine* _entityEditFilterEngine{};
|
||||
QScriptValue _entityEditFilterFunction{};
|
||||
QScriptValue _nullObjectForFilter{};
|
||||
std::function<bool()> _entityEditFilterHadUncaughtExceptions;
|
||||
|
||||
QStringList _entityScriptSourceWhitelist;
|
||||
EntityEditFilters* _entityEditFilters{};
|
||||
};
|
||||
|
||||
#endif // hifi_EntityTree_h
|
||||
|
|
|
@ -226,12 +226,10 @@ bool ZoneEntityItem::findDetailedRayIntersection(const glm::vec3& origin, const
|
|||
|
||||
void ZoneEntityItem::setFilterURL(QString url) {
|
||||
_filterURL = url;
|
||||
if (getTree()) {
|
||||
auto entityEditFilters = getTree()->getEntityEditFilters();
|
||||
if (entityEditFilters) {
|
||||
qCDebug(entities) << "adding filter " << url << "for zone" << getEntityItemID();
|
||||
entityEditFilters->addFilter(getEntityItemID(), url);
|
||||
}
|
||||
if (DependencyManager::isSet<EntityEditFilters>()) {
|
||||
auto entityEditFilters = DependencyManager::get<EntityEditFilters>();
|
||||
qCDebug(entities) << "adding filter " << url << "for zone" << getEntityItemID();
|
||||
entityEditFilters->addFilter(getEntityItemID(), url);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue