Showing the changes to libraries/physics/src/EntityMotionState.cpp (1 of 2 files). Show all
Unified · Split
| @@ -179,12 +179,41 @@ float EntityMotionState::computeMass(const ShapeInfo& shapeInfo) const { · 178 unmodified lines | ||
| 179 | 179 | return _entity->computeMass(); |
| 180 | 180 | } |
| 181 | 181 | |
| 182 | −void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, uint32_t frame) { | |
| 183 | 182 | |
| 184 | − qDebug() << "-------------------------------------------"; | |
| 185 | − qDebug() << "EntityMotionState::sendUpdate" << _type << _motionType << _isKinematic; | |
| 183 | +bool EntityMotionState::shouldSendUpdate(uint32_t simulationFrame) { | |
| 184 | + bool baseResult = this->ObjectMotionState::shouldSendUpdate(simulationFrame); | |
| 185 | + | |
| 186 | + if (!baseResult) { | |
| 187 | + return false; | |
| 188 | + } | |
| 189 | + | |
| 186 | 190 | auto nodeList = DependencyManager::get<NodeList>(); |
| 191 | + QString myNodeID = nodeList->getSessionUUID().toString(); | |
| 192 | + QString simulatorID = _entity->getSimulatorID(); | |
| 193 | + | |
| 194 | + if (simulatorID.isEmpty() && _body->isActive()) { | |
| 195 | + // The object is moving and nobody thinks they own the motion. set this Node as the simulator | |
| 196 | + _entity->setSimulatorID(myNodeID); | |
| 197 | + simulatorID = myNodeID; | |
| 198 | + } else if (simulatorID == myNodeID && !_body->isActive()) { | |
| 199 | + // we are the simulator and the object has stopped. give up "simulator" status | |
| 200 | + _entity->setSimulatorID(""); | |
| 201 | + simulatorID = ""; | |
| 202 | + } | |
| 203 | + | |
| 204 | + if (simulatorID != myNodeID) { | |
| 205 | + // some other Node is simulating this, so don't broadcast our computations. | |
| 206 | + qDebug() << "EntityMotionState::shouldSendUpdate baseResult=" << baseResult << "but" | |
| 207 | + << simulatorID << "!=" << myNodeID; | |
| 208 | + return false; | |
| 209 | + } | |
| 187 | 210 | |
| 211 | + qDebug() << "EntityMotionState::shouldSendUpdate baseResult=" << baseResult; | |
| 212 | + return baseResult; | |
| 213 | +} | |
| 214 | + | |
| 215 | + | |
| 216 | +void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, uint32_t frame) { | |
| 188 | 217 | if (!_entity->isKnownID()) { |
| 189 | 218 | return; // never update entities that are unknown |
| 190 | 219 | } |
| @@ -218,6 +247,12 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, uint32_ · 27 unmodified lines | ||
| 218 | 247 | } |
| 219 | 248 | |
| 220 | 249 | _sentMoving = ! (zeroSpeed && zeroSpin); |
| 250 | + | |
| 251 | + | |
| 252 | + qDebug() << "-------------------------------------------"; | |
| 253 | + qDebug() << "EntityMotionState::sendUpdate" << _sentMoving << _body->isActive(); | |
| 254 | + | |
| 255 | + | |
| 221 | 256 | } else { |
| 222 | 257 | _sentVelocity = _sentAngularVelocity = glm::vec3(0.0f); |
| 223 | 258 | _sentMoving = false; |