debugging stutter

This commit is contained in:
ZappoMan 2015-01-22 13:13:18 -08:00
parent d8d0972cb6
commit 14c7dc8eb9
7 changed files with 82 additions and 2 deletions

View file

@ -27,7 +27,13 @@ void EntityEditPacketSender::adjustEditPacketForClockSkew(PacketType type,
void EntityEditPacketSender::queueEditEntityMessage(PacketType type, EntityItemID modelID,
const EntityItemProperties& properties) {
qDebug() << "EntityEditPacketSender::queueEditEntityMessage()...";
qDebug() << " ID:" << modelID;
qDebug() << " properties:" << properties;
if (!_shouldSend) {
qDebug() << " BAIL EARLY! _shouldSend:" << _shouldSend;
return; // bail early
}
@ -36,6 +42,7 @@ void EntityEditPacketSender::queueEditEntityMessage(PacketType type, EntityItemI
int sizeOut = 0;
if (EntityItemProperties::encodeEntityEditPacket(type, modelID, properties, &bufferOut[0], _maxPacketSize, sizeOut)) {
qDebug() << " queueOctreeEditMessage() sizeOut:" << sizeOut;
queueOctreeEditMessage(type, bufferOut, sizeOut);
}
}

View file

@ -1064,6 +1064,9 @@ const float MIN_SPIN_DELTA = 0.0003f;
void EntityItem::updatePosition(const glm::vec3& value) {
if (glm::distance(_position, value) * (float)TREE_SCALE > MIN_POSITION_DELTA) {
qDebug() << "EntityItem::updatePosition()... ";
qDebug() << " new position:" << value;
qDebug() << " in meters:" << (value * (float) TREE_SCALE);
_position = value;
recalculateCollisionShape();
_dirtyFlags |= EntityItem::DIRTY_POSITION;
@ -1073,6 +1076,9 @@ void EntityItem::updatePosition(const glm::vec3& value) {
void EntityItem::updatePositionInMeters(const glm::vec3& value) {
glm::vec3 position = glm::clamp(value / (float) TREE_SCALE, 0.0f, 1.0f);
if (glm::distance(_position, position) * (float)TREE_SCALE > MIN_POSITION_DELTA) {
qDebug() << "EntityItem::updatePositionInMeters()... ";
qDebug() << " new position:" << position;
qDebug() << " in meters:" << value;
_position = position;
recalculateCollisionShape();
_dirtyFlags |= EntityItem::DIRTY_POSITION;

View file

@ -305,6 +305,7 @@ void EntityTree::processRemovedEntities(const DeleteEntityOperator& theOperator)
/// we're not changing the content of the tree, we're only changing the internal IDs that map entities from creator
/// based to known IDs. This means we don't have to recurse the tree to mark the changed path as dirty.
void EntityTree::handleAddEntityResponse(const QByteArray& packet) {
qDebug() << "EntityTree::handleAddEntityResponse()";
if (!getIsClient()) {
qDebug() << "UNEXPECTED!!! EntityTree::handleAddEntityResponse() with !getIsClient() ***";
@ -329,6 +330,9 @@ void EntityTree::handleAddEntityResponse(const QByteArray& packet) {
searchEntityID.id = entityID;
searchEntityID.creatorTokenID = creatorTokenID;
qDebug() << " creatorTokenID:" << creatorTokenID;
qDebug() << " entityID:" << entityID;
lockForWrite();
// find the creator token version, it's containing element, and the entity itself

View file

@ -795,11 +795,13 @@ int EntityTreeElement::readElementDataFromBuffer(const unsigned char* data, int
}
} else {
qDebug() << "EntityTreeElement::readElementDataFromBuffer() about to construct entity item";
entityItem = EntityTypes::constructEntityItem(dataAt, bytesLeftToRead, args);
if (entityItem) {
bytesForThisEntity = entityItem->readEntityDataFromBuffer(dataAt, bytesLeftToRead, args);
addEntityItem(entityItem); // add this new entity to this elements entities
entityItemID = entityItem->getEntityItemID();
qDebug() << " entityItemID:" << entityItemID;
_myTree->setContainingElement(entityItemID, this);
_myTree->postAddEntity(entityItem);
}

View file

@ -159,15 +159,23 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, uint32_
return; // never update entities that are unknown
}
if (_outgoingPacketFlags) {
qDebug() << "EntityMotionState::sendUpdate()...";
qDebug() << " _outgoingPacketFlags:" << _outgoingPacketFlags;
EntityItemProperties properties = _entity->getProperties();
qDebug() << " _entity->getProperties():" << properties << "line:" << __LINE__;
if (_outgoingPacketFlags & EntityItem::DIRTY_POSITION) {
btTransform worldTrans = _body->getWorldTransform();
_sentPosition = bulletToGLM(worldTrans.getOrigin());
properties.setPosition(_sentPosition + ObjectMotionState::getWorldOffset());
qDebug() << " _sentPosition:" << _sentPosition << "line:" << __LINE__;
qDebug() << " ObjectMotionState::getWorldOffset():" << ObjectMotionState::getWorldOffset() << "line:" << __LINE__;
_sentRotation = bulletToGLM(worldTrans.getRotation());
properties.setRotation(_sentRotation);
qDebug() << " after position properties:" << properties << "line:" << __LINE__;
}
if (_outgoingPacketFlags & EntityItem::DIRTY_VELOCITY) {
@ -197,6 +205,8 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, uint32_
properties.setGravity(_sentAcceleration);
// DANGER! EntityItem stores angularVelocity in degrees/sec!!!
properties.setAngularVelocity(glm::degrees(_sentAngularVelocity));
qDebug() << " after velocity properties:" << properties << "line:" << __LINE__;
}
// RELIABLE_SEND_HACK: count number of updates for entities at rest so we can stop sending them after some limit.
@ -217,6 +227,9 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, uint32_
EntityItemID id(_entity->getID());
EntityEditPacketSender* entityPacketSender = static_cast<EntityEditPacketSender*>(packetSender);
qDebug() << "EntityMotionState::sendUpdate()... about to call queueEditEntityMessage()";
qDebug() << " id:" << id;
qDebug() << " properties:" << properties;
entityPacketSender->queueEditEntityMessage(PacketTypeEntityAddOrEdit, id, properties);
// The outgoing flags only itemized WHAT to send, not WHETHER to send, hence we always set them

View file

@ -108,6 +108,18 @@ bool ObjectMotionState::doesNotNeedToSendUpdate() const {
bool ObjectMotionState::shouldSendUpdate(uint32_t simulationFrame) {
assert(_body);
// if we've never checked before, our _sentFrame will be 0, and we need to initialize our state
if (_sentFrame == 0) {
_sentPosition = bulletToGLM(_body->getWorldTransform().getOrigin());
_sentVelocity = bulletToGLM(_body->getLinearVelocity());
_sentAngularVelocity = bulletToGLM(_body->getAngularVelocity());
_sentFrame = simulationFrame;
return false;
}
uint32_t wasSentFrame = _sentFrame;
float dt = (float)(simulationFrame - _sentFrame) * PHYSICS_ENGINE_FIXED_SUBSTEP;
_sentFrame = simulationFrame;
bool isActive = _body->isActive();
@ -131,6 +143,10 @@ bool ObjectMotionState::shouldSendUpdate(uint32_t simulationFrame) {
// NOTE: math in done the simulation-frame, which is NOT necessarily the same as the world-frame
// due to _worldOffset.
glm::vec3 wasPosition = _sentPosition;
glm::vec3 wasVelocity = _sentVelocity;
glm::vec3 wasAcceleration = _sentAcceleration;
// compute position error
if (glm::length2(_sentVelocity) > 0.0f) {
@ -141,11 +157,40 @@ bool ObjectMotionState::shouldSendUpdate(uint32_t simulationFrame) {
btTransform worldTrans = _body->getWorldTransform();
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) {
return true;
qDebug() << "ObjectMotionState::shouldSendUpdate()... computing position error";
glm::vec3 bulletVelocity = bulletToGLM(_body->getLinearVelocity());
qDebug() << " was _sentFrame:" << wasSentFrame;
qDebug() << " now _sentFrame:" << _sentFrame;
qDebug() << " dt:" << dt;
qDebug() << " was _sentAcceleration:" << wasAcceleration;
qDebug() << " now _sentAcceleration:" << _sentAcceleration;
qDebug() << " bulletVelocity:" << bulletVelocity;
qDebug() << " was _sentVelocity:" << wasVelocity;
qDebug() << " now _sentVelocity:" << _sentVelocity;
qDebug() << " was _sentPosition:" << wasPosition;
qDebug() << " now _sentPosition:" << _sentPosition;
qDebug() << " bullet position:" << position;
qDebug() << " dx2:" << dx2;
qDebug() << " (dx2 > MAX_POSITION_ERROR_SQUARED)... considering";
if (wasSentFrame > 0) {
qDebug() << " (wasSentFrame > 0)... return TRUE";
return true;
} else {
qDebug() << " (wasSentFrame == 0)... ignore use bullet position for next _sentPosition";
_sentPosition = position;
}
} else {
//qDebug() << " (dx2 <= MAX_POSITION_ERROR_SQUARED)... FALL THROUGH... likely return false";
}
if (glm::length2(_sentAngularVelocity) > 0.0f) {

View file

@ -35,6 +35,9 @@ void PhysicsEngine::updateEntitiesInternal(const quint64& now) {
// (3) synchronize outgoing motion states
// (4) send outgoing packets
//qDebug() << "_numSubsteps:" << _numSubsteps;
// this is step (4)
QSet<ObjectMotionState*>::iterator stateItr = _outgoingPackets.begin();
while (stateItr != _outgoingPackets.end()) {