don't expect final kinematic simulation update

This commit is contained in:
Andrew Meadows 2019-09-12 17:02:19 -07:00
parent 36bc538354
commit bc119d6c85

View file

@ -84,48 +84,51 @@ EntityMotionState::~EntityMotionState() {
} }
void EntityMotionState::updateServerPhysicsVariables() { void EntityMotionState::updateServerPhysicsVariables() {
if (_ownershipState != EntityMotionState::OwnershipState::LocallyOwned) { // only slam these values if we are NOT the simulation owner
// only slam these values if we are NOT the simulation owner Transform localTransform;
Transform localTransform; _entity->getLocalTransformAndVelocities(localTransform, _serverVelocity, _serverAngularVelocity);
_entity->getLocalTransformAndVelocities(localTransform, _serverVelocity, _serverAngularVelocity); _serverPosition = localTransform.getTranslation();
_serverPosition = localTransform.getTranslation(); _serverRotation = localTransform.getRotation();
_serverRotation = localTransform.getRotation(); _serverAcceleration = _entity->getAcceleration();
_serverAcceleration = _entity->getAcceleration(); _serverActionData = _entity->getDynamicData();
_serverActionData = _entity->getDynamicData(); _lastStep = ObjectMotionState::getWorldSimulationStep();
_lastStep = ObjectMotionState::getWorldSimulationStep();
}
} }
void EntityMotionState::handleDeactivation() { void EntityMotionState::handleDeactivation() {
if (_entity->getDirtyFlags() & (Simulation::DIRTY_TRANSFORM | Simulation::DIRTY_VELOCITIES)) { if (_entity->getDirtyFlags() & (Simulation::DIRTY_TRANSFORM | Simulation::DIRTY_VELOCITIES)) {
// Some non-physical event (script-call or network-packet) has modified the entity's transform and/or velocities // Some non-physical event (script-call or network-packet) has modified the entity's transform and/or
// at the last minute before deactivation --> the values stored in _server* and _body are stale. // velocities at the last minute before deactivation --> the values stored in _server* and _body are stale.
// We assume the EntityMotionState is the last to know, so we copy from EntityItem and let things sort themselves out. // We assume the EntityMotionState is the last to know, so we copy from EntityItem to _server* variables
Transform localTransform; // here but don't clear the flags --> the will body be set straight before next simulation step.
_entity->getLocalTransformAndVelocities(localTransform, _serverVelocity, _serverAngularVelocity); updateServerPhysicsVariables();
_serverPosition = localTransform.getTranslation(); } else if (_body->isStaticOrKinematicObject() && _ownershipState != EntityMotionState::OwnershipState::LocallyOwned) {
_serverRotation = localTransform.getRotation(); // To allow the ESS to move entities around in a kinematic way we had to remove the requirement that
_serverAcceleration = _entity->getAcceleration(); // every moving+simulated entity has an authoritative simulation owner. As a result, we cannot rely
_serverActionData = _entity->getDynamicData(); // on a final authoritative update of kinmatic objects prior to deactivation in the local simulation.
_lastStep = ObjectMotionState::getWorldSimulationStep(); // For this case (unowned kinematic objects) we update the _server* variables for good measure but
} else { // leave the entity and body alone. They should have been updated correctly in the last call to
// copy _server data to entity // EntityMotionState::getWorldTransform().
Transform localTransform = _entity->getLocalTransform(); updateServerPhysicsVariables();
localTransform.setTranslation(_serverPosition); } else {
localTransform.setRotation(_serverRotation); // copy _server data to entity
_entity->setLocalTransformAndVelocities(localTransform, ENTITY_ITEM_ZERO_VEC3, ENTITY_ITEM_ZERO_VEC3); Transform localTransform = _entity->getLocalTransform();
// and also to RigidBody localTransform.setTranslation(_serverPosition);
btTransform worldTrans; localTransform.setRotation(_serverRotation);
worldTrans.setOrigin(glmToBullet(_entity->getWorldPosition())); _entity->setLocalTransformAndVelocities(localTransform, ENTITY_ITEM_ZERO_VEC3, ENTITY_ITEM_ZERO_VEC3);
worldTrans.setRotation(glmToBullet(_entity->getWorldOrientation())); // and also to RigidBody
_body->setWorldTransform(worldTrans); btTransform worldTrans;
// no need to update velocities... should already be zero worldTrans.setOrigin(glmToBullet(_entity->getWorldPosition()));
} worldTrans.setRotation(glmToBullet(_entity->getWorldOrientation()));
_body->setWorldTransform(worldTrans);
// no need to update velocities... should already be zero
}
} }
// virtual // virtual
void EntityMotionState::handleEasyChanges(uint32_t& flags) { void EntityMotionState::handleEasyChanges(uint32_t& flags) {
updateServerPhysicsVariables(); if (_ownershipState != EntityMotionState::OwnershipState::LocallyOwned) {
updateServerPhysicsVariables();
}
ObjectMotionState::handleEasyChanges(flags); ObjectMotionState::handleEasyChanges(flags);
if (flags & Simulation::DIRTY_SIMULATOR_ID) { if (flags & Simulation::DIRTY_SIMULATOR_ID) {