mirror of
https://github.com/overte-org/overte.git
synced 2025-08-12 09:54:18 +02:00
DRY sendBid() and sendUpdate()
This commit is contained in:
parent
766077204e
commit
59abc1d5b5
2 changed files with 10 additions and 38 deletions
|
@ -453,10 +453,7 @@ bool EntityMotionState::shouldSendUpdate(uint32_t simulationStep) {
|
||||||
return remoteSimulationOutOfSync(simulationStep);
|
return remoteSimulationOutOfSync(simulationStep);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EntityMotionState::sendBid(OctreeEditPacketSender* packetSender, uint32_t step) {
|
void EntityMotionState::updateSendVelocities() {
|
||||||
DETAILED_PROFILE_RANGE(simulation_physics, "Bid");
|
|
||||||
assert(entityTreeIsLocked());
|
|
||||||
|
|
||||||
if (!_body->isActive()) {
|
if (!_body->isActive()) {
|
||||||
// make sure all derivatives are zero
|
// make sure all derivatives are zero
|
||||||
clearObjectVelocities();
|
clearObjectVelocities();
|
||||||
|
@ -491,6 +488,13 @@ void EntityMotionState::sendBid(OctreeEditPacketSender* packetSender, uint32_t s
|
||||||
}
|
}
|
||||||
_numInactiveUpdates = 0;
|
_numInactiveUpdates = 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void EntityMotionState::sendBid(OctreeEditPacketSender* packetSender, uint32_t step) {
|
||||||
|
DETAILED_PROFILE_RANGE(simulation_physics, "Bid");
|
||||||
|
assert(entityTreeIsLocked());
|
||||||
|
|
||||||
|
updateSendVelocities();
|
||||||
|
|
||||||
EntityItemProperties properties;
|
EntityItemProperties properties;
|
||||||
Transform localTransform;
|
Transform localTransform;
|
||||||
|
@ -552,40 +556,7 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, uint32_
|
||||||
assert(entityTreeIsLocked());
|
assert(entityTreeIsLocked());
|
||||||
assert(isLocallyOwned());
|
assert(isLocallyOwned());
|
||||||
|
|
||||||
if (!_body->isActive()) {
|
updateSendVelocities();
|
||||||
// make sure all derivatives are zero
|
|
||||||
clearObjectVelocities();
|
|
||||||
_numInactiveUpdates++;
|
|
||||||
} else {
|
|
||||||
glm::vec3 gravity = _entity->getGravity();
|
|
||||||
|
|
||||||
// if this entity has been accelerated at close to gravity for a certain number of simulation-steps, let
|
|
||||||
// the entity server's estimates include gravity.
|
|
||||||
const uint8_t STEPS_TO_DECIDE_BALLISTIC = 4;
|
|
||||||
if (_accelerationNearlyGravityCount >= STEPS_TO_DECIDE_BALLISTIC) {
|
|
||||||
_entity->setAcceleration(gravity);
|
|
||||||
} else {
|
|
||||||
_entity->setAcceleration(Vectors::ZERO);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!_body->isStaticOrKinematicObject()) {
|
|
||||||
const float DYNAMIC_LINEAR_VELOCITY_THRESHOLD = 0.05f; // 5 cm/sec
|
|
||||||
const float DYNAMIC_ANGULAR_VELOCITY_THRESHOLD = 0.087266f; // ~5 deg/sec
|
|
||||||
|
|
||||||
bool movingSlowlyLinear =
|
|
||||||
glm::length2(_entity->getWorldVelocity()) < (DYNAMIC_LINEAR_VELOCITY_THRESHOLD * DYNAMIC_LINEAR_VELOCITY_THRESHOLD);
|
|
||||||
bool movingSlowlyAngular = glm::length2(_entity->getWorldAngularVelocity()) <
|
|
||||||
(DYNAMIC_ANGULAR_VELOCITY_THRESHOLD * DYNAMIC_ANGULAR_VELOCITY_THRESHOLD);
|
|
||||||
bool movingSlowly = movingSlowlyLinear && movingSlowlyAngular && _entity->getAcceleration() == Vectors::ZERO;
|
|
||||||
|
|
||||||
if (movingSlowly) {
|
|
||||||
// velocities might not be zero, but we'll fake them as such, which will hopefully help convince
|
|
||||||
// other simulating observers to deactivate their own copies
|
|
||||||
clearObjectVelocities();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_numInactiveUpdates = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// remember _serverFoo data for local prediction of server state
|
// remember _serverFoo data for local prediction of server state
|
||||||
Transform localTransform;
|
Transform localTransform;
|
||||||
|
|
|
@ -92,6 +92,7 @@ public:
|
||||||
OwnershipState getOwnershipState() const { return _ownershipState; }
|
OwnershipState getOwnershipState() const { return _ownershipState; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void updateSendVelocities();
|
||||||
uint64_t getNextBidExpiry() const { return _nextBidExpiry; }
|
uint64_t getNextBidExpiry() const { return _nextBidExpiry; }
|
||||||
void initForBid();
|
void initForBid();
|
||||||
void initForOwned();
|
void initForOwned();
|
||||||
|
|
Loading…
Reference in a new issue