From f85774c687cf870675996bb764d9471c892d9b0d Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 26 Jan 2015 09:45:33 -0800 Subject: [PATCH 01/12] adding some debugging --- .../entities/src/EntityEditPacketSender.cpp | 5 +++ libraries/physics/src/EntityMotionState.cpp | 3 ++ libraries/physics/src/ObjectMotionState.cpp | 35 ++++++++++++++++++- 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/libraries/entities/src/EntityEditPacketSender.cpp b/libraries/entities/src/EntityEditPacketSender.cpp index f2588d0493..a04e07ebb3 100644 --- a/libraries/entities/src/EntityEditPacketSender.cpp +++ b/libraries/entities/src/EntityEditPacketSender.cpp @@ -36,6 +36,11 @@ void EntityEditPacketSender::queueEditEntityMessage(PacketType type, EntityItemI int sizeOut = 0; if (EntityItemProperties::encodeEntityEditPacket(type, modelID, properties, &bufferOut[0], _maxPacketSize, sizeOut)) { + #ifdef WANT_DEBUG + qDebug() << "calling queueOctreeEditMessage()..."; + qDebug() << " id:" << modelID; + qDebug() << " properties:" << properties; + #endif queueOctreeEditMessage(type, bufferOut, sizeOut); } } diff --git a/libraries/physics/src/EntityMotionState.cpp b/libraries/physics/src/EntityMotionState.cpp index 96897ff527..a6a358faa0 100644 --- a/libraries/physics/src/EntityMotionState.cpp +++ b/libraries/physics/src/EntityMotionState.cpp @@ -227,6 +227,9 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, uint32_ EntityItemID id(_entity->getID()); EntityEditPacketSender* entityPacketSender = static_cast(packetSender); + #ifdef WANT_DEBUG + qDebug() << "EntityMotionState::sendUpdate()... calling queueEditEntityMessage()..."; + #endif entityPacketSender->queueEditEntityMessage(PacketTypeEntityAddOrEdit, id, properties); // The outgoing flags only itemized WHAT to send, not WHETHER to send, hence we always set them diff --git a/libraries/physics/src/ObjectMotionState.cpp b/libraries/physics/src/ObjectMotionState.cpp index dfa059d47f..7e9c6b76b6 100644 --- a/libraries/physics/src/ObjectMotionState.cpp +++ b/libraries/physics/src/ObjectMotionState.cpp @@ -111,6 +111,12 @@ bool ObjectMotionState::shouldSendUpdate(uint32_t simulationFrame) { _sentFrame = simulationFrame; return false; } + + #ifdef WANT_DEBUG + glm::vec3 wasPosition = _sentPosition; + glm::quat wasRotation = _sentRotation; + glm::vec3 wasAngularVelocity = _sentAngularVelocity; + #endif float dt = (float)(simulationFrame - _sentFrame) * PHYSICS_ENGINE_FIXED_SUBSTEP; _sentFrame = simulationFrame; @@ -147,11 +153,21 @@ bool ObjectMotionState::shouldSendUpdate(uint32_t simulationFrame) { glm::vec3 position = bulletToGLM(worldTrans.getOrigin()); float dx2 = glm::distance2(position, _sentPosition); + const float MAX_POSITION_ERROR_SQUARED = 0.001f; // 0.001 m^2 ~~> 0.03 m if (dx2 > MAX_POSITION_ERROR_SQUARED) { + + #ifdef WANT_DEBUG + qDebug() << ".... (dx2 > MAX_POSITION_ERROR_SQUARED) ...."; + qDebug() << "wasPosition:" << wasPosition; + qDebug() << "bullet position:" << position; + qDebug() << "_sentPosition:" << _sentPosition; + qDebug() << "dx2:" << dx2; + #endif + return true; } - + if (glm::length2(_sentAngularVelocity) > 0.0f) { // compute rotation error _sentAngularVelocity *= powf(1.0f - _angularDamping, dt); @@ -165,6 +181,23 @@ bool ObjectMotionState::shouldSendUpdate(uint32_t simulationFrame) { } const float MIN_ROTATION_DOT = 0.98f; glm::quat actualRotation = bulletToGLM(worldTrans.getRotation()); + + #ifdef WANT_DEBUG + if ((fabsf(glm::dot(actualRotation, _sentRotation)) < MIN_ROTATION_DOT)) { + qDebug() << ".... ((fabsf(glm::dot(actualRotation, _sentRotation)) < MIN_ROTATION_DOT)) ...."; + + qDebug() << "wasAngularVelocity:" << wasAngularVelocity; + qDebug() << "_sentAngularVelocity:" << _sentAngularVelocity; + + qDebug() << "length wasAngularVelocity:" << glm::length(wasAngularVelocity); + qDebug() << "length _sentAngularVelocity:" << glm::length(_sentAngularVelocity); + + qDebug() << "wasRotation:" << wasRotation; + qDebug() << "bullet actualRotation:" << actualRotation; + qDebug() << "_sentRotation:" << _sentRotation; + } + #endif + return (fabsf(glm::dot(actualRotation, _sentRotation)) < MIN_ROTATION_DOT); } From 73b9c06ec08e2bc0a275ee62b0327addce7b2e41 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 26 Jan 2015 11:13:30 -0800 Subject: [PATCH 02/12] added some debugging --- libraries/entities/src/EntityItem.cpp | 3 +++ libraries/entities/src/EntityItem.h | 3 ++- libraries/physics/src/EntityMotionState.cpp | 7 +++++++ libraries/physics/src/PhysicsEngine.cpp | 8 ++++++++ 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index 91aef39eea..3315cdd2e7 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -21,6 +21,9 @@ #include "EntityItem.h" #include "EntityTree.h" +quint64 EntityItem::lastCollisionTime = 0; + + void EntityItem::initFromEntityItemID(const EntityItemID& entityItemID) { _id = entityItemID.id; _creatorTokenID = entityItemID.creatorTokenID; diff --git a/libraries/entities/src/EntityItem.h b/libraries/entities/src/EntityItem.h index df619e2f69..ad540d1df9 100644 --- a/libraries/entities/src/EntityItem.h +++ b/libraries/entities/src/EntityItem.h @@ -42,7 +42,6 @@ class EntityTreeElementExtraEncodeData; /// one directly, instead you must only construct one of it's derived classes with additional features. class EntityItem { friend class EntityTreeElement; - public: enum EntityDirtyFlags { DIRTY_POSITION = 0x0001, @@ -55,6 +54,8 @@ public: DIRTY_UPDATEABLE = 0x0080, }; + static quint64 lastCollisionTime; + DONT_ALLOW_INSTANTIATION // This class can not be instantiated directly EntityItem(const EntityItemID& entityItemID); diff --git a/libraries/physics/src/EntityMotionState.cpp b/libraries/physics/src/EntityMotionState.cpp index a6a358faa0..02d7b77606 100644 --- a/libraries/physics/src/EntityMotionState.cpp +++ b/libraries/physics/src/EntityMotionState.cpp @@ -99,6 +99,13 @@ void EntityMotionState::setWorldTransform(const btTransform& worldTrans) { _outgoingPacketFlags = DIRTY_PHYSICS_FLAGS; EntityMotionState::enqueueOutgoingEntity(_entity); + + quint64 now = usecTimestampNow(); + qDebug() << "EntityMotionState::setWorldTransform()... changed entity:" << _entity->getEntityItemID(); + qDebug() << " last edited:" << _entity->getLastEdited() << formatUsecTime(now - _entity->getLastEdited()) << "ago"; + qDebug() << " last simulated:" << _entity->getLastSimulated() << formatUsecTime(now - _entity->getLastSimulated()) << "ago"; + qDebug() << " last updated:" << _entity->getLastUpdated() << formatUsecTime(now - _entity->getLastUpdated()) << "ago"; + qDebug() << " last collision:" << EntityItem::lastCollisionTime << formatUsecTime(now - EntityItem::lastCollisionTime) << "ago"; } void EntityMotionState::updateObjectEasy(uint32_t flags, uint32_t frame) { diff --git a/libraries/physics/src/PhysicsEngine.cpp b/libraries/physics/src/PhysicsEngine.cpp index dfd28dd8a4..fce8faf301 100644 --- a/libraries/physics/src/PhysicsEngine.cpp +++ b/libraries/physics/src/PhysicsEngine.cpp @@ -371,10 +371,18 @@ void PhysicsEngine::computeCollisionEvents() { if (B && B->getType() == MOTION_STATE_TYPE_ENTITY) { idB = static_cast(B)->getEntity()->getEntityItemID(); } + +qDebug() << "entityCollisionWithEntity()... idA:" << idA << "idB:" << idB << "*******************************"; +EntityItem::lastCollisionTime = usecTimestampNow(); + emit entityCollisionWithEntity(idA, idB, contactItr->second); } else if (B && B->getType() == MOTION_STATE_TYPE_ENTITY) { EntityItemID idA; EntityItemID idB = static_cast(B)->getEntity()->getEntityItemID(); + +qDebug() << "entityCollisionWithEntity()... idA:" << idA << "idB:" << idB << "*******************************"; +EntityItem::lastCollisionTime = usecTimestampNow(); + emit entityCollisionWithEntity(idA, idB, contactItr->second); } From a1ec44b8e0aa5640e1e660775b18bf168417dcd6 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 26 Jan 2015 12:05:57 -0800 Subject: [PATCH 03/12] add developer menu item to disable sending physics updates --- .../utilities/tools/developerMenuItems.js | 20 +++++++++++++++++++ libraries/entities/src/EntityItem.cpp | 2 ++ libraries/entities/src/EntityItem.h | 7 +++++++ .../entities/src/EntityScriptingInterface.cpp | 9 +++++++++ .../entities/src/EntityScriptingInterface.h | 3 +++ libraries/physics/src/EntityMotionState.cpp | 16 +++++++++------ libraries/physics/src/EntityMotionState.h | 1 + 7 files changed, 52 insertions(+), 6 deletions(-) diff --git a/examples/utilities/tools/developerMenuItems.js b/examples/utilities/tools/developerMenuItems.js index 3a274c7083..765e85579e 100644 --- a/examples/utilities/tools/developerMenuItems.js +++ b/examples/utilities/tools/developerMenuItems.js @@ -18,6 +18,7 @@ function setupMenus() { } if (!Menu.menuExists("Developer > Entities")) { Menu.addMenu("Developer > Entities"); + /* Menu.addMenuItem({ menuName: "Developer > Entities", menuItemName: "Display Model Bounds", isCheckable: true, isChecked: false }); Menu.addMenuItem({ menuName: "Developer > Entities", menuItemName: "Display Model Triangles", isCheckable: true, isChecked: false }); Menu.addMenuItem({ menuName: "Developer > Entities", menuItemName: "Display Model Element Bounds", isCheckable: true, isChecked: false }); @@ -26,9 +27,28 @@ function setupMenus() { Menu.addMenuItem({ menuName: "Developer > Entities", menuItemName: "Don't Attempt Render Entities as Scene", isCheckable: true, isChecked: false }); Menu.addMenuItem({ menuName: "Developer > Entities", menuItemName: "Don't Do Precision Picking", isCheckable: true, isChecked: false }); Menu.addMenuItem({ menuName: "Developer > Entities", menuItemName: "Disable Light Entities", isCheckable: true, isChecked: false }); + */ + Menu.addMenuItem({ menuName: "Developer > Entities", menuItemName: "Don't send collision updates to server", isCheckable: true, isChecked: false }); } } +Menu.menuItemEvent.connect(function (menuItem) { + print("menuItemEvent() in JS... menuItem=" + menuItem); + + if (menuItem == "Don't send collision updates to server") { + var dontSendUpdates = Menu.isOptionChecked("Don't send collision updates to server"); + print(" dontSendUpdates... checked=" + dontSendUpdates); + Entities.setSendPhysicsUpdates(!dontSendUpdates); + } +}); + +setupMenus(); + +// register our scriptEnding callback +Script.scriptEnding.connect(scriptEnding); + + + function scriptEnding() { Menu.removeMenu("Developer > Entities"); } diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index 3315cdd2e7..ab859c7282 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -22,6 +22,8 @@ #include "EntityTree.h" quint64 EntityItem::lastCollisionTime = 0; +bool EntityItem::_sendPhysicsUpdates = true; + void EntityItem::initFromEntityItemID(const EntityItemID& entityItemID) { diff --git a/libraries/entities/src/EntityItem.h b/libraries/entities/src/EntityItem.h index ad540d1df9..1c35a0aa3d 100644 --- a/libraries/entities/src/EntityItem.h +++ b/libraries/entities/src/EntityItem.h @@ -289,8 +289,15 @@ public: void setPhysicsInfo(void* data) { _physicsInfo = data; } EntityTreeElement* getElement() const { return _element; } + + static void setSendPhysicsUpdates(bool value) { _sendPhysicsUpdates = value; } + static bool getSendPhysicsUpdates() { return _sendPhysicsUpdates; } + + protected: + static bool _sendPhysicsUpdates; + virtual void initFromEntityItemID(const EntityItemID& entityItemID); // maybe useful to allow subclasses to init virtual void recalculateCollisionShape(); diff --git a/libraries/entities/src/EntityScriptingInterface.cpp b/libraries/entities/src/EntityScriptingInterface.cpp index 6226012052..599649aad0 100644 --- a/libraries/entities/src/EntityScriptingInterface.cpp +++ b/libraries/entities/src/EntityScriptingInterface.cpp @@ -14,6 +14,7 @@ #include "LightEntityItem.h" #include "ModelEntityItem.h" + EntityScriptingInterface::EntityScriptingInterface() : _nextCreatorTokenID(0), _entityTree(NULL) @@ -234,6 +235,14 @@ bool EntityScriptingInterface::getLightsArePickable() const { return LightEntityItem::getLightsArePickable(); } +void EntityScriptingInterface::setSendPhysicsUpdates(bool value) { + EntityItem::setSendPhysicsUpdates(value); +} + +bool EntityScriptingInterface::getSendPhysicsUpdates() const { + return EntityItem::getSendPhysicsUpdates(); +} + RayToEntityIntersectionResult::RayToEntityIntersectionResult() : intersects(false), diff --git a/libraries/entities/src/EntityScriptingInterface.h b/libraries/entities/src/EntityScriptingInterface.h index e0fc721516..3585cce946 100644 --- a/libraries/entities/src/EntityScriptingInterface.h +++ b/libraries/entities/src/EntityScriptingInterface.h @@ -99,6 +99,9 @@ public slots: Q_INVOKABLE void setLightsArePickable(bool value); Q_INVOKABLE bool getLightsArePickable() const; + Q_INVOKABLE void setSendPhysicsUpdates(bool value); + Q_INVOKABLE bool getSendPhysicsUpdates() const; + Q_INVOKABLE void dumpTree() const; signals: diff --git a/libraries/physics/src/EntityMotionState.cpp b/libraries/physics/src/EntityMotionState.cpp index 02d7b77606..c8b0133b86 100644 --- a/libraries/physics/src/EntityMotionState.cpp +++ b/libraries/physics/src/EntityMotionState.cpp @@ -232,12 +232,16 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, uint32_ properties.setLastEdited(_entity->getLastEdited()); } - EntityItemID id(_entity->getID()); - EntityEditPacketSender* entityPacketSender = static_cast(packetSender); - #ifdef WANT_DEBUG - qDebug() << "EntityMotionState::sendUpdate()... calling queueEditEntityMessage()..."; - #endif - entityPacketSender->queueEditEntityMessage(PacketTypeEntityAddOrEdit, id, properties); + if (EntityItem::getSendPhysicsUpdates()) { + EntityItemID id(_entity->getID()); + EntityEditPacketSender* entityPacketSender = static_cast(packetSender); + #ifdef WANT_DEBUG + qDebug() << "EntityMotionState::sendUpdate()... calling queueEditEntityMessage()..."; + #endif + entityPacketSender->queueEditEntityMessage(PacketTypeEntityAddOrEdit, id, properties); + } else { + qDebug() << "EntityMotionState::sendUpdate()... NOT sending update as requested."; + } // The outgoing flags only itemized WHAT to send, not WHETHER to send, hence we always set them // to the full set. These flags may be momentarily cleared by incoming external changes. diff --git a/libraries/physics/src/EntityMotionState.h b/libraries/physics/src/EntityMotionState.h index 5d98e545d9..5370f9ebb4 100644 --- a/libraries/physics/src/EntityMotionState.h +++ b/libraries/physics/src/EntityMotionState.h @@ -63,6 +63,7 @@ public: protected: EntityItem* _entity; + }; #endif // hifi_EntityMotionState_h From 08fbcbaf40e34a5b1227195eaff6a07e2e853462 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 26 Jan 2015 12:38:02 -0800 Subject: [PATCH 04/12] tweaks for debugging --- examples/controllers/hydra/gun.js | 3 ++- libraries/physics/src/EntityMotionState.cpp | 20 ++++++++++++-------- libraries/physics/src/PhysicsEngine.cpp | 8 ++++---- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/examples/controllers/hydra/gun.js b/examples/controllers/hydra/gun.js index 0c0740e12b..f3c1e14001 100644 --- a/examples/controllers/hydra/gun.js +++ b/examples/controllers/hydra/gun.js @@ -486,7 +486,8 @@ function mousePressEvent(event) { if (clickedOverlay == offButton) { Script.stop(); } else if (clickedOverlay == platformButton) { - makePlatform(-9.8, 1.0, 5); + var platformSize = 3; + makePlatform(-9.8, 1.0, platformSize); } else if (clickedOverlay == gridButton) { makeGrid("Box", 1.0, 3); } diff --git a/libraries/physics/src/EntityMotionState.cpp b/libraries/physics/src/EntityMotionState.cpp index c8b0133b86..02a0dfbf92 100644 --- a/libraries/physics/src/EntityMotionState.cpp +++ b/libraries/physics/src/EntityMotionState.cpp @@ -99,13 +99,15 @@ void EntityMotionState::setWorldTransform(const btTransform& worldTrans) { _outgoingPacketFlags = DIRTY_PHYSICS_FLAGS; EntityMotionState::enqueueOutgoingEntity(_entity); - - quint64 now = usecTimestampNow(); - qDebug() << "EntityMotionState::setWorldTransform()... changed entity:" << _entity->getEntityItemID(); - qDebug() << " last edited:" << _entity->getLastEdited() << formatUsecTime(now - _entity->getLastEdited()) << "ago"; - qDebug() << " last simulated:" << _entity->getLastSimulated() << formatUsecTime(now - _entity->getLastSimulated()) << "ago"; - qDebug() << " last updated:" << _entity->getLastUpdated() << formatUsecTime(now - _entity->getLastUpdated()) << "ago"; - qDebug() << " last collision:" << EntityItem::lastCollisionTime << formatUsecTime(now - EntityItem::lastCollisionTime) << "ago"; + + #ifdef WANT_DEBUG + quint64 now = usecTimestampNow(); + qDebug() << "EntityMotionState::setWorldTransform()... changed entity:" << _entity->getEntityItemID(); + qDebug() << " last edited:" << _entity->getLastEdited() << formatUsecTime(now - _entity->getLastEdited()) << "ago"; + qDebug() << " last simulated:" << _entity->getLastSimulated() << formatUsecTime(now - _entity->getLastSimulated()) << "ago"; + qDebug() << " last updated:" << _entity->getLastUpdated() << formatUsecTime(now - _entity->getLastUpdated()) << "ago"; + qDebug() << " last collision:" << EntityItem::lastCollisionTime << formatUsecTime(now - EntityItem::lastCollisionTime) << "ago"; + #endif } void EntityMotionState::updateObjectEasy(uint32_t flags, uint32_t frame) { @@ -240,7 +242,9 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, uint32_ #endif entityPacketSender->queueEditEntityMessage(PacketTypeEntityAddOrEdit, id, properties); } else { - qDebug() << "EntityMotionState::sendUpdate()... NOT sending update as requested."; + #ifdef WANT_DEBUG + qDebug() << "EntityMotionState::sendUpdate()... NOT sending update as requested."; + #endif } // The outgoing flags only itemized WHAT to send, not WHETHER to send, hence we always set them diff --git a/libraries/physics/src/PhysicsEngine.cpp b/libraries/physics/src/PhysicsEngine.cpp index fce8faf301..b427d78a69 100644 --- a/libraries/physics/src/PhysicsEngine.cpp +++ b/libraries/physics/src/PhysicsEngine.cpp @@ -372,16 +372,16 @@ void PhysicsEngine::computeCollisionEvents() { idB = static_cast(B)->getEntity()->getEntityItemID(); } -qDebug() << "entityCollisionWithEntity()... idA:" << idA << "idB:" << idB << "*******************************"; -EntityItem::lastCollisionTime = usecTimestampNow(); +//qDebug() << "entityCollisionWithEntity()... idA:" << idA << "idB:" << idB << "*******************************"; +//EntityItem::lastCollisionTime = usecTimestampNow(); emit entityCollisionWithEntity(idA, idB, contactItr->second); } else if (B && B->getType() == MOTION_STATE_TYPE_ENTITY) { EntityItemID idA; EntityItemID idB = static_cast(B)->getEntity()->getEntityItemID(); -qDebug() << "entityCollisionWithEntity()... idA:" << idA << "idB:" << idB << "*******************************"; -EntityItem::lastCollisionTime = usecTimestampNow(); +//qDebug() << "entityCollisionWithEntity()... idA:" << idA << "idB:" << idB << "*******************************"; +//EntityItem::lastCollisionTime = usecTimestampNow(); emit entityCollisionWithEntity(idA, idB, contactItr->second); } From 81185cfe5615ceecbc67eb0a89c8a203cdd1d692 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 26 Jan 2015 12:46:22 -0800 Subject: [PATCH 05/12] removed some debugging --- libraries/entities/src/EntityItem.cpp | 3 --- libraries/entities/src/EntityItem.h | 2 -- libraries/physics/src/EntityMotionState.cpp | 1 - libraries/physics/src/PhysicsEngine.cpp | 8 -------- 4 files changed, 14 deletions(-) diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index ab859c7282..b987e37f3b 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -21,11 +21,8 @@ #include "EntityItem.h" #include "EntityTree.h" -quint64 EntityItem::lastCollisionTime = 0; bool EntityItem::_sendPhysicsUpdates = true; - - void EntityItem::initFromEntityItemID(const EntityItemID& entityItemID) { _id = entityItemID.id; _creatorTokenID = entityItemID.creatorTokenID; diff --git a/libraries/entities/src/EntityItem.h b/libraries/entities/src/EntityItem.h index 1c35a0aa3d..2cba4692d0 100644 --- a/libraries/entities/src/EntityItem.h +++ b/libraries/entities/src/EntityItem.h @@ -54,8 +54,6 @@ public: DIRTY_UPDATEABLE = 0x0080, }; - static quint64 lastCollisionTime; - DONT_ALLOW_INSTANTIATION // This class can not be instantiated directly EntityItem(const EntityItemID& entityItemID); diff --git a/libraries/physics/src/EntityMotionState.cpp b/libraries/physics/src/EntityMotionState.cpp index 02a0dfbf92..01063a43d6 100644 --- a/libraries/physics/src/EntityMotionState.cpp +++ b/libraries/physics/src/EntityMotionState.cpp @@ -106,7 +106,6 @@ void EntityMotionState::setWorldTransform(const btTransform& worldTrans) { qDebug() << " last edited:" << _entity->getLastEdited() << formatUsecTime(now - _entity->getLastEdited()) << "ago"; qDebug() << " last simulated:" << _entity->getLastSimulated() << formatUsecTime(now - _entity->getLastSimulated()) << "ago"; qDebug() << " last updated:" << _entity->getLastUpdated() << formatUsecTime(now - _entity->getLastUpdated()) << "ago"; - qDebug() << " last collision:" << EntityItem::lastCollisionTime << formatUsecTime(now - EntityItem::lastCollisionTime) << "ago"; #endif } diff --git a/libraries/physics/src/PhysicsEngine.cpp b/libraries/physics/src/PhysicsEngine.cpp index b427d78a69..dfd28dd8a4 100644 --- a/libraries/physics/src/PhysicsEngine.cpp +++ b/libraries/physics/src/PhysicsEngine.cpp @@ -371,18 +371,10 @@ void PhysicsEngine::computeCollisionEvents() { if (B && B->getType() == MOTION_STATE_TYPE_ENTITY) { idB = static_cast(B)->getEntity()->getEntityItemID(); } - -//qDebug() << "entityCollisionWithEntity()... idA:" << idA << "idB:" << idB << "*******************************"; -//EntityItem::lastCollisionTime = usecTimestampNow(); - emit entityCollisionWithEntity(idA, idB, contactItr->second); } else if (B && B->getType() == MOTION_STATE_TYPE_ENTITY) { EntityItemID idA; EntityItemID idB = static_cast(B)->getEntity()->getEntityItemID(); - -//qDebug() << "entityCollisionWithEntity()... idA:" << idA << "idB:" << idB << "*******************************"; -//EntityItem::lastCollisionTime = usecTimestampNow(); - emit entityCollisionWithEntity(idA, idB, contactItr->second); } From d9835701b004467a6278ee10a79cc9fb8222a184 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 26 Jan 2015 12:48:57 -0800 Subject: [PATCH 06/12] added comment --- examples/utilities/tools/developerMenuItems.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/utilities/tools/developerMenuItems.js b/examples/utilities/tools/developerMenuItems.js index 765e85579e..419285eeb9 100644 --- a/examples/utilities/tools/developerMenuItems.js +++ b/examples/utilities/tools/developerMenuItems.js @@ -18,6 +18,9 @@ function setupMenus() { } if (!Menu.menuExists("Developer > Entities")) { Menu.addMenu("Developer > Entities"); + + // NOTE: these menu items aren't currently working. I've temporarily removed them. Will add them back once we + // rewire these to work /* Menu.addMenuItem({ menuName: "Developer > Entities", menuItemName: "Display Model Bounds", isCheckable: true, isChecked: false }); Menu.addMenuItem({ menuName: "Developer > Entities", menuItemName: "Display Model Triangles", isCheckable: true, isChecked: false }); @@ -47,8 +50,6 @@ setupMenus(); // register our scriptEnding callback Script.scriptEnding.connect(scriptEnding); - - function scriptEnding() { Menu.removeMenu("Developer > Entities"); } From 02c0700db326b6847bcab65cd75a56ccfda7847b Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 26 Jan 2015 17:25:06 -0800 Subject: [PATCH 07/12] support for skipping forward on new edit packets from server --- libraries/entities/src/EntityItem.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index b987e37f3b..673f23e328 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -560,6 +560,11 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef // server (clock skew adjusted). By setting it to "now" we are saying that the last position is to be // considered to be the correct position for "now" which is likely in the future from when it actually // was at that last known positition. + + float skipTimeForward = (float)(now - _lastSimulated) / (float)(USECS_PER_SECOND); + qDebug() << "skipTimeForward:" << skipTimeForward; + simulateKinematicMotion(skipTimeForward); + //simulate(now); _lastSimulated = now; } } From 83d1cc911a23f0d9f0addf705cf5de3cf8864c2b Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 26 Jan 2015 19:38:24 -0800 Subject: [PATCH 08/12] hacking --- libraries/entities/src/EntityItem.cpp | 6 ++++-- libraries/physics/src/EntityMotionState.cpp | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index 673f23e328..338009c280 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -562,8 +562,10 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef // was at that last known positition. float skipTimeForward = (float)(now - _lastSimulated) / (float)(USECS_PER_SECOND); - qDebug() << "skipTimeForward:" << skipTimeForward; - simulateKinematicMotion(skipTimeForward); + if (skipTimeForward > 0.0f) { + qDebug() << "skipTimeForward:" << skipTimeForward; + simulateKinematicMotion(skipTimeForward); + } //simulate(now); _lastSimulated = now; } diff --git a/libraries/physics/src/EntityMotionState.cpp b/libraries/physics/src/EntityMotionState.cpp index 01063a43d6..3355f12b47 100644 --- a/libraries/physics/src/EntityMotionState.cpp +++ b/libraries/physics/src/EntityMotionState.cpp @@ -97,6 +97,8 @@ void EntityMotionState::setWorldTransform(const btTransform& worldTrans) { // DANGER! EntityItem stores angularVelocity in degrees/sec!!! _entity->setAngularVelocity(glm::degrees(v)); + _entity->setLastSimulated(usecTimestampNow()); + _outgoingPacketFlags = DIRTY_PHYSICS_FLAGS; EntityMotionState::enqueueOutgoingEntity(_entity); From 45dbff67f8099a832f508a80e29bb0dc667edb61 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 27 Jan 2015 11:15:33 -0800 Subject: [PATCH 09/12] more hacking --- libraries/entities/src/BoxEntityItem.cpp | 9 ++++ libraries/entities/src/BoxEntityItem.h | 2 + libraries/entities/src/EntityItem.cpp | 58 +++++++++++++-------- libraries/entities/src/EntityItem.h | 4 ++ libraries/entities/src/SphereEntityItem.cpp | 11 ++++ libraries/entities/src/SphereEntityItem.h | 2 + libraries/physics/src/EntityMotionState.cpp | 8 ++- 7 files changed, 71 insertions(+), 23 deletions(-) diff --git a/libraries/entities/src/BoxEntityItem.cpp b/libraries/entities/src/BoxEntityItem.cpp index 88e1a4b6b1..25ef2e6aaf 100644 --- a/libraries/entities/src/BoxEntityItem.cpp +++ b/libraries/entities/src/BoxEntityItem.cpp @@ -101,3 +101,12 @@ void BoxEntityItem::computeShapeInfo(ShapeInfo& info) const { info.setBox(halfExtents); } +void BoxEntityItem::debugDump() const { + quint64 now = usecTimestampNow(); + qDebug() << " BOX EntityItem id:" << getEntityItemID() << "---------------------------------------------"; + qDebug() << " color:" << _color[0] << "," << _color[1] << "," << _color[2]; + qDebug() << " position:" << debugTreeVector(_position); + qDebug() << " dimensions:" << debugTreeVector(_dimensions); + qDebug() << " getLastEdited:" << debugTime(getLastEdited(), now); +} + diff --git a/libraries/entities/src/BoxEntityItem.h b/libraries/entities/src/BoxEntityItem.h index 3ce67369ee..8d68a13158 100644 --- a/libraries/entities/src/BoxEntityItem.h +++ b/libraries/entities/src/BoxEntityItem.h @@ -53,6 +53,8 @@ public: void computeShapeInfo(ShapeInfo& info) const; + virtual void debugDump() const; + protected: rgbColor _color; }; diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index 338009c280..0ebab1f19c 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -380,7 +380,11 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef float editedAgo = getEditedAgo(); QString agoAsString = formatSecondsElapsed(editedAgo); QString ageAsString = formatSecondsElapsed(getAge()); + qDebug() << "------------------------------------------"; qDebug() << "Loading entity " << getEntityItemID() << " from buffer..."; + qDebug() << "------------------------------------------"; + debugDump(); + qDebug() << "------------------------------------------"; qDebug() << " _created =" << _created; qDebug() << " age=" << getAge() << "seconds - " << ageAsString; qDebug() << " lastEdited =" << lastEdited; @@ -402,19 +406,17 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef bool fromSameServerEdit = (lastEditedFromBuffer == _lastEditedFromRemoteInRemoteTime); - if (wantDebug) { + if (true || wantDebug) { qDebug() << "data from server **************** "; - qDebug() << " entityItemID=" << getEntityItemID(); - qDebug() << " now=" << now; - qDebug() << " getLastEdited()=" << getLastEdited(); - qDebug() << " lastEditedFromBuffer=" << lastEditedFromBuffer << " (BEFORE clockskew adjust)"; - qDebug() << " clockSkew=" << clockSkew; - qDebug() << " lastEditedFromBufferAdjusted=" << lastEditedFromBufferAdjusted << " (AFTER clockskew adjust)"; - qDebug() << " _lastEditedFromRemote=" << _lastEditedFromRemote - << " (our local time the last server edit we accepted)"; - qDebug() << " _lastEditedFromRemoteInRemoteTime=" << _lastEditedFromRemoteInRemoteTime - << " (remote time the last server edit we accepted)"; - qDebug() << " fromSameServerEdit=" << fromSameServerEdit; + qDebug() << " entityItemID:" << getEntityItemID(); + qDebug() << " now:" << now; + qDebug() << " getLastEdited:" << debugTime(getLastEdited(), now); + qDebug() << " lastEditedFromBuffer:" << debugTime(lastEditedFromBuffer, now); + qDebug() << " clockSkew:" << debugTimeOnly(clockSkew); + qDebug() << " lastEditedFromBufferAdjusted:" << debugTime(lastEditedFromBufferAdjusted, now); + qDebug() << " _lastEditedFromRemote:" << debugTime(_lastEditedFromRemote, now); + qDebug() << " _lastEditedFromRemoteInRemoteTime:" << debugTime(_lastEditedFromRemoteInRemoteTime, now); + qDebug() << " fromSameServerEdit:" << fromSameServerEdit; } bool ignoreServerPacket = false; // assume we'll use this server packet @@ -438,13 +440,15 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef if (ignoreServerPacket) { overwriteLocalData = false; - if (wantDebug) { + if (true || wantDebug) { qDebug() << "IGNORING old data from server!!! ****************"; + debugDump(); } } else { - if (wantDebug) { + if (true || wantDebug) { qDebug() << "USING NEW data from server!!! ****************"; + debugDump(); } // don't allow _lastEdited to be in the future @@ -464,9 +468,9 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef if (overwriteLocalData) { _lastUpdated = lastEditedFromBufferAdjusted + updateDelta; // don't adjust for clock skew since we already did that if (wantDebug) { - qDebug() << "_lastUpdated =" << _lastUpdated; - qDebug() << "_lastEdited=" << _lastEdited; - qDebug() << "lastEditedFromBufferAdjusted=" << lastEditedFromBufferAdjusted; + qDebug() << " _lastUpdated:" << debugTime(_lastUpdated, now); + qDebug() << " _lastEdited:" << debugTime(_lastEdited, now); + qDebug() << " lastEditedFromBufferAdjusted:" << debugTime(lastEditedFromBufferAdjusted, now); } } encodedUpdateDelta = updateDeltaCoder; // determine true length @@ -482,15 +486,25 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef if (overwriteLocalData) { _lastSimulated = lastEditedFromBufferAdjusted + simulatedDelta; // don't adjust for clock skew since we already did that if (wantDebug) { - qDebug() << "_lastSimulated =" << _lastSimulated; - qDebug() << "_lastEdited=" << _lastEdited; - qDebug() << "lastEditedFromBufferAdjusted=" << lastEditedFromBufferAdjusted; + qDebug() << " _lastSimulated:" << debugTime(_lastSimulated, now); + qDebug() << " _lastEdited:" << debugTime(_lastEdited, now); + qDebug() << " lastEditedFromBufferAdjusted:" << debugTime(lastEditedFromBufferAdjusted, now); } } encodedSimulatedDelta = simulatedDeltaCoder; // determine true length dataAt += encodedSimulatedDelta.size(); bytesRead += encodedSimulatedDelta.size(); - } + } + + #if 1 //def WANT_DEBUG + if (overwriteLocalData) { + qDebug() << "EntityItem::readEntityDataFromBuffer()... changed entity:" << getEntityItemID(); + qDebug() << " getLastEdited:" << debugTime(getLastEdited(), now); + qDebug() << " getLastSimulated:" << debugTime(getLastSimulated(), now); + qDebug() << " getLastUpdated:" << debugTime(getLastUpdated(), now); + } + #endif + // Property Flags QByteArray encodedPropertyFlags = originalDataBuffer.mid(bytesRead); // maximum possible size @@ -592,7 +606,7 @@ void EntityItem::adjustEditPacketForClockSkew(unsigned char* editPacketBuffer, s memcpy(&lastEditedInLocalTime, dataAt, sizeof(lastEditedInLocalTime)); quint64 lastEditedInServerTime = lastEditedInLocalTime + clockSkew; memcpy(dataAt, &lastEditedInServerTime, sizeof(lastEditedInServerTime)); - const bool wantDebug = false; + const bool wantDebug = true; if (wantDebug) { qDebug("EntityItem::adjustEditPacketForClockSkew()..."); qDebug() << " lastEditedInLocalTime: " << lastEditedInLocalTime; diff --git a/libraries/entities/src/EntityItem.h b/libraries/entities/src/EntityItem.h index 2cba4692d0..58dc391458 100644 --- a/libraries/entities/src/EntityItem.h +++ b/libraries/entities/src/EntityItem.h @@ -36,6 +36,10 @@ class EntityTreeElementExtraEncodeData; #define DONT_ALLOW_INSTANTIATION virtual void pureVirtualFunctionPlaceHolder() = 0; #define ALLOW_INSTANTIATION virtual void pureVirtualFunctionPlaceHolder() { }; +#define debugTime(T, N) qPrintable(QString("%1 [ %2 ago]").arg(T, 16, 10).arg(formatUsecTime(N - T), 15)) +#define debugTimeOnly(T) qPrintable(QString("%1").arg(T, 16, 10)) +#define debugTreeVector(V) V << "[" << (V * (float)TREE_SCALE) << " in meters ]" + /// EntityItem class this is the base class for all entity types. It handles the basic properties and functionality available /// to all other entity types. In particular: postion, size, rotation, age, lifetime, velocity, gravity. You can not instantiate diff --git a/libraries/entities/src/SphereEntityItem.cpp b/libraries/entities/src/SphereEntityItem.cpp index 7f3d619e03..181e5851f6 100644 --- a/libraries/entities/src/SphereEntityItem.cpp +++ b/libraries/entities/src/SphereEntityItem.cpp @@ -132,3 +132,14 @@ bool SphereEntityItem::findDetailedRayIntersection(const glm::vec3& origin, cons } return false; } + + +void SphereEntityItem::debugDump() const { + quint64 now = usecTimestampNow(); + qDebug() << "SHPERE EntityItem id:" << getEntityItemID() << "---------------------------------------------"; + qDebug() << " color:" << _color[0] << "," << _color[1] << "," << _color[2]; + qDebug() << " position:" << debugTreeVector(_position); + qDebug() << " dimensions:" << debugTreeVector(_dimensions); + qDebug() << " getLastEdited:" << debugTime(getLastEdited(), now); +} + diff --git a/libraries/entities/src/SphereEntityItem.h b/libraries/entities/src/SphereEntityItem.h index c81f80d9ab..f76c9f5600 100644 --- a/libraries/entities/src/SphereEntityItem.h +++ b/libraries/entities/src/SphereEntityItem.h @@ -63,6 +63,8 @@ public: bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face, void** intersectedObject, bool precisionPicking) const; + virtual void debugDump() const; + protected: virtual void recalculateCollisionShape(); diff --git a/libraries/physics/src/EntityMotionState.cpp b/libraries/physics/src/EntityMotionState.cpp index 3355f12b47..01d9162314 100644 --- a/libraries/physics/src/EntityMotionState.cpp +++ b/libraries/physics/src/EntityMotionState.cpp @@ -228,9 +228,15 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, uint32_ // we only update lastEdited when we're sending new physics data // (i.e. NOT when we just simulate the positions forward, nore when we resend non-moving data) // NOTE: Andrew & Brad to discuss. Let's make sure we're using lastEdited, lastSimulated, and lastUpdated correctly - quint64 lastSimulated = _entity->getLastSimulated(); + quint64 now = usecTimestampNow(); + quint64 lastSimulated = _entity->getLastSimulated(); // or now??? _entity->setLastEdited(lastSimulated); properties.setLastEdited(lastSimulated); + + qDebug() << "EntityMotionState::sendUpdate()"; + qDebug() << " EntityItemId:" << _entity->getEntityItemID() << "---------------------------------------------"; + qDebug() << " lastSimulated:" << debugTime(lastSimulated, now); + } else { properties.setLastEdited(_entity->getLastEdited()); } From b1586d4f904420470a77cc900dd9c5dcb9f2b4b5 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 27 Jan 2015 11:29:17 -0800 Subject: [PATCH 10/12] move debug into ifdef --- libraries/entities/src/EntityItem.cpp | 106 ++++++-------------- libraries/physics/src/EntityMotionState.cpp | 10 +- 2 files changed, 38 insertions(+), 78 deletions(-) diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index 0ebab1f19c..86e116bf9f 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -167,13 +167,12 @@ OctreeElement::AppendState EntityItem::appendEntityData(OctreePacketData* packet quint64 lastEdited = getLastEdited(); - const bool wantDebug = false; - if (wantDebug) { + #ifdef WANT_DEBUG float editedAgo = getEditedAgo(); QString agoAsString = formatSecondsElapsed(editedAgo); qDebug() << "Writing entity " << getEntityItemID() << " to buffer, lastEdited =" << lastEdited << " ago=" << editedAgo << "seconds - " << agoAsString; - } + #endif bool successIDFits = false; bool successTypeFits = false; @@ -227,11 +226,6 @@ OctreeElement::AppendState EntityItem::appendEntityData(OctreePacketData* packet APPEND_ENTITY_PROPERTY(PROP_POSITION, appendPosition, getPosition()); APPEND_ENTITY_PROPERTY(PROP_DIMENSIONS, appendValue, getDimensions()); // NOTE: PROP_RADIUS obsolete - - if (wantDebug) { - qDebug() << " APPEND_ENTITY_PROPERTY() PROP_DIMENSIONS:" << getDimensions(); - } - APPEND_ENTITY_PROPERTY(PROP_ROTATION, appendValue, getRotation()); APPEND_ENTITY_PROPERTY(PROP_DENSITY, appendValue, getDensity()); APPEND_ENTITY_PROPERTY(PROP_VELOCITY, appendValue, getVelocity()); @@ -310,7 +304,6 @@ int EntityItem::expectedBytes() { int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLeftToRead, ReadBitstreamToTreeParams& args) { - bool wantDebug = false; if (args.bitstreamVersion < VERSION_ENTITIES_SUPPORT_SPLIT_MTU) { @@ -375,7 +368,7 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef _created = createdFromBuffer; } - if (wantDebug) { + #ifdef WANT_DEBUG quint64 lastEdited = getLastEdited(); float editedAgo = getEditedAgo(); QString agoAsString = formatSecondsElapsed(editedAgo); @@ -389,7 +382,7 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef qDebug() << " age=" << getAge() << "seconds - " << ageAsString; qDebug() << " lastEdited =" << lastEdited; qDebug() << " ago=" << editedAgo << "seconds - " << agoAsString; - } + #endif quint64 lastEditedFromBuffer = 0; quint64 lastEditedFromBufferAdjusted = 0; @@ -406,7 +399,7 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef bool fromSameServerEdit = (lastEditedFromBuffer == _lastEditedFromRemoteInRemoteTime); - if (true || wantDebug) { + #ifdef WANT_DEBUG qDebug() << "data from server **************** "; qDebug() << " entityItemID:" << getEntityItemID(); qDebug() << " now:" << now; @@ -417,7 +410,7 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef qDebug() << " _lastEditedFromRemote:" << debugTime(_lastEditedFromRemote, now); qDebug() << " _lastEditedFromRemoteInRemoteTime:" << debugTime(_lastEditedFromRemoteInRemoteTime, now); qDebug() << " fromSameServerEdit:" << fromSameServerEdit; - } + #endif bool ignoreServerPacket = false; // assume we'll use this server packet @@ -440,16 +433,16 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef if (ignoreServerPacket) { overwriteLocalData = false; - if (true || wantDebug) { + #ifdef WANT_DEBUG qDebug() << "IGNORING old data from server!!! ****************"; debugDump(); - } + #endif } else { - if (true || wantDebug) { + #ifdef WANT_DEBUG qDebug() << "USING NEW data from server!!! ****************"; debugDump(); - } + #endif // don't allow _lastEdited to be in the future _lastEdited = lastEditedFromBufferAdjusted; @@ -467,11 +460,11 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef quint64 updateDelta = updateDeltaCoder; if (overwriteLocalData) { _lastUpdated = lastEditedFromBufferAdjusted + updateDelta; // don't adjust for clock skew since we already did that - if (wantDebug) { + #ifdef WANT_DEBUG qDebug() << " _lastUpdated:" << debugTime(_lastUpdated, now); qDebug() << " _lastEdited:" << debugTime(_lastEdited, now); qDebug() << " lastEditedFromBufferAdjusted:" << debugTime(lastEditedFromBufferAdjusted, now); - } + #endif } encodedUpdateDelta = updateDeltaCoder; // determine true length dataAt += encodedUpdateDelta.size(); @@ -485,18 +478,18 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef quint64 simulatedDelta = simulatedDeltaCoder; if (overwriteLocalData) { _lastSimulated = lastEditedFromBufferAdjusted + simulatedDelta; // don't adjust for clock skew since we already did that - if (wantDebug) { + #ifdef WANT_DEBUG qDebug() << " _lastSimulated:" << debugTime(_lastSimulated, now); qDebug() << " _lastEdited:" << debugTime(_lastEdited, now); qDebug() << " lastEditedFromBufferAdjusted:" << debugTime(lastEditedFromBufferAdjusted, now); - } + #endif } encodedSimulatedDelta = simulatedDeltaCoder; // determine true length dataAt += encodedSimulatedDelta.size(); bytesRead += encodedSimulatedDelta.size(); } - #if 1 //def WANT_DEBUG + #ifdef WANT_DEBUG if (overwriteLocalData) { qDebug() << "EntityItem::readEntityDataFromBuffer()... changed entity:" << getEntityItemID(); qDebug() << " getLastEdited:" << debugTime(getLastEdited(), now); @@ -524,23 +517,11 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef if (overwriteLocalData) { setRadius(fromBuffer); } - - if (wantDebug) { - qDebug() << " readEntityDataFromBuffer() OLD FORMAT... found PROP_RADIUS"; - } - } } else { READ_ENTITY_PROPERTY_SETTER(PROP_DIMENSIONS, glm::vec3, setDimensions); - if (wantDebug) { - qDebug() << " readEntityDataFromBuffer() NEW FORMAT... look for PROP_DIMENSIONS"; - } } - if (wantDebug) { - qDebug() << " readEntityDataFromBuffer() _dimensions:" << getDimensionsInMeters() << " in meters"; - } - READ_ENTITY_PROPERTY_QUAT_SETTER(PROP_ROTATION, updateRotation); READ_ENTITY_PROPERTY_SETTER(PROP_DENSITY, float, updateDensity); READ_ENTITY_PROPERTY_SETTER(PROP_VELOCITY, glm::vec3, updateVelocity); @@ -557,13 +538,6 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef READ_ENTITY_PROPERTY(PROP_LOCKED, bool, _locked); READ_ENTITY_PROPERTY_STRING(PROP_USER_DATA,setUserData); - if (wantDebug) { - qDebug() << " readEntityDataFromBuffer() _registrationPoint:" << _registrationPoint; - qDebug() << " readEntityDataFromBuffer() _visible:" << _visible; - qDebug() << " readEntityDataFromBuffer() _ignoreForCollisions:" << _ignoreForCollisions; - qDebug() << " readEntityDataFromBuffer() _collisionsWillMove:" << _collisionsWillMove; - } - bytesRead += readEntitySubclassDataFromBuffer(dataAt, (bytesLeftToRead - bytesRead), args, propertyFlags, overwriteLocalData); recalculateCollisionShape(); @@ -577,10 +551,11 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef float skipTimeForward = (float)(now - _lastSimulated) / (float)(USECS_PER_SECOND); if (skipTimeForward > 0.0f) { - qDebug() << "skipTimeForward:" << skipTimeForward; + #ifdef WANT_DEBUG + qDebug() << "skipTimeForward:" << skipTimeForward; + #endif simulateKinematicMotion(skipTimeForward); } - //simulate(now); _lastSimulated = now; } } @@ -606,13 +581,12 @@ void EntityItem::adjustEditPacketForClockSkew(unsigned char* editPacketBuffer, s memcpy(&lastEditedInLocalTime, dataAt, sizeof(lastEditedInLocalTime)); quint64 lastEditedInServerTime = lastEditedInLocalTime + clockSkew; memcpy(dataAt, &lastEditedInServerTime, sizeof(lastEditedInServerTime)); - const bool wantDebug = true; - if (wantDebug) { + #ifdef WANT_DEBUG qDebug("EntityItem::adjustEditPacketForClockSkew()..."); qDebug() << " lastEditedInLocalTime: " << lastEditedInLocalTime; qDebug() << " clockSkew: " << clockSkew; qDebug() << " lastEditedInServerTime: " << lastEditedInServerTime; - } + #endif } float EntityItem::computeMass() const { @@ -667,15 +641,13 @@ bool EntityItem::isRestingOnSurface() const { } void EntityItem::simulate(const quint64& now) { - bool wantDebug = false; - if (_lastSimulated == 0) { _lastSimulated = now; } float timeElapsed = (float)(now - _lastSimulated) / (float)(USECS_PER_SECOND); - if (wantDebug) { + #ifdef WANT_DEBUG qDebug() << "********** EntityItem::simulate()"; qDebug() << " entity ID=" << getEntityItemID(); qDebug() << " now=" << now; @@ -710,27 +682,23 @@ void EntityItem::simulate(const quint64& now) { qDebug() << " getAge()=" << getAge(); qDebug() << " getLifetime()=" << getLifetime(); } - } - - if (wantDebug) { qDebug() << " ********** EntityItem::simulate() .... SETTING _lastSimulated=" << _lastSimulated; - } + #endif simulateKinematicMotion(timeElapsed); _lastSimulated = now; } void EntityItem::simulateKinematicMotion(float timeElapsed) { - bool wantDebug = false; if (hasAngularVelocity()) { // angular damping glm::vec3 angularVelocity = getAngularVelocity(); if (_angularDamping > 0.0f) { angularVelocity *= powf(1.0f - _angularDamping, timeElapsed); - if (wantDebug) { + #ifdef WANT_DEBUG qDebug() << " angularDamping :" << _angularDamping; qDebug() << " newAngularVelocity:" << angularVelocity; - } + #endif setAngularVelocity(angularVelocity); } @@ -758,19 +726,19 @@ void EntityItem::simulateKinematicMotion(float timeElapsed) { glm::vec3 velocity = getVelocity(); if (_damping > 0.0f) { velocity *= powf(1.0f - _damping, timeElapsed); - if (wantDebug) { + #ifdef WANT_DEBUG qDebug() << " damping:" << _damping; qDebug() << " velocity AFTER dampingResistance:" << velocity; qDebug() << " glm::length(velocity):" << glm::length(velocity); qDebug() << " velocityEspilon :" << ENTITY_ITEM_EPSILON_VELOCITY_LENGTH; - } + #endif } // integrate position forward glm::vec3 position = getPosition(); glm::vec3 newPosition = position + (velocity * timeElapsed); - if (wantDebug) { + #ifdef WANT_DEBUG qDebug() << " EntityItem::simulate()...."; qDebug() << " timeElapsed:" << timeElapsed; qDebug() << " old AACube:" << getMaximumAACube(); @@ -780,7 +748,7 @@ void EntityItem::simulateKinematicMotion(float timeElapsed) { qDebug() << " getDistanceToBottomOfEntity():" << getDistanceToBottomOfEntity() * (float)TREE_SCALE << " in meters"; qDebug() << " newPosition:" << newPosition; qDebug() << " glm::distance(newPosition, position):" << glm::distance(newPosition, position); - } + #endif position = newPosition; @@ -803,12 +771,12 @@ void EntityItem::simulateKinematicMotion(float timeElapsed) { setVelocity(velocity); } - if (wantDebug) { + #ifdef WANT_DEBUG qDebug() << " new position:" << position; qDebug() << " new velocity:" << velocity; qDebug() << " new AACube:" << getMaximumAACube(); qDebug() << " old getAABox:" << getAABox(); - } + #endif } } @@ -882,13 +850,12 @@ bool EntityItem::setProperties(const EntityItemProperties& properties) { if (somethingChanged) { somethingChangedNotification(); // notify derived classes that something has changed - bool wantDebug = false; uint64_t now = usecTimestampNow(); - if (wantDebug) { + #ifdef WANT_DEBUG int elapsed = now - getLastEdited(); qDebug() << "EntityItem::setProperties() AFTER update... edited AGO=" << elapsed << "now=" << now << " getLastEdited()=" << getLastEdited(); - } + #endif if (_created != UNKNOWN_CREATED_TIME) { setLastEdited(now); } @@ -1030,15 +997,6 @@ void EntityItem::setRadius(float value) { float diameter = value * 2.0f; float maxDimension = sqrt((diameter * diameter) / 3.0f); _dimensions = glm::vec3(maxDimension, maxDimension, maxDimension); - - bool wantDebug = false; - if (wantDebug) { - qDebug() << "EntityItem::setRadius()..."; - qDebug() << " radius:" << value; - qDebug() << " diameter:" << diameter; - qDebug() << " maxDimension:" << maxDimension; - qDebug() << " _dimensions:" << _dimensions; - } } // TODO: get rid of all users of this function... diff --git a/libraries/physics/src/EntityMotionState.cpp b/libraries/physics/src/EntityMotionState.cpp index 01d9162314..6283229dea 100644 --- a/libraries/physics/src/EntityMotionState.cpp +++ b/libraries/physics/src/EntityMotionState.cpp @@ -228,14 +228,16 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, uint32_ // we only update lastEdited when we're sending new physics data // (i.e. NOT when we just simulate the positions forward, nore when we resend non-moving data) // NOTE: Andrew & Brad to discuss. Let's make sure we're using lastEdited, lastSimulated, and lastUpdated correctly - quint64 now = usecTimestampNow(); quint64 lastSimulated = _entity->getLastSimulated(); // or now??? _entity->setLastEdited(lastSimulated); properties.setLastEdited(lastSimulated); - qDebug() << "EntityMotionState::sendUpdate()"; - qDebug() << " EntityItemId:" << _entity->getEntityItemID() << "---------------------------------------------"; - qDebug() << " lastSimulated:" << debugTime(lastSimulated, now); + #ifdef WANT_DEBUG + quint64 now = usecTimestampNow(); + qDebug() << "EntityMotionState::sendUpdate()"; + qDebug() << " EntityItemId:" << _entity->getEntityItemID() << "---------------------------------------------"; + qDebug() << " lastSimulated:" << debugTime(lastSimulated, now); + #endif //def WANT_DEBUG } else { properties.setLastEdited(_entity->getLastEdited()); From 94e04e2d7d1a5299d91a321e75354826714e1987 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 27 Jan 2015 11:34:46 -0800 Subject: [PATCH 11/12] removed extra whitespace --- libraries/physics/src/EntityMotionState.h | 1 - 1 file changed, 1 deletion(-) diff --git a/libraries/physics/src/EntityMotionState.h b/libraries/physics/src/EntityMotionState.h index 5370f9ebb4..5d98e545d9 100644 --- a/libraries/physics/src/EntityMotionState.h +++ b/libraries/physics/src/EntityMotionState.h @@ -63,7 +63,6 @@ public: protected: EntityItem* _entity; - }; #endif // hifi_EntityMotionState_h From 23892ab1e70a4e9abe7f07c164370fe2d90d2944 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 27 Jan 2015 11:38:14 -0800 Subject: [PATCH 12/12] fixed comments --- libraries/entities/src/EntityItem.cpp | 12 +++++------- libraries/physics/src/EntityMotionState.cpp | 2 +- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index 86e116bf9f..64cbf8ab04 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -542,13 +542,11 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef recalculateCollisionShape(); if (overwriteLocalData && (getDirtyFlags() & (EntityItem::DIRTY_POSITION | EntityItem::DIRTY_VELOCITY))) { - // TODO: Andrew & Brad to discuss -- this probably should not be "now" but instead should be the last - // simulated time from server. The logic should maybe be: the position changed from the server, so the - // position we just set can be thought of as the position at the time it was last simulated by the - // server (clock skew adjusted). By setting it to "now" we are saying that the last position is to be - // considered to be the correct position for "now" which is likely in the future from when it actually - // was at that last known positition. - + // 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 + // is sending us data with a known "last simulated" time. That time is likely in the past, and therefore + // this "new" data is actually slightly out of date. We calculate the time we need to skip forward and + // use our simulation helper routine to get a best estimate of where the entity should be. float skipTimeForward = (float)(now - _lastSimulated) / (float)(USECS_PER_SECOND); if (skipTimeForward > 0.0f) { #ifdef WANT_DEBUG diff --git a/libraries/physics/src/EntityMotionState.cpp b/libraries/physics/src/EntityMotionState.cpp index 6283229dea..acff3ed64a 100644 --- a/libraries/physics/src/EntityMotionState.cpp +++ b/libraries/physics/src/EntityMotionState.cpp @@ -228,7 +228,7 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, uint32_ // we only update lastEdited when we're sending new physics data // (i.e. NOT when we just simulate the positions forward, nore when we resend non-moving data) // NOTE: Andrew & Brad to discuss. Let's make sure we're using lastEdited, lastSimulated, and lastUpdated correctly - quint64 lastSimulated = _entity->getLastSimulated(); // or now??? + quint64 lastSimulated = _entity->getLastSimulated(); _entity->setLastEdited(lastSimulated); properties.setLastEdited(lastSimulated);