split entity-add and entity-edit messages

This commit is contained in:
Seth Alves 2015-05-20 14:52:03 -07:00
parent 124ff68cee
commit 4a59dc24c5
6 changed files with 26 additions and 19 deletions

View file

@ -21,7 +21,7 @@
void EntityEditPacketSender::adjustEditPacketForClockSkew(PacketType type, void EntityEditPacketSender::adjustEditPacketForClockSkew(PacketType type,
unsigned char* editBuffer, size_t length, int clockSkew) { unsigned char* editBuffer, size_t length, int clockSkew) {
if (type == PacketTypeEntityAddOrEdit) { if (type == PacketTypeEntityAdd || type == PacketTypeEntityEdit) {
EntityItem::adjustEditPacketForClockSkew(editBuffer, length, clockSkew); EntityItem::adjustEditPacketForClockSkew(editBuffer, length, clockSkew);
} }
} }

View file

@ -92,7 +92,7 @@ QUuid EntityScriptingInterface::addEntity(const EntityItemProperties& properties
// queue the packet // queue the packet
if (success) { if (success) {
queueEntityMessage(PacketTypeEntityAddOrEdit, id, propertiesWithSimID); queueEntityMessage(PacketTypeEntityAdd, id, propertiesWithSimID);
} }
return id; return id;
@ -144,12 +144,12 @@ QUuid EntityScriptingInterface::editEntity(QUuid id, const EntityItemProperties&
entity->setLastBroadcast(usecTimestampNow()); entity->setLastBroadcast(usecTimestampNow());
modifiedProperties.setType(entity->getType()); modifiedProperties.setType(entity->getType());
bidForSimulationOwnership(modifiedProperties); bidForSimulationOwnership(modifiedProperties);
queueEntityMessage(PacketTypeEntityAddOrEdit, entityID, modifiedProperties); queueEntityMessage(PacketTypeEntityEdit, entityID, modifiedProperties);
return id; return id;
} }
} }
queueEntityMessage(PacketTypeEntityAddOrEdit, entityID, properties); queueEntityMessage(PacketTypeEntityEdit, entityID, properties);
return id; return id;
} }

View file

