EntityRenderer::EntityRenderer(const EntityItemPointer& entity) : _entity(entity) { connect(entity.get(), &EntityItem::requestRenderUpdate, this, [&] { _needsRenderUpdate = true; emit requestRenderUpdate(); }); _materials = entity->getMaterials(); }
EntityMotionState::EntityMotionState(btCollisionShape* shape, EntityItemPointer entity) : ObjectMotionState(nullptr), _entityPtr(entity), _entity(entity.get()), _serverPosition(0.0f), _serverRotation(), _serverVelocity(0.0f), _serverAngularVelocity(0.0f), _serverGravity(0.0f), _serverAcceleration(0.0f), _serverActionData(QByteArray()), _lastVelocity(0.0f), _measuredAcceleration(0.0f), _nextOwnershipBid(0), _measuredDeltaTime(0.0f), _lastMeasureStep(0), _lastStep(0), _loopsWithoutOwner(0), _accelerationNearlyGravityCount(0), _numInactiveUpdates(1), _outgoingPriority(0) { _type = MOTIONSTATE_TYPE_ENTITY; assert(_entity); assert(entityTreeIsLocked()); setMass(_entity->computeMass()); // we need the side-effects of EntityMotionState::setShape() so we call it explicitly here // rather than pass the legit shape pointer to the ObjectMotionState ctor above. setShape(shape); }
void PhysicalEntitySimulation::handleOutgoingChanges(const VectorOfMotionStates& motionStates, const QUuid& sessionID) { QMutexLocker lock(&_mutex); // walk the motionStates looking for those that correspond to entities for (auto stateItr : motionStates) { ObjectMotionState* state = &(*stateItr); if (state && state->getType() == MOTIONSTATE_TYPE_ENTITY) { EntityMotionState* entityState = static_cast<EntityMotionState*>(state); EntityItemPointer entity = entityState->getEntity(); assert(entity.get()); if (entityState->isCandidateForOwnership(sessionID)) { _outgoingChanges.insert(entityState); } _entitiesToSort.insert(entity); } } uint32_t numSubsteps = _physicsEngine->getNumSubsteps(); if (_lastStepSendPackets != numSubsteps) { _lastStepSendPackets = numSubsteps; if (sessionID.isNull()) { // usually don't get here, but if so --> nothing to do _outgoingChanges.clear(); return; } // look for entities to prune or update QSet<EntityMotionState*>::iterator stateItr = _outgoingChanges.begin(); while (stateItr != _outgoingChanges.end()) { EntityMotionState* state = *stateItr; if (!state->isCandidateForOwnership(sessionID)) { // prune stateItr = _outgoingChanges.erase(stateItr); } else if (state->shouldSendUpdate(numSubsteps, sessionID)) { // update state->sendUpdate(_entityPacketSender, sessionID, numSubsteps); ++stateItr; } else { ++stateItr; } } } }