PhysicalEntitySimulation sends outgoing packets

This commit is contained in:
Andrew Meadows 2015-04-28 17:12:29 -07:00
parent 2f9306ee77
commit c0a5753317
3 changed files with 32 additions and 11 deletions

View file

@ -27,7 +27,7 @@ void SimpleEntitySimulation::updateEntitiesInternal(const quint64& now) {
_movableButStoppedEntities.insert(entity);
} else {
entity->simulate(now);
_entitiesToBeSorted.insert(entity);
_entitiesToSort.insert(entity);
++itemItr;
}
}

View file

@ -46,16 +46,16 @@ void PhysicalEntitySimulation::updateEntitiesInternal(const quint64& now) {
// TODO: add back non-physical kinematic objects and step them forward here
}
/* {
void PhysicalEntitySimulation::sendOutgoingPackets() {
uint32_t numSubsteps = _physicsEngine->getNumSubsteps();
if (_lastNumSubstepsAtUpdateInternal != numSubsteps) {
_lastNumSubstepsAtUpdateInternal = numSubsteps;
SetOfMotionStates::iterator stateItr = _outgoingPackets.begin();
while (stateItr != _outgoingPackets.end()) {
ObjectMotionState* state = *stateItr;
SetOfMotionStates::iterator stateItr = _outgoingChanges.begin();
while (stateItr != _outgoingChanges.end()) {
EntityMotionState* state = static_cast<EntityMotionState*>(*stateItr);
if (state->doesNotNeedToSendUpdate()) {
stateItr = _outgoingPackets.erase(stateItr);
stateItr = _outgoingChanges.erase(stateItr);
} else if (state->shouldSendUpdate(numSubsteps)) {
state->sendUpdate(_entityPacketSender, numSubsteps);
++stateItr;
@ -64,7 +64,7 @@ void PhysicalEntitySimulation::updateEntitiesInternal(const quint64& now) {
}
}
}
} */
}
void PhysicalEntitySimulation::addEntityInternal(EntityItem* entity) {
assert(entity);
@ -114,15 +114,15 @@ void PhysicalEntitySimulation::entityChangedInternal(EntityItem* entity) {
}
void PhysicalEntitySimulation::sortEntitiesThatMovedInternal() {
// entities that have been simulated forward (hence in the _entitiesToBeSorted list)
// entities that have been simulated forward (hence in the _entitiesToSort list)
// also need to be put in the outgoingPackets list
QSet<EntityItem*>::iterator entityItr = _entitiesToBeSorted.begin();
for (auto entityItr : _entitiesToBeSorted) {
QSet<EntityItem*>::iterator entityItr = _entitiesToSort.begin();
for (auto entityItr : _entitiesToSort) {
EntityItem* entity = *entityItr;
void* physicsInfo = entity->getPhysicsInfo();
assert(physicsInfo);
// BOOKMARK XXX -- Andrew to fix this next
_outgoingPackets.insert(static_cast<ObjectMotionState*>(physicsInfo));
_outgoingChanges.insert(static_cast<ObjectMotionState*>(physicsInfo));
}
}
@ -203,6 +203,21 @@ VectorOfMotionStates& PhysicalEntitySimulation::getObjectsToChange() {
return _tempSet;
}
void PhysicalEntitySimulation::handleOutgoingChanges(SetOfMotionStates& motionStates) {
SetOfMotionStates::iterator stateItr = motionStates.begin();
while (stateItr != motionStates.end()) {
ObjectMotionState* state = *stateItr;
if (state->getType() == MOTION_STATE_TYPE_ENTITY) {
EntityMotionState* entityState = static_cast<EntityMotionState*>(state);
_outgoingChanges.insert(entityState);
stateItr = motionStates.erase(stateItr);
} else {
++stateItr;
}
}
sendOutgoingPackets();
}
void PhysicalEntitySimulation::bump(EntityItem* bumpEntity) {
}

View file

@ -47,13 +47,19 @@ public:
VectorOfMotionStates& getObjectsToAdd();
VectorOfMotionStates& getObjectsToChange();
void handleOutgoingChanges(SetOfMotionStates& motionStates);
private:
void bump(EntityItem* bumpEntity);
// incoming changes
SetOfEntities _pendingRemoves; // entities to be removed from simulation
SetOfEntities _pendingAdds; // entities to be be added to simulation
SetOfEntities _pendingChanges; // entities already in simulation that need to be changed
// outgoing changes
SetOfEntities _outgoingChanges; // entities for which we need to send updates to entity-server
SetOfMotionStates _physicalEntities; // MotionStates of entities in PhysicsEngine
VectorOfMotionStates _tempSet; // temporary list valid immediately after call to getObjectsToRemove/Add/Update()