mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 08:37:19 +02:00
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:
parent
b5bfbba759
commit
3cf31ff701
5 changed files with 32 additions and 32 deletions
|
@ -289,6 +289,10 @@ const QString& RenderableModelEntityItem::getCollisionModelURL() const {
|
||||||
|
|
||||||
bool RenderableModelEntityItem::isReadyToComputeShape() {
|
bool RenderableModelEntityItem::isReadyToComputeShape() {
|
||||||
|
|
||||||
|
if (_shapeType != SHAPE_TYPE_COMPOUND && _shapeType != SHAPE_TYPE_CONVEX_HULL) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (!_model) {
|
if (!_model) {
|
||||||
return false; // hmm...
|
return false; // hmm...
|
||||||
}
|
}
|
||||||
|
@ -316,6 +320,11 @@ bool RenderableModelEntityItem::isReadyToComputeShape() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderableModelEntityItem::computeShapeInfo(ShapeInfo& info) {
|
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()) {
|
if (_model->getCollisionURL().isEmpty() || _model->getURL().isEmpty()) {
|
||||||
info.setParams(getShapeType(), 0.5f * getDimensions());
|
info.setParams(getShapeType(), 0.5f * getDimensions());
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -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
|
/// Adds a new entity item to the tree
|
||||||
void EntityTree::postAddEntity(EntityItem* entity) {
|
void EntityTree::postAddEntity(EntityItem* entity) {
|
||||||
assert(entity);
|
assert(entity);
|
||||||
|
|
|
@ -82,7 +82,6 @@ public:
|
||||||
virtual void update();
|
virtual void update();
|
||||||
|
|
||||||
// The newer API...
|
// The newer API...
|
||||||
EntityItem* getOrCreateEntityItem(const EntityItemID& entityID, const EntityItemProperties& properties);
|
|
||||||
void postAddEntity(EntityItem* entityItem);
|
void postAddEntity(EntityItem* entityItem);
|
||||||
|
|
||||||
EntityItem* addEntity(const EntityItemID& entityID, const EntityItemProperties& properties);
|
EntityItem* addEntity(const EntityItemID& entityID, const EntityItemProperties& properties);
|
||||||
|
|
|
@ -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...
|
// 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
|
// 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
|
// 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?
|
// TODO: Do we need to also do this?
|
||||||
// 3) remember the old cube for the entity so we can mark it as dirty
|
// 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();
|
QString entityScriptBefore = entityItem->getScript();
|
||||||
bool bestFitBefore = bestFitEntityBounds(entityItem);
|
bool bestFitBefore = bestFitEntityBounds(entityItem);
|
||||||
EntityTreeElement* currentContainingElement = _myTree->getContainingElement(entityItemID);
|
EntityTreeElement* currentContainingElement = _myTree->getContainingElement(entityItemID);
|
||||||
|
@ -750,7 +757,7 @@ int EntityTreeElement::readElementDataFromBuffer(const unsigned char* data, int
|
||||||
if (bestFitBefore != bestFitAfter) {
|
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 (!bestFitBefore && bestFitAfter) {
|
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) {
|
if (currentContainingElement != this) {
|
||||||
currentContainingElement->removeEntityItem(entityItem);
|
currentContainingElement->removeEntityItem(entityItem);
|
||||||
addEntityItem(entityItem);
|
addEntityItem(entityItem);
|
||||||
|
|
|
@ -216,20 +216,22 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, uint32_
|
||||||
properties.setRotation(_sentRotation);
|
properties.setRotation(_sentRotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
const float MINIMUM_EXTRAPOLATION_SPEED_SQUARED = 1.0e-4f; // 1cm/sec
|
bool zeroSpeed = true;
|
||||||
bool zeroSpeed = (glm::length2(_sentVelocity) < MINIMUM_EXTRAPOLATION_SPEED_SQUARED);
|
bool zeroSpin = true;
|
||||||
const float MINIMUM_EXTRAPOLATION_SPIN_SQUARED = 0.004f; // ~0.01 rotation/sec
|
|
||||||
bool zeroSpin = glm::length2(_sentAngularVelocity) < MINIMUM_EXTRAPOLATION_SPIN_SQUARED;
|
|
||||||
|
|
||||||
if (_outgoingPacketFlags & EntityItem::DIRTY_VELOCITY) {
|
if (_outgoingPacketFlags & EntityItem::DIRTY_VELOCITY) {
|
||||||
if (_body->isActive()) {
|
if (_body->isActive()) {
|
||||||
_sentVelocity = bulletToGLM(_body->getLinearVelocity());
|
_sentVelocity = bulletToGLM(_body->getLinearVelocity());
|
||||||
_sentAngularVelocity = bulletToGLM(_body->getAngularVelocity());
|
_sentAngularVelocity = bulletToGLM(_body->getAngularVelocity());
|
||||||
|
|
||||||
// if the speeds are very small we zero them out
|
// 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) {
|
if (zeroSpeed) {
|
||||||
_sentVelocity = glm::vec3(0.0f);
|
_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) {
|
if (zeroSpin) {
|
||||||
_sentAngularVelocity = glm::vec3(0.0f);
|
_sentAngularVelocity = glm::vec3(0.0f);
|
||||||
}
|
}
|
||||||
|
@ -249,15 +251,12 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, uint32_
|
||||||
auto nodeList = DependencyManager::get<NodeList>();
|
auto nodeList = DependencyManager::get<NodeList>();
|
||||||
QString myNodeID = nodeList->getSessionUUID().toString();
|
QString myNodeID = nodeList->getSessionUUID().toString();
|
||||||
QString simulatorID = _entity->getSimulatorID();
|
QString simulatorID = _entity->getSimulatorID();
|
||||||
qDebug() << "EntityMotionState::sendUpdate" << (zeroSpin && zeroSpin) << "me:" << myNodeID << "owner:" << simulatorID;
|
|
||||||
if (simulatorID.isEmpty() && !(zeroSpin && zeroSpin)) {
|
if (simulatorID.isEmpty() && !(zeroSpin && zeroSpin)) {
|
||||||
// The object is moving and nobody thinks they own the motion. set this Node as the simulator
|
// The object is moving and nobody thinks they own the motion. set this Node as the simulator
|
||||||
qDebug() << "claiming simulator ownership";
|
|
||||||
_entity->setSimulatorID(myNodeID);
|
_entity->setSimulatorID(myNodeID);
|
||||||
properties.setSimulatorID(myNodeID);
|
properties.setSimulatorID(myNodeID);
|
||||||
} else if (simulatorID == myNodeID && zeroSpin && zeroSpin) {
|
} else if (simulatorID == myNodeID && zeroSpin && zeroSpin) {
|
||||||
// we are the simulator and the object has stopped. give up "simulator" status
|
// we are the simulator and the object has stopped. give up "simulator" status
|
||||||
qDebug() << "releasing simulator ownership";
|
|
||||||
_entity->setSimulatorID("");
|
_entity->setSimulatorID("");
|
||||||
properties.setSimulatorID("");
|
properties.setSimulatorID("");
|
||||||
}
|
}
|
||||||
|
@ -279,7 +278,8 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, uint32_
|
||||||
#ifdef WANT_DEBUG
|
#ifdef WANT_DEBUG
|
||||||
quint64 now = usecTimestampNow();
|
quint64 now = usecTimestampNow();
|
||||||
qCDebug(physics) << "EntityMotionState::sendUpdate()";
|
qCDebug(physics) << "EntityMotionState::sendUpdate()";
|
||||||
qCDebug(physics) << " EntityItemId:" << _entity->getEntityItemID() << "---------------------------------------------";
|
qCDebug(physics) << " EntityItemId:" << _entity->getEntityItemID()
|
||||||
|
<< "---------------------------------------------";
|
||||||
qCDebug(physics) << " lastSimulated:" << debugTime(lastSimulated, now);
|
qCDebug(physics) << " lastSimulated:" << debugTime(lastSimulated, now);
|
||||||
#endif //def WANT_DEBUG
|
#endif //def WANT_DEBUG
|
||||||
|
|
||||||
|
@ -287,12 +287,16 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, uint32_
|
||||||
properties.setLastEdited(_entity->getLastEdited());
|
properties.setLastEdited(_entity->getLastEdited());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (EntityItem::getSendPhysicsUpdates()) {
|
if (EntityItem::getSendPhysicsUpdates() && _numNonMovingUpdates < 4) {
|
||||||
EntityItemID id(_entity->getID());
|
EntityItemID id(_entity->getID());
|
||||||
EntityEditPacketSender* entityPacketSender = static_cast<EntityEditPacketSender*>(packetSender);
|
EntityEditPacketSender* entityPacketSender = static_cast<EntityEditPacketSender*>(packetSender);
|
||||||
#ifdef WANT_DEBUG
|
#ifdef WANT_DEBUG
|
||||||
qCDebug(physics) << "EntityMotionState::sendUpdate()... calling queueEditEntityMessage()...";
|
qCDebug(physics) << "EntityMotionState::sendUpdate()... calling queueEditEntityMessage()...";
|
||||||
#endif
|
#endif
|
||||||
|
qDebug() << "EntityMotionState::sendUpdate" << (zeroSpin && zeroSpin)
|
||||||
|
<< _sentMoving
|
||||||
|
<< _numNonMovingUpdates
|
||||||
|
<< "me:" << myNodeID << "owner:" << simulatorID;
|
||||||
entityPacketSender->queueEditEntityMessage(PacketTypeEntityAddOrEdit, id, properties);
|
entityPacketSender->queueEditEntityMessage(PacketTypeEntityAddOrEdit, id, properties);
|
||||||
} else {
|
} else {
|
||||||
#ifdef WANT_DEBUG
|
#ifdef WANT_DEBUG
|
||||||
|
|
Loading…
Reference in a new issue