move DIRTY_FLAGS out of EntityItem namespace

This commit is contained in:
Andrew Meadows 2015-10-15 09:06:31 -07:00
parent 2b32b23299
commit fa17b77d70
13 changed files with 117 additions and 100 deletions

View file

@ -1034,7 +1034,7 @@ int Avatar::parseDataFromBuffer(const QByteArray& buffer) {
const float MOVE_DISTANCE_THRESHOLD = 0.001f; const float MOVE_DISTANCE_THRESHOLD = 0.001f;
_moving = glm::distance(oldPosition, _position) > MOVE_DISTANCE_THRESHOLD; _moving = glm::distance(oldPosition, _position) > MOVE_DISTANCE_THRESHOLD;
if (_moving && _motionState) { if (_moving && _motionState) {
_motionState->addDirtyFlags(EntityItem::DIRTY_POSITION); _motionState->addDirtyFlags(Simulation::DIRTY_POSITION);
} }
endUpdate(); endUpdate();

View file

@ -309,7 +309,7 @@ void AvatarManager::updateAvatarPhysicsShape(const QUuid& id) {
auto avatar = std::static_pointer_cast<Avatar>(avatarItr.value()); auto avatar = std::static_pointer_cast<Avatar>(avatarItr.value());
AvatarMotionState* motionState = avatar->getMotionState(); AvatarMotionState* motionState = avatar->getMotionState();
if (motionState) { if (motionState) {
motionState->addDirtyFlags(EntityItem::DIRTY_SHAPE); motionState->addDirtyFlags(Simulation::DIRTY_SHAPE);
} else { } else {
ShapeInfo shapeInfo; ShapeInfo shapeInfo;
avatar->computeShapeInfo(shapeInfo); avatar->computeShapeInfo(shapeInfo);

View file

@ -1057,7 +1057,7 @@ void RenderablePolyVoxEntityItem::getMeshAsync() {
gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::RAW))); gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::RAW)));
_meshLock.lockForWrite(); _meshLock.lockForWrite();
_dirtyFlags |= EntityItem::DIRTY_SHAPE | EntityItem::DIRTY_MASS; _dirtyFlags |= Simulation::DIRTY_SHAPE | Simulation::DIRTY_MASS;
_mesh = mesh; _mesh = mesh;
_meshDirty = true; _meshDirty = true;
_meshLock.unlock(); _meshLock.unlock();

View file

