mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 06:44:06 +02:00
move _accelerationNearlyGravityCount and _shouldClaimSimulationOwnership from EntityItem to EntityMotionState
This commit is contained in:
parent
4ca076ed94
commit
9e96026c52
5 changed files with 35 additions and 29 deletions
|
@ -47,7 +47,6 @@ EntityItem::EntityItem(const EntityItemID& entityItemID) :
|
|||
_velocity(ENTITY_ITEM_DEFAULT_VELOCITY),
|
||||
_gravity(ENTITY_ITEM_DEFAULT_GRAVITY),
|
||||
_acceleration(ENTITY_ITEM_DEFAULT_ACCELERATION),
|
||||
_accelerationNearlyGravityCount(0),
|
||||
_damping(ENTITY_ITEM_DEFAULT_DAMPING),
|
||||
_lifetime(ENTITY_ITEM_DEFAULT_LIFETIME),
|
||||
_script(ENTITY_ITEM_DEFAULT_SCRIPT),
|
||||
|
@ -61,7 +60,6 @@ EntityItem::EntityItem(const EntityItemID& entityItemID) :
|
|||
_userData(ENTITY_ITEM_DEFAULT_USER_DATA),
|
||||
_simulatorID(ENTITY_ITEM_DEFAULT_SIMULATOR_ID),
|
||||
_simulatorIDChangedTime(0),
|
||||
_shouldClaimSimulationOwnership(false),
|
||||
_marketplaceID(ENTITY_ITEM_DEFAULT_MARKETPLACE_ID),
|
||||
_physicsInfo(NULL),
|
||||
_dirtyFlags(0),
|
||||
|
|
|
@ -258,8 +258,6 @@ public:
|
|||
QUuid getSimulatorID() const { return _simulatorID; }
|
||||
void setSimulatorID(const QUuid& value);
|
||||
quint64 getSimulatorIDChangedTime() const { return _simulatorIDChangedTime; }
|
||||
void setShouldClaimSimulationOwnership(bool value) { _shouldClaimSimulationOwnership = value; }
|
||||
bool getShouldClaimSimulationOwnership() { return _shouldClaimSimulationOwnership; }
|
||||
|
||||
const QString& getMarketplaceID() const { return _marketplaceID; }
|
||||
void setMarketplaceID(const QString& value) { _marketplaceID = value; }
|
||||
|
@ -311,10 +309,6 @@ public:
|
|||
static void setSendPhysicsUpdates(bool value) { _sendPhysicsUpdates = value; }
|
||||
static bool getSendPhysicsUpdates() { return _sendPhysicsUpdates; }
|
||||
|
||||
void incrementAccelerationNearlyGravityCount() { _accelerationNearlyGravityCount++; }
|
||||
void resetAccelerationNearlyGravityCount() { _accelerationNearlyGravityCount = 0; }
|
||||
quint8 getAccelerationNearlyGravityCount() { return _accelerationNearlyGravityCount; }
|
||||
|
||||
protected:
|
||||
|
||||
static bool _sendPhysicsUpdates;
|
||||
|
@ -344,7 +338,6 @@ protected:
|
|||
glm::vec3 _velocity;
|
||||
glm::vec3 _gravity;
|
||||
glm::vec3 _acceleration;
|
||||
quint8 _accelerationNearlyGravityCount;
|
||||
float _damping;
|
||||
float _lifetime;
|
||||
QString _script;
|
||||
|
@ -358,7 +351,6 @@ protected:
|
|||
QString _userData;
|
||||
QUuid _simulatorID; // id of Node which is currently responsible for simulating this Entity
|
||||
quint64 _simulatorIDChangedTime; // when was _simulatorID last updated?
|
||||
bool _shouldClaimSimulationOwnership;
|
||||
QString _marketplaceID;
|
||||
|
||||
// NOTE: Damping is applied like this: v *= pow(1 - damping, dt)
|
||||
|
|
|
@ -35,8 +35,11 @@ void EntityMotionState::enqueueOutgoingEntity(EntityItem* entity) {
|
|||
_outgoingEntityList->insert(entity);
|
||||
}
|
||||
|
||||
EntityMotionState::EntityMotionState(EntityItem* entity)
|
||||
: _entity(entity) {
|
||||
EntityMotionState::EntityMotionState(EntityItem* entity) :
|
||||
_entity(entity),
|
||||
_accelerationNearlyGravityCount(0),
|
||||
_shouldClaimSimulationOwnership(false)
|
||||
{
|
||||
_type = MOTION_STATE_TYPE_ENTITY;
|
||||
assert(entity != NULL);
|
||||
}
|
||||
|
@ -192,7 +195,7 @@ bool EntityMotionState::shouldSendUpdate(uint32_t simulationFrame) {
|
|||
return false;
|
||||
}
|
||||
|
||||
if (_entity->getShouldClaimSimulationOwnership()) {
|
||||
if (getShouldClaimSimulationOwnership()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -219,19 +222,19 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, uint32_
|
|||
float accVsGravity = glm::abs(glm::length(_measuredAcceleration) - gravityLength);
|
||||
if (accVsGravity < ACCELERATION_EQUIVALENT_EPSILON_RATIO * gravityLength) {
|
||||
// acceleration measured during the most recent simulation step was close to gravity.
|
||||
if (_entity->getAccelerationNearlyGravityCount() < STEPS_TO_DECIDE_BALLISTIC) {
|
||||
if (getAccelerationNearlyGravityCount() < STEPS_TO_DECIDE_BALLISTIC) {
|
||||
// only increment this if we haven't reached the threshold yet. this is to avoid
|
||||
// overflowing the counter.
|
||||
_entity->incrementAccelerationNearlyGravityCount();
|
||||
incrementAccelerationNearlyGravityCount();
|
||||
}
|
||||
} else {
|
||||
// acceleration wasn't similar to this entities gravity, so reset the went-ballistic counter
|
||||
_entity->resetAccelerationNearlyGravityCount();
|
||||
resetAccelerationNearlyGravityCount();
|
||||
}
|
||||
|
||||
// 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.
|
||||
if (_entity->getAccelerationNearlyGravityCount() >= STEPS_TO_DECIDE_BALLISTIC) {
|
||||
if (getAccelerationNearlyGravityCount() >= STEPS_TO_DECIDE_BALLISTIC) {
|
||||
_entity->setAcceleration(_entity->getGravity());
|
||||
} else {
|
||||
_entity->setAcceleration(glm::vec3(0.0f));
|
||||
|
@ -283,10 +286,10 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, uint32_
|
|||
QUuid myNodeID = nodeList->getSessionUUID();
|
||||
QUuid simulatorID = _entity->getSimulatorID();
|
||||
|
||||
if (_entity->getShouldClaimSimulationOwnership()) {
|
||||
if (getShouldClaimSimulationOwnership()) {
|
||||
_entity->setSimulatorID(myNodeID);
|
||||
properties.setSimulatorID(myNodeID);
|
||||
_entity->setShouldClaimSimulationOwnership(false);
|
||||
setShouldClaimSimulationOwnership(false);
|
||||
}
|
||||
|
||||
if (simulatorID == myNodeID && zeroSpeed && zeroSpin) {
|
||||
|
|
|
@ -64,8 +64,17 @@ public:
|
|||
|
||||
EntityItem* getEntity() const { return _entity; }
|
||||
|
||||
void incrementAccelerationNearlyGravityCount() { _accelerationNearlyGravityCount++; }
|
||||
void resetAccelerationNearlyGravityCount() { _accelerationNearlyGravityCount = 0; }
|
||||
quint8 getAccelerationNearlyGravityCount() { return _accelerationNearlyGravityCount; }
|
||||
|
||||
void setShouldClaimSimulationOwnership(bool value) { _shouldClaimSimulationOwnership = value; }
|
||||
bool getShouldClaimSimulationOwnership() { return _shouldClaimSimulationOwnership; }
|
||||
|
||||
protected:
|
||||
EntityItem* _entity;
|
||||
quint8 _accelerationNearlyGravityCount;
|
||||
bool _shouldClaimSimulationOwnership;
|
||||
};
|
||||
|
||||
#endif // hifi_EntityMotionState_h
|
||||
|
|
|
@ -392,9 +392,11 @@ void PhysicsEngine::computeCollisionEvents() {
|
|||
}
|
||||
|
||||
void* a = objectA->getUserPointer();
|
||||
EntityItem* entityA = a ? static_cast<EntityMotionState*>(a)->getEntity() : NULL;
|
||||
EntityMotionState* entityMotionStateA = static_cast<EntityMotionState*>(a);
|
||||
EntityItem* entityA = entityMotionStateA ? entityMotionStateA->getEntity() : NULL;
|
||||
void* b = objectB->getUserPointer();
|
||||
EntityItem* entityB = b ? static_cast<EntityMotionState*>(b)->getEntity() : NULL;
|
||||
EntityMotionState* entityMotionStateB = static_cast<EntityMotionState*>(b);
|
||||
EntityItem* entityB = entityMotionStateB ? entityMotionStateB->getEntity() : NULL;
|
||||
if (a || b) {
|
||||
// the manifold has up to 4 distinct points, but only extract info from the first
|
||||
_contactMap[ContactKey(a, b)].update(_numContactFrames, contactManifold->getContactPoint(0), _originOffset);
|
||||
|
@ -403,14 +405,14 @@ void PhysicsEngine::computeCollisionEvents() {
|
|||
// ownership of anything that collides with our avatar.
|
||||
if (entityA && entityB && !objectA->isStaticOrKinematicObject() && !objectB->isStaticOrKinematicObject()) {
|
||||
if (entityA->getSimulatorID() == myNodeID ||
|
||||
entityA->getShouldClaimSimulationOwnership() ||
|
||||
entityMotionStateA->getShouldClaimSimulationOwnership() ||
|
||||
objectA == characterCollisionObject) {
|
||||
entityB->setShouldClaimSimulationOwnership(true);
|
||||
entityMotionStateB->setShouldClaimSimulationOwnership(true);
|
||||
}
|
||||
if (entityB->getSimulatorID() == myNodeID ||
|
||||
entityB->getShouldClaimSimulationOwnership() ||
|
||||
entityMotionStateA->getShouldClaimSimulationOwnership() ||
|
||||
objectB == characterCollisionObject) {
|
||||
entityA->setShouldClaimSimulationOwnership(true);
|
||||
entityMotionStateB->setShouldClaimSimulationOwnership(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -543,17 +545,19 @@ void PhysicsEngine::bump(EntityItem* bumpEntity) {
|
|||
void* a = objectA->getUserPointer();
|
||||
void* b = objectB->getUserPointer();
|
||||
if (a && b) {
|
||||
EntityItem* entityA = a ? static_cast<EntityMotionState*>(a)->getEntity() : NULL;
|
||||
EntityItem* entityB = b ? static_cast<EntityMotionState*>(b)->getEntity() : NULL;
|
||||
EntityMotionState* entityMotionStateA = static_cast<EntityMotionState*>(a);
|
||||
EntityMotionState* entityMotionStateB = static_cast<EntityMotionState*>(b);
|
||||
EntityItem* entityA = entityMotionStateA ? entityMotionStateA->getEntity() : NULL;
|
||||
EntityItem* entityB = entityMotionStateB ? entityMotionStateB->getEntity() : NULL;
|
||||
if (entityA && entityB) {
|
||||
if (entityA == bumpEntity) {
|
||||
entityB->setShouldClaimSimulationOwnership(true);
|
||||
entityMotionStateB->setShouldClaimSimulationOwnership(true);
|
||||
if (!objectB->isActive()) {
|
||||
objectB->setActivationState(ACTIVE_TAG);
|
||||
}
|
||||
}
|
||||
if (entityB == bumpEntity) {
|
||||
entityA->setShouldClaimSimulationOwnership(true);
|
||||
entityMotionStateA->setShouldClaimSimulationOwnership(true);
|
||||
if (!objectA->isActive()) {
|
||||
objectA->setActivationState(ACTIVE_TAG);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue