diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index 3ec5839cbc..27125364f1 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -55,7 +55,7 @@ uint32_t EntityItem::getIDfromCreatorTokenID(uint32_t creatorTokenID) { if (_tokenIDsToIDs.find(creatorTokenID) != _tokenIDsToIDs.end()) { return _tokenIDsToIDs[creatorTokenID]; } - return UNKNOWN_MODEL_ID; + return UNKNOWN_ENTITY_ID; } uint32_t EntityItem::getNextCreatorTokenID() { @@ -84,7 +84,7 @@ void EntityItem::handleAddEntityResponse(const QByteArray& packet) { EntityItem::EntityItem() { _type = EntityTypes::Base; rgbColor noColor = { 0, 0, 0 }; - init(glm::vec3(0,0,0), 0, noColor, NEW_MODEL); + init(glm::vec3(0,0,0), 0, noColor, NEW_ENTITY); } void EntityItem::initFromEntityItemID(const EntityItemID& entityItemID) { @@ -101,14 +101,14 @@ void EntityItem::initFromEntityItemID(const EntityItemID& entityItemID) { rgbColor noColor = { 0, 0, 0 }; memcpy(_color, noColor, sizeof(_color)); _shouldBeDeleted = false; - _modelURL = MODEL_DEFAULT_MODEL_URL; - _rotation = MODEL_DEFAULT_MODEL_ROTATION; + _modelURL = ENTITY_DEFAULT_MODEL_URL; + _rotation = ENTITY_DEFAULT_ROTATION; // animation related - _animationURL = MODEL_DEFAULT_ANIMATION_URL; + _animationURL = ENTITY_DEFAULT_ANIMATION_URL; _animationIsPlaying = false; _animationFrameIndex = 0.0f; - _animationFPS = MODEL_DEFAULT_ANIMATION_FPS; + _animationFPS = ENTITY_DEFAULT_ANIMATION_FPS; _glowLevel = 0.0f; _jointMappingCompleted = false; @@ -130,7 +130,7 @@ EntityItem::~EntityItem() { } void EntityItem::init(glm::vec3 position, float radius, rgbColor color, uint32_t id) { - if (id == NEW_MODEL) { + if (id == NEW_ENTITY) { _id = _nextID; _nextID++; } else { @@ -144,14 +144,14 @@ void EntityItem::init(glm::vec3 position, float radius, rgbColor color, uint32_t _radius = radius; memcpy(_color, color, sizeof(_color)); _shouldBeDeleted = false; - _modelURL = MODEL_DEFAULT_MODEL_URL; - _rotation = MODEL_DEFAULT_MODEL_ROTATION; + _modelURL = ENTITY_DEFAULT_MODEL_URL; + _rotation = ENTITY_DEFAULT_ROTATION; // animation related - _animationURL = MODEL_DEFAULT_ANIMATION_URL; + _animationURL = ENTITY_DEFAULT_ANIMATION_URL; _animationIsPlaying = false; _animationFrameIndex = 0.0f; - _animationFPS = MODEL_DEFAULT_ANIMATION_FPS; + _animationFPS = ENTITY_DEFAULT_ANIMATION_FPS; _glowLevel = 0.0f; _jointMappingCompleted = false; _lastAnimated = now; @@ -554,7 +554,7 @@ int EntityItem::oldVersionReadEntityDataFromBuffer(const unsigned char* data, in dataAt += bytes; bytesRead += bytes; - if (args.bitstreamVersion >= VERSION_MODELS_HAVE_ANIMATION) { + if (args.bitstreamVersion >= VERSION_ENTITIES_HAVE_ANIMATION) { // animationURL uint16_t animationURLLength; memcpy(&animationURLLength, dataAt, sizeof(animationURLLength)); @@ -594,14 +594,14 @@ EntityItemID EntityItem::readEntityItemIDFromBuffer(const unsigned char* data, i quint32 id = idCoder; result.id = id; result.isKnownID = true; - result.creatorTokenID = UNKNOWN_MODEL_TOKEN; + result.creatorTokenID = UNKNOWN_ENTITY_TOKEN; } return result; } int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLeftToRead, ReadBitstreamToTreeParams& args) { - if (args.bitstreamVersion < VERSION_MODELS_SUPPORT_SPLIT_MTU) { + if (args.bitstreamVersion < VERSION_ENTITIES_SUPPORT_SPLIT_MTU) { return oldVersionReadEntityDataFromBuffer(data, bytesLeftToRead, args); } @@ -631,7 +631,7 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef dataAt += encodedID.size(); bytesRead += encodedID.size(); _id = idCoder; - _creatorTokenID = UNKNOWN_MODEL_TOKEN; // if we know the id, then we don't care about the creator token + _creatorTokenID = UNKNOWN_ENTITY_TOKEN; // if we know the id, then we don't care about the creator token _newlyCreated = false; // type @@ -786,11 +786,11 @@ EntityItem EntityItem::fromEditPacket(const unsigned char* data, int length, int qDebug() << "EntityItem EntityItem::fromEditPacket() editID=" << editID; } - bool isNewEntityItem = (editID == NEW_MODEL); + bool isNewEntityItem = (editID == NEW_ENTITY); // special case for handling "new" modelItems if (isNewEntityItem) { - // If this is a NEW_MODEL, then we assume that there's an additional uint32_t creatorToken, that + // If this is a NEW_ENTITY, then we assume that there's an additional uint32_t creatorToken, that // we want to send back to the creator as an map to the actual id uint32_t creatorTokenID; memcpy(&creatorTokenID, dataAt, sizeof(creatorTokenID)); @@ -801,7 +801,7 @@ EntityItem EntityItem::fromEditPacket(const unsigned char* data, int length, int newEntityItem._newlyCreated = true; valid = true; } else { - // look up the existing modelItem + // look up the existing entityItem const EntityItem* existingEntityItem = tree->findEntityByID(editID, true); // copy existing properties before over-writing with new properties @@ -809,8 +809,8 @@ EntityItem EntityItem::fromEditPacket(const unsigned char* data, int length, int newEntityItem = *existingEntityItem; valid = true; } else { - // the user attempted to edit a modelItem that doesn't exist - qDebug() << "user attempted to edit a modelItem that doesn't exist... editID=" << editID; + // the user attempted to edit a entityItem that doesn't exist + qDebug() << "user attempted to edit a entityItem that doesn't exist... editID=" << editID; tree->debugDumpMap(); valid = false; @@ -844,35 +844,35 @@ EntityItem EntityItem::fromEditPacket(const unsigned char* data, int length, int } // radius - if (isNewEntityItem || ((packetContainsBits & MODEL_PACKET_CONTAINS_RADIUS) == MODEL_PACKET_CONTAINS_RADIUS)) { + if (isNewEntityItem || ((packetContainsBits & ENTITY_PACKET_CONTAINS_RADIUS) == ENTITY_PACKET_CONTAINS_RADIUS)) { memcpy(&newEntityItem._radius, dataAt, sizeof(newEntityItem._radius)); dataAt += sizeof(newEntityItem._radius); processedBytes += sizeof(newEntityItem._radius); } // position - if (isNewEntityItem || ((packetContainsBits & MODEL_PACKET_CONTAINS_POSITION) == MODEL_PACKET_CONTAINS_POSITION)) { + if (isNewEntityItem || ((packetContainsBits & ENTITY_PACKET_CONTAINS_POSITION) == ENTITY_PACKET_CONTAINS_POSITION)) { memcpy(&newEntityItem._position, dataAt, sizeof(newEntityItem._position)); dataAt += sizeof(newEntityItem._position); processedBytes += sizeof(newEntityItem._position); } // color - if (isNewEntityItem || ((packetContainsBits & MODEL_PACKET_CONTAINS_COLOR) == MODEL_PACKET_CONTAINS_COLOR)) { + if (isNewEntityItem || ((packetContainsBits & ENTITY_PACKET_CONTAINS_COLOR) == ENTITY_PACKET_CONTAINS_COLOR)) { memcpy(newEntityItem._color, dataAt, sizeof(newEntityItem._color)); dataAt += sizeof(newEntityItem._color); processedBytes += sizeof(newEntityItem._color); } // shouldBeDeleted - if (isNewEntityItem || ((packetContainsBits & MODEL_PACKET_CONTAINS_SHOULDDIE) == MODEL_PACKET_CONTAINS_SHOULDDIE)) { + if (isNewEntityItem || ((packetContainsBits & ENTITY_PACKET_CONTAINS_SHOULDDIE) == ENTITY_PACKET_CONTAINS_SHOULDDIE)) { memcpy(&newEntityItem._shouldBeDeleted, dataAt, sizeof(newEntityItem._shouldBeDeleted)); dataAt += sizeof(newEntityItem._shouldBeDeleted); processedBytes += sizeof(newEntityItem._shouldBeDeleted); } // modelURL - if (isNewEntityItem || ((packetContainsBits & MODEL_PACKET_CONTAINS_MODEL_URL) == MODEL_PACKET_CONTAINS_MODEL_URL)) { + if (isNewEntityItem || ((packetContainsBits & ENTITY_PACKET_CONTAINS_MODEL_URL) == ENTITY_PACKET_CONTAINS_MODEL_URL)) { uint16_t modelURLLength; memcpy(&modelURLLength, dataAt, sizeof(modelURLLength)); dataAt += sizeof(modelURLLength); @@ -885,14 +885,14 @@ EntityItem EntityItem::fromEditPacket(const unsigned char* data, int length, int // modelRotation if (isNewEntityItem || ((packetContainsBits & - MODEL_PACKET_CONTAINS_MODEL_ROTATION) == MODEL_PACKET_CONTAINS_MODEL_ROTATION)) { + ENTITY_PACKET_CONTAINS_ROTATION) == ENTITY_PACKET_CONTAINS_ROTATION)) { int bytes = unpackOrientationQuatFromBytes(dataAt, newEntityItem._rotation); dataAt += bytes; processedBytes += bytes; } // animationURL - if (isNewEntityItem || ((packetContainsBits & MODEL_PACKET_CONTAINS_ANIMATION_URL) == MODEL_PACKET_CONTAINS_ANIMATION_URL)) { + if (isNewEntityItem || ((packetContainsBits & ENTITY_PACKET_CONTAINS_ANIMATION_URL) == ENTITY_PACKET_CONTAINS_ANIMATION_URL)) { uint16_t animationURLLength; memcpy(&animationURLLength, dataAt, sizeof(animationURLLength)); dataAt += sizeof(animationURLLength); @@ -905,7 +905,7 @@ EntityItem EntityItem::fromEditPacket(const unsigned char* data, int length, int // animationIsPlaying if (isNewEntityItem || ((packetContainsBits & - MODEL_PACKET_CONTAINS_ANIMATION_PLAYING) == MODEL_PACKET_CONTAINS_ANIMATION_PLAYING)) { + ENTITY_PACKET_CONTAINS_ANIMATION_PLAYING) == ENTITY_PACKET_CONTAINS_ANIMATION_PLAYING)) { memcpy(&newEntityItem._animationIsPlaying, dataAt, sizeof(newEntityItem._animationIsPlaying)); dataAt += sizeof(newEntityItem._animationIsPlaying); @@ -914,7 +914,7 @@ EntityItem EntityItem::fromEditPacket(const unsigned char* data, int length, int // animationFrameIndex if (isNewEntityItem || ((packetContainsBits & - MODEL_PACKET_CONTAINS_ANIMATION_FRAME) == MODEL_PACKET_CONTAINS_ANIMATION_FRAME)) { + ENTITY_PACKET_CONTAINS_ANIMATION_FRAME) == ENTITY_PACKET_CONTAINS_ANIMATION_FRAME)) { memcpy(&newEntityItem._animationFrameIndex, dataAt, sizeof(newEntityItem._animationFrameIndex)); dataAt += sizeof(newEntityItem._animationFrameIndex); @@ -923,7 +923,7 @@ EntityItem EntityItem::fromEditPacket(const unsigned char* data, int length, int // animationFPS if (isNewEntityItem || ((packetContainsBits & - MODEL_PACKET_CONTAINS_ANIMATION_FPS) == MODEL_PACKET_CONTAINS_ANIMATION_FPS)) { + ENTITY_PACKET_CONTAINS_ANIMATION_FPS) == ENTITY_PACKET_CONTAINS_ANIMATION_FPS)) { memcpy(&newEntityItem._animationFPS, dataAt, sizeof(newEntityItem._animationFPS)); dataAt += sizeof(newEntityItem._animationFPS); @@ -957,15 +957,15 @@ bool EntityItem::encodeEntityEditMessageDetails(PacketType command, EntityItemID unsigned char* copyAt = bufferOut; sizeOut = 0; - // get the octal code for the modelItem + // get the octal code for the entityItem // this could be a problem if the caller doesn't include position.... glm::vec3 rootPosition(0); float rootScale = 0.5f; unsigned char* octcode = pointToOctalCode(rootPosition.x, rootPosition.y, rootPosition.z, rootScale); - // TODO: Consider this old code... including the correct octree for where the modelItem will go matters for - // modelItem servers with different jurisdictions, but for now, we'll send everything to the root, since the + // TODO: Consider this old code... including the correct octree for where the entityItem will go matters for + // entityItem servers with different jurisdictions, but for now, we'll send everything to the root, since the // tree does the right thing... // //unsigned char* octcode = pointToOctalCode(details[i].position.x, details[i].position.y, @@ -980,7 +980,7 @@ bool EntityItem::encodeEntityEditMessageDetails(PacketType command, EntityItemID sizeOut += lengthOfOctcode; // Now add our edit content details... - bool isNewEntityItem = (id.id == NEW_MODEL); + bool isNewEntityItem = (id.id == NEW_ENTITY); // id memcpy(copyAt, &id.id, sizeof(id.id)); @@ -989,7 +989,7 @@ bool EntityItem::encodeEntityEditMessageDetails(PacketType command, EntityItemID // special case for handling "new" modelItems if (isNewEntityItem) { - // If this is a NEW_MODEL, then we assume that there's an additional uint32_t creatorToken, that + // If this is a NEW_ENTITY, then we assume that there's an additional uint32_t creatorToken, that // we want to send back to the creator as an map to the actual id memcpy(copyAt, &id.creatorTokenID, sizeof(id.creatorTokenID)); copyAt += sizeof(id.creatorTokenID); @@ -1002,7 +1002,7 @@ bool EntityItem::encodeEntityEditMessageDetails(PacketType command, EntityItemID copyAt += sizeof(lastEdited); sizeOut += sizeof(lastEdited); - // For new modelItems, all remaining items are mandatory, for an edited modelItem, All of the remaining items are + // For new modelItems, all remaining items are mandatory, for an edited entityItem, All of the remaining items are // optional, and may or may not be included based on their included values in the properties included bits uint16_t packetContainsBits = properties.getChangedBits(); if (!isNewEntityItem) { @@ -1012,7 +1012,7 @@ bool EntityItem::encodeEntityEditMessageDetails(PacketType command, EntityItemID } // radius - if (isNewEntityItem || ((packetContainsBits & MODEL_PACKET_CONTAINS_RADIUS) == MODEL_PACKET_CONTAINS_RADIUS)) { + if (isNewEntityItem || ((packetContainsBits & ENTITY_PACKET_CONTAINS_RADIUS) == ENTITY_PACKET_CONTAINS_RADIUS)) { float radius = properties.getRadius() / (float) TREE_SCALE; memcpy(copyAt, &radius, sizeof(radius)); copyAt += sizeof(radius); @@ -1020,7 +1020,7 @@ bool EntityItem::encodeEntityEditMessageDetails(PacketType command, EntityItemID } // position - if (isNewEntityItem || ((packetContainsBits & MODEL_PACKET_CONTAINS_POSITION) == MODEL_PACKET_CONTAINS_POSITION)) { + if (isNewEntityItem || ((packetContainsBits & ENTITY_PACKET_CONTAINS_POSITION) == ENTITY_PACKET_CONTAINS_POSITION)) { glm::vec3 position = properties.getPosition() / (float)TREE_SCALE; memcpy(copyAt, &position, sizeof(position)); copyAt += sizeof(position); @@ -1028,7 +1028,7 @@ bool EntityItem::encodeEntityEditMessageDetails(PacketType command, EntityItemID } // color - if (isNewEntityItem || ((packetContainsBits & MODEL_PACKET_CONTAINS_COLOR) == MODEL_PACKET_CONTAINS_COLOR)) { + if (isNewEntityItem || ((packetContainsBits & ENTITY_PACKET_CONTAINS_COLOR) == ENTITY_PACKET_CONTAINS_COLOR)) { rgbColor color = { properties.getColor().red, properties.getColor().green, properties.getColor().blue }; memcpy(copyAt, color, sizeof(color)); copyAt += sizeof(color); @@ -1036,7 +1036,7 @@ bool EntityItem::encodeEntityEditMessageDetails(PacketType command, EntityItemID } // shoulDie - if (isNewEntityItem || ((packetContainsBits & MODEL_PACKET_CONTAINS_SHOULDDIE) == MODEL_PACKET_CONTAINS_SHOULDDIE)) { + if (isNewEntityItem || ((packetContainsBits & ENTITY_PACKET_CONTAINS_SHOULDDIE) == ENTITY_PACKET_CONTAINS_SHOULDDIE)) { bool shouldBeDeleted = properties.getShouldBeDeleted(); memcpy(copyAt, &shouldBeDeleted, sizeof(shouldBeDeleted)); copyAt += sizeof(shouldBeDeleted); @@ -1044,7 +1044,7 @@ bool EntityItem::encodeEntityEditMessageDetails(PacketType command, EntityItemID } // modelURL - if (isNewEntityItem || ((packetContainsBits & MODEL_PACKET_CONTAINS_MODEL_URL) == MODEL_PACKET_CONTAINS_MODEL_URL)) { + if (isNewEntityItem || ((packetContainsBits & ENTITY_PACKET_CONTAINS_MODEL_URL) == ENTITY_PACKET_CONTAINS_MODEL_URL)) { uint16_t urlLength = properties.getModelURL().size() + 1; memcpy(copyAt, &urlLength, sizeof(urlLength)); copyAt += sizeof(urlLength); @@ -1055,14 +1055,14 @@ bool EntityItem::encodeEntityEditMessageDetails(PacketType command, EntityItemID } // modelRotation - if (isNewEntityItem || ((packetContainsBits & MODEL_PACKET_CONTAINS_MODEL_ROTATION) == MODEL_PACKET_CONTAINS_MODEL_ROTATION)) { + if (isNewEntityItem || ((packetContainsBits & ENTITY_PACKET_CONTAINS_ROTATION) == ENTITY_PACKET_CONTAINS_ROTATION)) { int bytes = packOrientationQuatToBytes(copyAt, properties.getRotation()); copyAt += bytes; sizeOut += bytes; } // animationURL - if (isNewEntityItem || ((packetContainsBits & MODEL_PACKET_CONTAINS_ANIMATION_URL) == MODEL_PACKET_CONTAINS_ANIMATION_URL)) { + if (isNewEntityItem || ((packetContainsBits & ENTITY_PACKET_CONTAINS_ANIMATION_URL) == ENTITY_PACKET_CONTAINS_ANIMATION_URL)) { uint16_t urlLength = properties.getAnimationURL().size() + 1; memcpy(copyAt, &urlLength, sizeof(urlLength)); copyAt += sizeof(urlLength); @@ -1074,7 +1074,7 @@ bool EntityItem::encodeEntityEditMessageDetails(PacketType command, EntityItemID // animationIsPlaying if (isNewEntityItem || ((packetContainsBits & - MODEL_PACKET_CONTAINS_ANIMATION_PLAYING) == MODEL_PACKET_CONTAINS_ANIMATION_PLAYING)) { + ENTITY_PACKET_CONTAINS_ANIMATION_PLAYING) == ENTITY_PACKET_CONTAINS_ANIMATION_PLAYING)) { bool animationIsPlaying = properties.getAnimationIsPlaying(); memcpy(copyAt, &animationIsPlaying, sizeof(animationIsPlaying)); @@ -1084,7 +1084,7 @@ bool EntityItem::encodeEntityEditMessageDetails(PacketType command, EntityItemID // animationFrameIndex if (isNewEntityItem || ((packetContainsBits & - MODEL_PACKET_CONTAINS_ANIMATION_FRAME) == MODEL_PACKET_CONTAINS_ANIMATION_FRAME)) { + ENTITY_PACKET_CONTAINS_ANIMATION_FRAME) == ENTITY_PACKET_CONTAINS_ANIMATION_FRAME)) { float animationFrameIndex = properties.getAnimationFrameIndex(); memcpy(copyAt, &animationFrameIndex, sizeof(animationFrameIndex)); @@ -1094,7 +1094,7 @@ bool EntityItem::encodeEntityEditMessageDetails(PacketType command, EntityItemID // animationFPS if (isNewEntityItem || ((packetContainsBits & - MODEL_PACKET_CONTAINS_ANIMATION_FPS) == MODEL_PACKET_CONTAINS_ANIMATION_FPS)) { + ENTITY_PACKET_CONTAINS_ANIMATION_FPS) == ENTITY_PACKET_CONTAINS_ANIMATION_FPS)) { float animationFPS = properties.getAnimationFPS(); memcpy(copyAt, &animationFPS, sizeof(animationFPS)); @@ -1127,8 +1127,8 @@ void EntityItem::adjustEditPacketForClockSkew(unsigned char* codeColorBuffer, ss memcpy(&id, dataAt, sizeof(id)); dataAt += sizeof(id); // special case for handling "new" modelItems - if (id == NEW_MODEL) { - // If this is a NEW_MODEL, then we assume that there's an additional uint32_t creatorToken, that + if (id == NEW_ENTITY) { + // If this is a NEW_ENTITY, then we assume that there's an additional uint32_t creatorToken, that // we want to send back to the creator as an map to the actual id dataAt += sizeof(uint32_t); } @@ -1271,17 +1271,17 @@ void EntityItem::setProperties(const EntityItemProperties& properties, bool forc EntityItemProperties::EntityItemProperties() : _position(0), _color(), - _radius(MODEL_DEFAULT_RADIUS), + _radius(ENTITY_DEFAULT_RADIUS), _shouldBeDeleted(false), _modelURL(""), - _rotation(MODEL_DEFAULT_MODEL_ROTATION), + _rotation(ENTITY_DEFAULT_ROTATION), _animationURL(""), _animationIsPlaying(false), _animationFrameIndex(0.0), - _animationFPS(MODEL_DEFAULT_ANIMATION_FPS), + _animationFPS(ENTITY_DEFAULT_ANIMATION_FPS), _glowLevel(0.0f), - _id(UNKNOWN_MODEL_ID), + _id(UNKNOWN_ENTITY_ID), _idSet(false), _lastEdited(usecTimestampNow()), @@ -1314,43 +1314,43 @@ void EntityItemProperties::debugDump() const { uint16_t EntityItemProperties::getChangedBits() const { uint16_t changedBits = 0; if (_radiusChanged) { - changedBits += MODEL_PACKET_CONTAINS_RADIUS; + changedBits += ENTITY_PACKET_CONTAINS_RADIUS; } if (_positionChanged) { - changedBits += MODEL_PACKET_CONTAINS_POSITION; + changedBits += ENTITY_PACKET_CONTAINS_POSITION; } if (_colorChanged) { - changedBits += MODEL_PACKET_CONTAINS_COLOR; + changedBits += ENTITY_PACKET_CONTAINS_COLOR; } if (_shouldBeDeletedChanged) { - changedBits += MODEL_PACKET_CONTAINS_SHOULDDIE; + changedBits += ENTITY_PACKET_CONTAINS_SHOULDDIE; } if (_modelURLChanged) { - changedBits += MODEL_PACKET_CONTAINS_MODEL_URL; + changedBits += ENTITY_PACKET_CONTAINS_MODEL_URL; } if (_rotationChanged) { - changedBits += MODEL_PACKET_CONTAINS_MODEL_ROTATION; + changedBits += ENTITY_PACKET_CONTAINS_ROTATION; } if (_animationURLChanged) { - changedBits += MODEL_PACKET_CONTAINS_ANIMATION_URL; + changedBits += ENTITY_PACKET_CONTAINS_ANIMATION_URL; } if (_animationIsPlayingChanged) { - changedBits += MODEL_PACKET_CONTAINS_ANIMATION_PLAYING; + changedBits += ENTITY_PACKET_CONTAINS_ANIMATION_PLAYING; } if (_animationFrameIndexChanged) { - changedBits += MODEL_PACKET_CONTAINS_ANIMATION_FRAME; + changedBits += ENTITY_PACKET_CONTAINS_ANIMATION_FRAME; } if (_animationFPSChanged) { - changedBits += MODEL_PACKET_CONTAINS_ANIMATION_FPS; + changedBits += ENTITY_PACKET_CONTAINS_ANIMATION_FPS; } return changedBits; @@ -1383,7 +1383,7 @@ QScriptValue EntityItemProperties::copyToScriptValue(QScriptEngine* engine) cons if (_idSet) { properties.setProperty("id", _id); - properties.setProperty("isKnownID", (_id != UNKNOWN_MODEL_ID)); + properties.setProperty("isKnownID", (_id != UNKNOWN_ENTITY_ID)); } // Sitting properties support @@ -1541,60 +1541,60 @@ void EntityItemProperties::copyFromScriptValue(const QScriptValue &object) { _lastEdited = usecTimestampNow(); } -void EntityItemProperties::copyToEntityItem(EntityItem& modelItem, bool forceCopy) const { +void EntityItemProperties::copyToEntityItem(EntityItem& entityItem, bool forceCopy) const { bool somethingChanged = false; if (_positionChanged || forceCopy) { - modelItem.setPosition(_position / (float) TREE_SCALE); + entityItem.setPosition(_position / (float) TREE_SCALE); somethingChanged = true; } if (_colorChanged || forceCopy) { - modelItem.setColor(_color); + entityItem.setColor(_color); somethingChanged = true; } if (_radiusChanged || forceCopy) { - modelItem.setRadius(_radius / (float) TREE_SCALE); + entityItem.setRadius(_radius / (float) TREE_SCALE); somethingChanged = true; } if (_shouldBeDeletedChanged || forceCopy) { - modelItem.setShouldBeDeleted(_shouldBeDeleted); + entityItem.setShouldBeDeleted(_shouldBeDeleted); somethingChanged = true; } if (_modelURLChanged || forceCopy) { - modelItem.setModelURL(_modelURL); + entityItem.setModelURL(_modelURL); somethingChanged = true; } if (_rotationChanged || forceCopy) { - modelItem.setRotation(_rotation); + entityItem.setRotation(_rotation); somethingChanged = true; } if (_animationURLChanged || forceCopy) { - modelItem.setAnimationURL(_animationURL); + entityItem.setAnimationURL(_animationURL); somethingChanged = true; } if (_animationIsPlayingChanged || forceCopy) { - modelItem.setAnimationIsPlaying(_animationIsPlaying); + entityItem.setAnimationIsPlaying(_animationIsPlaying); somethingChanged = true; } if (_animationFrameIndexChanged || forceCopy) { - modelItem.setAnimationFrameIndex(_animationFrameIndex); + entityItem.setAnimationFrameIndex(_animationFrameIndex); somethingChanged = true; } if (_animationFPSChanged || forceCopy) { - modelItem.setAnimationFPS(_animationFPS); + entityItem.setAnimationFPS(_animationFPS); somethingChanged = true; } if (_glowLevelChanged || forceCopy) { - modelItem.setGlowLevel(_glowLevel); + entityItem.setGlowLevel(_glowLevel); somethingChanged = true; } @@ -1606,25 +1606,25 @@ void EntityItemProperties::copyToEntityItem(EntityItem& modelItem, bool forceCop qDebug() << "EntityItemProperties::copyToEntityItem() AFTER update... edited AGO=" << elapsed << "now=" << now << " _lastEdited=" << _lastEdited; } - modelItem.setLastEdited(_lastEdited); + entityItem.setLastEdited(_lastEdited); } } -void EntityItemProperties::copyFromEntityItem(const EntityItem& modelItem) { - _position = modelItem.getPosition() * (float) TREE_SCALE; - _color = modelItem.getXColor(); - _radius = modelItem.getRadius() * (float) TREE_SCALE; - _shouldBeDeleted = modelItem.getShouldBeDeleted(); - _modelURL = modelItem.getModelURL(); - _rotation = modelItem.getRotation(); - _animationURL = modelItem.getAnimationURL(); - _animationIsPlaying = modelItem.getAnimationIsPlaying(); - _animationFrameIndex = modelItem.getAnimationFrameIndex(); - _animationFPS = modelItem.getAnimationFPS(); - _glowLevel = modelItem.getGlowLevel(); - _sittingPoints = modelItem.getSittingPoints(); // sitting support +void EntityItemProperties::copyFromEntityItem(const EntityItem& entityItem) { + _position = entityItem.getPosition() * (float) TREE_SCALE; + _color = entityItem.getXColor(); + _radius = entityItem.getRadius() * (float) TREE_SCALE; + _shouldBeDeleted = entityItem.getShouldBeDeleted(); + _modelURL = entityItem.getModelURL(); + _rotation = entityItem.getRotation(); + _animationURL = entityItem.getAnimationURL(); + _animationIsPlaying = entityItem.getAnimationIsPlaying(); + _animationFrameIndex = entityItem.getAnimationFrameIndex(); + _animationFPS = entityItem.getAnimationFPS(); + _glowLevel = entityItem.getGlowLevel(); + _sittingPoints = entityItem.getSittingPoints(); // sitting support - _id = modelItem.getID(); + _id = entityItem.getID(); _idSet = true; _positionChanged = false; diff --git a/libraries/entities/src/EntityItem.h b/libraries/entities/src/EntityItem.h index 8748bca52e..d74efb5f05 100644 --- a/libraries/entities/src/EntityItem.h +++ b/libraries/entities/src/EntityItem.h @@ -38,27 +38,27 @@ class VoxelEditPacketSender; class VoxelsScriptingInterface; struct VoxelDetail; -const uint32_t NEW_MODEL = 0xFFFFFFFF; -const uint32_t UNKNOWN_MODEL_TOKEN = 0xFFFFFFFF; -const uint32_t UNKNOWN_MODEL_ID = 0xFFFFFFFF; +const uint32_t NEW_ENTITY = 0xFFFFFFFF; +const uint32_t UNKNOWN_ENTITY_TOKEN = 0xFFFFFFFF; +const uint32_t UNKNOWN_ENTITY_ID = 0xFFFFFFFF; -const uint16_t MODEL_PACKET_CONTAINS_RADIUS = 1; -const uint16_t MODEL_PACKET_CONTAINS_POSITION = 2; -const uint16_t MODEL_PACKET_CONTAINS_COLOR = 4; -const uint16_t MODEL_PACKET_CONTAINS_SHOULDDIE = 8; -const uint16_t MODEL_PACKET_CONTAINS_MODEL_URL = 16; -const uint16_t MODEL_PACKET_CONTAINS_MODEL_ROTATION = 32; -const uint16_t MODEL_PACKET_CONTAINS_ANIMATION_URL = 64; -const uint16_t MODEL_PACKET_CONTAINS_ANIMATION_PLAYING = 128; -const uint16_t MODEL_PACKET_CONTAINS_ANIMATION_FRAME = 256; -const uint16_t MODEL_PACKET_CONTAINS_ANIMATION_FPS = 512; +const uint16_t ENTITY_PACKET_CONTAINS_RADIUS = 1; +const uint16_t ENTITY_PACKET_CONTAINS_POSITION = 2; +const uint16_t ENTITY_PACKET_CONTAINS_COLOR = 4; +const uint16_t ENTITY_PACKET_CONTAINS_SHOULDDIE = 8; +const uint16_t ENTITY_PACKET_CONTAINS_MODEL_URL = 16; +const uint16_t ENTITY_PACKET_CONTAINS_ROTATION = 32; +const uint16_t ENTITY_PACKET_CONTAINS_ANIMATION_URL = 64; +const uint16_t ENTITY_PACKET_CONTAINS_ANIMATION_PLAYING = 128; +const uint16_t ENTITY_PACKET_CONTAINS_ANIMATION_FRAME = 256; +const uint16_t ENTITY_PACKET_CONTAINS_ANIMATION_FPS = 512; -const float MODEL_DEFAULT_RADIUS = 0.1f / TREE_SCALE; -const float MINIMUM_MODEL_ELEMENT_SIZE = (1.0f / 100000.0f) / TREE_SCALE; // smallest size container -const QString MODEL_DEFAULT_MODEL_URL(""); -const glm::quat MODEL_DEFAULT_MODEL_ROTATION; -const QString MODEL_DEFAULT_ANIMATION_URL(""); -const float MODEL_DEFAULT_ANIMATION_FPS = 30.0f; +const float ENTITY_DEFAULT_RADIUS = 0.1f / TREE_SCALE; +const float ENTITY_MINIMUM_ELEMENT_SIZE = (1.0f / 100000.0f) / TREE_SCALE; // smallest size container +const QString ENTITY_DEFAULT_MODEL_URL(""); +const glm::quat ENTITY_DEFAULT_ROTATION; +const QString ENTITY_DEFAULT_ANIMATION_URL(""); +const float ENTITY_DEFAULT_ANIMATION_FPS = 30.0f; // PropertyFlags support @@ -98,9 +98,9 @@ enum EntityPropertyList { typedef PropertyFlags EntityPropertyFlags; -/// A collection of properties of a model item used in the scripting API. Translates between the actual properties of a model -/// and a JavaScript style hash/QScriptValue storing a set of properties. Used in scripting to set/get the complete set of -/// model item properties via JavaScript hashes/QScriptValues +/// A collection of properties of an entity item used in the scripting API. Translates between the actual properties of an +/// entity and a JavaScript style hash/QScriptValue storing a set of properties. Used in scripting to set/get the complete +/// set of entity item properties via JavaScript hashes/QScriptValues /// all units for position, radius, etc are in meter units class EntityItemProperties { public: @@ -109,8 +109,8 @@ public: QScriptValue copyToScriptValue(QScriptEngine* engine) const; void copyFromScriptValue(const QScriptValue& object); - void copyToEntityItem(EntityItem& modelItem, bool forceCopy = false) const; - void copyFromEntityItem(const EntityItem& modelItem); + void copyToEntityItem(EntityItem& entityItem, bool forceCopy = false) const; + void copyFromEntityItem(const EntityItem& entityItem); const glm::vec3& getPosition() const { return _position; } xColor getColor() const { return _color; } @@ -144,7 +144,7 @@ public: void setGlowLevel(float value) { _glowLevel = value; _glowLevelChanged = true; } /// used by EntityScriptingInterface to return EntityItemProperties for unknown models - void setIsUnknownID() { _id = UNKNOWN_MODEL_ID; _idSet = true; } + void setIsUnknownID() { _id = UNKNOWN_ENTITY_ID; _idSet = true; } glm::vec3 getMinimumPoint() const { return _position - glm::vec3(_radius, _radius, _radius); } glm::vec3 getMaximumPoint() const { return _position + glm::vec3(_radius, _radius, _radius); } @@ -195,13 +195,13 @@ void EntityItemPropertiesFromScriptValue(const QScriptValue &object, EntityItemP class EntityItemID { public: EntityItemID() : - id(NEW_MODEL), creatorTokenID(UNKNOWN_MODEL_TOKEN), isKnownID(false) { }; + id(NEW_ENTITY), creatorTokenID(UNKNOWN_ENTITY_TOKEN), isKnownID(false) { }; EntityItemID(uint32_t id, uint32_t creatorTokenID, bool isKnownID) : id(id), creatorTokenID(creatorTokenID), isKnownID(isKnownID) { }; EntityItemID(uint32_t id) : - id(id), creatorTokenID(UNKNOWN_MODEL_TOKEN), isKnownID(true) { }; + id(id), creatorTokenID(UNKNOWN_ENTITY_TOKEN), isKnownID(true) { }; uint32_t id; uint32_t creatorTokenID; @@ -213,7 +213,7 @@ inline bool operator<(const EntityItemID& a, const EntityItemID& b) { } inline bool operator==(const EntityItemID& a, const EntityItemID& b) { - if (a.id == UNKNOWN_MODEL_ID && b.id == UNKNOWN_MODEL_ID) { + if (a.id == UNKNOWN_ENTITY_ID && b.id == UNKNOWN_ENTITY_ID) { return a.creatorTokenID == b.creatorTokenID; } return a.id == b.id; @@ -221,7 +221,7 @@ inline bool operator==(const EntityItemID& a, const EntityItemID& b) { inline uint qHash(const EntityItemID& a, uint seed) { qint64 temp; - if (a.id == UNKNOWN_MODEL_ID) { + if (a.id == UNKNOWN_ENTITY_ID) { temp = -a.creatorTokenID; } else { temp = a.id; @@ -283,7 +283,7 @@ public: float getGlowLevel() const { return _glowLevel; } QVector getSittingPoints() const { return _sittingPoints; } - EntityItemID getEntityItemID() const { return EntityItemID(getID(), getCreatorTokenID(), getID() != UNKNOWN_MODEL_ID); } + EntityItemID getEntityItemID() const { return EntityItemID(getID(), getCreatorTokenID(), getID() != UNKNOWN_ENTITY_ID); } EntityItemProperties getProperties() const; /// The last updated/simulated time of this model from the time perspective of the authoritative server/source @@ -300,7 +300,7 @@ public: bool getShouldBeDeleted() const { return _shouldBeDeleted; } uint32_t getCreatorTokenID() const { return _creatorTokenID; } bool isNewlyCreated() const { return _newlyCreated; } - bool isKnownID() const { return getID() != UNKNOWN_MODEL_ID; } + bool isKnownID() const { return getID() != UNKNOWN_ENTITY_ID; } /// set position in domain scale units (0.0 - 1.0) void setPosition(const glm::vec3& value) { _position = value; } @@ -369,7 +369,7 @@ public: protected: void initFromEntityItemID(const EntityItemID& entityItemID); - virtual void init(glm::vec3 position, float radius, rgbColor color, uint32_t id = NEW_MODEL); + virtual void init(glm::vec3 position, float radius, rgbColor color, uint32_t id = NEW_ENTITY); glm::vec3 _position; rgbColor _color; diff --git a/libraries/entities/src/EntityScriptingInterface.cpp b/libraries/entities/src/EntityScriptingInterface.cpp index d9ae89d28a..55fd986598 100644 --- a/libraries/entities/src/EntityScriptingInterface.cpp +++ b/libraries/entities/src/EntityScriptingInterface.cpp @@ -29,7 +29,7 @@ EntityItemID EntityScriptingInterface::addEntity(const EntityItemProperties& pro // The application will keep track of creatorTokenID uint32_t creatorTokenID = EntityItem::getNextCreatorTokenID(); - EntityItemID id(NEW_MODEL, creatorTokenID, false ); + EntityItemID id(NEW_ENTITY, creatorTokenID, false ); // queue the packet queueEntityMessage(PacketTypeEntityAddOrEdit, id, properties); @@ -49,7 +49,7 @@ EntityItemID EntityScriptingInterface::identifyEntity(EntityItemID entityID) { if (!entityID.isKnownID) { actualID = EntityItem::getIDfromCreatorTokenID(entityID.creatorTokenID); - if (actualID == UNKNOWN_MODEL_ID) { + if (actualID == UNKNOWN_ENTITY_ID) { return entityID; // bailing early } @@ -92,7 +92,7 @@ EntityItemID EntityScriptingInterface::editEntity(EntityItemID entityID, const E } // if at this point, we know the id, send the update to the model server - if (actualID != UNKNOWN_MODEL_ID) { + if (actualID != UNKNOWN_ENTITY_ID) { entityID.id = actualID; entityID.isKnownID = true; queueEntityMessage(PacketTypeEntityAddOrEdit, entityID, properties); @@ -109,9 +109,9 @@ EntityItemID EntityScriptingInterface::editEntity(EntityItemID entityID, const E } -// TODO: This deleteEntity() method uses the PacketType_MODEL_ADD_OR_EDIT message to send +// TODO: This deleteEntity() method uses the PacketTypeEntityAddOrEdit message to send // a changed model with a shouldDie() property set to true. This works and is currently the only -// way to tell the model server to delete a model. But we should change this to use the PacketType_MODEL_ERASE +// way to tell the model server to delete a model. But we should change this to use the PacketTypeEntityErase // message which takes a list of model id's to delete. void EntityScriptingInterface::deleteEntity(EntityItemID entityID) { @@ -127,7 +127,7 @@ void EntityScriptingInterface::deleteEntity(EntityItemID entityID) { } // if at this point, we know the id, send the update to the model server - if (actualID != UNKNOWN_MODEL_ID) { + if (actualID != UNKNOWN_ENTITY_ID) { entityID.id = actualID; entityID.isKnownID = true; queueEntityMessage(PacketTypeEntityAddOrEdit, entityID, properties); @@ -142,7 +142,7 @@ void EntityScriptingInterface::deleteEntity(EntityItemID entityID) { } EntityItemID EntityScriptingInterface::findClosestEntity(const glm::vec3& center, float radius) const { - EntityItemID result(UNKNOWN_MODEL_ID, UNKNOWN_MODEL_TOKEN, false); + EntityItemID result(UNKNOWN_ENTITY_ID, UNKNOWN_ENTITY_TOKEN, false); if (_entityTree) { _entityTree->lockForRead(); const EntityItem* closestEntity = _entityTree->findClosestEntity(center/(float)TREE_SCALE, @@ -166,7 +166,7 @@ QVector EntityScriptingInterface::findEntities(const glm::vec3& ce _entityTree->unlock(); foreach (const EntityItem* model, models) { - EntityItemID thisEntityItemID(model->getID(), UNKNOWN_MODEL_TOKEN, true); + EntityItemID thisEntityItemID(model->getID(), UNKNOWN_ENTITY_TOKEN, true); result << thisEntityItemID; } } diff --git a/libraries/entities/src/EntityTree.cpp b/libraries/entities/src/EntityTree.cpp index 3927834695..395b39fea5 100644 --- a/libraries/entities/src/EntityTree.cpp +++ b/libraries/entities/src/EntityTree.cpp @@ -218,59 +218,59 @@ void EntityTree::storeEntity(const EntityItem& model, const SharedNodePointer& s } -void EntityTree::updateEntity(const EntityItemID& modelID, const EntityItemProperties& properties) { - EntityItem updateItem(modelID); +void EntityTree::updateEntity(const EntityItemID& entityID, const EntityItemProperties& properties) { + EntityItem updateItem(entityID); bool wantDebug = false; if (wantDebug) { - qDebug() << "EntityTree::updateEntity(modelID, properties) line:" << __LINE__ << "updateItem:"; + qDebug() << "EntityTree::updateEntity(entityID, properties) line:" << __LINE__ << "updateItem:"; updateItem.debugDump(); } // since the properties might not be complete, they may only contain some values, // we need to first see if we already have the model in our tree, and make a copy of // its existing properties first - EntityTreeElement* containingElement = getContainingElement(modelID); + EntityTreeElement* containingElement = getContainingElement(entityID); if (wantDebug) { - qDebug() << "EntityTree::updateEntity(modelID, properties) containingElement=" << containingElement; + qDebug() << "EntityTree::updateEntity(entityID, properties) containingElement=" << containingElement; } if (containingElement) { - const EntityItem* oldEntity = containingElement->getEntityWithEntityItemID(modelID); + const EntityItem* oldEntity = containingElement->getEntityWithEntityItemID(entityID); if (oldEntity) { EntityItemProperties oldProps = oldEntity->getProperties(); if (wantDebug) { - qDebug() << "EntityTree::updateEntity(modelID, properties) ********** COPY PROPERTIES FROM oldEntity=" << oldEntity << "*******************"; - qDebug() << "EntityTree::updateEntity(modelID, properties) oldEntity=" << oldEntity; + qDebug() << "EntityTree::updateEntity(entityID, properties) ********** COPY PROPERTIES FROM oldEntity=" << oldEntity << "*******************"; + qDebug() << "EntityTree::updateEntity(entityID, properties) oldEntity=" << oldEntity; oldProps.debugDump(); - qDebug() << "EntityTree::updateEntity(modelID, properties) line:" << __LINE__ << "about to call updateItem.setProperties(oldProps);"; + qDebug() << "EntityTree::updateEntity(entityID, properties) line:" << __LINE__ << "about to call updateItem.setProperties(oldProps);"; } updateItem.setProperties(oldProps, true); // force copy if (wantDebug) { - qDebug() << "EntityTree::updateEntity(modelID, properties) line:" << __LINE__ << "updateItem:"; + qDebug() << "EntityTree::updateEntity(entityID, properties) line:" << __LINE__ << "updateItem:"; updateItem.debugDump(); } } else { if (wantDebug) { - qDebug() << "EntityTree::updateEntity(modelID, properties) WAIT WHAT!!! COULDN'T FIND oldEntity=" << oldEntity; + qDebug() << "EntityTree::updateEntity(entityID, properties) WAIT WHAT!!! COULDN'T FIND oldEntity=" << oldEntity; } } } updateItem.setProperties(properties); if (wantDebug) { - qDebug() << "EntityTree::updateEntity(modelID, properties) line:" << __LINE__ << "updateItem:"; + qDebug() << "EntityTree::updateEntity(entityID, properties) line:" << __LINE__ << "updateItem:"; updateItem.debugDump(); } storeEntity(updateItem); } -void EntityTree::addEntity(const EntityItemID& modelID, const EntityItemProperties& properties) { - EntityItem updateItem(modelID, properties); +void EntityTree::addEntity(const EntityItemID& entityID, const EntityItemProperties& properties) { + EntityItem updateItem(entityID, properties); storeEntity(updateItem); } @@ -413,18 +413,18 @@ bool DeleteEntityOperator::PostRecursion(OctreeElement* element) { return keepSearching; // if we haven't yet found it, keep looking } -void EntityTree::deleteEntity(const EntityItemID& modelID) { +void EntityTree::deleteEntity(const EntityItemID& entityID) { // NOTE: callers must lock the tree before using this method // First, look for the existing model in the tree.. - DeleteEntityOperator theOperator(this, modelID); + DeleteEntityOperator theOperator(this, entityID); recurseTreeWithOperator(&theOperator); _isDirty = true; bool wantDebug = false; if (wantDebug) { - EntityTreeElement* containingElement = getContainingElement(modelID); + EntityTreeElement* containingElement = getContainingElement(entityID); qDebug() << "EntityTree::storeEntity().... after store... containingElement=" << containingElement; } } @@ -433,9 +433,9 @@ void EntityTree::deleteEntitys(QSet modelIDs) { // NOTE: callers must lock the tree before using this method DeleteEntityOperator theOperator(this); - foreach(const EntityItemID& modelID, modelIDs) { + foreach(const EntityItemID& entityID, modelIDs) { // First, look for the existing model in the tree.. - theOperator.modelToDelete(modelID); + theOperator.modelToDelete(entityID); } recurseTreeWithOperator(&theOperator); @@ -443,8 +443,8 @@ void EntityTree::deleteEntitys(QSet modelIDs) { bool wantDebug = false; if (wantDebug) { - foreach(const EntityItemID& modelID, modelIDs) { - EntityTreeElement* containingElement = getContainingElement(modelID); + foreach(const EntityItemID& entityID, modelIDs) { + EntityTreeElement* containingElement = getContainingElement(entityID); qDebug() << "EntityTree::storeEntity().... after store... containingElement=" << containingElement; } } @@ -487,19 +487,19 @@ void EntityTree::handleAddEntityResponse(const QByteArray& packet) { memcpy(&creatorTokenID, dataAt, sizeof(creatorTokenID)); dataAt += sizeof(creatorTokenID); - uint32_t modelID; - memcpy(&modelID, dataAt, sizeof(modelID)); - dataAt += sizeof(modelID); + uint32_t entityID; + memcpy(&entityID, dataAt, sizeof(entityID)); + dataAt += sizeof(entityID); if (wantDebug) { qDebug() << " creatorTokenID=" << creatorTokenID; - qDebug() << " modelID=" << modelID; + qDebug() << " entityID=" << entityID; } // update models in our tree bool assumeEntityFound = !getIsViewing(); // if we're not a viewing tree, then we don't have to find the actual model FindAndUpdateEntityItemIDArgs args = { - modelID, + entityID, creatorTokenID, false, assumeEntityFound, @@ -507,7 +507,7 @@ void EntityTree::handleAddEntityResponse(const QByteArray& packet) { }; if (wantDebug) { - qDebug() << "looking for creatorTokenID=" << creatorTokenID << " modelID=" << modelID + qDebug() << "looking for creatorTokenID=" << creatorTokenID << " entityID=" << entityID << " getIsViewing()=" << getIsViewing(); } lockForWrite(); @@ -638,24 +638,24 @@ void EntityTree::findEntities(const AACube& cube, QVector foundEnti } const EntityItem* EntityTree::findEntityByID(uint32_t id, bool alreadyLocked) const { - EntityItemID modelID(id); + EntityItemID entityID(id); bool wantDebug = false; if (wantDebug) { qDebug() << "EntityTree::findEntityByID()..."; qDebug() << " id=" << id; - qDebug() << " modelID=" << modelID; + qDebug() << " entityID=" << entityID; qDebug() << "_modelToElementMap=" << _modelToElementMap; } - return findEntityByEntityItemID(modelID); + return findEntityByEntityItemID(entityID); } -const EntityItem* EntityTree::findEntityByEntityItemID(const EntityItemID& modelID) const { +const EntityItem* EntityTree::findEntityByEntityItemID(const EntityItemID& entityID) const { const EntityItem* foundEntity = NULL; - EntityTreeElement* containingElement = getContainingElement(modelID); + EntityTreeElement* containingElement = getContainingElement(entityID); if (containingElement) { - foundEntity = containingElement->getEntityWithEntityItemID(modelID); + foundEntity = containingElement->getEntityWithEntityItemID(entityID); } return foundEntity; } @@ -829,10 +829,10 @@ bool EntityTree::encodeEntitysDeletedSince(OCTREE_PACKET_SEQUENCE sequenceNumber // if the timestamp is more recent then out last sent time, include it if (iterator.key() > sinceTime) { - uint32_t modelID = values.at(valueItem); - memcpy(copyAt, &modelID, sizeof(modelID)); - copyAt += sizeof(modelID); - outputLength += sizeof(modelID); + uint32_t entityID = values.at(valueItem); + memcpy(copyAt, &entityID, sizeof(entityID)); + copyAt += sizeof(entityID); + outputLength += sizeof(entityID); numberOfIds++; // check to make sure we have room for one more id... @@ -916,12 +916,12 @@ void EntityTree::processEraseMessage(const QByteArray& dataByteArray, const Shar break; // bail to prevent buffer overflow } - uint32_t modelID = 0; // placeholder for now - memcpy(&modelID, dataAt, sizeof(modelID)); - dataAt += sizeof(modelID); - processedBytes += sizeof(modelID); + uint32_t entityID = 0; // placeholder for now + memcpy(&entityID, dataAt, sizeof(entityID)); + dataAt += sizeof(entityID); + processedBytes += sizeof(entityID); - EntityItemID entityItemID(modelID); + EntityItemID entityItemID(entityID); modelItemIDsToDelete << entityItemID; } deleteEntitys(modelItemIDsToDelete); diff --git a/libraries/entities/src/EntityTreeElement.cpp b/libraries/entities/src/EntityTreeElement.cpp index 7eaaa1c716..953d3718d6 100644 --- a/libraries/entities/src/EntityTreeElement.cpp +++ b/libraries/entities/src/EntityTreeElement.cpp @@ -1,6 +1,6 @@ // // EntityTreeElement.cpp -// libraries/models/src +// libraries/entities/src // // Created by Brad Hefta-Gaub on 12/4/13. // Copyright 2013 High Fidelity, Inc. @@ -51,8 +51,8 @@ EntityTreeElement* EntityTreeElement::addChildAtIndex(int index) { } -// TODO: This will attempt to store as many models as will fit in the packetData, if an individual model won't -// fit, but some models did fit, then the element outputs what can fit. Once the general Octree::encodeXXX() +// TODO: This will attempt to store as many entities as will fit in the packetData, if an individual entity won't +// fit, but some entities did fit, then the element outputs what can fit. Once the general Octree::encodeXXX() // process supports partial encoding of an octree element, this will need to be updated to handle spanning its // contents across multiple packets. OctreeElement::AppendState EntityTreeElement::appendElementData(OctreePacketData* packetData, @@ -62,35 +62,35 @@ OctreeElement::AppendState EntityTreeElement::appendElementData(OctreePacketData // first, check the params.extraEncodeData to see if there's any partial re-encode data for this element OctreeElementExtraEncodeData* extraEncodeData = params.extraEncodeData; - EntityTreeElementExtraEncodeData* modelTreeElementExtraEncodeData = NULL; + EntityTreeElementExtraEncodeData* entityTreeElementExtraEncodeData = NULL; bool hadElementExtraData = false; if (extraEncodeData && extraEncodeData->contains(this)) { - modelTreeElementExtraEncodeData = static_cast(extraEncodeData->value(this)); + entityTreeElementExtraEncodeData = static_cast(extraEncodeData->value(this)); hadElementExtraData = true; } else { // if there wasn't one already, then create one - modelTreeElementExtraEncodeData = new EntityTreeElementExtraEncodeData(); + entityTreeElementExtraEncodeData = new EntityTreeElementExtraEncodeData(); } LevelDetails elementLevel = packetData->startLevel(); - // write our models out... first determine which of the models are in view based on our params + // write our entities out... first determine which of the entities are in view based on our params uint16_t numberOfEntities = 0; uint16_t actualNumberOfEntities = 0; QVector indexesOfEntitiesToInclude; for (uint16_t i = 0; i < _entityItems->size(); i++) { - const EntityItem& model = (*_entityItems)[i]; + const EntityItem& entity = (*_entityItems)[i]; bool includeThisEntity = true; if (hadElementExtraData) { - includeThisEntity = modelTreeElementExtraEncodeData->includedItems.contains(model.getEntityItemID()); + includeThisEntity = entityTreeElementExtraEncodeData->includedItems.contains(entity.getEntityItemID()); } if (includeThisEntity && params.viewFrustum) { - AACube modelCube = model.getAACube(); - modelCube.scale(TREE_SCALE); - if (params.viewFrustum->cubeInFrustum(modelCube) == ViewFrustum::OUTSIDE) { + AACube entityCube = entity.getAACube(); + entityCube.scale(TREE_SCALE); + if (params.viewFrustum->cubeInFrustum(entityCube) == ViewFrustum::OUTSIDE) { includeThisEntity = false; // out of view, don't include it } } @@ -106,30 +106,30 @@ OctreeElement::AppendState EntityTreeElement::appendElementData(OctreePacketData if (successAppendEntityCount) { foreach (uint16_t i, indexesOfEntitiesToInclude) { - const EntityItem& model = (*_entityItems)[i]; + const EntityItem& entity = (*_entityItems)[i]; - LevelDetails modelLevel = packetData->startLevel(); + LevelDetails entityLevel = packetData->startLevel(); - OctreeElement::AppendState appendEntityState = model.appendEntityData(packetData, params, modelTreeElementExtraEncodeData); + OctreeElement::AppendState appendEntityState = entity.appendEntityData(packetData, params, entityTreeElementExtraEncodeData); - // If none of this model data was able to be appended, then discard it - // and don't include it in our model count + // If none of this entity data was able to be appended, then discard it + // and don't include it in our entity count if (appendEntityState == OctreeElement::NONE) { - packetData->discardLevel(modelLevel); + packetData->discardLevel(entityLevel); } else { // If either ALL or some of it got appended, then end the level (commit it) - // and include the model in our final count of models - packetData->endLevel(modelLevel); + // and include the entity in our final count of entities + packetData->endLevel(entityLevel); actualNumberOfEntities++; } - // If the model item got completely appended, then we can remove it from the extra encode data + // If the entity item got completely appended, then we can remove it from the extra encode data if (appendEntityState == OctreeElement::COMPLETED) { - modelTreeElementExtraEncodeData->includedItems.remove(model.getEntityItemID()); + entityTreeElementExtraEncodeData->includedItems.remove(entity.getEntityItemID()); } - // If any part of the model items didn't fit, then the element is considered partial - // NOTE: if the model item didn't fit or only partially fit, then the model item should have + // If any part of the entity items didn't fit, then the element is considered partial + // NOTE: if the entity item didn't fit or only partially fit, then the entity item should have // added itself to the extra encode data. if (appendEntityState != OctreeElement::COMPLETED) { appendElementState = OctreeElement::PARTIAL; @@ -137,32 +137,32 @@ OctreeElement::AppendState EntityTreeElement::appendElementData(OctreePacketData } } - // If we were provided with extraEncodeData, and we allocated and/or got modelTreeElementExtraEncodeData + // If we were provided with extraEncodeData, and we allocated and/or got entityTreeElementExtraEncodeData // then we need to do some additional processing, namely make sure our extraEncodeData is up to date for // this octree element. - if (extraEncodeData && modelTreeElementExtraEncodeData) { + if (extraEncodeData && entityTreeElementExtraEncodeData) { // If after processing we have some includedItems left in it, then make sure we re-add it back to our map - if (modelTreeElementExtraEncodeData->includedItems.size()) { - extraEncodeData->insert(this, modelTreeElementExtraEncodeData); + if (entityTreeElementExtraEncodeData->includedItems.size()) { + extraEncodeData->insert(this, entityTreeElementExtraEncodeData); } else { // otherwise, clean things up... extraEncodeData->remove(this); - delete modelTreeElementExtraEncodeData; + delete entityTreeElementExtraEncodeData; } } - // Determine if no models at all were able to fit + // Determine if no entities at all were able to fit bool noEntitiesFit = (numberOfEntities > 0 && actualNumberOfEntities == 0); - // If we wrote fewer models than we expected, update the number of models in our packet + // If we wrote fewer entities than we expected, update the number of entities in our packet bool successUpdateEntityCount = true; if (!noEntitiesFit && numberOfEntities != actualNumberOfEntities) { successUpdateEntityCount = packetData->updatePriorBytes(numberOfEntitiesOffset, (const unsigned char*)&actualNumberOfEntities, sizeof(actualNumberOfEntities)); } - // If we weren't able to update our model count, or we couldn't fit any models, then + // If we weren't able to update our entity count, or we couldn't fit any entities, then // we should discard our element and return a result of NONE if (!successUpdateEntityCount || noEntitiesFit) { packetData->discardLevel(elementLevel); @@ -174,15 +174,15 @@ OctreeElement::AppendState EntityTreeElement::appendElementData(OctreePacketData return appendElementState; } -bool EntityTreeElement::containsEntityBounds(const EntityItem& model) const { - glm::vec3 clampedMin = glm::clamp(model.getMinimumPoint(), 0.0f, 1.0f); - glm::vec3 clampedMax = glm::clamp(model.getMaximumPoint(), 0.0f, 1.0f); +bool EntityTreeElement::containsEntityBounds(const EntityItem& entity) const { + glm::vec3 clampedMin = glm::clamp(entity.getMinimumPoint(), 0.0f, 1.0f); + glm::vec3 clampedMax = glm::clamp(entity.getMaximumPoint(), 0.0f, 1.0f); return _cube.contains(clampedMin) && _cube.contains(clampedMax); } -bool EntityTreeElement::bestFitEntityBounds(const EntityItem& model) const { - glm::vec3 clampedMin = glm::clamp(model.getMinimumPoint(), 0.0f, 1.0f); - glm::vec3 clampedMax = glm::clamp(model.getMaximumPoint(), 0.0f, 1.0f); +bool EntityTreeElement::bestFitEntityBounds(const EntityItem& entity) const { + glm::vec3 clampedMin = glm::clamp(entity.getMinimumPoint(), 0.0f, 1.0f); + glm::vec3 clampedMax = glm::clamp(entity.getMaximumPoint(), 0.0f, 1.0f); if (_cube.contains(clampedMin) && _cube.contains(clampedMax)) { int childForMinimumPoint = getMyChildContainingPoint(clampedMin); int childForMaximumPoint = getMyChildContainingPoint(clampedMax); @@ -192,7 +192,7 @@ bool EntityTreeElement::bestFitEntityBounds(const EntityItem& model) const { return true; } // If I contain both the minimum and maximum point, but two different children of mine - // contain those points, then I am the best fit for that model + // contain those points, then I am the best fit for that entity if (childForMinimumPoint != childForMaximumPoint) { return true; } @@ -202,24 +202,24 @@ bool EntityTreeElement::bestFitEntityBounds(const EntityItem& model) const { void EntityTreeElement::update(EntityTreeUpdateArgs& args) { args._totalElements++; - // update our contained models - QList::iterator modelItr = _entityItems->begin(); - while(modelItr != _entityItems->end()) { - EntityItem& model = (*modelItr); + // update our contained entities + QList::iterator entityItr = _entityItems->begin(); + while(entityItr != _entityItems->end()) { + EntityItem& entity = (*entityItr); args._totalItems++; // TODO: this _lastChanged isn't actually changing because we're not marking this element as changed. // how do we want to handle this??? We really only want to consider an element changed when it is // edited... not just animated... - model.update(_lastChanged); + entity.update(_lastChanged); - // If the model wants to die, or if it's left our bounding box, then move it - // into the arguments moving models. These will be added back or deleted completely - if (model.getShouldBeDeleted() || !bestFitEntityBounds(model)) { - args._movingEntities.push_back(model); + // If the entity wants to die, or if it's left our bounding box, then move it + // into the arguments moving entities. These will be added back or deleted completely + if (entity.getShouldBeDeleted() || !bestFitEntityBounds(entity)) { + args._movingEntities.push_back(entity); - // erase this model - modelItr = _entityItems->erase(modelItr); + // erase this entity + entityItr = _entityItems->erase(entityItr); args._movingItems++; @@ -227,11 +227,11 @@ void EntityTreeElement::update(EntityTreeUpdateArgs& args) { markWithChangedTime(); // TODO: is this a good place to change the containing element map??? - qDebug() << "EntityTreeElement::update()... calling _myTree->setContainingElement(model.getEntityItemID(), NULL); ********"; - _myTree->setContainingElement(model.getEntityItemID(), NULL); + qDebug() << "EntityTreeElement::update()... calling _myTree->setContainingElement(entity.getEntityItemID(), NULL); ********"; + _myTree->setContainingElement(entity.getEntityItemID(), NULL); } else { - ++modelItr; + ++entityItr; } } } @@ -240,7 +240,7 @@ bool EntityTreeElement::findDetailedRayIntersection(const glm::vec3& origin, con bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face, void** intersectedObject) { - // only called if we do intersect our bounding cube, but find if we actually intersect with models... + // only called if we do intersect our bounding cube, but find if we actually intersect with entities... QList::iterator entityItr = _entityItems->begin(); QList::const_iterator entityEnd = _entityItems->end(); @@ -350,7 +350,7 @@ bool EntityTreeElement::findSpherePenetration(const glm::vec3& center, float rad return false; } -// TODO: the old model code has support for sittingPoints... need to determine how to handle this... +// TODO: the old entity code has support for sittingPoints... need to determine how to handle this... // for local editors, the old updateModels(id, properties) had this code... // if (found) { // thisModel.setProperties(properties); @@ -368,7 +368,7 @@ bool EntityTreeElement::updateEntity(const EntityItem& entity) { // NOTE: this method must first lookup the entity by ID, hence it is O(N) // and "entity is not found" is worst-case (full N) but maybe we don't care? - // (guaranteed that num entitys per elemen is small?) + // (guaranteed that num entities per elemen is small?) uint16_t numberOfEntities = _entityItems->size(); for (uint16_t i = 0; i < numberOfEntities; i++) { EntityItem& thisEntity = (*_entityItems)[i]; @@ -437,9 +437,9 @@ void EntityTreeElement::updateEntityItemID(FindAndUpdateEntityItemIDArgs* args) } } - // if we're in an isViewing tree, we also need to look for an kill any viewed entitys + // if we're in an isViewing tree, we also need to look for an kill any viewed entities if (!args->viewedEntityFound && args->isViewing) { - if (thisEntity.getCreatorTokenID() == UNKNOWN_MODEL_TOKEN && thisEntity.getID() == args->entityID) { + if (thisEntity.getCreatorTokenID() == UNKNOWN_ENTITY_TOKEN && thisEntity.getID() == args->entityID) { if (wantDebug) { qDebug() << "EntityTreeElement::updateEntityItemID()... VIEWED entity FOUND??? " @@ -502,7 +502,7 @@ void EntityTreeElement::getEntities(const AACube& box, QVector& fou } const EntityItem* EntityTreeElement::getEntityWithID(uint32_t id) const { - // NOTE: this lookup is O(N) but maybe we don't care? (guaranteed that num entitys per elemen is small?) + // NOTE: this lookup is O(N) but maybe we don't care? (guaranteed that num entities per elemen is small?) const EntityItem* foundEntity = NULL; uint16_t numberOfEntities = _entityItems->size(); for (uint16_t i = 0; i < numberOfEntities; i++) { @@ -515,7 +515,7 @@ const EntityItem* EntityTreeElement::getEntityWithID(uint32_t id) const { } const EntityItem* EntityTreeElement::getEntityWithEntityItemID(const EntityItemID& id) const { - // NOTE: this lookup is O(N) but maybe we don't care? (guaranteed that num entitys per elemen is small?) + // NOTE: this lookup is O(N) but maybe we don't care? (guaranteed that num entities per elemen is small?) const EntityItem* foundEntity = NULL; uint16_t numberOfEntities = _entityItems->size(); for (uint16_t i = 0; i < numberOfEntities; i++) { @@ -571,7 +571,7 @@ int EntityTreeElement::readElementDataFromBuffer(const unsigned char* data, int int expectedBytesPerEntity = EntityItem::expectedBytes(); if (bytesLeftToRead >= (int)sizeof(numberOfEntities)) { - // read our entitys in.... + // read our entities in.... numberOfEntities = *(uint16_t*)dataAt; dataAt += sizeof(numberOfEntities); diff --git a/libraries/networking/src/PacketHeaders.cpp b/libraries/networking/src/PacketHeaders.cpp index 1dbf81fdea..679b33ee0f 100644 --- a/libraries/networking/src/PacketHeaders.cpp +++ b/libraries/networking/src/PacketHeaders.cpp @@ -75,7 +75,7 @@ PacketVersion versionForPacketType(PacketType type) { case PacketTypeParticleErase: return 1; case PacketTypeEntityData: - return VERSION_MODELS_SUPPORT_SPLIT_MTU; + return VERSION_ENTITIES_SUPPORT_SPLIT_MTU; case PacketTypeEntityErase: return 1; default: diff --git a/libraries/networking/src/PacketHeaders.h b/libraries/networking/src/PacketHeaders.h index a57c516b5e..afd1843379 100644 --- a/libraries/networking/src/PacketHeaders.h +++ b/libraries/networking/src/PacketHeaders.h @@ -111,8 +111,8 @@ PacketType packetTypeForPacket(const char* packet); int arithmeticCodingValueFromBuffer(const char* checkValue); int numBytesArithmeticCodingFromBuffer(const char* checkValue); -const PacketVersion VERSION_MODELS_HAVE_ANIMATION = 1; +const PacketVersion VERSION_ENTITIES_HAVE_ANIMATION = 1; const PacketVersion VERSION_ROOT_ELEMENT_HAS_DATA = 2; -const PacketVersion VERSION_MODELS_SUPPORT_SPLIT_MTU = 3; +const PacketVersion VERSION_ENTITIES_SUPPORT_SPLIT_MTU = 3; #endif // hifi_PacketHeaders_h