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,7 +84,6 @@ EntityMotionState::~EntityMotionState() {
}
void EntityMotionState::updateServerPhysicsVariables() {
if (_ownershipState != EntityMotionState::OwnershipState::LocallyOwned) {
// only slam these values if we are NOT the simulation owner
Transform localTransform;
_entity->getLocalTransformAndVelocities(localTransform, _serverVelocity, _serverAngularVelocity);
@ -94,20 +93,22 @@ void EntityMotionState::updateServerPhysicsVariables() {
_serverActionData = _entity->getDynamicData();
_lastStep = ObjectMotionState::getWorldSimulationStep();
}
}
void EntityMotionState::handleDeactivation() {
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
// 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.
Transform localTransform;
_entity->getLocalTransformAndVelocities(localTransform, _serverVelocity, _serverAngularVelocity);
_serverPosition = localTransform.getTranslation();
_serverRotation = localTransform.getRotation();
_serverAcceleration = _entity->getAcceleration();
_serverActionData = _entity->getDynamicData();
_lastStep = ObjectMotionState::getWorldSimulationStep();
// Some non-physical event (script-call or network-packet) has modified the entity's transform and/or
// 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 to _server* variables
// here but don't clear the flags --> the will body be set straight before next simulation step.
updateServerPhysicsVariables();
} else if (_body->isStaticOrKinematicObject() && _ownershipState != EntityMotionState::OwnershipState::LocallyOwned) {
// To allow the ESS to move entities around in a kinematic way we had to remove the requirement that
// every moving+simulated entity has an authoritative simulation owner. As a result, we cannot rely
// on a final authoritative update of kinmatic objects prior to deactivation in the local simulation.
// For this case (unowned kinematic objects) we update the _server* variables for good measure but
// leave the entity and body alone. They should have been updated correctly in the last call to
// EntityMotionState::getWorldTransform().
updateServerPhysicsVariables();
} else {
// copy _server data to entity
Transform localTransform = _entity->getLocalTransform();
@ -125,7 +126,9 @@ void EntityMotionState::handleDeactivation() {
// virtual
void EntityMotionState::handleEasyChanges(uint32_t& flags) {
if (_ownershipState != EntityMotionState::OwnershipState::LocallyOwned) {
updateServerPhysicsVariables();
}
ObjectMotionState::handleEasyChanges(flags);
if (flags & Simulation::DIRTY_SIMULATOR_ID) {