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() { 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);
@ -93,21 +92,23 @@ void EntityMotionState::updateServerPhysicsVariables() {
_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
// leave the entity and body alone. They should have been updated correctly in the last call to
// EntityMotionState::getWorldTransform().
updateServerPhysicsVariables();
} else { } else {
// copy _server data to entity // copy _server data to entity
Transform localTransform = _entity->getLocalTransform(); Transform localTransform = _entity->getLocalTransform();
@ -125,7 +126,9 @@ void EntityMotionState::handleDeactivation() {
// virtual // virtual
void EntityMotionState::handleEasyChanges(uint32_t& flags) { void EntityMotionState::handleEasyChanges(uint32_t& flags) {
if (_ownershipState != EntityMotionState::OwnershipState::LocallyOwned) {
updateServerPhysicsVariables(); updateServerPhysicsVariables();
}
ObjectMotionState::handleEasyChanges(flags); ObjectMotionState::handleEasyChanges(flags);
if (flags & Simulation::DIRTY_SIMULATOR_ID) { if (flags & Simulation::DIRTY_SIMULATOR_ID) {