fix to allow modelEntityItems with shape of box into physicsengine. ignore entity updates echoed back to us. stop broadcasting after 3 non-moving updates

This commit is contained in:
Seth Alves 2015-04-14 13:32:02 -07:00
parent b5bfbba759
commit 3cf31ff701
5 changed files with 32 additions and 32 deletions

View file

@ -289,6 +289,10 @@ const QString& RenderableModelEntityItem::getCollisionModelURL() const {
bool RenderableModelEntityItem::isReadyToComputeShape() {
if (_shapeType != SHAPE_TYPE_COMPOUND && _shapeType != SHAPE_TYPE_CONVEX_HULL) {
return true;
}
if (!_model) {
return false; // hmm...
}
@ -316,6 +320,11 @@ bool RenderableModelEntityItem::isReadyToComputeShape() {
}
void RenderableModelEntityItem::computeShapeInfo(ShapeInfo& info) {
if (_shapeType != SHAPE_TYPE_COMPOUND && _shapeType != SHAPE_TYPE_CONVEX_HULL) {
info.setParams(getShapeType(), 0.5f * getDimensions());
return;
}
if (_model->getCollisionURL().isEmpty() || _model->getURL().isEmpty()) {
info.setParams(getShapeType(), 0.5f * getDimensions());
} else {

View file

@ -69,25 +69,6 @@ bool EntityTree::handlesEditPacketType(PacketType packetType) const {
}
}
/// Give an EntityItemID and EntityItemProperties, this will either find the correct entity that already exists
/// in the tree or it will create a new entity of the type specified by the properties and return that item.
/// In the case that it creates a new item, the item will be properly added to the tree and all appropriate lookup hashes.
EntityItem* EntityTree::getOrCreateEntityItem(const EntityItemID& entityID, const EntityItemProperties& properties) {
EntityItem* result = NULL;
// we need to first see if we already have the entity in our tree by finding the containing element of the entity
EntityTreeElement* containingElement = getContainingElement(entityID);
if (containingElement) {
result = containingElement->getEntityWithEntityItemID(entityID);
}
// if the element does not exist, then create a new one of the specified type...
if (!result) {
result = addEntity(entityID, properties);
}
return result;
}
/// Adds a new entity item to the tree
void EntityTree::postAddEntity(EntityItem* entity) {
assert(entity);

View file

@ -82,7 +82,6 @@ public:
virtual void update();
// The newer API...
EntityItem* getOrCreateEntityItem(const EntityItemID& entityID, const EntityItemProperties& properties);
void postAddEntity(EntityItem* entityItem);
EntityItem* addEntity(const EntityItemID& entityID, const EntityItemProperties& properties);

View file

@ -731,12 +731,19 @@ int EntityTreeElement::readElementDataFromBuffer(const unsigned char* data, int
}
// If the item already exists in our tree, we want do the following...
// 0) if this node is the simulator for the entity, ignore the update packet
// 1) allow the existing item to read from the databuffer
// 2) check to see if after reading the item, the containing element is still correct, fix it if needed
//
// TODO: Do we need to also do this?
// 3) remember the old cube for the entity so we can mark it as dirty
if (entityItem) {
auto nodeList = DependencyManager::get<NodeList>();
QString myNodeID = nodeList->getSessionUUID().toString();
if (entityItem && entityItem->getSimulatorID() == myNodeID) {
// do nothing, this was echoed back to us
qDebug() << "IGNORING ECHOED ENTITY UPDATE";
// _myTree->entityChanged(entityItem);
} else if (entityItem) {
QString entityScriptBefore = entityItem->getScript();
bool bestFitBefore = bestFitEntityBounds(entityItem);
EntityTreeElement* currentContainingElement = _myTree->getContainingElement(entityItemID);
@ -750,7 +757,7 @@ int EntityTreeElement::readElementDataFromBuffer(const unsigned char* data, int
if (bestFitBefore != bestFitAfter) {
// This is the case where the entity existed, and is in some element in our tree...
if (!bestFitBefore && bestFitAfter) {
// This is the case where the entity existed, and is in some element in our tree...
// This is the case where the entity existed, and is in some element in our tree...
if (currentContainingElement != this) {
currentContainingElement->removeEntityItem(entityItem);
addEntityItem(entityItem);

View file

@ -216,20 +216,22 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, uint32_
properties.setRotation(_sentRotation);
}
const float MINIMUM_EXTRAPOLATION_SPEED_SQUARED = 1.0e-4f; // 1cm/sec
bool zeroSpeed = (glm::length2(_sentVelocity) < MINIMUM_EXTRAPOLATION_SPEED_SQUARED);
const float MINIMUM_EXTRAPOLATION_SPIN_SQUARED = 0.004f; // ~0.01 rotation/sec
bool zeroSpin = glm::length2(_sentAngularVelocity) < MINIMUM_EXTRAPOLATION_SPIN_SQUARED;
bool zeroSpeed = true;
bool zeroSpin = true;
if (_outgoingPacketFlags & EntityItem::DIRTY_VELOCITY) {
if (_body->isActive()) {
_sentVelocity = bulletToGLM(_body->getLinearVelocity());
_sentAngularVelocity = bulletToGLM(_body->getAngularVelocity());
// if the speeds are very small we zero them out
const float MINIMUM_EXTRAPOLATION_SPEED_SQUARED = 1.0e-4f; // 1cm/sec
zeroSpeed = (glm::length2(_sentVelocity) < MINIMUM_EXTRAPOLATION_SPEED_SQUARED);
if (zeroSpeed) {
_sentVelocity = glm::vec3(0.0f);
}
const float MINIMUM_EXTRAPOLATION_SPIN_SQUARED = 0.004f; // ~0.01 rotation/sec
zeroSpin = glm::length2(_sentAngularVelocity) < MINIMUM_EXTRAPOLATION_SPIN_SQUARED;
if (zeroSpin) {
_sentAngularVelocity = glm::vec3(0.0f);
}
@ -249,15 +251,12 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, uint32_
auto nodeList = DependencyManager::get<NodeList>();
QString myNodeID = nodeList->getSessionUUID().toString();
QString simulatorID = _entity->getSimulatorID();
qDebug() << "EntityMotionState::sendUpdate" << (zeroSpin && zeroSpin) << "me:" << myNodeID << "owner:" << simulatorID;
if (simulatorID.isEmpty() && !(zeroSpin && zeroSpin)) {
// The object is moving and nobody thinks they own the motion. set this Node as the simulator
qDebug() << "claiming simulator ownership";
_entity->setSimulatorID(myNodeID);
properties.setSimulatorID(myNodeID);
} else if (simulatorID == myNodeID && zeroSpin && zeroSpin) {
// we are the simulator and the object has stopped. give up "simulator" status
qDebug() << "releasing simulator ownership";
_entity->setSimulatorID("");
properties.setSimulatorID("");
}
@ -279,7 +278,8 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, uint32_
#ifdef WANT_DEBUG
quint64 now = usecTimestampNow();
qCDebug(physics) << "EntityMotionState::sendUpdate()";
qCDebug(physics) << " EntityItemId:" << _entity->getEntityItemID() << "---------------------------------------------";
qCDebug(physics) << " EntityItemId:" << _entity->getEntityItemID()
<< "---------------------------------------------";
qCDebug(physics) << " lastSimulated:" << debugTime(lastSimulated, now);
#endif //def WANT_DEBUG
@ -287,12 +287,16 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, uint32_
properties.setLastEdited(_entity->getLastEdited());
}
if (EntityItem::getSendPhysicsUpdates()) {
if (EntityItem::getSendPhysicsUpdates() && _numNonMovingUpdates < 4) {
EntityItemID id(_entity->getID());
EntityEditPacketSender* entityPacketSender = static_cast<EntityEditPacketSender*>(packetSender);
#ifdef WANT_DEBUG
qCDebug(physics) << "EntityMotionState::sendUpdate()... calling queueEditEntityMessage()...";
#endif
qDebug() << "EntityMotionState::sendUpdate" << (zeroSpin && zeroSpin)
<< _sentMoving
<< _numNonMovingUpdates
<< "me:" << myNodeID << "owner:" << simulatorID;
entityPacketSender->queueEditEntityMessage(PacketTypeEntityAddOrEdit, id, properties);
} else {
#ifdef WANT_DEBUG