@ -630,7 +630,7 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef
bytesRead += bytes; bytesRead += bytes;
if (_simulationOwner.set(newSimOwner)) { if (_simulationOwner.set(newSimOwner)) {
_dirtyFlags |= EntityItem::DIRTY_SIMULATOR_ID; _dirtyFlags |= Simulation::DIRTY_SIMULATOR_ID;
} }
} }
{ // When we own the simulation we don't accept updates to the entity's transform/velocities { // When we own the simulation we don't accept updates to the entity's transform/velocities
@ -729,7 +729,7 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef
READ_ENTITY_PROPERTY(PROP_MARKETPLACE_ID, QString, setMarketplaceID); READ_ENTITY_PROPERTY(PROP_MARKETPLACE_ID, QString, setMarketplaceID);
} }
if (overwriteLocalData && (getDirtyFlags() & (EntityItem::DIRTY_TRANSFORM | EntityItem::DIRTY_VELOCITIES))) { if (overwriteLocalData && (getDirtyFlags() & (Simulation::DIRTY_TRANSFORM | Simulation::DIRTY_VELOCITIES))) {
// NOTE: This code is attempting to "repair" the old data we just got from the server to make it more // NOTE: This code is attempting to "repair" the old data we just got from the server to make it more
// closely match where the entities should be if they'd stepped forward in time to "now". The server // closely match where the entities should be if they'd stepped forward in time to "now". The server
// is sending us data with a known "last simulated" time. That time is likely in the past, and therefore // is sending us data with a known "last simulated" time. That time is likely in the past, and therefore
@ -813,7 +813,7 @@ void EntityItem::updateDensity(float density) {
if (fabsf(_density - clampedDensity) / _density > ACTIVATION_RELATIVE_DENSITY_DELTA) { if (fabsf(_density - clampedDensity) / _density > ACTIVATION_RELATIVE_DENSITY_DELTA) {
// the density has changed enough that we should update the physics simulation // the density has changed enough that we should update the physics simulation
_dirtyFlags |= EntityItem::DIRTY_MASS; _dirtyFlags |= Simulation::DIRTY_MASS;
} }
} }
} }
@ -905,7 +905,7 @@ void EntityItem::simulateKinematicMotion(float timeElapsed, bool setFlags) {
const float EPSILON_ANGULAR_VELOCITY_LENGTH = 0.0017453f; // 0.0017453 rad/sec = 0.1f degrees/sec const float EPSILON_ANGULAR_VELOCITY_LENGTH = 0.0017453f; // 0.0017453 rad/sec = 0.1f degrees/sec
if (angularSpeed < EPSILON_ANGULAR_VELOCITY_LENGTH) { if (angularSpeed < EPSILON_ANGULAR_VELOCITY_LENGTH) {
if (setFlags && angularSpeed > 0.0f) { if (setFlags && angularSpeed > 0.0f) {
_dirtyFlags |= EntityItem::DIRTY_MOTION_TYPE; _dirtyFlags |= Simulation::DIRTY_MOTION_TYPE;
} }
_angularVelocity = ENTITY_ITEM_ZERO_VEC3; _angularVelocity = ENTITY_ITEM_ZERO_VEC3;
} else { } else {
@ -967,7 +967,7 @@ void EntityItem::simulateKinematicMotion(float timeElapsed, bool setFlags) {
if (speed < EPSILON_LINEAR_VELOCITY_LENGTH) { if (speed < EPSILON_LINEAR_VELOCITY_LENGTH) {
setVelocity(ENTITY_ITEM_ZERO_VEC3); setVelocity(ENTITY_ITEM_ZERO_VEC3);
if (setFlags && speed > 0.0f) { if (setFlags && speed > 0.0f) {
_dirtyFlags |= EntityItem::DIRTY_MOTION_TYPE; _dirtyFlags |= Simulation::DIRTY_MOTION_TYPE;
} }
} else { } else {
setPosition(position); setPosition(position);
@ -1134,7 +1134,7 @@ bool EntityItem::setProperties(const EntityItemProperties& properties) {
#endif #endif
setLastEdited(now); setLastEdited(now);
somethingChangedNotification(); // notify derived classes that something has changed somethingChangedNotification(); // notify derived classes that something has changed
if (getDirtyFlags() & (EntityItem::DIRTY_TRANSFORM | EntityItem::DIRTY_VELOCITIES)) { if (getDirtyFlags() & (Simulation::DIRTY_TRANSFORM | Simulation::DIRTY_VELOCITIES)) {
// anything that sets the transform or velocity must update _lastSimulated which is used // anything that sets the transform or velocity must update _lastSimulated which is used
// for kinematic extrapolation (e.g. we want to extrapolate forward from this moment // for kinematic extrapolation (e.g. we want to extrapolate forward from this moment
// when position and/or velocity was changed). // when position and/or velocity was changed).
@ -1302,10 +1302,10 @@ void EntityItem::computeShapeInfo(ShapeInfo& info) {
void EntityItem::updatePosition(const glm::vec3& value) { void EntityItem::updatePosition(const glm::vec3& value) {
auto delta = glm::distance(getPosition(), value); auto delta = glm::distance(getPosition(), value);
if (delta > IGNORE_POSITION_DELTA) { if (delta > IGNORE_POSITION_DELTA) {
_dirtyFlags |= EntityItem::DIRTY_POSITION; _dirtyFlags |= Simulation::DIRTY_POSITION;
setPosition(value); setPosition(value);
if (delta > ACTIVATION_POSITION_DELTA) { if (delta > ACTIVATION_POSITION_DELTA) {
_dirtyFlags |= EntityItem::DIRTY_PHYSICS_ACTIVATION; _dirtyFlags |= Simulation::DIRTY_PHYSICS_ACTIVATION;
} }
} }
} }
@ -1316,7 +1316,7 @@ void EntityItem::updateDimensions(const glm::vec3& value) {
setDimensions(value); setDimensions(value);
if (delta > ACTIVATION_DIMENSIONS_DELTA) { if (delta > ACTIVATION_DIMENSIONS_DELTA) {
// rebuilding the shape will always activate // rebuilding the shape will always activate
_dirtyFlags |= (EntityItem::DIRTY_SHAPE | EntityItem::DIRTY_MASS); _dirtyFlags |= (Simulation::DIRTY_SHAPE | Simulation::DIRTY_MASS);
} }
} }
} }
@ -1327,10 +1327,10 @@ void EntityItem::updateRotation(const glm::quat& rotation) {
auto alignmentDot = glm::abs(glm::dot(getRotation(), rotation)); auto alignmentDot = glm::abs(glm::dot(getRotation(), rotation));
if (alignmentDot < IGNORE_ALIGNMENT_DOT) { if (alignmentDot < IGNORE_ALIGNMENT_DOT) {
_dirtyFlags |= EntityItem::DIRTY_ROTATION; _dirtyFlags |= Simulation::DIRTY_ROTATION;
} }
if (alignmentDot < ACTIVATION_ALIGNMENT_DOT) { if (alignmentDot < ACTIVATION_ALIGNMENT_DOT) {
_dirtyFlags |= EntityItem::DIRTY_PHYSICS_ACTIVATION; _dirtyFlags |= Simulation::DIRTY_PHYSICS_ACTIVATION;
} }
} }
} }
@ -1357,14 +1357,14 @@ void EntityItem::updateMass(float mass) {
if (fabsf(_density - oldDensity) / _density > ACTIVATION_RELATIVE_DENSITY_DELTA) { if (fabsf(_density - oldDensity) / _density > ACTIVATION_RELATIVE_DENSITY_DELTA) {
// the density has changed enough that we should update the physics simulation // the density has changed enough that we should update the physics simulation
_dirtyFlags |= EntityItem::DIRTY_MASS; _dirtyFlags |= Simulation::DIRTY_MASS;
} }
} }
void EntityItem::updateVelocity(const glm::vec3& value) { void EntityItem::updateVelocity(const glm::vec3& value) {
auto delta = glm::distance(_velocity, value); auto delta = glm::distance(_velocity, value);
if (delta > IGNORE_LINEAR_VELOCITY_DELTA) { if (delta > IGNORE_LINEAR_VELOCITY_DELTA) {
_dirtyFlags |= EntityItem::DIRTY_LINEAR_VELOCITY; _dirtyFlags |= Simulation::DIRTY_LINEAR_VELOCITY;
const float MIN_LINEAR_SPEED = 0.001f; const float MIN_LINEAR_SPEED = 0.001f;
if (glm::length(value) < MIN_LINEAR_SPEED) { if (glm::length(value) < MIN_LINEAR_SPEED) {
_velocity = ENTITY_ITEM_ZERO_VEC3; _velocity = ENTITY_ITEM_ZERO_VEC3;
@ -1372,7 +1372,7 @@ void EntityItem::updateVelocity(const glm::vec3& value) {
_velocity = value; _velocity = value;
// only activate when setting non-zero velocity // only activate when setting non-zero velocity
if (delta > ACTIVATION_LINEAR_VELOCITY_DELTA) { if (delta > ACTIVATION_LINEAR_VELOCITY_DELTA) {
_dirtyFlags |= EntityItem::DIRTY_PHYSICS_ACTIVATION; _dirtyFlags |= Simulation::DIRTY_PHYSICS_ACTIVATION;
} }
} }
} }
@ -1382,7 +1382,7 @@ void EntityItem::updateDamping(float value) {
auto clampedDamping = glm::clamp(value, 0.0f, 1.0f); auto clampedDamping = glm::clamp(value, 0.0f, 1.0f);
if (fabsf(_damping - clampedDamping) > IGNORE_DAMPING_DELTA) { if (fabsf(_damping - clampedDamping) > IGNORE_DAMPING_DELTA) {
_damping = clampedDamping; _damping = clampedDamping;
_dirtyFlags |= EntityItem::DIRTY_MATERIAL; _dirtyFlags |= Simulation::DIRTY_MATERIAL;
} }
} }
@ -1390,9 +1390,9 @@ void EntityItem::updateGravity(const glm::vec3& value) {
auto delta = glm::distance(_gravity, value); auto delta = glm::distance(_gravity, value);
if (delta > IGNORE_GRAVITY_DELTA) { if (delta > IGNORE_GRAVITY_DELTA) {
_gravity = value; _gravity = value;
_dirtyFlags |= EntityItem::DIRTY_LINEAR_VELOCITY; _dirtyFlags |= Simulation::DIRTY_LINEAR_VELOCITY;
if (delta > ACTIVATION_GRAVITY_DELTA) { if (delta > ACTIVATION_GRAVITY_DELTA) {
_dirtyFlags |= EntityItem::DIRTY_PHYSICS_ACTIVATION; _dirtyFlags |= Simulation::DIRTY_PHYSICS_ACTIVATION;
} }
} }
} }
@ -1400,7 +1400,7 @@ void EntityItem::updateGravity(const glm::vec3& value) {
void EntityItem::updateAngularVelocity(const glm::vec3& value) { void EntityItem::updateAngularVelocity(const glm::vec3& value) {
auto delta = glm::distance(_angularVelocity, value); auto delta = glm::distance(_angularVelocity, value);
if (delta > IGNORE_ANGULAR_VELOCITY_DELTA) { if (delta > IGNORE_ANGULAR_VELOCITY_DELTA) {
_dirtyFlags |= EntityItem::DIRTY_ANGULAR_VELOCITY; _dirtyFlags |= Simulation::DIRTY_ANGULAR_VELOCITY;
const float MIN_ANGULAR_SPEED = 0.0002f; const float MIN_ANGULAR_SPEED = 0.0002f;
if (glm::length(value) < MIN_ANGULAR_SPEED) { if (glm::length(value) < MIN_ANGULAR_SPEED) {
_angularVelocity = ENTITY_ITEM_ZERO_VEC3; _angularVelocity = ENTITY_ITEM_ZERO_VEC3;
@ -1408,7 +1408,7 @@ void EntityItem::updateAngularVelocity(const glm::vec3& value) {
_angularVelocity = value; _angularVelocity = value;
// only activate when setting non-zero velocity // only activate when setting non-zero velocity
if (delta > ACTIVATION_ANGULAR_VELOCITY_DELTA) { if (delta > ACTIVATION_ANGULAR_VELOCITY_DELTA) {
_dirtyFlags |= EntityItem::DIRTY_PHYSICS_ACTIVATION; _dirtyFlags |= Simulation::DIRTY_PHYSICS_ACTIVATION;
} }
} }
} }
@ -1418,21 +1418,21 @@ void EntityItem::updateAngularDamping(float value) {
auto clampedDamping = glm::clamp(value, 0.0f, 1.0f); auto clampedDamping = glm::clamp(value, 0.0f, 1.0f);
if (fabsf(_angularDamping - clampedDamping) > IGNORE_DAMPING_DELTA) { if (fabsf(_angularDamping - clampedDamping) > IGNORE_DAMPING_DELTA) {
_angularDamping = clampedDamping; _angularDamping = clampedDamping;
_dirtyFlags |= EntityItem::DIRTY_MATERIAL; _dirtyFlags |= Simulation::DIRTY_MATERIAL;
} }
} }
void EntityItem::updateIgnoreForCollisions(bool value) { void EntityItem::updateIgnoreForCollisions(bool value) {
if (_ignoreForCollisions != value) { if (_ignoreForCollisions != value) {
_ignoreForCollisions = value; _ignoreForCollisions = value;
_dirtyFlags |= EntityItem::DIRTY_COLLISION_GROUP; _dirtyFlags |= Simulation::DIRTY_COLLISION_GROUP;
} }
} }
void EntityItem::updateCollisionsWillMove(bool value) { void EntityItem::updateCollisionsWillMove(bool value) {
if (_collisionsWillMove != value) { if (_collisionsWillMove != value) {
_collisionsWillMove = value; _collisionsWillMove = value;
_dirtyFlags |= EntityItem::DIRTY_MOTION_TYPE; _dirtyFlags |= Simulation::DIRTY_MOTION_TYPE;
} }
} }
@ -1440,7 +1440,7 @@ void EntityItem::updateRestitution(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) { if (_restitution != clampedValue) {
_restitution = clampedValue; _restitution = clampedValue;
_dirtyFlags |= EntityItem::DIRTY_MATERIAL; _dirtyFlags |= Simulation::DIRTY_MATERIAL;
} }
} }
@ -1448,7 +1448,7 @@ void EntityItem::updateFriction(float value) {
float clampedValue = glm::max(glm::min(ENTITY_ITEM_MAX_FRICTION, value), ENTITY_ITEM_MIN_FRICTION); float clampedValue = glm::max(glm::min(ENTITY_ITEM_MAX_FRICTION, value), ENTITY_ITEM_MIN_FRICTION);
if (_friction != clampedValue) { if (_friction != clampedValue) {
_friction = clampedValue; _friction = clampedValue;
_dirtyFlags |= EntityItem::DIRTY_MATERIAL; _dirtyFlags |= Simulation::DIRTY_MATERIAL;
} }
} }
@ -1465,14 +1465,14 @@ void EntityItem::setFriction(float value) {
void EntityItem::updateLifetime(float value) { void EntityItem::updateLifetime(float value) {
if (_lifetime != value) { if (_lifetime != value) {
_lifetime = value; _lifetime = value;
_dirtyFlags |= EntityItem::DIRTY_LIFETIME; _dirtyFlags |= Simulation::DIRTY_LIFETIME;
} }
} }
void EntityItem::updateCreated(uint64_t value) { void EntityItem::updateCreated(uint64_t value) {
if (_created != value) { if (_created != value) {
_created = value; _created = value;
_dirtyFlags |= EntityItem::DIRTY_LIFETIME; _dirtyFlags |= Simulation::DIRTY_LIFETIME;
} }
} }
@ -1486,7 +1486,7 @@ void EntityItem::setSimulationOwner(const SimulationOwner& owner) {
void EntityItem::updateSimulatorID(const QUuid& value) { void EntityItem::updateSimulatorID(const QUuid& value) {
if (_simulationOwner.setID(value)) { if (_simulationOwner.setID(value)) {
_dirtyFlags |= EntityItem::DIRTY_SIMULATOR_ID; _dirtyFlags |= Simulation::DIRTY_SIMULATOR_ID;
} }
} }
@ -1494,7 +1494,7 @@ void EntityItem::clearSimulationOwnership() {
_simulationOwner.clear(); _simulationOwner.clear();
// don't bother setting the DIRTY_SIMULATOR_ID flag because clearSimulationOwnership() // don't bother setting the DIRTY_SIMULATOR_ID flag because clearSimulationOwnership()
// is only ever called entity-server-side and the flags are only used client-side // is only ever called entity-server-side and the flags are only used client-side
//_dirtyFlags |= EntityItem::DIRTY_SIMULATOR_ID; //_dirtyFlags |= Simulation::DIRTY_SIMULATOR_ID;
} }
@ -1533,7 +1533,7 @@ bool EntityItem::addActionInternal(EntitySimulation* simulation, EntityActionPoi
serializeActions(success, newDataCache); serializeActions(success, newDataCache);
if (success) { if (success) {
_allActionsDataCache = newDataCache; _allActionsDataCache = newDataCache;
_dirtyFlags |= EntityItem::DIRTY_PHYSICS_ACTIVATION; _dirtyFlags |= Simulation::DIRTY_PHYSICS_ACTIVATION;
} }
return success; return success;
} }
@ -1552,7 +1552,7 @@ bool EntityItem::updateAction(EntitySimulation* simulation, const QUuid& actionI
success = action->updateArguments(arguments); success = action->updateArguments(arguments);
if (success) { if (success) {
serializeActions(success, _allActionsDataCache); serializeActions(success, _allActionsDataCache);
_dirtyFlags |= EntityItem::DIRTY_PHYSICS_ACTIVATION; _dirtyFlags |= Simulation::DIRTY_PHYSICS_ACTIVATION;
} else { } else {
qDebug() << "EntityItem::updateAction failed"; qDebug() << "EntityItem::updateAction failed";
} }
@ -1588,7 +1588,7 @@ bool EntityItem::removeActionInternal(const QUuid& actionID, EntitySimulation* s
bool success = true; bool success = true;
serializeActions(success, _allActionsDataCache); serializeActions(success, _allActionsDataCache);
_dirtyFlags |= EntityItem::DIRTY_PHYSICS_ACTIVATION; _dirtyFlags |= Simulation::DIRTY_PHYSICS_ACTIVATION;
return success; return success;
} }
return false; return false;
@ -1607,7 +1607,7 @@ bool EntityItem::clearActions(EntitySimulation* simulation) {
// empty _serializedActions means no actions for the EntityItem // empty _serializedActions means no actions for the EntityItem
_actionsToRemove.clear(); _actionsToRemove.clear();
_allActionsDataCache.clear(); _allActionsDataCache.clear();
_dirtyFlags |= EntityItem::DIRTY_PHYSICS_ACTIVATION; _dirtyFlags |= Simulation::DIRTY_PHYSICS_ACTIVATION;
}); });
return true; return true;
} }