@ -65,7 +65,8 @@ void EntityTree::eraseAllOctreeElements(bool createNewRoot) {
bool EntityTree::handlesEditPacketType(PacketType packetType) const { bool EntityTree::handlesEditPacketType(PacketType packetType) const {
// we handle these types of "edit" packets // we handle these types of "edit" packets
switch (packetType) { switch (packetType) {
case PacketTypeEntityAddOrEdit: case PacketTypeEntityAdd:
case PacketTypeEntityEdit:
case PacketTypeEntityErase: case PacketTypeEntityErase:
return true; return true;
default: default:
@ -559,20 +560,19 @@ int EntityTree::processEditPacketData(PacketType packetType, const unsigned char
break; break;
} }
case PacketTypeEntityAddOrEdit: { case PacketTypeEntityAdd:
case PacketTypeEntityEdit: {
EntityItemID entityItemID; EntityItemID entityItemID;
EntityItemProperties properties; EntityItemProperties properties;
bool validEditPacket = EntityItemProperties::decodeEntityEditPacket(editData, maxLength, bool validEditPacket = EntityItemProperties::decodeEntityEditPacket(editData, maxLength,
processedBytes, entityItemID, properties); processedBytes, entityItemID, properties);
// If we got a valid edit packet, then it could be a new entity or it could be an update to // If we got a valid edit packet, then it could be a new entity or it could be an update to
// an existing entity... handle appropriately // an existing entity... handle appropriately
if (validEditPacket) { if (validEditPacket) {
// search for the entity by EntityItemID // search for the entity by EntityItemID
EntityItem* existingEntity = findEntityByEntityItemID(entityItemID); EntityItem* existingEntity = findEntityByEntityItemID(entityItemID);
if (existingEntity && packetType == PacketTypeEntityEdit) {
// If this is a knownID, then it should exist in our tree
if (existingEntity) {
// if the EntityItem exists, then update it // if the EntityItem exists, then update it
if (wantEditLogging()) { if (wantEditLogging()) {
qCDebug(entities) << "User [" << senderNode->getUUID() << "] editing entity. ID:" << entityItemID; qCDebug(entities) << "User [" << senderNode->getUUID() << "] editing entity. ID:" << entityItemID;
@ -580,7 +580,7 @@ int EntityTree::processEditPacketData(PacketType packetType, const unsigned char
} }
updateEntity(entityItemID, properties, senderNode); updateEntity(entityItemID, properties, senderNode);
existingEntity->markAsChangedOnServer(); existingEntity->markAsChangedOnServer();
} else { } else if (packetType == PacketTypeEntityAdd) {
if (senderNode->getCanRez()) { if (senderNode->getCanRez()) {
// this is a new entity... assign a new entityID // this is a new entity... assign a new entityID
if (wantEditLogging()) { if (wantEditLogging()) {
@ -599,8 +599,11 @@ int EntityTree::processEditPacketData(PacketType packetType, const unsigned char
} }
} else { } else {
qCDebug(entities) << "User without 'rez rights' [" << senderNode->getUUID() << "] attempted to add an entity."; qCDebug(entities) << "User without 'rez rights' [" << senderNode->getUUID()
<< "] attempted to add an entity.";
} }
} else {
qCDebug(entities) << "Add or Edit failed." << packetType << existingEntity;
} }
} }
break; break;
@ -1009,7 +1012,7 @@ bool EntityTree::sendEntitiesOperation(OctreeElement* element, void* extraData)
properties.markAllChanged(); // so the entire property set is considered new, since we're making a new entity properties.markAllChanged(); // so the entire property set is considered new, since we're making a new entity
// queue the packet to send to the server // queue the packet to send to the server
args->packetSender->queueEditEntityMessage(PacketTypeEntityAddOrEdit, newID, properties); args->packetSender->queueEditEntityMessage(PacketTypeEntityAdd, newID, properties);
// also update the local tree instantly (note: this is not our tree, but an alternate tree) // also update the local tree instantly (note: this is not our tree, but an alternate tree)
if (args->localTree) { if (args->localTree) {

View file

@ -70,7 +70,8 @@ PacketVersion versionForPacketType(PacketType packetType) {
return 1; return 1;
case PacketTypeStopNode: case PacketTypeStopNode:
return 1; return 1;
case PacketTypeEntityAddOrEdit: case PacketTypeEntityAdd:
case PacketTypeEntityEdit:
case PacketTypeEntityData: case PacketTypeEntityData:
return VERSION_NO_ENTITY_ID_SWAP; return VERSION_NO_ENTITY_ID_SWAP;
case PacketTypeEntityErase: case PacketTypeEntityErase:
@ -117,7 +118,6 @@ QString nameForPacketType(PacketType packetType) {
PACKET_TYPE_NAME_LOOKUP(PacketTypeNodeJsonStats); PACKET_TYPE_NAME_LOOKUP(PacketTypeNodeJsonStats);
PACKET_TYPE_NAME_LOOKUP(PacketTypeEntityQuery); PACKET_TYPE_NAME_LOOKUP(PacketTypeEntityQuery);
PACKET_TYPE_NAME_LOOKUP(PacketTypeEntityData); PACKET_TYPE_NAME_LOOKUP(PacketTypeEntityData);
PACKET_TYPE_NAME_LOOKUP(PacketTypeEntityAddOrEdit);
PACKET_TYPE_NAME_LOOKUP(PacketTypeEntityErase); PACKET_TYPE_NAME_LOOKUP(PacketTypeEntityErase);
PACKET_TYPE_NAME_LOOKUP(PacketTypeOctreeDataNack); PACKET_TYPE_NAME_LOOKUP(PacketTypeOctreeDataNack);
PACKET_TYPE_NAME_LOOKUP(PacketTypeStopNode); PACKET_TYPE_NAME_LOOKUP(PacketTypeStopNode);
@ -128,6 +128,8 @@ QString nameForPacketType(PacketType packetType) {
PACKET_TYPE_NAME_LOOKUP(PacketTypeIceServerHeartbeatResponse); PACKET_TYPE_NAME_LOOKUP(PacketTypeIceServerHeartbeatResponse);
PACKET_TYPE_NAME_LOOKUP(PacketTypeUnverifiedPing); PACKET_TYPE_NAME_LOOKUP(PacketTypeUnverifiedPing);
PACKET_TYPE_NAME_LOOKUP(PacketTypeUnverifiedPingReply); PACKET_TYPE_NAME_LOOKUP(PacketTypeUnverifiedPingReply);
PACKET_TYPE_NAME_LOOKUP(PacketTypeEntityAdd);
PACKET_TYPE_NAME_LOOKUP(PacketTypeEntityEdit);
default: default:
return QString("Type: ") + QString::number((int)packetType); return QString("Type: ") + QString::number((int)packetType);
} }

View file

@ -68,9 +68,9 @@ enum PacketType {
PacketTypeNodeJsonStats, PacketTypeNodeJsonStats,
PacketTypeEntityQuery, // 40 PacketTypeEntityQuery, // 40
PacketTypeEntityData, PacketTypeEntityData,
PacketTypeEntityAddOrEdit,
PacketTypeEntityErase,
UNUSED_11, UNUSED_11,
PacketTypeEntityErase,
UNUSED_12,
PacketTypeOctreeDataNack, // 45 PacketTypeOctreeDataNack, // 45
PacketTypeStopNode, PacketTypeStopNode,
PacketTypeAudioEnvironment, PacketTypeAudioEnvironment,
@ -79,7 +79,9 @@ enum PacketType {
PacketTypeIceServerHeartbeat, // 50 PacketTypeIceServerHeartbeat, // 50
PacketTypeIceServerHeartbeatResponse, PacketTypeIceServerHeartbeatResponse,
PacketTypeUnverifiedPing, PacketTypeUnverifiedPing,
PacketTypeUnverifiedPingReply PacketTypeUnverifiedPingReply,
PacketTypeEntityAdd,
PacketTypeEntityEdit
}; };
typedef char PacketVersion; typedef char PacketVersion;

View file

@ -433,7 +433,7 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, const Q
qCDebug(physics) << "EntityMotionState::sendUpdate()... calling queueEditEntityMessage()..."; qCDebug(physics) << "EntityMotionState::sendUpdate()... calling queueEditEntityMessage()...";
#endif #endif
entityPacketSender->queueEditEntityMessage(PacketTypeEntityAddOrEdit, id, properties); entityPacketSender->queueEditEntityMessage(PacketTypeEntityEdit, id, properties);
_entity->setLastBroadcast(usecTimestampNow()); _entity->setLastBroadcast(usecTimestampNow());
} else { } else {
#ifdef WANT_DEBUG #ifdef WANT_DEBUG