mirror of
https://github.com/lubosz/overte.git
synced 2025-08-07 18:21:16 +02:00
cleanup some writeLocks
This commit is contained in:
parent
b5199220ab
commit
baff900839
1 changed files with 73 additions and 62 deletions
|
@ -1734,9 +1734,11 @@ void EntityItem::setParentID(const QUuid& value) {
|
||||||
void EntityItem::setDimensions(const glm::vec3& value) {
|
void EntityItem::setDimensions(const glm::vec3& value) {
|
||||||
glm::vec3 newDimensions = glm::max(value, glm::vec3(0.0f)); // can never have negative dimensions
|
glm::vec3 newDimensions = glm::max(value, glm::vec3(0.0f)); // can never have negative dimensions
|
||||||
if (getDimensions() != newDimensions) {
|
if (getDimensions() != newDimensions) {
|
||||||
_dimensions = newDimensions;
|
withWriteLock([&] {
|
||||||
markDirtyFlags(Simulation::DIRTY_SHAPE | Simulation::DIRTY_MASS);
|
_dimensions = newDimensions;
|
||||||
_queryAACubeSet = false;
|
_dirtyFlags |= (Simulation::DIRTY_SHAPE | Simulation::DIRTY_MASS);
|
||||||
|
_queryAACubeSet = false;
|
||||||
|
});
|
||||||
locationChanged();
|
locationChanged();
|
||||||
dimensionsChanged();
|
dimensionsChanged();
|
||||||
}
|
}
|
||||||
|
@ -1783,29 +1785,33 @@ void EntityItem::setVelocity(const glm::vec3& value) {
|
||||||
|
|
||||||
void EntityItem::setDamping(float value) {
|
void EntityItem::setDamping(float value) {
|
||||||
auto clampedDamping = glm::clamp(value, 0.0f, 1.0f);
|
auto clampedDamping = glm::clamp(value, 0.0f, 1.0f);
|
||||||
if (_damping != clampedDamping) {
|
withWriteLock([&] {
|
||||||
_damping = clampedDamping;
|
if (_damping != clampedDamping) {
|
||||||
_dirtyFlags |= Simulation::DIRTY_MATERIAL;
|
_damping = clampedDamping;
|
||||||
}
|
_dirtyFlags |= Simulation::DIRTY_MATERIAL;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void EntityItem::setGravity(const glm::vec3& value) {
|
void EntityItem::setGravity(const glm::vec3& value) {
|
||||||
if (_gravity != value) {
|
withWriteLock([&] {
|
||||||
if (getShapeType() == SHAPE_TYPE_STATIC_MESH) {
|
if (_gravity != value) {
|
||||||
_gravity = Vectors::ZERO;
|
if (getShapeType() == SHAPE_TYPE_STATIC_MESH) {
|
||||||
} else {
|
_gravity = Vectors::ZERO;
|
||||||
float magnitude = glm::length(value);
|
} else {
|
||||||
if (!glm::isnan(magnitude)) {
|
float magnitude = glm::length(value);
|
||||||
const float MAX_ACCELERATION_OF_GRAVITY = 10.0f * 9.8f; // 10g
|
if (!glm::isnan(magnitude)) {
|
||||||
if (magnitude > MAX_ACCELERATION_OF_GRAVITY) {
|
const float MAX_ACCELERATION_OF_GRAVITY = 10.0f * 9.8f; // 10g
|
||||||
_gravity = (MAX_ACCELERATION_OF_GRAVITY / magnitude) * value;
|
if (magnitude > MAX_ACCELERATION_OF_GRAVITY) {
|
||||||
} else {
|
_gravity = (MAX_ACCELERATION_OF_GRAVITY / magnitude) * value;
|
||||||
_gravity = value;
|
} else {
|
||||||
|
_gravity = value;
|
||||||
|
}
|
||||||
|
_dirtyFlags |= Simulation::DIRTY_LINEAR_VELOCITY;
|
||||||
}
|
}
|
||||||
_dirtyFlags |= Simulation::DIRTY_LINEAR_VELOCITY;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void EntityItem::setAngularVelocity(const glm::vec3& value) {
|
void EntityItem::setAngularVelocity(const glm::vec3& value) {
|
||||||
|
@ -1834,47 +1840,58 @@ void EntityItem::setAngularVelocity(const glm::vec3& value) {
|
||||||
|
|
||||||
void EntityItem::setAngularDamping(float value) {
|
void EntityItem::setAngularDamping(float value) {
|
||||||
auto clampedDamping = glm::clamp(value, 0.0f, 1.0f);
|
auto clampedDamping = glm::clamp(value, 0.0f, 1.0f);
|
||||||
if (_angularDamping != clampedDamping) {
|
withWriteLock([&] {
|
||||||
_angularDamping = clampedDamping;
|
if (_angularDamping != clampedDamping) {
|
||||||
_dirtyFlags |= Simulation::DIRTY_MATERIAL;
|
_angularDamping = clampedDamping;
|
||||||
}
|
_dirtyFlags |= Simulation::DIRTY_MATERIAL;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void EntityItem::setCollisionless(bool value) {
|
void EntityItem::setCollisionless(bool value) {
|
||||||
if (_collisionless != value) {
|
withWriteLock([&] {
|
||||||
_collisionless = value;
|
if (_collisionless != value) {
|
||||||
_dirtyFlags |= Simulation::DIRTY_COLLISION_GROUP;
|
_collisionless = value;
|
||||||
}
|
_dirtyFlags |= Simulation::DIRTY_COLLISION_GROUP;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void EntityItem::setCollisionMask(uint8_t value) {
|
void EntityItem::setCollisionMask(uint8_t value) {
|
||||||
if ((_collisionMask & ENTITY_COLLISION_MASK_DEFAULT) != (value & ENTITY_COLLISION_MASK_DEFAULT)) {
|
withWriteLock([&] {
|
||||||
_collisionMask = (value & ENTITY_COLLISION_MASK_DEFAULT);
|
if ((_collisionMask & ENTITY_COLLISION_MASK_DEFAULT) != (value & ENTITY_COLLISION_MASK_DEFAULT)) {
|
||||||
_dirtyFlags |= Simulation::DIRTY_COLLISION_GROUP;
|
_collisionMask = (value & ENTITY_COLLISION_MASK_DEFAULT);
|
||||||
}
|
_dirtyFlags |= Simulation::DIRTY_COLLISION_GROUP;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void EntityItem::setDynamic(bool value) {
|
void EntityItem::setDynamic(bool value) {
|
||||||
if (getDynamic() != value) {
|
if (getDynamic() != value) {
|
||||||
// dynamic and STATIC_MESH are incompatible so we check for that case
|
withWriteLock([&] {
|
||||||
if (value && getShapeType() == SHAPE_TYPE_STATIC_MESH) {
|
// dynamic and STATIC_MESH are incompatible so we check for that case
|
||||||
if (_dynamic) {
|
if (value && getShapeType() == SHAPE_TYPE_STATIC_MESH) {
|
||||||
_dynamic = false;
|
if (_dynamic) {
|
||||||
|
_dynamic = false;
|
||||||
|
_dirtyFlags |= Simulation::DIRTY_MOTION_TYPE;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
_dynamic = value;
|
||||||
_dirtyFlags |= Simulation::DIRTY_MOTION_TYPE;
|
_dirtyFlags |= Simulation::DIRTY_MOTION_TYPE;
|
||||||
}
|
}
|
||||||
} else {
|
});
|
||||||
_dynamic = value;
|
|
||||||
_dirtyFlags |= Simulation::DIRTY_MOTION_TYPE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EntityItem::setRestitution(float value) {
|
void EntityItem::setRestitution(float value) {
|
||||||
float clampedValue = glm::max(glm::min(ENTITY_ITEM_MAX_RESTITUTION, value), ENTITY_ITEM_MIN_RESTITUTION);
|
float clampedValue = glm::max(glm::min(ENTITY_ITEM_MAX_RESTITUTION, value), ENTITY_ITEM_MIN_RESTITUTION);
|
||||||
if (_restitution != clampedValue) {
|
withWriteLock([&] {
|
||||||
_restitution = clampedValue;
|
if (_restitution != clampedValue) {
|
||||||
_dirtyFlags |= Simulation::DIRTY_MATERIAL;
|
_restitution = clampedValue;
|
||||||
}
|
_dirtyFlags |= Simulation::DIRTY_MATERIAL;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EntityItem::setFriction(float value) {
|
void EntityItem::setFriction(float value) {
|
||||||
|
@ -1888,17 +1905,21 @@ void EntityItem::setFriction(float value) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void EntityItem::setLifetime(float value) {
|
void EntityItem::setLifetime(float value) {
|
||||||
if (_lifetime != value) {
|
withWriteLock([&] {
|
||||||
_lifetime = value;
|
if (_lifetime != value) {
|
||||||
_dirtyFlags |= Simulation::DIRTY_LIFETIME;
|
_lifetime = value;
|
||||||
}
|
_dirtyFlags |= Simulation::DIRTY_LIFETIME;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void EntityItem::setCreated(uint64_t value) {
|
void EntityItem::setCreated(uint64_t value) {
|
||||||
if (_created != value) {
|
withWriteLock([&] {
|
||||||
_created = value;
|
if (_created != value) {
|
||||||
_dirtyFlags |= Simulation::DIRTY_LIFETIME;
|
_created = value;
|
||||||
}
|
_dirtyFlags |= Simulation::DIRTY_LIFETIME;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void EntityItem::computeCollisionGroupAndFinalMask(int16_t& group, int16_t& mask) const {
|
void EntityItem::computeCollisionGroupAndFinalMask(int16_t& group, int16_t& mask) const {
|
||||||
|
@ -1970,16 +1991,6 @@ void EntityItem::setSimulationOwner(const QUuid& id, quint8 priority) {
|
||||||
_simulationOwner.set(id, priority);
|
_simulationOwner.set(id, priority);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
void EntityItem::setSimulationOwner(const SimulationOwner& owner) {
|
|
||||||
if (wantTerseEditLogging() && _simulationOwner != owner) {
|
|
||||||
qCDebug(entities) << "sim ownership for" << getDebugName() << "is now" << owner;
|
|
||||||
}
|
|
||||||
|
|
||||||
_simulationOwner.set(owner);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
void EntityItem::setSimulationOwner(const SimulationOwner& owner) {
|
void EntityItem::setSimulationOwner(const SimulationOwner& owner) {
|
||||||
// NOTE: this method only used by EntityServer. The Interface uses special code in readEntityDataFromBuffer().
|
// NOTE: this method only used by EntityServer. The Interface uses special code in readEntityDataFromBuffer().
|
||||||
if (wantTerseEditLogging() && _simulationOwner != owner) {
|
if (wantTerseEditLogging() && _simulationOwner != owner) {
|
||||||
|
|
Loading…
Reference in a new issue