Fix sequence number encoding issue

Don't mix QDataStream and readPrimitive. Also fix logic
issues in completion check; move new packet type; don't
reset known sent entities upon initial completion;
other reviewer recommendations.
This commit is contained in:
Simon Walton 2018-07-31 13:54:22 -07:00
parent 8c512ec19b
commit a320308eaf
6 changed files with 13 additions and 13 deletions

View file

@ -160,12 +160,11 @@ bool EntityTreeSendThread::traverseTreeAndSendContents(SharedNodePointer node, O
if (sendComplete && nodeData->wantReportInitialCompletion() && _traversal.finished()) { if (sendComplete && nodeData->wantReportInitialCompletion() && _traversal.finished()) {
// Dealt with all nearby entities. // Dealt with all nearby entities.
nodeData->setReportInitialCompletion(false); nodeData->setReportInitialCompletion(false);
resetState();
// Send EntityQueryInitialResultsComplete reliable packet ... // Send EntityQueryInitialResultsComplete reliable packet ...
auto initialCompletion = NLPacket::create(PacketType::EntityQueryInitialResultsComplete, -1, true); auto initialCompletion = NLPacket::create(PacketType::EntityQueryInitialResultsComplete,
QDataStream initialCompletionStream(initialCompletion.get()); sizeof(OCTREE_PACKET_SEQUENCE), true);
initialCompletionStream << OCTREE_PACKET_SEQUENCE(nodeData->getSequenceNumber() - 1U); initialCompletion->writePrimitive(OCTREE_PACKET_SEQUENCE(nodeData->getSequenceNumber() - 1U));
DependencyManager::get<NodeList>()->sendPacket(std::move(initialCompletion), *node.data()); DependencyManager::get<NodeList>()->sendPacket(std::move(initialCompletion), *node.data());
} }

View file

@ -5483,6 +5483,7 @@ void Application::update(float deltaTime) {
// we've received a new full-scene octree stats packet, or it's been long enough to try again anyway // we've received a new full-scene octree stats packet, or it's been long enough to try again anyway
_lastPhysicsCheckTime = now; _lastPhysicsCheckTime = now;
_fullSceneCounterAtLastPhysicsCheck = _fullSceneReceivedCounter; _fullSceneCounterAtLastPhysicsCheck = _fullSceneReceivedCounter;
_lastQueriedViews.clear(); // Force new view.
// process octree stats packets are sent in between full sends of a scene (this isn't currently true). // process octree stats packets are sent in between full sends of a scene (this isn't currently true).
// We keep physics disabled until we've received a full scene and everything near the avatar in that // We keep physics disabled until we've received a full scene and everything near the avatar in that

View file

@ -135,7 +135,7 @@ void OctreePacketProcessor::resetCompletionSequenceNumber() {
namespace { namespace {
template<typename T> bool lessThanWraparound(int a, int b) { template<typename T> bool lessThanWraparound(int a, int b) {
constexpr int MAX_T_VALUE = std::numeric_limits<T>::max(); constexpr int MAX_T_VALUE = std::numeric_limits<T>::max();
if (b < a) { if (b <= a) {
b += MAX_T_VALUE; b += MAX_T_VALUE;
} }
return (b - a) < (MAX_T_VALUE / 2); return (b - a) < (MAX_T_VALUE / 2);
@ -146,5 +146,5 @@ bool OctreePacketProcessor::octreeSequenceIsComplete(int sequenceNumber) const {
Locker lock(_completionMutex); Locker lock(_completionMutex);
// If we've received the flagged seq # and the current one is >= it. // If we've received the flagged seq # and the current one is >= it.
return _completionSequenceNumberValid && return _completionSequenceNumberValid &&
!lessThanWraparound<OCTREE_PACKET_SEQUENCE>(_completionSequenceNumber, sequenceNumber); !lessThanWraparound<OCTREE_PACKET_SEQUENCE>(sequenceNumber, _completionSequenceNumber);
} }

View file

@ -95,7 +95,7 @@ PacketVersion versionForPacketType(PacketType packetType) {
case PacketType::AvatarIdentityRequest: case PacketType::AvatarIdentityRequest:
return 22; return 22;
default: default:
return 22; return 21;
} }
} }

View file

@ -126,13 +126,13 @@ public:
EntityScriptCallMethod, EntityScriptCallMethod,
ChallengeOwnershipRequest, ChallengeOwnershipRequest,
ChallengeOwnershipReply, ChallengeOwnershipReply,
EntityQueryInitialResultsComplete,
OctreeDataFileRequest, OctreeDataFileRequest,
OctreeDataFileReply, OctreeDataFileReply,
OctreeDataPersist, OctreeDataPersist,
EntityClone, EntityClone,
EntityQueryInitialResultsComplete,
NUM_PACKET_TYPE NUM_PACKET_TYPE
}; };

View file

@ -156,11 +156,11 @@ local packet_types = {
[92] = "EntityScriptCallMethod", [92] = "EntityScriptCallMethod",
[93] = "ChallengeOwnershipRequest", [93] = "ChallengeOwnershipRequest",
[94] = "ChallengeOwnershipReply", [94] = "ChallengeOwnershipReply",
[95] = "EntityQueryInitialResultsComplete", [95] = "OctreeDataFileRequest",
[96] = "OctreeDataFileRequest", [96] = "OctreeDataFileReply",
[97] = "OctreeDataFileReply", [97] = "OctreeDataPersist",
[98] = "OctreeDataPersist", [98] = "EntityClone",
[99] = "EntityClone" [99] = "EntityQueryInitialResultsComplete"
} }
local unsourced_packet_types = { local unsourced_packet_types = {