View file

@ -29,6 +29,7 @@
#include "EntityPropertyFlags.h" #include "EntityPropertyFlags.h"
#include "EntityTypes.h" #include "EntityTypes.h"
#include "SimulationOwner.h" #include "SimulationOwner.h"
#include "SimulationFlags.h"
class EntitySimulation; class EntitySimulation;
class EntityTreeElement; class EntityTreeElement;
@ -102,24 +103,6 @@ class EntityItem : public std::enable_shared_from_this<EntityItem>, public ReadW
friend class EntityTreeElement; friend class EntityTreeElement;
friend class EntitySimulation; friend class EntitySimulation;
public: public:
enum EntityDirtyFlags {
DIRTY_POSITION = 0x0001,
DIRTY_ROTATION = 0x0002,
DIRTY_LINEAR_VELOCITY = 0x0004,
DIRTY_ANGULAR_VELOCITY = 0x0008,
DIRTY_MASS = 0x0010,
DIRTY_COLLISION_GROUP = 0x0020,
DIRTY_MOTION_TYPE = 0x0040,
DIRTY_SHAPE = 0x0080,
DIRTY_LIFETIME = 0x0100,
DIRTY_UPDATEABLE = 0x0200,
DIRTY_MATERIAL = 0x00400,
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
};
DONT_ALLOW_INSTANTIATION // This class can not be instantiated directly DONT_ALLOW_INSTANTIATION // This class can not be instantiated directly
@ -411,7 +394,7 @@ public:
void getAllTerseUpdateProperties(EntityItemProperties& properties) const; void getAllTerseUpdateProperties(EntityItemProperties& properties) const;
void flagForOwnership() { _dirtyFlags |= DIRTY_SIMULATOR_OWNERSHIP; } void flagForOwnership() { _dirtyFlags |= Simulation::DIRTY_SIMULATOR_OWNERSHIP; }
bool addAction(EntitySimulation* simulation, EntityActionPointer action); bool addAction(EntitySimulation* simulation, EntityActionPointer action);
bool updateAction(EntitySimulation* simulation, const QUuid& actionID, const QVariantMap& arguments); bool updateAction(EntitySimulation* simulation, const QUuid& actionID, const QVariantMap& arguments);

