mirror of
https://github.com/JulianGro/overte.git
synced 2025-08-05 05:42:44 +02:00
Merge pull request #9617 from howard-stearns/physics-packets
Physics packets
This commit is contained in:
commit
1c7c0f7a76
7 changed files with 31 additions and 14 deletions
|
@ -34,7 +34,7 @@ EntityServer::EntityServer(ReceivedMessage& message) :
|
|||
DependencyManager::set<ScriptCache>();
|
||||
|
||||
auto& packetReceiver = DependencyManager::get<NodeList>()->getPacketReceiver();
|
||||
packetReceiver.registerListenerForTypes({ PacketType::EntityAdd, PacketType::EntityEdit, PacketType::EntityErase },
|
||||
packetReceiver.registerListenerForTypes({ PacketType::EntityAdd, PacketType::EntityEdit, PacketType::EntityErase, PacketType::EntityPhysics },
|
||||
this, "handleEntityPacket");
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ void EntityEditPacketSender::processEntityEditNackPacket(QSharedPointer<Received
|
|||
}
|
||||
|
||||
void EntityEditPacketSender::adjustEditPacketForClockSkew(PacketType type, QByteArray& buffer, qint64 clockSkew) {
|
||||
if (type == PacketType::EntityAdd || type == PacketType::EntityEdit) {
|
||||
if (type == PacketType::EntityAdd || type == PacketType::EntityEdit || type == PacketType::EntityPhysics) {
|
||||
EntityItem::adjustEditPacketForClockSkew(buffer, clockSkew);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -104,6 +104,7 @@ bool EntityTree::handlesEditPacketType(PacketType packetType) const {
|
|||
case PacketType::EntityAdd:
|
||||
case PacketType::EntityEdit:
|
||||
case PacketType::EntityErase:
|
||||
case PacketType::EntityPhysics:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
|
@ -931,10 +932,15 @@ void EntityTree::initEntityEditFilterEngine(QScriptEngine* engine, std::function
|
|||
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(EntityItemProperties& propertiesIn, EntityItemProperties& propertiesOut, bool& wasChanged, bool isAdd) {
|
||||
bool EntityTree::filterProperties(EntityItemProperties& propertiesIn, EntityItemProperties& propertiesOut, bool& wasChanged, FilterType filterType) {
|
||||
if (!_entityEditFilterEngine) {
|
||||
propertiesOut = propertiesIn;
|
||||
wasChanged = false; // not changed
|
||||
|
@ -953,7 +959,7 @@ bool EntityTree::filterProperties(EntityItemProperties& propertiesIn, EntityItem
|
|||
auto in = QJsonValue::fromVariant(inputValues.toVariant()); // grab json copy now, because the inputValues might be side effected by the filter.
|
||||
QScriptValueList args;
|
||||
args << inputValues;
|
||||
args << isAdd;
|
||||
args << filterType;
|
||||
|
||||
QScriptValue result = _entityEditFilterFunction.call(_nullObjectForFilter, args);
|
||||
if (_entityEditFilterHadUncaughtExceptions()) {
|
||||
|
@ -1001,6 +1007,7 @@ int EntityTree::processEditPacketData(ReceivedMessage& message, const unsigned c
|
|||
|
||||
case PacketType::EntityAdd:
|
||||
isAdd = true; // fall through to next case
|
||||
case PacketType::EntityPhysics:
|
||||
case PacketType::EntityEdit: {
|
||||
quint64 startDecode = 0, endDecode = 0;
|
||||
quint64 startLookup = 0, endLookup = 0;
|
||||
|
@ -1010,6 +1017,7 @@ int EntityTree::processEditPacketData(ReceivedMessage& message, const unsigned c
|
|||
quint64 startLogging = 0, endLogging = 0;
|
||||
|
||||
bool suppressDisallowedScript = false;
|
||||
bool isPhysics = message.getType() == PacketType::EntityPhysics;
|
||||
|
||||
_totalEditMessages++;
|
||||
|
||||
|
@ -1021,6 +1029,7 @@ int EntityTree::processEditPacketData(ReceivedMessage& message, const unsigned c
|
|||
entityItemID, properties);
|
||||
endDecode = usecTimestampNow();
|
||||
|
||||
|
||||
if (validEditPacket && !_entityScriptSourceWhitelist.isEmpty() && !properties.getScript().isEmpty()) {
|
||||
bool passedWhiteList = false;
|
||||
|
||||
|
@ -1053,8 +1062,7 @@ int EntityTree::processEditPacketData(ReceivedMessage& message, const unsigned c
|
|||
}
|
||||
}
|
||||
|
||||
if ((isAdd ||
|
||||
(message.getType() == PacketType::EntityEdit && properties.lifetimeChanged())) &&
|
||||
if ((isAdd || properties.lifetimeChanged()) &&
|
||||
!senderNode->getCanRez() && senderNode->getCanRezTmp()) {
|
||||
// this node is only allowed to rez temporary entities. if need be, cap the lifetime.
|
||||
if (properties.getLifetime() == ENTITY_ITEM_IMMORTAL_LIFETIME ||
|
||||
|
@ -1070,8 +1078,9 @@ int EntityTree::processEditPacketData(ReceivedMessage& message, const unsigned c
|
|||
|
||||
startFilter = usecTimestampNow();
|
||||
bool wasChanged = false;
|
||||
// Having (un)lock rights bypasses the filter.
|
||||
bool allowed = senderNode->isAllowedEditor() || filterProperties(properties, properties, wasChanged, isAdd);
|
||||
// Having (un)lock rights bypasses the filter, unless it's a physics result.
|
||||
FilterType filterType = isPhysics ? FilterType::Physics : (isAdd ? FilterType::Add : FilterType::Edit);
|
||||
bool allowed = (!isPhysics && senderNode->isAllowedEditor()) || filterProperties(properties, properties, wasChanged, filterType);
|
||||
if (!allowed) {
|
||||
auto timestamp = properties.getLastEdited();
|
||||
properties = EntityItemProperties();
|
||||
|
@ -1088,7 +1097,7 @@ int EntityTree::processEditPacketData(ReceivedMessage& message, const unsigned c
|
|||
startLookup = usecTimestampNow();
|
||||
EntityItemPointer existingEntity = findEntityByEntityItemID(entityItemID);
|
||||
endLookup = usecTimestampNow();
|
||||
if (existingEntity && message.getType() == PacketType::EntityEdit) {
|
||||
if (existingEntity && !isAdd) {
|
||||
|
||||
if (suppressDisallowedScript) {
|
||||
bumpTimestamp(properties);
|
||||
|
|
|
@ -60,6 +60,11 @@ public:
|
|||
class EntityTree : public Octree, public SpatialParentTree {
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum FilterType {
|
||||
Add,
|
||||
Edit,
|
||||
Physics
|
||||
};
|
||||
EntityTree(bool shouldReaverage = false);
|
||||
virtual ~EntityTree();
|
||||
|
||||
|
@ -357,7 +362,7 @@ protected:
|
|||
|
||||
float _maxTmpEntityLifetime { DEFAULT_MAX_TMP_ENTITY_LIFETIME };
|
||||
|
||||
bool filterProperties(EntityItemProperties& propertiesIn, EntityItemProperties& propertiesOut, bool& wasChanged, bool isAdd);
|
||||
bool filterProperties(EntityItemProperties& propertiesIn, EntityItemProperties& propertiesOut, bool& wasChanged, FilterType filterType);
|
||||
bool _hasEntityEditFilter{ false };
|
||||
QScriptEngine* _entityEditFilterEngine{};
|
||||
QScriptValue _entityEditFilterFunction{};
|
||||
|
|
|
@ -48,7 +48,8 @@ PacketVersion versionForPacketType(PacketType packetType) {
|
|||
case PacketType::EntityAdd:
|
||||
case PacketType::EntityEdit:
|
||||
case PacketType::EntityData:
|
||||
return VERSION_ENTITIES_SERVER_SCRIPTS;
|
||||
case PacketType::EntityPhysics:
|
||||
return VERSION_ENTITIES_PHYSICS_PACKET;
|
||||
case PacketType::EntityQuery:
|
||||
return static_cast<PacketVersion>(EntityQueryPacketVersion::JsonFilter);
|
||||
case PacketType::AvatarIdentity:
|
||||
|
|
|
@ -110,7 +110,8 @@ public:
|
|||
EntityScriptGetStatus,
|
||||
EntityScriptGetStatusReply,
|
||||
ReloadEntityServerScript,
|
||||
LAST_PACKET_TYPE = ReloadEntityServerScript
|
||||
EntityPhysics,
|
||||
LAST_PACKET_TYPE = EntityPhysics
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -201,6 +202,7 @@ const PacketVersion VERSION_WEB_ENTITIES_SUPPORT_DPI = 63;
|
|||
const PacketVersion VERSION_ENTITIES_ARROW_ACTION = 64;
|
||||
const PacketVersion VERSION_ENTITIES_LAST_EDITED_BY = 65;
|
||||
const PacketVersion VERSION_ENTITIES_SERVER_SCRIPTS = 66;
|
||||
const PacketVersion VERSION_ENTITIES_PHYSICS_PACKET = 67;
|
||||
|
||||
enum class EntityQueryPacketVersion: PacketVersion {
|
||||
JsonFilter = 18
|
||||
|
|
|
@ -614,7 +614,7 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, uint32_
|
|||
properties.setClientOnly(_entity->getClientOnly());
|
||||
properties.setOwningAvatarID(_entity->getOwningAvatarID());
|
||||
|
||||
entityPacketSender->queueEditEntityMessage(PacketType::EntityEdit, tree, id, properties);
|
||||
entityPacketSender->queueEditEntityMessage(PacketType::EntityPhysics, tree, id, properties);
|
||||
_entity->setLastBroadcast(now);
|
||||
|
||||
// if we've moved an entity with children, check/update the queryAACube of all descendents and tell the server
|
||||
|
@ -630,7 +630,7 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, uint32_
|
|||
newQueryCubeProperties.setClientOnly(entityDescendant->getClientOnly());
|
||||
newQueryCubeProperties.setOwningAvatarID(entityDescendant->getOwningAvatarID());
|
||||
|
||||
entityPacketSender->queueEditEntityMessage(PacketType::EntityEdit, tree,
|
||||
entityPacketSender->queueEditEntityMessage(PacketType::EntityPhysics, tree,
|
||||
descendant->getID(), newQueryCubeProperties);
|
||||
entityDescendant->setLastBroadcast(now);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue