mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 01:24:03 +02:00
rather than keeping track of previous pos/rot sent by server, use a new flag that indicates that the values should be updated in the physics engine, but that the object should not be woken
This commit is contained in:
parent
6e6793cbcc
commit
218393a2b3
3 changed files with 40 additions and 62 deletions
|
@ -65,13 +65,7 @@ EntityItem::EntityItem(const EntityItemID& entityItemID) :
|
|||
_marketplaceID(ENTITY_ITEM_DEFAULT_MARKETPLACE_ID),
|
||||
_physicsInfo(NULL),
|
||||
_dirtyFlags(0),
|
||||
_element(NULL),
|
||||
_previousPositionFromServer(ENTITY_ITEM_ZERO_VEC3),
|
||||
_previousRotationFromServer(ENTITY_ITEM_DEFAULT_ROTATION),
|
||||
_previousVelocityFromServer(ENTITY_ITEM_ZERO_VEC3),
|
||||
_previousAngularVelocityFromServer(ENTITY_ITEM_ZERO_VEC3),
|
||||
_previousGravityFromServer(ENTITY_ITEM_ZERO_VEC3),
|
||||
_previousAccelerationFromServer(ENTITY_ITEM_ZERO_VEC3)
|
||||
_element(NULL)
|
||||
{
|
||||
quint64 now = usecTimestampNow();
|
||||
_lastSimulated = now;
|
||||
|
@ -1100,12 +1094,10 @@ void EntityItem::updatePositionInDomainUnits(const glm::vec3& value) {
|
|||
}
|
||||
|
||||
void EntityItem::updatePosition(const glm::vec3& value) {
|
||||
if (/* false && */ value == _previousPositionFromServer) {
|
||||
if (value != _position) {
|
||||
auto distance = glm::distance(_position, value);
|
||||
_dirtyFlags |= (distance > MIN_POSITION_DELTA) ? EntityItem::DIRTY_POSITION : EntityItem::DIRTY_PHYSICS_NO_WAKE;
|
||||
_position = value;
|
||||
} else if (glm::distance(_position, value) > MIN_POSITION_DELTA) {
|
||||
_position = value;
|
||||
_previousPositionFromServer = value;
|
||||
_dirtyFlags |= EntityItem::DIRTY_POSITION;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1122,12 +1114,10 @@ void EntityItem::updateDimensions(const glm::vec3& value) {
|
|||
}
|
||||
|
||||
void EntityItem::updateRotation(const glm::quat& rotation) {
|
||||
if (/* false && */ rotation == _previousRotationFromServer) {
|
||||
if (rotation != _rotation) {
|
||||
auto alignmentDot = glm::abs(glm::dot(_rotation, rotation));
|
||||
_dirtyFlags |= (alignmentDot < MIN_ALIGNMENT_DOT) ? EntityItem::DIRTY_POSITION : EntityItem::DIRTY_PHYSICS_NO_WAKE;
|
||||
_rotation = rotation;
|
||||
} else if (glm::abs(glm::dot(_rotation, rotation)) < MIN_ALIGNMENT_DOT) {
|
||||
_rotation = rotation;
|
||||
_previousRotationFromServer = rotation;
|
||||
_dirtyFlags |= EntityItem::DIRTY_POSITION;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1161,20 +1151,15 @@ void EntityItem::updateVelocityInDomainUnits(const glm::vec3& value) {
|
|||
}
|
||||
|
||||
void EntityItem::updateVelocity(const glm::vec3& value) {
|
||||
if (/* false && */ value == _previousVelocityFromServer) {
|
||||
if (glm::length(value) < MIN_VELOCITY_DELTA) {
|
||||
_velocity = ENTITY_ITEM_ZERO_VEC3;
|
||||
} else {
|
||||
_velocity = value;
|
||||
}
|
||||
} else if (glm::distance(_velocity, value) > MIN_VELOCITY_DELTA) {
|
||||
if (glm::length(value) < MIN_VELOCITY_DELTA) {
|
||||
_velocity = ENTITY_ITEM_ZERO_VEC3;
|
||||
} else {
|
||||
_velocity = value;
|
||||
}
|
||||
_previousVelocityFromServer = value;
|
||||
if (value != _velocity) {
|
||||
auto distance = glm::distance(_velocity, value);
|
||||
// _dirtyFlags |= (distance > MIN_VELOCITY_DELTA) ? EntityItem::DIRTY_VELOCITY : EntityItem::DIRTY_PHYSICS_NO_WAKE;
|
||||
_dirtyFlags |= EntityItem::DIRTY_VELOCITY;
|
||||
if (distance < MIN_VELOCITY_DELTA) {
|
||||
_velocity = ENTITY_ITEM_ZERO_VEC3;
|
||||
} else {
|
||||
_velocity = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1191,39 +1176,36 @@ void EntityItem::updateGravityInDomainUnits(const glm::vec3& value) {
|
|||
}
|
||||
|
||||
void EntityItem::updateGravity(const glm::vec3& value) {
|
||||
if (/* false && */ value == _previousGravityFromServer) {
|
||||
_gravity = value;
|
||||
} else if (glm::distance(_gravity, value) > MIN_GRAVITY_DELTA) {
|
||||
_gravity = value;
|
||||
_previousGravityFromServer = value;
|
||||
auto distance = glm::distance(_gravity, value);
|
||||
// if (value != _gravity) {
|
||||
if (distance > MIN_GRAVITY_DELTA) {
|
||||
// _dirtyFlags |= (distance > MIN_GRAVITY_DELTA) ? EntityItem::DIRTY_VELOCITY : EntityItem::DIRTY_PHYSICS_NO_WAKE;
|
||||
_dirtyFlags |= EntityItem::DIRTY_VELOCITY;
|
||||
_gravity = value;
|
||||
}
|
||||
}
|
||||
|
||||
void EntityItem::updateAcceleration(const glm::vec3& value) {
|
||||
if (/* false && */ value == _previousAccelerationFromServer) {
|
||||
_acceleration = value;
|
||||
} else if (glm::distance(_acceleration, value) > MIN_ACCELERATION_DELTA) {
|
||||
_acceleration = value;
|
||||
_previousAccelerationFromServer = value;
|
||||
auto distance = glm::distance(_acceleration, value);
|
||||
// if (value != _acceleration) {
|
||||
if (distance > MIN_ACCELERATION_DELTA) {
|
||||
// _dirtyFlags |= (distance > MIN_ACCELERATION_DELTA) ? EntityItem::DIRTY_VELOCITY : EntityItem::DIRTY_PHYSICS_NO_WAKE;
|
||||
_dirtyFlags |= EntityItem::DIRTY_VELOCITY;
|
||||
_acceleration = value;
|
||||
}
|
||||
}
|
||||
|
||||
void EntityItem::updateAngularVelocity(const glm::vec3& value) {
|
||||
if (/* false && */ value == _previousAngularVelocityFromServer) {
|
||||
if (glm::length(value) < MIN_SPIN_DELTA) {
|
||||
_angularVelocity = ENTITY_ITEM_ZERO_VEC3;
|
||||
} else {
|
||||
_angularVelocity = value;
|
||||
}
|
||||
} else if (glm::distance(_angularVelocity, value) > MIN_SPIN_DELTA) {
|
||||
if (glm::length(value) < MIN_SPIN_DELTA) {
|
||||
_angularVelocity = ENTITY_ITEM_ZERO_VEC3;
|
||||
} else {
|
||||
_angularVelocity = value;
|
||||
}
|
||||
auto distance = glm::distance(_angularVelocity, value);
|
||||
// if (value != _angularVelocity) {
|
||||
if (distance > MIN_SPIN_DELTA) {
|
||||
// _dirtyFlags |= (distance > MIN_SPIN_DELTA) ? EntityItem::DIRTY_VELOCITY : EntityItem::DIRTY_PHYSICS_NO_WAKE;
|
||||
_dirtyFlags |= EntityItem::DIRTY_VELOCITY;
|
||||
if (glm::length(value) < MIN_SPIN_DELTA) {
|
||||
_angularVelocity = ENTITY_ITEM_ZERO_VEC3;
|
||||
} else {
|
||||
_angularVelocity = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ public:
|
|||
DIRTY_SHAPE = 0x0020,
|
||||
DIRTY_LIFETIME = 0x0040,
|
||||
DIRTY_UPDATEABLE = 0x0080,
|
||||
DIRTY_TWEAK = 0x0100
|
||||
DIRTY_PHYSICS_NO_WAKE = 0x0100 // we want to update values in physics engine without "waking" the object up
|
||||
};
|
||||
|
||||
DONT_ALLOW_INSTANTIATION // This class can not be instantiated directly
|
||||
|
@ -369,13 +369,6 @@ protected:
|
|||
uint32_t _dirtyFlags; // things that have changed from EXTERNAL changes (via script or packet) but NOT from simulation
|
||||
|
||||
EntityTreeElement* _element; // back pointer to containing Element
|
||||
|
||||
glm::vec3 _previousPositionFromServer;
|
||||
glm::quat _previousRotationFromServer;
|
||||
glm::vec3 _previousVelocityFromServer;
|
||||
glm::vec3 _previousAngularVelocityFromServer;
|
||||
glm::vec3 _previousGravityFromServer;
|
||||
glm::vec3 _previousAccelerationFromServer;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -132,7 +132,7 @@ void EntityMotionState::setWorldTransform(const btTransform& worldTrans) {
|
|||
}
|
||||
|
||||
void EntityMotionState::updateObjectEasy(uint32_t flags, uint32_t step) {
|
||||
if (flags & (EntityItem::DIRTY_POSITION | EntityItem::DIRTY_VELOCITY)) {
|
||||
if (flags & (EntityItem::DIRTY_POSITION | EntityItem::DIRTY_VELOCITY | EntityItem::DIRTY_PHYSICS_NO_WAKE)) {
|
||||
if (flags & EntityItem::DIRTY_POSITION) {
|
||||
_sentPosition = _entity->getPosition() - ObjectMotionState::getWorldOffset();
|
||||
btTransform worldTrans;
|
||||
|
@ -147,6 +147,10 @@ void EntityMotionState::updateObjectEasy(uint32_t flags, uint32_t step) {
|
|||
updateObjectVelocities();
|
||||
}
|
||||
_sentStep = step;
|
||||
|
||||
if (flags & (EntityItem::DIRTY_POSITION | EntityItem::DIRTY_VELOCITY)) {
|
||||
_body->activate();
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: entity support for friction and restitution
|
||||
|
@ -166,7 +170,6 @@ void EntityMotionState::updateObjectEasy(uint32_t flags, uint32_t step) {
|
|||
_body->setMassProps(mass, inertia);
|
||||
_body->updateInertiaTensor();
|
||||
}
|
||||
_body->activate();
|
||||
};
|
||||
|
||||
void EntityMotionState::updateObjectVelocities() {
|
||||
|
|
Loading…
Reference in a new issue