mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 16:18:05 +02:00
refactor bumpTimestamp, and fix implementation of wasChanged
This commit is contained in:
parent
d9182cd38d
commit
2e9b26057e
2 changed files with 33 additions and 18 deletions
|
@ -932,17 +932,36 @@ bool EntityTree::filterProperties(const EntityItemProperties& propertiesIn, Enti
|
||||||
return true; // allowed
|
return true; // allowed
|
||||||
}
|
}
|
||||||
QScriptValue inputValues = propertiesIn.copyToScriptValue(&_entityEditFilterEngine, true, true);
|
QScriptValue inputValues = propertiesIn.copyToScriptValue(&_entityEditFilterEngine, true, true);
|
||||||
qDebug() << "input" << propertiesIn << inputValues.toVariant();
|
auto in = QJsonValue::fromVariant(inputValues.toVariant()); // grab json copy now, because the inputValues might be side effected by the filter.
|
||||||
|
qDebug() << "fixme filter input" << propertiesIn << inputValues.toVariant() << in;
|
||||||
QScriptValueList args;
|
QScriptValueList args;
|
||||||
args << inputValues;
|
args << inputValues;
|
||||||
|
|
||||||
QScriptValue result = _entityEditFilterEngine.newObject();
|
QScriptValue result = _entityEditFilterFunction.call(_nullObjectForFilter, args);
|
||||||
result = _entityEditFilterFunction.call(_nullObjectForFilter, args);
|
|
||||||
|
|
||||||
propertiesOut.copyFromScriptValue(result, false);
|
propertiesOut.copyFromScriptValue(result, false);
|
||||||
wasChanged = result.equals(inputValues); // not changed
|
bool accepted = result.isObject(); // filters should return null or false to completely reject edit or add
|
||||||
qDebug() << "result" << propertiesOut << result.toVariant() << wasChanged;
|
if (accepted) {
|
||||||
return result.isObject(); // filters should return null or false to completely reject edit or add
|
// Javascript objects are == only if they are the same object. To compare arbitrary values, we need to use JSON.
|
||||||
|
|
||||||
|
auto out = QJsonValue::fromVariant(result.toVariant());
|
||||||
|
bool eq = in == out;
|
||||||
|
qDebug() << "in:" << in << "out:" << out << "eq:" << eq;
|
||||||
|
wasChanged = !eq;
|
||||||
|
}
|
||||||
|
|
||||||
|
qDebug() << "fixme filter result" << propertiesOut << result.toVariant() << "accepted:" << accepted << "changed:" << (accepted && wasChanged);
|
||||||
|
return accepted;
|
||||||
|
}
|
||||||
|
|
||||||
|
void EntityTree::bumpTimestamp(EntityItemProperties& properties) { //fixme put class/header
|
||||||
|
const quint64 LAST_EDITED_SERVERSIDE_BUMP = 1; // usec
|
||||||
|
// also bump up the lastEdited time of the properties so that the interface that created this edit
|
||||||
|
// will accept our adjustment to lifetime back into its own entity-tree.
|
||||||
|
if (properties.getLastEdited() == UNKNOWN_CREATED_TIME) {
|
||||||
|
properties.setLastEdited(usecTimestampNow());
|
||||||
|
}
|
||||||
|
properties.setLastEdited(properties.getLastEdited() + LAST_EDITED_SERVERSIDE_BUMP);
|
||||||
}
|
}
|
||||||
|
|
||||||
int EntityTree::processEditPacketData(ReceivedMessage& message, const unsigned char* editData, int maxLength,
|
int EntityTree::processEditPacketData(ReceivedMessage& message, const unsigned char* editData, int maxLength,
|
||||||
|
@ -971,7 +990,6 @@ int EntityTree::processEditPacketData(ReceivedMessage& message, const unsigned c
|
||||||
quint64 startFilter = 0, endFilter = 0;
|
quint64 startFilter = 0, endFilter = 0;
|
||||||
quint64 startLogging = 0, endLogging = 0;
|
quint64 startLogging = 0, endLogging = 0;
|
||||||
|
|
||||||
const quint64 LAST_EDITED_SERVERSIDE_BUMP = 1; // usec
|
|
||||||
bool suppressDisallowedScript = false;
|
bool suppressDisallowedScript = false;
|
||||||
|
|
||||||
_totalEditMessages++;
|
_totalEditMessages++;
|
||||||
|
@ -1016,12 +1034,7 @@ int EntityTree::processEditPacketData(ReceivedMessage& message, const unsigned c
|
||||||
if (properties.getLifetime() == ENTITY_ITEM_IMMORTAL_LIFETIME ||
|
if (properties.getLifetime() == ENTITY_ITEM_IMMORTAL_LIFETIME ||
|
||||||
properties.getLifetime() > _maxTmpEntityLifetime) {
|
properties.getLifetime() > _maxTmpEntityLifetime) {
|
||||||
properties.setLifetime(_maxTmpEntityLifetime);
|
properties.setLifetime(_maxTmpEntityLifetime);
|
||||||
// also bump up the lastEdited time of the properties so that the interface that created this edit
|
bumpTimestamp(properties);
|
||||||
// will accept our adjustment to lifetime back into its own entity-tree.
|
|
||||||
if (properties.getLastEdited() == UNKNOWN_CREATED_TIME) {
|
|
||||||
properties.setLastEdited(usecTimestampNow());
|
|
||||||
}
|
|
||||||
properties.setLastEdited(properties.getLastEdited() + LAST_EDITED_SERVERSIDE_BUMP);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1036,12 +1049,13 @@ int EntityTree::processEditPacketData(ReceivedMessage& message, const unsigned c
|
||||||
properties = EntityItemProperties();
|
properties = EntityItemProperties();
|
||||||
}
|
}
|
||||||
if (!allowed || wasChanged) {
|
if (!allowed || wasChanged) {
|
||||||
if (properties.getLastEdited() == UNKNOWN_CREATED_TIME) {
|
bumpTimestamp(properties);
|
||||||
properties.setLastEdited(usecTimestampNow());
|
if (properties.getSimulationOwner().getID() == senderNode->getUUID()) {
|
||||||
|
qDebug() << "fixme Suppressing ownership from" << senderNode->getUUID();
|
||||||
|
properties.setSimulationOwner(QUuid(), 0);
|
||||||
}
|
}
|
||||||
properties.setLastEdited(properties.getLastEdited() + LAST_EDITED_SERVERSIDE_BUMP);
|
|
||||||
}
|
}
|
||||||
qDebug() << "filtered:" << properties;
|
qDebug() << "fixme final:" << properties;
|
||||||
endFilter = usecTimestampNow();
|
endFilter = usecTimestampNow();
|
||||||
|
|
||||||
// search for the entity by EntityItemID
|
// search for the entity by EntityItemID
|
||||||
|
@ -1051,7 +1065,7 @@ int EntityTree::processEditPacketData(ReceivedMessage& message, const unsigned c
|
||||||
if (existingEntity && message.getType() == PacketType::EntityEdit) {
|
if (existingEntity && message.getType() == PacketType::EntityEdit) {
|
||||||
|
|
||||||
if (suppressDisallowedScript) {
|
if (suppressDisallowedScript) {
|
||||||
properties.setLastEdited(properties.getLastEdited() + LAST_EDITED_SERVERSIDE_BUMP);
|
bumpTimestamp(properties);
|
||||||
properties.setScript(existingEntity->getScript());
|
properties.setScript(existingEntity->getScript());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -289,6 +289,7 @@ protected:
|
||||||
static bool findInBoxOperation(OctreeElementPointer element, void* extraData);
|
static bool findInBoxOperation(OctreeElementPointer element, void* extraData);
|
||||||
static bool findInFrustumOperation(OctreeElementPointer element, void* extraData);
|
static bool findInFrustumOperation(OctreeElementPointer element, void* extraData);
|
||||||
static bool sendEntitiesOperation(OctreeElementPointer element, void* extraData);
|
static bool sendEntitiesOperation(OctreeElementPointer element, void* extraData);
|
||||||
|
static void bumpTimestamp(EntityItemProperties& properties);
|
||||||
|
|
||||||
void notifyNewlyCreatedEntity(const EntityItem& newEntity, const SharedNodePointer& senderNode);
|
void notifyNewlyCreatedEntity(const EntityItem& newEntity, const SharedNodePointer& senderNode);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue