remove debug code

This commit is contained in:
Andrew Meadows 2015-06-25 10:22:13 -07:00
parent 12fc18092b
commit 44d3074561
8 changed files with 24 additions and 141 deletions

View file

@ -9,8 +9,7 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include <iostream> // adebug
#include <sstream> // adebug
#include "EntityItem.h"
#include <QtCore/QObject>
@ -25,12 +24,10 @@
#include <SoundCache.h>
#include "EntityScriptingInterface.h"
#include "EntityItem.h"
#include "EntitiesLogging.h"
#include "EntityTree.h"
#include "EntitySimulation.h"
const char* plankyBlock2 = "PlankyBlock46"; // adebug
const quint64 DEFAULT_SIMULATOR_CHANGE_LOCKOUT_PERIOD = (quint64)(0.2f * USECS_PER_SECOND);
const quint64 MAX_SIMULATOR_CHANGE_LOCKOUT_PERIOD = 2 * USECS_PER_SECOND;
@ -327,8 +324,6 @@ int EntityItem::expectedBytes() {
// clients use this method to unpack FULL updates from entity-server
int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLeftToRead, ReadBitstreamToTreeParams& args) {
static quint64 maxSkipTime = 0; // adebug
if (args.bitstreamVersion < VERSION_ENTITIES_SUPPORT_SPLIT_MTU) {
// NOTE: This shouldn't happen. The only versions of the bit stream that didn't support split mtu buffers should
@ -444,7 +439,6 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef
#endif
bool ignoreServerPacket = false; // assume we'll use this server packet
std::ostringstream debugOutput;
// If this packet is from the same server edit as the last packet we accepted from the server
// we probably want to use it.
@ -453,8 +447,6 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef
// the most recent packet from this server time
if (_lastEdited > _lastEditedFromRemote) {
ignoreServerPacket = true;
} else {
debugOutput << "adebug fromSameServerEdit for '" << _name.toStdString() << "' le - lefr = " << (_lastEdited - _lastEditedFromRemote) << std::flush; // adebug
}
} else {
// If this isn't from the same sever packet, then honor our skew adjusted times...
@ -462,8 +454,6 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef
// then we will not be changing our values, instead we just read and skip the data
if (_lastEdited > lastEditedFromBufferAdjusted) {
ignoreServerPacket = true;
} else {
debugOutput << "adebug honor skew adjust for '" << _name.toStdString() << "' le - lefba = " << (_lastEdited - lastEditedFromBufferAdjusted) << std::flush; // adebug
}
}
@ -550,7 +540,7 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef
// rules that we expect the server to be using, so it is possible that we'll sometimes ignore
// the incoming _simulatorID data (e.g. we might know something that the server does not... yet).
// BOOKMARK TODO adebug: follow pattern where the class unpacks itself
// BOOKMARK TODO adebug: follow pattern where the class unpacks itself?
if (propertyFlags.getHasProperty(PROP_SIMULATION_OWNER)) {
QByteArray simOwnerData;
int bytes = OctreePacketData::unpackDataFromBytes(dataAt, simOwnerData);
@ -559,16 +549,9 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef
dataAt += bytes;
bytesRead += bytes;
SimulationOwner oldOwner = _simulationOwner; // adebug
if (_simulationOwner.set(newSimOwner)) {
std::cout << "adebug something changed: owner = " << _simulationOwner << std::endl; // adebug
_dirtyFlags |= EntityItem::DIRTY_SIMULATOR_ID;
}
if (oldOwner != _simulationOwner) {
std::cout << "adebug ownership changed from " << oldOwner.getID().toString().toStdString() << ":" << int(oldOwner.getPriority()) << " to "
<< _simulationOwner.getID().toString().toStdString() << ":" << int(_simulationOwner.getPriority())
<< std::endl; // adebug
}
}
}
@ -652,11 +635,6 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef
// use our simulation helper routine to get a best estimate of where the entity should be.
const float MIN_TIME_SKIP = 0.0f;
const float MAX_TIME_SKIP = 1.0f; // in seconds
quint64 dt = now - lastSimulatedFromBufferAdjusted;
if (dt > maxSkipTime) {
maxSkipTime = dt;
std::cout << "adebug maxSkipTime = " << maxSkipTime << " for '" << _name.toStdString() << "'" << std::endl; // adebug
}
float skipTimeForward = glm::clamp((float)(now - lastSimulatedFromBufferAdjusted) / (float)(USECS_PER_SECOND),
MIN_TIME_SKIP, MAX_TIME_SKIP);
if (skipTimeForward > 0.0f) {
@ -672,8 +650,7 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef
auto nodeList = DependencyManager::get<NodeList>();
const QUuid& myNodeID = nodeList->getSessionUUID();
if (overwriteLocalData) {
// TODO adebug: make this use operator==()
if (_simulationOwner.matchesID(myNodeID)) {
if (_simulationOwner.matchesValidID(myNodeID)) {
// we own the simulation, so we keep our transform+velocities and remove any related dirty flags
// rather than accept the values in the packet
setPosition(savePosition);
@ -682,8 +659,6 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef
_angularVelocity = saveAngularVelocity;
_dirtyFlags &= ~(EntityItem::DIRTY_TRANSFORM | EntityItem::DIRTY_VELOCITIES);
} else {
std::cout << "adebug myNode = " << myNodeID.toString().toStdString() << " owner = " << _simulationOwner.getID().toString().toStdString() << std::endl; // adebug
std::cout << debugOutput.str() << std::endl; // adebug
_lastSimulated = now;
}
}
@ -903,11 +878,6 @@ void EntityItem::simulateKinematicMotion(float timeElapsed, bool setFlags) {
}
}
void EntityItem::clearDirtyFlags(uint32_t mask) {
// adebug TODO: move this back to header after done debugging
_dirtyFlags &= ~mask;
}
bool EntityItem::isMoving() const {
return hasVelocity() || hasAngularVelocity();
}
@ -1041,9 +1011,6 @@ bool EntityItem::setProperties(const EntityItemProperties& properties) {
SET_ENTITY_PROPERTY_FROM_PROPERTIES(description, setDescription);
if (somethingChanged) {
if (_name == plankyBlock2) {
std::cout << "adebug update for '" << _name.toStdString() << "'" << std::endl; // adebug
}
uint64_t now = usecTimestampNow();
#ifdef WANT_DEBUG
int elapsed = now - getLastEdited();
@ -1411,19 +1378,12 @@ void EntityItem::setSimulationOwner(const SimulationOwner& owner) {
}
void EntityItem::updateSimulatorID(const QUuid& value) {
QUuid oldID = _simulationOwner.getID();
if (_simulationOwner.setID(value)) {
_dirtyFlags |= EntityItem::DIRTY_SIMULATOR_ID;
if (oldID != _simulationOwner.getID() && _name == plankyBlock2) {
std::cout << "adebug updateSimulatorID for '" << _name.toStdString() << "' from " << oldID.toString().toStdString() << " to " << value.toString().toStdString() << std::endl; // adebug
}
}
}
void EntityItem::clearSimulationOwnership() {
if (_name == plankyBlock2) {
std::cout << "adebug clearSimulationOwnership for '" << _name.toStdString() << "'" << std::endl; // adebug
}
_simulationOwner.clear();
// don't bother setting the DIRTY_SIMULATOR_ID flag because clearSimulatorOwnership()
// is only ever called entity-server-side and the flags are only used client-side

View file

@ -362,8 +362,7 @@ public:
virtual void updateShapeType(ShapeType type) { /* do nothing */ }
uint32_t getDirtyFlags() const { return _dirtyFlags; }
//void clearDirtyFlags(uint32_t mask = 0xffffffff) { _dirtyFlags &= ~mask; }
void clearDirtyFlags(uint32_t mask = 0xffffffff);
void clearDirtyFlags(uint32_t mask = 0xffffffff) { _dirtyFlags &= ~mask; }
bool isMoving() const;

View file

@ -17,7 +17,6 @@
#include <ByteCountCoding.h>
#include <GLMHelpers.h>
#include <RegisteredMetaTypes.h>
#include <StreamUtils.h> // adebug
#include "EntitiesLogging.h"
#include "EntityItem.h"
@ -712,19 +711,15 @@ bool EntityItemProperties::encodeEntityEditPacket(PacketType command, EntityItem
LevelDetails propertyLevel = packetData->startLevel();
successPropertyFits = packetData->appendValue(properties._simulationOwner.toByteArray());
if (successPropertyFits) {
// std::cout << "adebug appending ownerhip data" << std::endl; // adebug
// StreamUtil::dump(std::cout, properties._simulationOwner.toByteArray());
propertyFlags |= PROP_SIMULATION_OWNER;
propertiesDidntFit -= PROP_SIMULATION_OWNER;
propertyCount++;
packetData->endLevel(propertyLevel);
} else {
// std::cout << "adebug ownership data did not fit" << std::endl; // adebug
packetData->discardLevel(propertyLevel);
appendState = OctreeElement::PARTIAL;
}
} else {
// std::cout << "adebug property doesn't have ownerhip data" << std::endl; // adebug
propertiesDidntFit -= PROP_SIMULATION_OWNER;
}
@ -992,10 +987,6 @@ bool EntityItemProperties::decodeEntityEditPacket(const unsigned char* data, int
SimulationOwner simOwner;
simOwner.fromByteArray(fromBuffer);
properties.setSimulationOwner(simOwner);
// std::cout << "adebug decoding ownerhip data" << std::endl; // adebug
// StreamUtil::dump(std::cout, fromBuffer);
} else {
// std::cout << "adebug no ownership info to decode" << std::endl; // adebug
}
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_POSITION, glm::vec3, setPosition);

View file

@ -9,7 +9,6 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include <iostream> // adebug
#include "EntityScriptingInterface.h"
#include <VariantMapToScriptValue.h>

View file

@ -11,6 +11,7 @@
#include "SimulationOwner.h"
#include <iostream> // included for tests
#include <assert.h>
#include <NumericalConstants.h>
@ -86,7 +87,7 @@ void SimulationOwner::updateExpiry() {
_expiry = usecTimestampNow() + OWNERSHIP_LOCKOUT_EXPIRY;
}
// TODO: move this test code out
// NOTE: eventually this code will be moved into unit tests
// static debug
void SimulationOwner::test() {
{ // test default constructor
@ -153,10 +154,6 @@ void SimulationOwner::test() {
}
}
bool SimulationOwner::operator==(const SimulationOwner& other) {
return (_id == other._id && _priority == other._priority);
}
bool SimulationOwner::operator!=(const SimulationOwner& other) {
return (_id != other._id && _priority != other._priority);
}
@ -175,12 +172,6 @@ SimulationOwner& SimulationOwner::operator=(const SimulationOwner& other) {
return *this;
}
// friend of SimulationOwner
std::ostream& operator<<(std::ostream& s, const SimulationOwner& simOwner) {
s << "{ id : " << simOwner._id.toString().toStdString() << ", priority : " << (int)simOwner._priority << " }";
return s;
}
QDebug& operator<<(QDebug& d, const SimulationOwner& simOwner) {
d << "{ id : " << simOwner << ", priority : " << (int)simOwner._priority << " }";
return d;

View file

@ -12,8 +12,6 @@
#ifndef hifi_SimulationOwner_h
#define hifi_SimulationOwner_h
#include <iostream>
#include <QtCore/QDebug>
#include <QtCore/QByteArray>
@ -50,18 +48,18 @@ public:
bool set(const SimulationOwner& owner);
bool isNull() const { return _id.isNull(); }
bool matchesID(const QUuid& id) const { return _id == id && !_id.isNull(); }
bool matchesValidID(const QUuid& id) const { return _id == id && !_id.isNull(); }
void updateExpiry();
bool hasExpired() const { return usecTimestampNow() > _expiry; }
bool operator>=(quint8 priority) const { return _priority >= priority; }
bool operator==(const SimulationOwner& other);
bool operator==(const SimulationOwner& other) { return (_id == other._id && _priority == other._priority); }
bool operator!=(const SimulationOwner& other);
SimulationOwner& operator=(const SimulationOwner& other);
friend std::ostream& operator<<(std::ostream& s, const SimulationOwner& simOwner);
friend QDebug& operator<<(QDebug& d, const SimulationOwner& simOwner);
// debug

View file

@ -22,8 +22,6 @@
#ifdef WANT_DEBUG_ENTITY_TREE_LOCKS
#include "EntityTree.h"
#endif
//const char* plankyBlock = "PlankyBlock46"; // adebug
const char* plankyBlock = "magenta"; // adebug
static const float ACCELERATION_EQUIVALENT_EPSILON_RATIO = 0.1f;
static const quint8 STEPS_TO_DECIDE_BALLISTIC = 4;
@ -98,17 +96,10 @@ void EntityMotionState::updateServerPhysicsVariables() {
// virtual
void EntityMotionState::handleEasyChanges(uint32_t flags, PhysicsEngine* engine) {
assert(entityTreeIsLocked());
// if (_entity && _entity->getName() == plankyBlock) {
// quint64 dt = (usecTimestampNow() - _activationTime) / 1000; // adebug
// std::cout << "adebug handleEasyChanges flags = 0x" << std::hex << flags << std::dec << " dt = " << dt << std::endl; // adebug
// }
updateServerPhysicsVariables();
ObjectMotionState::handleEasyChanges(flags, engine);
if (flags & EntityItem::DIRTY_SIMULATOR_ID) {
// if (_entity && _entity->getName() == plankyBlock) {
// std::cout << "adebug handleEasyChanges() '" << _entity->getName().toStdString() << "' found DIRTY_SIMULATOR_ID flag" << std::endl; // adebug
// }
_loopsWithoutOwner = 0;
if (_entity->getSimulatorID().isNull()) {
// simulation ownership is being removed
@ -117,26 +108,12 @@ void EntityMotionState::handleEasyChanges(uint32_t flags, PhysicsEngine* engine)
flags &= ~EntityItem::DIRTY_PHYSICS_ACTIVATION;
// hint to Bullet that the object is deactivating
_body->setActivationState(WANTS_DEACTIVATION);
// if (_entity && _entity->getName() == plankyBlock) {
// std::cout << "adebug handleEasyChanges() '" << _entity->getName().toStdString() << "' clearing ownership so _candidatePriority goes to 0" << std::endl; // adebug
// }
_candidatePriority = 0;
if (_expectedOwnership != -1) {
std::cout << "adebug unexpected loss of ownership '" << _entity->getName().toStdString() << "' expected -1 but got " << _expectedOwnership << std::endl; // adebug
}
_expectedOwnership = 0;
_outgoingPriority = 0;
} else {
_nextOwnershipBid = usecTimestampNow() + USECS_BETWEEN_OWNERSHIP_BIDS;
if (engine->getSessionID() == _entity->getSimulatorID() || _entity->getSimulatorPriority() > _candidatePriority) {
if (engine->getSessionID() == _entity->getSimulatorID() || _entity->getSimulatorPriority() > _outgoingPriority) {
// we own the simulation or our priority looses to remote
// if (_entity && _entity->getName() == plankyBlock) {
// std::cout << "adebug handleEasyChanges() '" << _entity->getName().toStdString() << "' we own it so _candidatePriority goes to 0" << std::endl; // adebug
// }
if (_expectedOwnership != 1) {
std::cout << "adebug unexpected gain of ownership '" << _entity->getName().toStdString() << "' expected 1 but got " << _expectedOwnership << " _candidatePriority = " << int(_candidatePriority) << std::endl; // adebug
}
_expectedOwnership = 0;
_candidatePriority = 0;
_outgoingPriority = 0;
}
}
}
@ -144,7 +121,7 @@ void EntityMotionState::handleEasyChanges(uint32_t flags, PhysicsEngine* engine)
// also known as "bid for ownership with SCRIPT priority"
// we're manipulating this object directly via script, so we artificially
// manipulate the logic to trigger an immediate bid for ownership
setSimulatorPriorityHint(SCRIPT_EDIT_SIMULATOR_PRIORITY);
setOutgoingPriority(SCRIPT_EDIT_SIMULATOR_PRIORITY);
}
if ((flags & EntityItem::DIRTY_PHYSICS_ACTIVATION) && !_body->isActive()) {
_body->activate();
@ -224,11 +201,7 @@ void EntityMotionState::setWorldTransform(const btTransform& worldTrans) {
if (_loopsWithoutOwner > LOOPS_FOR_SIMULATION_ORPHAN && usecTimestampNow() > _nextOwnershipBid) {
//qDebug() << "Warning -- claiming something I saw moving." << getName();
quint64 dt = (usecTimestampNow() - _activationTime) / 1000; // adebug
if (_entity && _entity->getName() == plankyBlock) {
std::cout << "adebug setWorldTransform() bid for orphan '" << _entity->getName().toStdString() << "' dt = " << dt << std::endl; // adebug
}
setSimulatorPriorityHint(VOLUNTEER_SIMULATOR_PRIORITY);
setOutgoingPriority(VOLUNTEER_SIMULATOR_PRIORITY);
}
}
@ -260,7 +233,7 @@ bool EntityMotionState::isCandidateForOwnership(const QUuid& sessionID) const {
return false;
}
assert(entityTreeIsLocked());
return _candidatePriority > 0 || sessionID == _entity->getSimulatorID();
return _outgoingPriority > 0 || sessionID == _entity->getSimulatorID();
}
bool EntityMotionState::remoteSimulationOutOfSync(uint32_t simulationStep) {
@ -377,13 +350,10 @@ bool EntityMotionState::shouldSendUpdate(uint32_t simulationStep, const QUuid& s
if (_entity->getSimulatorID() != sessionID) {
// we don't own the simulation, but maybe we should...
if (_candidatePriority > 0) {
if (_candidatePriority < _entity->getSimulatorPriority()) {
if (_outgoingPriority > 0) {
if (_outgoingPriority < _entity->getSimulatorPriority()) {
// our priority looses to remote, so we don't bother to bid
if (_entity && _entity->getName() == plankyBlock) {
std::cout << "adebug shouldSendUpdate() '" << _entity->getName().toStdString() << "' clear priority " << int(_candidatePriority) << " in favor of remote priority " << int(_entity->getSimulatorPriority()) << std::endl; // adebug
}
_candidatePriority = 0;
_outgoingPriority = 0;
return false;
}
return usecTimestampNow() > _nextOwnershipBid;
@ -478,28 +448,15 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, const Q
if (!active) {
// we own the simulation but the entity has stopped, so we tell the server that we're clearing simulatorID
// but we remember that we do still own it... and rely on the server to tell us that we don't
std::cout << "adebug releasing ownership of '" << _entity->getName().toStdString() << "' for inactivity" << std::endl; // adebug
properties.clearSimulationOwner();
if (_entity && _entity->getName() == plankyBlock) {
std::cout << "adebug sendUpdate() send clear ownership for '" << _entity->getName().toStdString() << "'" << std::endl; // adebug
}
_expectedOwnership = -1;
} else {
// re-assert the simulation info
properties.setSimulationOwner(sessionID, _entity->getSimulatorPriority());
_expectedOwnership = 0;
}
} else {
// we don't own the simulation for this entity yet, but we're sending a bid for it
quint64 dt = (usecTimestampNow() - _activationTime) / 1000; // adebug
uint8_t bidPriority = glm::max<uint8_t>(_candidatePriority, VOLUNTEER_SIMULATOR_PRIORITY); // adebug
if (_entity && _entity->getName() == plankyBlock) {
std::cout << "adebug sendUpdate() bid for ownership of '" << _entity->getName().toStdString() << "' dt = " << dt << " with priority " << int(bidPriority) << std::endl; // adebug
}
properties.setSimulationOwner(sessionID, glm::max<uint8_t>(_candidatePriority, VOLUNTEER_SIMULATOR_PRIORITY));
properties.setSimulationOwner(sessionID, glm::max<uint8_t>(_outgoingPriority, VOLUNTEER_SIMULATOR_PRIORITY));
_nextOwnershipBid = now + USECS_BETWEEN_OWNERSHIP_BIDS;
_expectedOwnership = 1;
//_candidatePriority = 0; // TODO: it would be nice to not have to clear this until we get a message back that ownership has changed
}
if (EntityItem::getSendPhysicsUpdates()) {
@ -559,7 +516,7 @@ void EntityMotionState::bump(uint8_t priority) {
if (_entity) {
//uint8_t inheritedPriority = priority < 2 ? 1 : priority - 1;
uint8_t inheritedPriority = VOLUNTEER_SIMULATOR_PRIORITY;
setSimulatorPriorityHint(inheritedPriority);
setOutgoingPriority(inheritedPriority);
}
}
@ -589,10 +546,6 @@ void EntityMotionState::measureBodyAcceleration() {
_measuredAcceleration = (velocity / powf(1.0f - _body->getLinearDamping(), dt) - _lastVelocity) * invDt;
_lastVelocity = velocity;
if (numSubsteps > PHYSICS_ENGINE_MAX_NUM_SUBSTEPS) {
if (_entity && _entity->getName() == plankyBlock) {
std::cout << "adebug measureBodyAcceleration() activate '" << _entity->getName().toStdString() << "'" << std::endl; // adebug
}
_activationTime = usecTimestampNow(); // adebug
_loopsWithoutOwner = 0;
_lastStep = ObjectMotionState::getWorldSimulationStep();
_sentInactive = false;
@ -635,12 +588,6 @@ int16_t EntityMotionState::computeCollisionGroup() {
return COLLISION_GROUP_DEFAULT;
}
void EntityMotionState::setSimulatorPriorityHint(uint8_t priority) {
uint8_t oldPriority = _candidatePriority;
_candidatePriority = glm::max<uint8_t>(_candidatePriority, priority);
if (_candidatePriority != oldPriority) {
if (_entity && _entity->getName() == plankyBlock) {
std::cout << "adebug setSimulatorPriorityHint() '" << _entity->getName().toStdString() << "' _candidatePrioity changed from " << int(oldPriority) << " to " << int(_candidatePriority) << std::endl; // adebug
}
}
void EntityMotionState::setOutgoingPriority(uint8_t priority) {
_outgoingPriority = glm::max<uint8_t>(_outgoingPriority, priority);
}

View file

@ -82,7 +82,7 @@ public:
virtual int16_t computeCollisionGroup();
// eternal logic can suggest a simuator priority bid for the next outgoing update
void setSimulatorPriorityHint(uint8_t priority);
void setOutgoingPriority(uint8_t priority);
friend class PhysicalEntitySimulation;
@ -116,9 +116,7 @@ protected:
quint8 _accelerationNearlyGravityCount;
quint64 _nextOwnershipBid = 0;
uint32_t _loopsWithoutOwner;
uint8_t _candidatePriority = 0;
quint64 _activationTime = 0; // adebug
int _expectedOwnership = 0; // adebug
uint8_t _outgoingPriority = 0;
};
#endif // hifi_EntityMotionState_h