History

if an entity is being moved and has no sim-id, set sim-id to local node-id. if it has a sim-id, and it's not the same as the local node's, don't broadcast the change

Seth Alves committed 11 years ago

Commit eace91e1 parent e2af93d2 files · +39 −3Browse files

Showing the changes to libraries/physics/src/EntityMotionState.cpp (1 of 2 files). Show all

Unified · Split

libraries/physics/src/EntityMotionState.cpp+38−3
@@ -179,12 +179,41 @@ float EntityMotionState::computeMass(const ShapeInfo& shapeInfo) const { · 178 unmodified lines
179179 return _entity->computeMass();
180180 }
181181
182−void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, uint32_t frame) {
183182
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+
186190 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+ }
187210
211+ qDebug() << "EntityMotionState::shouldSendUpdate baseResult=" << baseResult;
212+ return baseResult;
213+}
214+
215+
216+void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, uint32_t frame) {
188217 if (!_entity->isKnownID()) {
189218 return; // never update entities that are unknown
190219 }
@@ -218,6 +247,12 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, uint32_ · 27 unmodified lines
218247 }
219248
220249 _sentMoving = ! (zeroSpeed && zeroSpin);
250+
251+
252+ qDebug() << "-------------------------------------------";
253+ qDebug() << "EntityMotionState::sendUpdate" << _sentMoving << _body->isActive();
254+
255+
221256 } else {
222257 _sentVelocity = _sentAngularVelocity = glm::vec3(0.0f);
223258 _sentMoving = false;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t