mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 19:04:32 +02:00
claim ownership faster for scripted manipulations
This commit is contained in:
parent
7c793c6397
commit
2579247c34
5 changed files with 39 additions and 33 deletions
|
@ -96,8 +96,9 @@ public:
|
|||
DIRTY_LIFETIME = 0x0100,
|
||||
DIRTY_UPDATEABLE = 0x0200,
|
||||
DIRTY_MATERIAL = 0x00400,
|
||||
DIRTY_PHYSICS_ACTIVATION = 0x0800, // we want to activate the object
|
||||
DIRTY_SIMULATOR_ID = 0x1000,
|
||||
DIRTY_PHYSICS_ACTIVATION = 0x0800, // should activate object in physics engine
|
||||
DIRTY_SIMULATOR_OWNERSHIP = 0x1000, // should claim simulator ownership
|
||||
DIRTY_SIMULATOR_ID = 0x2000, // the simulatorID has changed
|
||||
DIRTY_TRANSFORM = DIRTY_POSITION | DIRTY_ROTATION,
|
||||
DIRTY_VELOCITIES = DIRTY_LINEAR_VELOCITY | DIRTY_ANGULAR_VELOCITY
|
||||
};
|
||||
|
@ -387,6 +388,8 @@ public:
|
|||
|
||||
void getAllTerseUpdateProperties(EntityItemProperties& properties) const;
|
||||
|
||||
void flagForOwnership() { _dirtyFlags |= DIRTY_SIMULATOR_OWNERSHIP; }
|
||||
|
||||
bool addAction(EntitySimulation* simulation, EntityActionPointer action);
|
||||
bool updateAction(EntitySimulation* simulation, const QUuid& actionID, const QVariantMap& arguments);
|
||||
bool removeAction(EntitySimulation* simulation, const QUuid& actionID);
|
||||
|
|
|
@ -161,6 +161,7 @@ QUuid EntityScriptingInterface::editEntity(QUuid id, EntityItemProperties proper
|
|||
} else {
|
||||
// we make a bid for simulation ownership
|
||||
properties.setSimulatorOwnership(myNodeID, SCRIPT_EDIT_SIMULATOR_PRIORITY);
|
||||
entity->flagForOwnership();
|
||||
}
|
||||
}
|
||||
entity->setLastBroadcast(usecTimestampNow());
|
||||
|
|
|
@ -58,8 +58,7 @@ bool entityTreeIsLocked() {
|
|||
EntityMotionState::EntityMotionState(btCollisionShape* shape, EntityItemPointer entity) :
|
||||
ObjectMotionState(shape),
|
||||
_entity(entity),
|
||||
_sentActive(false),
|
||||
_numNonMovingUpdates(0),
|
||||
_sentInactive(true),
|
||||
_lastStep(0),
|
||||
_serverPosition(0.0f),
|
||||
_serverRotation(),
|
||||
|
@ -117,6 +116,13 @@ void EntityMotionState::handleEasyChanges(uint32_t flags) {
|
|||
}
|
||||
}
|
||||
}
|
||||
if (flags & EntityItem::DIRTY_SIMULATOR_OWNERSHIP) {
|
||||
// we're manipulating this object directly via script, so we artificially
|
||||
// manipulate the logic to trigger an immediate bid for ownership
|
||||
_candidateForOwnership = true;
|
||||
_loopsSinceOwnershipBid = uint32_t(-1);
|
||||
_loopsWithoutOwner = uint32_t(-1);
|
||||
}
|
||||
if ((flags & EntityItem::DIRTY_PHYSICS_ACTIVATION) && !_body->isActive()) {
|
||||
_body->activate();
|
||||
}
|
||||
|
@ -197,6 +203,7 @@ void EntityMotionState::setWorldTransform(const btTransform& worldTrans) {
|
|||
if (_loopsWithoutOwner > OWNERSHIP_BID_DELAY) {
|
||||
//qDebug() << "Warning -- claiming something I saw moving." << getName();
|
||||
_candidateForOwnership = true;
|
||||
_loopsSinceOwnershipBid = uint32_t(-1);
|
||||
}
|
||||
} else {
|
||||
_loopsWithoutOwner = 0;
|
||||
|
@ -243,7 +250,7 @@ bool EntityMotionState::remoteSimulationOutOfSync(uint32_t simulationStep) {
|
|||
_serverVelocity = bulletToGLM(_body->getLinearVelocity());
|
||||
_serverAngularVelocity = bulletToGLM(_body->getAngularVelocity());
|
||||
_lastStep = simulationStep;
|
||||
_sentActive = false;
|
||||
_sentInactive = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -257,7 +264,7 @@ bool EntityMotionState::remoteSimulationOutOfSync(uint32_t simulationStep) {
|
|||
float dt = (float)(numSteps) * PHYSICS_ENGINE_FIXED_SUBSTEP;
|
||||
|
||||
const float INACTIVE_UPDATE_PERIOD = 0.5f;
|
||||
if (!_sentActive) {
|
||||
if (_sentInactive) {
|
||||
// we resend the inactive update every INACTIVE_UPDATE_PERIOD
|
||||
// until it is removed from the outgoing updates
|
||||
// (which happens when we don't own the simulation and it isn't touching our simulation)
|
||||
|
@ -345,30 +352,23 @@ bool EntityMotionState::shouldSendUpdate(uint32_t simulationStep, const QUuid& s
|
|||
assert(_body);
|
||||
assert(entityTreeIsLocked());
|
||||
|
||||
if (!remoteSimulationOutOfSync(simulationStep)) {
|
||||
_candidateForOwnership = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (_entity->getSimulatorID() == sessionID) {
|
||||
// we own the simulation
|
||||
_candidateForOwnership = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
const uint32_t FRAMES_BETWEEN_OWNERSHIP_CLAIMS = 30;
|
||||
if (_candidateForOwnership) {
|
||||
_candidateForOwnership = false;
|
||||
++_loopsSinceOwnershipBid;
|
||||
if (_loopsSinceOwnershipBid > FRAMES_BETWEEN_OWNERSHIP_CLAIMS) {
|
||||
// we don't own the simulation, but it's time to bid for it
|
||||
_loopsSinceOwnershipBid = 0;
|
||||
return true;
|
||||
if (_entity->getSimulatorID() != sessionID) {
|
||||
// we don't own the simulation, but maybe we should...
|
||||
if (_candidateForOwnership) {
|
||||
_candidateForOwnership = false;
|
||||
++_loopsSinceOwnershipBid;
|
||||
const uint32_t FRAMES_BETWEEN_OWNERSHIP_CLAIMS = 30;
|
||||
if (_loopsSinceOwnershipBid > FRAMES_BETWEEN_OWNERSHIP_CLAIMS) {
|
||||
// it's time to bid for ownership
|
||||
_loopsSinceOwnershipBid = 0;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
_candidateForOwnership = false;
|
||||
return false;
|
||||
|
||||
return remoteSimulationOutOfSync(simulationStep);
|
||||
}
|
||||
|
||||
void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, const QUuid& sessionID, uint32_t step) {
|
||||
|
@ -382,7 +382,7 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, const Q
|
|||
_entity->setVelocity(zero);
|
||||
_entity->setAngularVelocity(zero);
|
||||
_entity->setAcceleration(zero);
|
||||
_sentActive = false;
|
||||
_sentInactive = true;
|
||||
} else {
|
||||
float gravityLength = glm::length(_entity->getGravity());
|
||||
float accVsGravity = glm::abs(glm::length(_measuredAcceleration) - gravityLength);
|
||||
|
@ -419,7 +419,7 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, const Q
|
|||
_entity->setVelocity(zero);
|
||||
_entity->setAngularVelocity(zero);
|
||||
}
|
||||
_sentActive = true;
|
||||
_sentInactive = false;
|
||||
}
|
||||
|
||||
// remember properties for local server prediction
|
||||
|
@ -543,8 +543,11 @@ void EntityMotionState::measureBodyAcceleration() {
|
|||
_measuredAcceleration = (velocity / powf(1.0f - _body->getLinearDamping(), dt) - _lastVelocity) * invDt;
|
||||
_lastVelocity = velocity;
|
||||
if (numSubsteps > PHYSICS_ENGINE_MAX_NUM_SUBSTEPS && !_candidateForOwnership) {
|
||||
// object has just been re-activated so clear ownership logic
|
||||
_loopsSinceOwnershipBid = 0;
|
||||
_loopsWithoutOwner = 0;
|
||||
_lastStep = ObjectMotionState::getWorldSimulationStep();
|
||||
_sentInactive = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -96,8 +96,7 @@ protected:
|
|||
|
||||
EntityItemPointer _entity;
|
||||
|
||||
bool _sentActive; // true if body was active when we sent last update
|
||||
int _numNonMovingUpdates; // RELIABLE_SEND_HACK for "not so reliable" resends of packets for non-moving objects
|
||||
bool _sentInactive; // true if body was inactive when we sent last update
|
||||
|
||||
// these are for the prediction of the remote server's simple extrapolation
|
||||
uint32_t _lastStep; // last step of server extrapolation
|
||||
|
|
|
@ -40,7 +40,7 @@ enum MotionStateType {
|
|||
const uint32_t HARD_DIRTY_PHYSICS_FLAGS = (uint32_t)(EntityItem::DIRTY_MOTION_TYPE | EntityItem::DIRTY_SHAPE);
|
||||
const uint32_t EASY_DIRTY_PHYSICS_FLAGS = (uint32_t)(EntityItem::DIRTY_TRANSFORM | EntityItem::DIRTY_VELOCITIES |
|
||||
EntityItem::DIRTY_MASS | EntityItem::DIRTY_COLLISION_GROUP |
|
||||
EntityItem::DIRTY_MATERIAL);
|
||||
EntityItem::DIRTY_MATERIAL | EntityItem::DIRTY_SIMULATOR_OWNERSHIP);
|
||||
|
||||
// These are the set of incoming flags that the PhysicsEngine needs to hear about:
|
||||
const uint32_t DIRTY_PHYSICS_FLAGS = (uint32_t)(HARD_DIRTY_PHYSICS_FLAGS | EASY_DIRTY_PHYSICS_FLAGS |
|
||||
|
|
Loading…
Reference in a new issue