View file

@ -198,7 +198,7 @@ void EntitySimulation::changeEntity(EntityItemPointer entity) {
// we must check for that case here, however we rely on the change event to have set DIRTY_POSITION flag. // we must check for that case here, however we rely on the change event to have set DIRTY_POSITION flag.
bool wasRemoved = false; bool wasRemoved = false;
uint32_t dirtyFlags = entity->getDirtyFlags(); uint32_t dirtyFlags = entity->getDirtyFlags();
if (dirtyFlags & EntityItem::DIRTY_POSITION) { if (dirtyFlags & Simulation::DIRTY_POSITION) {
AACube domainBounds(glm::vec3((float)-HALF_TREE_SCALE), (float)TREE_SCALE); AACube domainBounds(glm::vec3((float)-HALF_TREE_SCALE), (float)TREE_SCALE);
AACube newCube = entity->getMaximumAACube(); AACube newCube = entity->getMaximumAACube();
if (!domainBounds.touches(newCube)) { if (!domainBounds.touches(newCube)) {
@ -214,7 +214,7 @@ void EntitySimulation::changeEntity(EntityItemPointer entity) {
} }
} }
if (!wasRemoved) { if (!wasRemoved) {
if (dirtyFlags & EntityItem::DIRTY_LIFETIME) { if (dirtyFlags & Simulation::DIRTY_LIFETIME) {
if (entity->isMortal()) { if (entity->isMortal()) {
_mortalEntities.insert(entity); _mortalEntities.insert(entity);
quint64 expiry = entity->getExpiry(); quint64 expiry = entity->getExpiry();
@ -224,7 +224,7 @@ void EntitySimulation::changeEntity(EntityItemPointer entity) {
} else { } else {
_mortalEntities.remove(entity); _mortalEntities.remove(entity);
} }
entity->clearDirtyFlags(EntityItem::DIRTY_LIFETIME); entity->clearDirtyFlags(Simulation::DIRTY_LIFETIME);
} }
if (entity->needsToCallUpdate()) { if (entity->needsToCallUpdate()) {
_entitiesToUpdate.insert(entity); _entitiesToUpdate.insert(entity);

View file

@ -28,18 +28,18 @@ typedef QVector<EntityItemPointer> VectorOfEntities;
// the EntitySimulation needs to know when these things change on an entity, // the EntitySimulation needs to know when these things change on an entity,
// so it can sort EntityItem or relay its state to the PhysicsEngine. // so it can sort EntityItem or relay its state to the PhysicsEngine.
const int DIRTY_SIMULATION_FLAGS = const int DIRTY_SIMULATION_FLAGS =
EntityItem::DIRTY_POSITION | Simulation::DIRTY_POSITION |
EntityItem::DIRTY_ROTATION | Simulation::DIRTY_ROTATION |
EntityItem::DIRTY_LINEAR_VELOCITY | Simulation::DIRTY_LINEAR_VELOCITY |
EntityItem::DIRTY_ANGULAR_VELOCITY | Simulation::DIRTY_ANGULAR_VELOCITY |
EntityItem::DIRTY_MASS | Simulation::DIRTY_MASS |
EntityItem::DIRTY_COLLISION_GROUP | Simulation::DIRTY_COLLISION_GROUP |
EntityItem::DIRTY_MOTION_TYPE | Simulation::DIRTY_MOTION_TYPE |
EntityItem::DIRTY_SHAPE | Simulation::DIRTY_SHAPE |
EntityItem::DIRTY_LIFETIME | Simulation::DIRTY_LIFETIME |
EntityItem::DIRTY_UPDATEABLE | Simulation::DIRTY_UPDATEABLE |
EntityItem::DIRTY_MATERIAL | Simulation::DIRTY_MATERIAL |
EntityItem::DIRTY_SIMULATOR_ID; Simulation::DIRTY_SIMULATOR_ID;
class EntitySimulation : public QObject { class EntitySimulation : public QObject {
Q_OBJECT Q_OBJECT

View file

@ -66,7 +66,7 @@ bool ModelEntityItem::setProperties(const EntityItemProperties& properties) {
bool somethingChangedInAnimations = _animationProperties.setProperties(properties); bool somethingChangedInAnimations = _animationProperties.setProperties(properties);
if (somethingChangedInAnimations) { if (somethingChangedInAnimations) {
_dirtyFlags |= EntityItem::DIRTY_UPDATEABLE; _dirtyFlags |= Simulation::DIRTY_UPDATEABLE;
} }
somethingChanged = somethingChanged || somethingChangedInAnimations; somethingChanged = somethingChanged || somethingChangedInAnimations;
@ -128,7 +128,7 @@ int ModelEntityItem::readEntitySubclassDataFromBuffer(const unsigned char* data,
READ_ENTITY_PROPERTY(PROP_SHAPE_TYPE, ShapeType, updateShapeType); READ_ENTITY_PROPERTY(PROP_SHAPE_TYPE, ShapeType, updateShapeType);
if (animationPropertiesChanged) { if (animationPropertiesChanged) {
_dirtyFlags |= EntityItem::DIRTY_UPDATEABLE; _dirtyFlags |= Simulation::DIRTY_UPDATEABLE;
somethingChanged = true; somethingChanged = true;
} }
@ -300,7 +300,7 @@ void ModelEntityItem::updateShapeType(ShapeType type) {
if (type != _shapeType) { if (type != _shapeType) {
_shapeType = type; _shapeType = type;
_dirtyFlags |= EntityItem::DIRTY_SHAPE | EntityItem::DIRTY_MASS; _dirtyFlags |= Simulation::DIRTY_SHAPE | Simulation::DIRTY_MASS;
} }
} }
@ -316,13 +316,13 @@ ShapeType ModelEntityItem::getShapeType() const {
void ModelEntityItem::setCompoundShapeURL(const QString& url) { void ModelEntityItem::setCompoundShapeURL(const QString& url) {
if (_compoundShapeURL != url) { if (_compoundShapeURL != url) {
_compoundShapeURL = url; _compoundShapeURL = url;
_dirtyFlags |= EntityItem::DIRTY_SHAPE | EntityItem::DIRTY_MASS; _dirtyFlags |= Simulation::DIRTY_SHAPE | Simulation::DIRTY_MASS;
_shapeType = _compoundShapeURL.isEmpty() ? SHAPE_TYPE_NONE : SHAPE_TYPE_COMPOUND; _shapeType = _compoundShapeURL.isEmpty() ? SHAPE_TYPE_NONE : SHAPE_TYPE_COMPOUND;
} }
} }
void ModelEntityItem::setAnimationURL(const QString& url) { void ModelEntityItem::setAnimationURL(const QString& url) {
_dirtyFlags |= EntityItem::DIRTY_UPDATEABLE; _dirtyFlags |= Simulation::DIRTY_UPDATEABLE;
_animationProperties.setURL(url); _animationProperties.setURL(url);
} }
@ -388,16 +388,16 @@ void ModelEntityItem::setAnimationSettings(const QString& value) {
setAnimationStartAutomatically(startAutomatically); setAnimationStartAutomatically(startAutomatically);
} }
_dirtyFlags |= EntityItem::DIRTY_UPDATEABLE; _dirtyFlags |= Simulation::DIRTY_UPDATEABLE;
} }
void ModelEntityItem::setAnimationIsPlaying(bool value) { void ModelEntityItem::setAnimationIsPlaying(bool value) {
_dirtyFlags |= EntityItem::DIRTY_UPDATEABLE; _dirtyFlags |= Simulation::DIRTY_UPDATEABLE;
_animationLoop.setRunning(value); _animationLoop.setRunning(value);
} }
void ModelEntityItem::setAnimationFPS(float value) { void ModelEntityItem::setAnimationFPS(float value) {
_dirtyFlags |= EntityItem::DIRTY_UPDATEABLE; _dirtyFlags |= Simulation::DIRTY_UPDATEABLE;
_animationLoop.setFPS(value); _animationLoop.setFPS(value);
} }

View file

@ -597,7 +597,7 @@ void ParticleEffectEntityItem::debugDump() const {
void ParticleEffectEntityItem::updateShapeType(ShapeType type) { void ParticleEffectEntityItem::updateShapeType(ShapeType type) {
if (type != _shapeType) { if (type != _shapeType) {
_shapeType = type; _shapeType = type;
_dirtyFlags |= EntityItem::DIRTY_SHAPE | EntityItem::DIRTY_MASS; _dirtyFlags |= Simulation::DIRTY_SHAPE | Simulation::DIRTY_MASS;
} }
} }

View file

@ -0,0 +1,34 @@
//
// SimulationFlags.h
// libraries/physics/src
//
// Created by Andrew Meadows 2015.10.14
// Copyright 2015 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#ifndef hifi_SimulationFlags_h
#define hifi_SimulationFlags_h
namespace Simulation {
const uint32_t DIRTY_POSITION = 0x0001;
const uint32_t DIRTY_ROTATION = 0x0002;
const uint32_t DIRTY_LINEAR_VELOCITY = 0x0004;
const uint32_t DIRTY_ANGULAR_VELOCITY = 0x0008;
const uint32_t DIRTY_MASS = 0x0010;
const uint32_t DIRTY_COLLISION_GROUP = 0x0020;
const uint32_t DIRTY_MOTION_TYPE = 0x0040;
const uint32_t DIRTY_SHAPE = 0x0080;
const uint32_t DIRTY_LIFETIME = 0x0100;
const uint32_t DIRTY_UPDATEABLE = 0x0200;
const uint32_t DIRTY_MATERIAL = 0x00400;
const uint32_t DIRTY_PHYSICS_ACTIVATION = 0x0800; // should activate object in physics engine
const uint32_t DIRTY_SIMULATOR_OWNERSHIP = 0x1000; // should claim simulator ownership
const uint32_t DIRTY_SIMULATOR_ID = 0x2000; // the simulatorID has changed
const uint32_t DIRTY_TRANSFORM = DIRTY_POSITION | DIRTY_ROTATION;
const uint32_t DIRTY_VELOCITIES = DIRTY_LINEAR_VELOCITY | DIRTY_ANGULAR_VELOCITY;
};
#endif // hifi_SimulationFlags_h

View file

@ -93,13 +93,13 @@ bool EntityMotionState::handleEasyChanges(uint32_t flags, PhysicsEngine* engine)
updateServerPhysicsVariables(); updateServerPhysicsVariables();
ObjectMotionState::handleEasyChanges(flags, engine); ObjectMotionState::handleEasyChanges(flags, engine);
if (flags & EntityItem::DIRTY_SIMULATOR_ID) { if (flags & Simulation::DIRTY_SIMULATOR_ID) {
_loopsWithoutOwner = 0; _loopsWithoutOwner = 0;
if (_entity->getSimulatorID().isNull()) { if (_entity->getSimulatorID().isNull()) {
// simulation ownership is being removed // simulation ownership is being removed
// remove the ACTIVATION flag because this object is coming to rest // remove the ACTIVATION flag because this object is coming to rest
// according to a remote simulation and we don't want to wake it up again // according to a remote simulation and we don't want to wake it up again
flags &= ~EntityItem::DIRTY_PHYSICS_ACTIVATION; flags &= ~Simulation::DIRTY_PHYSICS_ACTIVATION;
// hint to Bullet that the object is deactivating // hint to Bullet that the object is deactivating
_body->setActivationState(WANTS_DEACTIVATION); _body->setActivationState(WANTS_DEACTIVATION);
_outgoingPriority = NO_PRORITY; _outgoingPriority = NO_PRORITY;
@ -111,13 +111,13 @@ bool EntityMotionState::handleEasyChanges(uint32_t flags, PhysicsEngine* engine)
} }
} }
} }
if (flags & EntityItem::DIRTY_SIMULATOR_OWNERSHIP) { if (flags & Simulation::DIRTY_SIMULATOR_OWNERSHIP) {
// (DIRTY_SIMULATOR_OWNERSHIP really means "we should bid for ownership with SCRIPT priority") // (DIRTY_SIMULATOR_OWNERSHIP really means "we should bid for ownership with SCRIPT priority")
// we're manipulating this object directly via script, so we artificially // we're manipulating this object directly via script, so we artificially
// manipulate the logic to trigger an immediate bid for ownership // manipulate the logic to trigger an immediate bid for ownership
setOutgoingPriority(SCRIPT_EDIT_SIMULATION_PRIORITY); setOutgoingPriority(SCRIPT_EDIT_SIMULATION_PRIORITY);
} }
if ((flags & EntityItem::DIRTY_PHYSICS_ACTIVATION) && !_body->isActive()) { if ((flags & Simulation::DIRTY_PHYSICS_ACTIVATION) && !_body->isActive()) {
_body->activate(); _body->activate();
} }
@ -503,7 +503,7 @@ uint32_t EntityMotionState::getIncomingDirtyFlags() {
bool isMoving = _entity->isMoving(); bool isMoving = _entity->isMoving();
if (((bodyFlags & btCollisionObject::CF_STATIC_OBJECT) && isMoving) || if (((bodyFlags & btCollisionObject::CF_STATIC_OBJECT) && isMoving) ||
(bodyFlags & btCollisionObject::CF_KINEMATIC_OBJECT && !isMoving)) { (bodyFlags & btCollisionObject::CF_KINEMATIC_OBJECT && !isMoving)) {
dirtyFlags |= EntityItem::DIRTY_MOTION_TYPE; dirtyFlags |= Simulation::DIRTY_MOTION_TYPE;
} }
} }
return dirtyFlags; return dirtyFlags;

View file

@ -126,34 +126,34 @@ void ObjectMotionState::setRigidBody(btRigidBody* body) {
} }
bool ObjectMotionState::handleEasyChanges(uint32_t flags, PhysicsEngine* engine) { bool ObjectMotionState::handleEasyChanges(uint32_t flags, PhysicsEngine* engine) {
if (flags & EntityItem::DIRTY_POSITION) { if (flags & Simulation::DIRTY_POSITION) {
btTransform worldTrans; btTransform worldTrans;
if (flags & EntityItem::DIRTY_ROTATION) { if (flags & Simulation::DIRTY_ROTATION) {
worldTrans.setRotation(glmToBullet(getObjectRotation())); worldTrans.setRotation(glmToBullet(getObjectRotation()));
} else { } else {
worldTrans = _body->getWorldTransform(); worldTrans = _body->getWorldTransform();
} }
worldTrans.setOrigin(glmToBullet(getObjectPosition())); worldTrans.setOrigin(glmToBullet(getObjectPosition()));
_body->setWorldTransform(worldTrans); _body->setWorldTransform(worldTrans);
} else if (flags & EntityItem::DIRTY_ROTATION) { } else if (flags & Simulation::DIRTY_ROTATION) {
btTransform worldTrans = _body->getWorldTransform(); btTransform worldTrans = _body->getWorldTransform();
worldTrans.setRotation(glmToBullet(getObjectRotation())); worldTrans.setRotation(glmToBullet(getObjectRotation()));
_body->setWorldTransform(worldTrans); _body->setWorldTransform(worldTrans);
} }
if (flags & EntityItem::DIRTY_LINEAR_VELOCITY) { if (flags & Simulation::DIRTY_LINEAR_VELOCITY) {
_body->setLinearVelocity(glmToBullet(getObjectLinearVelocity())); _body->setLinearVelocity(glmToBullet(getObjectLinearVelocity()));
_body->setGravity(glmToBullet(getObjectGravity())); _body->setGravity(glmToBullet(getObjectGravity()));
} }
if (flags & EntityItem::DIRTY_ANGULAR_VELOCITY) { if (flags & Simulation::DIRTY_ANGULAR_VELOCITY) {
_body->setAngularVelocity(glmToBullet(getObjectAngularVelocity())); _body->setAngularVelocity(glmToBullet(getObjectAngularVelocity()));
} }
if (flags & EntityItem::DIRTY_MATERIAL) { if (flags & Simulation::DIRTY_MATERIAL) {
updateBodyMaterialProperties(); updateBodyMaterialProperties();
} }
if (flags & EntityItem::DIRTY_MASS) { if (flags & Simulation::DIRTY_MASS) {
updateBodyMassProperties(); updateBodyMassProperties();
} }
@ -161,7 +161,7 @@ bool ObjectMotionState::handleEasyChanges(uint32_t flags, PhysicsEngine* engine)
} }
bool ObjectMotionState::handleHardAndEasyChanges(uint32_t flags, PhysicsEngine* engine) { bool ObjectMotionState::handleHardAndEasyChanges(uint32_t flags, PhysicsEngine* engine) {
if (flags & EntityItem::DIRTY_SHAPE) { if (flags & Simulation::DIRTY_SHAPE) {
// make sure the new shape is valid // make sure the new shape is valid
if (!isReadyToComputeShape()) { if (!isReadyToComputeShape()) {
return false; return false;
@ -170,7 +170,7 @@ bool ObjectMotionState::handleHardAndEasyChanges(uint32_t flags, PhysicsEngine*
if (!newShape) { if (!newShape) {
qCDebug(physics) << "Warning: failed to generate new shape!"; qCDebug(physics) << "Warning: failed to generate new shape!";
// failed to generate new shape! --> keep old shape and remove shape-change flag // failed to generate new shape! --> keep old shape and remove shape-change flag
flags &= ~EntityItem::DIRTY_SHAPE; flags &= ~Simulation::DIRTY_SHAPE;
// TODO: force this object out of PhysicsEngine rather than just use the old shape // TODO: force this object out of PhysicsEngine rather than just use the old shape
if ((flags & HARD_DIRTY_PHYSICS_FLAGS) == 0) { if ((flags & HARD_DIRTY_PHYSICS_FLAGS) == 0) {
// no HARD flags remain, so do any EASY changes // no HARD flags remain, so do any EASY changes
@ -186,7 +186,7 @@ bool ObjectMotionState::handleHardAndEasyChanges(uint32_t flags, PhysicsEngine*
_body->setCollisionShape(_shape); _body->setCollisionShape(_shape);
} else { } else {
// huh... the shape didn't actually change, so we clear the DIRTY_SHAPE flag // huh... the shape didn't actually change, so we clear the DIRTY_SHAPE flag
flags &= ~EntityItem::DIRTY_SHAPE; flags &= ~Simulation::DIRTY_SHAPE;
} }
} }
if (flags & EASY_DIRTY_PHYSICS_FLAGS) { if (flags & EASY_DIRTY_PHYSICS_FLAGS) {

View file

@ -37,18 +37,18 @@ enum MotionStateType {
// The update flags trigger two varieties of updates: "hard" which require the body to be pulled // The update flags trigger two varieties of updates: "hard" which require the body to be pulled
// and re-added to the physics engine and "easy" which just updates the body properties. // and re-added to the physics engine and "easy" which just updates the body properties.
const uint32_t HARD_DIRTY_PHYSICS_FLAGS = (uint32_t)(EntityItem::DIRTY_MOTION_TYPE | EntityItem::DIRTY_SHAPE | const uint32_t HARD_DIRTY_PHYSICS_FLAGS = (uint32_t)(Simulation::DIRTY_MOTION_TYPE | Simulation::DIRTY_SHAPE |
EntityItem::DIRTY_COLLISION_GROUP); Simulation::DIRTY_COLLISION_GROUP);
const uint32_t EASY_DIRTY_PHYSICS_FLAGS = (uint32_t)(EntityItem::DIRTY_TRANSFORM | EntityItem::DIRTY_VELOCITIES | const uint32_t EASY_DIRTY_PHYSICS_FLAGS = (uint32_t)(Simulation::DIRTY_TRANSFORM | Simulation::DIRTY_VELOCITIES |
EntityItem::DIRTY_MASS | EntityItem::DIRTY_MATERIAL | Simulation::DIRTY_MASS | Simulation::DIRTY_MATERIAL |
EntityItem::DIRTY_SIMULATOR_ID | EntityItem::DIRTY_SIMULATOR_OWNERSHIP); Simulation::DIRTY_SIMULATOR_ID | Simulation::DIRTY_SIMULATOR_OWNERSHIP);
// These are the set of incoming flags that the PhysicsEngine needs to hear about: // 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 | const uint32_t DIRTY_PHYSICS_FLAGS = (uint32_t)(HARD_DIRTY_PHYSICS_FLAGS | EASY_DIRTY_PHYSICS_FLAGS |
EntityItem::DIRTY_PHYSICS_ACTIVATION); Simulation::DIRTY_PHYSICS_ACTIVATION);
// These are the outgoing flags that the PhysicsEngine can affect: // These are the outgoing flags that the PhysicsEngine can affect:
const uint32_t OUTGOING_DIRTY_PHYSICS_FLAGS = EntityItem::DIRTY_TRANSFORM | EntityItem::DIRTY_VELOCITIES; const uint32_t OUTGOING_DIRTY_PHYSICS_FLAGS = Simulation::DIRTY_TRANSFORM | Simulation::DIRTY_VELOCITIES;
class OctreeEditPacketSender; class OctreeEditPacketSender;