mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-07-17 17:37:49 +02:00
Merge branch 'master' of github.com:highfidelity/hifi into polyvox
This commit is contained in:
commit
4961c10e17
2 changed files with 277 additions and 294 deletions
|
@ -318,15 +318,6 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef
|
||||||
return 0;
|
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 saveAngularVelocity = _angularVelocity;
|
|
||||||
// glm::vec3 saveGravity = _gravity;
|
|
||||||
// glm::vec3 saveAcceleration = _acceleration;
|
|
||||||
|
|
||||||
|
|
||||||
// Header bytes
|
// Header bytes
|
||||||
// object ID [16 bytes]
|
// object ID [16 bytes]
|
||||||
// ByteCountCoded(type code) [~1 byte]
|
// ByteCountCoded(type code) [~1 byte]
|
||||||
|
@ -337,7 +328,15 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef
|
||||||
const int MINIMUM_HEADER_BYTES = 27;
|
const int MINIMUM_HEADER_BYTES = 27;
|
||||||
|
|
||||||
int bytesRead = 0;
|
int bytesRead = 0;
|
||||||
if (bytesLeftToRead >= MINIMUM_HEADER_BYTES) {
|
if (bytesLeftToRead < MINIMUM_HEADER_BYTES) {
|
||||||
|
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 saveAngularVelocity = _angularVelocity;
|
||||||
|
|
||||||
int originalLength = bytesLeftToRead;
|
int originalLength = bytesLeftToRead;
|
||||||
QByteArray originalDataBuffer((const char*)data, originalLength);
|
QByteArray originalDataBuffer((const char*)data, originalLength);
|
||||||
|
@ -449,7 +448,6 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef
|
||||||
debugDump();
|
debugDump();
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
#ifdef WANT_DEBUG
|
#ifdef WANT_DEBUG
|
||||||
qCDebug(entities) << "USING NEW data from server!!! ****************";
|
qCDebug(entities) << "USING NEW data from server!!! ****************";
|
||||||
debugDump();
|
debugDump();
|
||||||
|
@ -573,7 +571,12 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef
|
||||||
READ_ENTITY_PROPERTY(PROP_USER_DATA, QString, setUserData);
|
READ_ENTITY_PROPERTY(PROP_USER_DATA, QString, setUserData);
|
||||||
|
|
||||||
if (args.bitstreamVersion >= VERSION_ENTITIES_HAVE_ACCELERATION) {
|
if (args.bitstreamVersion >= VERSION_ENTITIES_HAVE_ACCELERATION) {
|
||||||
|
// we always accept the server's notion of simulatorID, so we fake overwriteLocalData as true
|
||||||
|
// before we try to READ_ENTITY_PROPERTY it
|
||||||
|
bool temp = overwriteLocalData;
|
||||||
|
overwriteLocalData = true;
|
||||||
READ_ENTITY_PROPERTY(PROP_SIMULATOR_ID, QUuid, updateSimulatorID);
|
READ_ENTITY_PROPERTY(PROP_SIMULATOR_ID, QUuid, updateSimulatorID);
|
||||||
|
overwriteLocalData = temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.bitstreamVersion >= VERSION_ENTITIES_HAS_MARKETPLACE_ID) {
|
if (args.bitstreamVersion >= VERSION_ENTITIES_HAS_MARKETPLACE_ID) {
|
||||||
|
@ -616,20 +619,17 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef
|
||||||
}
|
}
|
||||||
_lastSimulated = now;
|
_lastSimulated = now;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
auto nodeList = DependencyManager::get<NodeList>();
|
auto nodeList = DependencyManager::get<NodeList>();
|
||||||
const QUuid& myNodeID = nodeList->getSessionUUID();
|
const QUuid& myNodeID = nodeList->getSessionUUID();
|
||||||
if (_simulatorID == myNodeID && !_simulatorID.isNull()) {
|
if (overwriteLocalData && _simulatorID == myNodeID && !_simulatorID.isNull()) {
|
||||||
// the packet that produced this bitstream originally came from physics simulations performed by
|
// we own the simulation, so we keep our transform+velocities and remove any related dirty flags
|
||||||
// this node, so our version has to be newer than what the packet contained.
|
// rather than accept the values in the packet
|
||||||
_position = savePosition;
|
_position = savePosition;
|
||||||
_rotation = saveRotation;
|
_rotation = saveRotation;
|
||||||
// _velocity = saveVelocity;
|
_velocity = saveVelocity;
|
||||||
// _angularVelocity = saveAngularVelocity;
|
_angularVelocity = saveAngularVelocity;
|
||||||
// _gravity = saveGravity;
|
_dirtyFlags &= ~(EntityItem::DIRTY_TRANSFORM | EntityItem::DIRTY_VELOCITIES);
|
||||||
// _acceleration = saveAcceleration;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return bytesRead;
|
return bytesRead;
|
||||||
|
@ -949,40 +949,25 @@ bool EntityItem::setProperties(const EntityItemProperties& properties) {
|
||||||
SET_ENTITY_PROPERTY_FROM_PROPERTIES(name, setName);
|
SET_ENTITY_PROPERTY_FROM_PROPERTIES(name, setName);
|
||||||
|
|
||||||
if (somethingChanged) {
|
if (somethingChanged) {
|
||||||
somethingChangedNotification(); // notify derived classes that something has changed
|
|
||||||
uint64_t now = usecTimestampNow();
|
uint64_t now = usecTimestampNow();
|
||||||
#ifdef WANT_DEBUG
|
#ifdef WANT_DEBUG
|
||||||
int elapsed = now - getLastEdited();
|
int elapsed = now - getLastEdited();
|
||||||
qCDebug(entities) << "EntityItem::setProperties() AFTER update... edited AGO=" << elapsed <<
|
qCDebug(entities) << "EntityItem::setProperties() AFTER update... edited AGO=" << elapsed <<
|
||||||
"now=" << now << " getLastEdited()=" << getLastEdited();
|
"now=" << now << " getLastEdited()=" << getLastEdited();
|
||||||
#endif
|
#endif
|
||||||
if (_created != UNKNOWN_CREATED_TIME) {
|
|
||||||
setLastEdited(now);
|
setLastEdited(now);
|
||||||
|
somethingChangedNotification(); // notify derived classes that something has changed
|
||||||
|
if (_created == UNKNOWN_CREATED_TIME) {
|
||||||
|
_created = now;
|
||||||
}
|
}
|
||||||
if (getDirtyFlags() & (EntityItem::DIRTY_TRANSFORM | EntityItem::DIRTY_VELOCITIES)) {
|
if (getDirtyFlags() & (EntityItem::DIRTY_TRANSFORM | EntityItem::DIRTY_VELOCITIES)) {
|
||||||
// TODO: Andrew & Brad to discuss. Is this correct? Maybe it is. Need to think through all cases.
|
// anything that sets the transform or velocity must update _lastSimulated which is used
|
||||||
|
// for kinematic extrapolation (e.g. we want to extrapolate forward from this moment
|
||||||
|
// when position and/or velocity was changed).
|
||||||
_lastSimulated = now;
|
_lastSimulated = now;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// timestamps
|
|
||||||
quint64 timestamp = properties.getCreated();
|
|
||||||
if (_created == UNKNOWN_CREATED_TIME && timestamp != UNKNOWN_CREATED_TIME) {
|
|
||||||
quint64 now = usecTimestampNow();
|
|
||||||
if (timestamp > now) {
|
|
||||||
timestamp = now;
|
|
||||||
}
|
|
||||||
_created = timestamp;
|
|
||||||
|
|
||||||
timestamp = properties.getLastEdited();
|
|
||||||
if (timestamp > now) {
|
|
||||||
timestamp = now;
|
|
||||||
} else if (timestamp < _created) {
|
|
||||||
timestamp = _created;
|
|
||||||
}
|
|
||||||
_lastEdited = timestamp;
|
|
||||||
}
|
|
||||||
|
|
||||||
return somethingChanged;
|
return somethingChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -132,7 +132,6 @@ void EntityMotionState::getWorldTransform(btTransform& worldTrans) const {
|
||||||
uint32_t thisStep = ObjectMotionState::getWorldSimulationStep();
|
uint32_t thisStep = ObjectMotionState::getWorldSimulationStep();
|
||||||
float dt = (thisStep - _lastKinematicStep) * PHYSICS_ENGINE_FIXED_SUBSTEP;
|
float dt = (thisStep - _lastKinematicStep) * PHYSICS_ENGINE_FIXED_SUBSTEP;
|
||||||
_entity->simulateKinematicMotion(dt);
|
_entity->simulateKinematicMotion(dt);
|
||||||
_entity->setLastSimulated(usecTimestampNow());
|
|
||||||
|
|
||||||
// bypass const-ness so we can remember the step
|
// bypass const-ness so we can remember the step
|
||||||
const_cast<EntityMotionState*>(this)->_lastKinematicStep = thisStep;
|
const_cast<EntityMotionState*>(this)->_lastKinematicStep = thisStep;
|
||||||
|
@ -401,13 +400,12 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, const Q
|
||||||
properties.setAcceleration(_serverAcceleration);
|
properties.setAcceleration(_serverAcceleration);
|
||||||
properties.setAngularVelocity(_serverAngularVelocity);
|
properties.setAngularVelocity(_serverAngularVelocity);
|
||||||
|
|
||||||
// we only update lastEdited when we're sending new physics data
|
// set the LastEdited of the properties but NOT the entity itself
|
||||||
quint64 lastSimulated = _entity->getLastSimulated();
|
quint64 now = usecTimestampNow();
|
||||||
_entity->setLastEdited(lastSimulated);
|
properties.setLastEdited(now);
|
||||||
properties.setLastEdited(lastSimulated);
|
|
||||||
|
|
||||||
#ifdef WANT_DEBUG
|
#ifdef WANT_DEBUG
|
||||||
quint64 now = usecTimestampNow();
|
quint64 lastSimulated = _entity->getLastSimulated();
|
||||||
qCDebug(physics) << "EntityMotionState::sendUpdate()";
|
qCDebug(physics) << "EntityMotionState::sendUpdate()";
|
||||||
qCDebug(physics) << " EntityItemId:" << _entity->getEntityItemID()
|
qCDebug(physics) << " EntityItemId:" << _entity->getEntityItemID()
|
||||||
<< "---------------------------------------------";
|
<< "---------------------------------------------";
|
||||||
|
|
Loading…
Reference in a new issue