mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 19:59:28 +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),
|
_marketplaceID(ENTITY_ITEM_DEFAULT_MARKETPLACE_ID),
|
||||||
_physicsInfo(NULL),
|
_physicsInfo(NULL),
|
||||||
_dirtyFlags(0),
|
_dirtyFlags(0),
|
||||||
_element(NULL),
|
_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)
|
|
||||||
{
|
{
|
||||||
quint64 now = usecTimestampNow();
|
quint64 now = usecTimestampNow();
|
||||||
_lastSimulated = now;
|
_lastSimulated = now;
|
||||||
|
@ -1100,12 +1094,10 @@ void EntityItem::updatePositionInDomainUnits(const glm::vec3& value) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void EntityItem::updatePosition(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;
|
_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) {
|
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;
|
_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) {
|
void EntityItem::updateVelocity(const glm::vec3& value) {
|
||||||
if (/* false && */ value == _previousVelocityFromServer) {
|
if (value != _velocity) {
|
||||||
if (glm::length(value) < MIN_VELOCITY_DELTA) {
|
auto distance = glm::distance(_velocity, value);
|
||||||
_velocity = ENTITY_ITEM_ZERO_VEC3;
|
// _dirtyFlags |= (distance > MIN_VELOCITY_DELTA) ? EntityItem::DIRTY_VELOCITY : EntityItem::DIRTY_PHYSICS_NO_WAKE;
|
||||||
} 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;
|
|
||||||
_dirtyFlags |= EntityItem::DIRTY_VELOCITY;
|
_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) {
|
void EntityItem::updateGravity(const glm::vec3& value) {
|
||||||
if (/* false && */ value == _previousGravityFromServer) {
|
auto distance = glm::distance(_gravity, value);
|
||||||
_gravity = value;
|
// if (value != _gravity) {
|
||||||
} else if (glm::distance(_gravity, value) > MIN_GRAVITY_DELTA) {
|
if (distance > MIN_GRAVITY_DELTA) {
|
||||||
_gravity = value;
|
// _dirtyFlags |= (distance > MIN_GRAVITY_DELTA) ? EntityItem::DIRTY_VELOCITY : EntityItem::DIRTY_PHYSICS_NO_WAKE;
|
||||||
_previousGravityFromServer = value;
|
|
||||||
_dirtyFlags |= EntityItem::DIRTY_VELOCITY;
|
_dirtyFlags |= EntityItem::DIRTY_VELOCITY;
|
||||||
|
_gravity = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EntityItem::updateAcceleration(const glm::vec3& value) {
|
void EntityItem::updateAcceleration(const glm::vec3& value) {
|
||||||
if (/* false && */ value == _previousAccelerationFromServer) {
|
auto distance = glm::distance(_acceleration, value);
|
||||||
_acceleration = value;
|
// if (value != _acceleration) {
|
||||||
} else if (glm::distance(_acceleration, value) > MIN_ACCELERATION_DELTA) {
|
if (distance > MIN_ACCELERATION_DELTA) {
|
||||||
_acceleration = value;
|
// _dirtyFlags |= (distance > MIN_ACCELERATION_DELTA) ? EntityItem::DIRTY_VELOCITY : EntityItem::DIRTY_PHYSICS_NO_WAKE;
|
||||||
_previousAccelerationFromServer = value;
|
|
||||||
_dirtyFlags |= EntityItem::DIRTY_VELOCITY;
|
_dirtyFlags |= EntityItem::DIRTY_VELOCITY;
|
||||||
|
_acceleration = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EntityItem::updateAngularVelocity(const glm::vec3& value) {
|
void EntityItem::updateAngularVelocity(const glm::vec3& value) {
|
||||||
if (/* false && */ value == _previousAngularVelocityFromServer) {
|
auto distance = glm::distance(_angularVelocity, value);
|
||||||
if (glm::length(value) < MIN_SPIN_DELTA) {
|
// if (value != _angularVelocity) {
|
||||||
_angularVelocity = ENTITY_ITEM_ZERO_VEC3;
|
if (distance > MIN_SPIN_DELTA) {
|
||||||
} else {
|
// _dirtyFlags |= (distance > MIN_SPIN_DELTA) ? EntityItem::DIRTY_VELOCITY : EntityItem::DIRTY_PHYSICS_NO_WAKE;
|
||||||
_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;
|
|
||||||
}
|
|
||||||
_dirtyFlags |= EntityItem::DIRTY_VELOCITY;
|
_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_SHAPE = 0x0020,
|
||||||
DIRTY_LIFETIME = 0x0040,
|
DIRTY_LIFETIME = 0x0040,
|
||||||
DIRTY_UPDATEABLE = 0x0080,
|
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
|
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
|
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
|
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) {
|
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) {
|
if (flags & EntityItem::DIRTY_POSITION) {
|
||||||
_sentPosition = _entity->getPosition() - ObjectMotionState::getWorldOffset();
|
_sentPosition = _entity->getPosition() - ObjectMotionState::getWorldOffset();
|
||||||
btTransform worldTrans;
|
btTransform worldTrans;
|
||||||
|
@ -147,6 +147,10 @@ void EntityMotionState::updateObjectEasy(uint32_t flags, uint32_t step) {
|
||||||
updateObjectVelocities();
|
updateObjectVelocities();
|
||||||
}
|
}
|
||||||
_sentStep = step;
|
_sentStep = step;
|
||||||
|
|
||||||
|
if (flags & (EntityItem::DIRTY_POSITION | EntityItem::DIRTY_VELOCITY)) {
|
||||||
|
_body->activate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: entity support for friction and restitution
|
// 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->setMassProps(mass, inertia);
|
||||||
_body->updateInertiaTensor();
|
_body->updateInertiaTensor();
|
||||||
}
|
}
|
||||||
_body->activate();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void EntityMotionState::updateObjectVelocities() {
|
void EntityMotionState::updateObjectVelocities() {
|
||||||
|
|
Loading…
Reference in a new issue