handle ignoring simulation data echoed back to us differently

This commit is contained in:
Seth Alves 2015-04-20 16:36:56 -07:00
parent 23f1767634
commit 6107682658
3 changed files with 27 additions and 14 deletions

View file

@ -313,8 +313,7 @@ int EntityItem::expectedBytes() {
}
int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLeftToRead, ReadBitstreamToTreeParams& args,
bool ignoreServerPacket) {
int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLeftToRead, ReadBitstreamToTreeParams& args) {
if (args.bitstreamVersion < VERSION_ENTITIES_SUPPORT_SPLIT_MTU) {
@ -325,6 +324,14 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef
return 0;
}
// if this bitstream indicates that this node is the simulation owner, ignore any physics-related updates.
glm::vec3 savePosition = _position;
glm::quat saveRotation = _rotation;
glm::vec3 saveVelocity = _velocity;
glm::vec3 saveGravity = _gravity;
glm::vec3 saveAcceleration = _acceleration;
// Header bytes
// object ID [16 bytes]
// ByteCountCoded(type code) [~1 byte]
@ -398,6 +405,8 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef
quint64 lastEditedFromBuffer = 0;
quint64 lastEditedFromBufferAdjusted = 0;
bool ignoreServerPacket = false;
// TODO: we could make this encoded as a delta from _created
// _lastEdited
memcpy(&lastEditedFromBuffer, dataAt, sizeof(lastEditedFromBuffer));
@ -608,6 +617,20 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef
_lastSimulated = now;
}
}
auto nodeList = DependencyManager::get<NodeList>();
const QUuid& myNodeID = nodeList->getSessionUUID();
if (_simulatorID == myNodeID) {
// the packet that produced this bitstream originally came from physics simulations performed by
// this node, so our version has to be newer than what the packet contained.
_position = savePosition;
_rotation = saveRotation;
_velocity = saveVelocity;
_gravity = saveGravity;
_acceleration = saveAcceleration;
}
return bytesRead;
}

View file

@ -113,8 +113,7 @@ public:
static EntityItemID readEntityItemIDFromBuffer(const unsigned char* data, int bytesLeftToRead,
ReadBitstreamToTreeParams& args);
virtual int readEntityDataFromBuffer(const unsigned char* data, int bytesLeftToRead, ReadBitstreamToTreeParams& args,
bool ignoreServerPacket = false);
virtual int readEntityDataFromBuffer(const unsigned char* data, int bytesLeftToRead, ReadBitstreamToTreeParams& args);
virtual int readEntitySubclassDataFromBuffer(const unsigned char* data, int bytesLeftToRead,
ReadBitstreamToTreeParams& args,

View file

@ -716,10 +716,6 @@ int EntityTreeElement::readElementDataFromBuffer(const unsigned char* data, int
bytesRead += sizeof(numberOfEntities);
if (bytesLeftToRead >= (int)(numberOfEntities * expectedBytesPerEntity)) {
// look up the Id of this Node
auto nodeList = DependencyManager::get<NodeList>();
QUuid myNodeID = nodeList->getSessionUUID();
for (uint16_t i = 0; i < numberOfEntities; i++) {
int bytesForThisEntity = 0;
EntityItemID entityItemID;
@ -744,12 +740,7 @@ int EntityTreeElement::readElementDataFromBuffer(const unsigned char* data, int
bool bestFitBefore = bestFitEntityBounds(entityItem);
EntityTreeElement* currentContainingElement = _myTree->getContainingElement(entityItemID);
// this Node was the original source of this packet, so read it, but ignore it.
/// XXX what should be done here? Do we need to ignore packets which show us as simulator owner? XXX
// bool shouldIgnore = (entityItem && entityItem->getSimulatorID() == myNodeID); XXX
bool shouldIgnore = false;
bytesForThisEntity = entityItem->readEntityDataFromBuffer(dataAt, bytesLeftToRead, args, shouldIgnore);
bytesForThisEntity = entityItem->readEntityDataFromBuffer(dataAt, bytesLeftToRead, args);
if (entityItem->getDirtyFlags()) {
_myTree->entityChanged(entityItem);
}