From c35edd8eb433f2ebe6d5b2dc3c674189da0bcc40 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Tue, 5 May 2015 16:40:10 -0700 Subject: [PATCH] some debugging on Andrew's refactor --- .../src/RenderableDebugableEntityItem.cpp | 16 ++++++++++------ libraries/entities/src/EntityItem.cpp | 2 ++ libraries/entities/src/EntitySimulation.cpp | 2 +- libraries/entities/src/EntityTree.cpp | 2 +- libraries/physics/src/EntityMotionState.cpp | 3 ++- libraries/physics/src/ObjectMotionState.h | 3 ++- 6 files changed, 18 insertions(+), 10 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableDebugableEntityItem.cpp b/libraries/entities-renderer/src/RenderableDebugableEntityItem.cpp index 196d3c2898..4d38d0d747 100644 --- a/libraries/entities-renderer/src/RenderableDebugableEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableDebugableEntityItem.cpp @@ -86,10 +86,14 @@ void RenderableDebugableEntityItem::render(EntityItem* entity, RenderArgs* args) glm::vec3 position; glm::quat rotation; - if (PhysicsEngine::getBodyLocation(entity->getPhysicsInfo(), position, rotation)) { - glm::vec3 positionOffset = glm::abs(position - entity->getPosition()); - if (positionOffset[0] > 0.001 || positionOffset[1] > 0.001 || positionOffset[2] > 0.001) { - qDebug() << positionOffset[0] << positionOffset[1] << positionOffset[2]; - } - } + + // + // XXX for future debugging + // + // if (PhysicsEngine::getBodyLocation(entity->getPhysicsInfo(), position, rotation)) { + // glm::vec3 positionOffset = glm::abs(position - entity->getPosition()); + // if (positionOffset[0] > 0.001 || positionOffset[1] > 0.001 || positionOffset[2] > 0.001) { + // qDebug() << positionOffset[0] << positionOffset[1] << positionOffset[2]; + // } + // } } diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index c5083d5cf8..a3bb410b2c 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -1189,6 +1189,7 @@ void EntityItem::updateVelocity(const glm::vec3& value) { _velocity = value; } _dirtyFlags |= EntityItem::DIRTY_LINEAR_VELOCITY; + _dirtyFlags |= EntityItem::DIRTY_PHYSICS_ACTIVATION; } } @@ -1221,6 +1222,7 @@ void EntityItem::updateAngularVelocity(const glm::vec3& value) { auto distance = glm::distance(_angularVelocity, value); if (distance > MIN_SPIN_DELTA) { _dirtyFlags |= EntityItem::DIRTY_ANGULAR_VELOCITY; + _dirtyFlags |= EntityItem::DIRTY_PHYSICS_ACTIVATION; if (glm::length(value) < MIN_SPIN_DELTA) { _angularVelocity = ENTITY_ITEM_ZERO_VEC3; } else { diff --git a/libraries/entities/src/EntitySimulation.cpp b/libraries/entities/src/EntitySimulation.cpp index f11ffd015d..761a496c44 100644 --- a/libraries/entities/src/EntitySimulation.cpp +++ b/libraries/entities/src/EntitySimulation.cpp @@ -48,7 +48,6 @@ void EntitySimulation::getEntitiesToDelete(VectorOfEntities& entitiesToDelete) { } void EntitySimulation::addEntityInternal(EntityItem* entity) { - entity->_simulated = true; if (entity->isMoving() && !entity->getPhysicsInfo()) { _simpleKinematicEntities.insert(entity); } @@ -154,6 +153,7 @@ void EntitySimulation::addEntity(EntityItem* entity) { _entitiesToUpdate.insert(entity); } addEntityInternal(entity); + entity->_simulated = true; // DirtyFlags are used to signal changes to entities that have already been added, // so we can clear them for this entity which has just been added. diff --git a/libraries/entities/src/EntityTree.cpp b/libraries/entities/src/EntityTree.cpp index dbbbbc0cd2..5aea021e7a 100644 --- a/libraries/entities/src/EntityTree.cpp +++ b/libraries/entities/src/EntityTree.cpp @@ -159,7 +159,7 @@ bool EntityTree::updateEntityWithElement(EntityItem* entity, const EntityItemPro uint32_t newFlags = entity->getDirtyFlags() & ~preFlags; if (newFlags) { - if (_simulation) { + if (_simulation) { if (newFlags & DIRTY_SIMULATION_FLAGS) { _simulation->lock(); _simulation->changeEntity(entity); diff --git a/libraries/physics/src/EntityMotionState.cpp b/libraries/physics/src/EntityMotionState.cpp index dc095590da..a9faff36b4 100644 --- a/libraries/physics/src/EntityMotionState.cpp +++ b/libraries/physics/src/EntityMotionState.cpp @@ -393,7 +393,8 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, uint32_ uint32_t EntityMotionState::getIncomingDirtyFlags() const { uint32_t dirtyFlags = 0; if (_body && _entity) { - _entity->getDirtyFlags(); + dirtyFlags = _entity->getDirtyFlags(); + _entity->clearDirtyFlags(); // we add DIRTY_MOTION_TYPE if the body's motion type disagrees with entity velocity settings int bodyFlags = _body->getCollisionFlags(); bool isMoving = _entity->isMoving(); diff --git a/libraries/physics/src/ObjectMotionState.h b/libraries/physics/src/ObjectMotionState.h index d0dc9afc88..b2fcf8ceae 100644 --- a/libraries/physics/src/ObjectMotionState.h +++ b/libraries/physics/src/ObjectMotionState.h @@ -36,7 +36,8 @@ enum MotionStateType { // 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 EASY_DIRTY_PHYSICS_FLAGS = (uint32_t)(EntityItem::DIRTY_TRANSFORM | EntityItem::DIRTY_VELOCITIES | - EntityItem::DIRTY_MASS | EntityItem::DIRTY_COLLISION_GROUP | EntityItem::DIRTY_MATERIAL); + EntityItem::DIRTY_MASS | EntityItem::DIRTY_COLLISION_GROUP | + EntityItem::DIRTY_MATERIAL | EntityItem::DIRTY_PHYSICS_ACTIVATION); // These are the set of incoming flags that the PhysicsEngine needs to hear about: const uint32_t DIRTY_PHYSICS_FLAGS = HARD_DIRTY_PHYSICS_FLAGS | EASY_DIRTY_PHYSICS_FLAGS;