more renaming work

This commit is contained in:
ZappoMan 2014-06-27 09:14:17 -07:00
parent d25ba66b21
commit ad7a768fff
7 changed files with 224 additions and 225 deletions

View file

@ -57,12 +57,12 @@ void EntityItem::handleAddEntityResponse(const QByteArray& packet) {
memcpy(&creatorTokenID, dataAt, sizeof(creatorTokenID)); memcpy(&creatorTokenID, dataAt, sizeof(creatorTokenID));
dataAt += sizeof(creatorTokenID); dataAt += sizeof(creatorTokenID);
uint32_t modelItemID; uint32_t entityItemID;
memcpy(&modelItemID, dataAt, sizeof(modelItemID)); memcpy(&entityItemID, dataAt, sizeof(entityItemID));
dataAt += sizeof(modelItemID); dataAt += sizeof(entityItemID);
// add our token to id mapping // add our token to id mapping
_tokenIDsToIDs[creatorTokenID] = modelItemID; _tokenIDsToIDs[creatorTokenID] = entityItemID;
} }
EntityItem::EntityItem() { EntityItem::EntityItem() {
@ -70,9 +70,9 @@ EntityItem::EntityItem() {
init(glm::vec3(0,0,0), 0, noColor, NEW_MODEL); init(glm::vec3(0,0,0), 0, noColor, NEW_MODEL);
} }
void EntityItem::initFromEntityItemID(const EntityItemID& modelItemID) { void EntityItem::initFromEntityItemID(const EntityItemID& entityItemID) {
_id = modelItemID.id; _id = entityItemID.id;
_creatorTokenID = modelItemID.creatorTokenID; _creatorTokenID = entityItemID.creatorTokenID;
// init values with defaults before calling setProperties // init values with defaults before calling setProperties
uint64_t now = usecTimestampNow(); uint64_t now = usecTimestampNow();
@ -83,7 +83,7 @@ void EntityItem::initFromEntityItemID(const EntityItemID& modelItemID) {
_radius = 0; _radius = 0;
rgbColor noColor = { 0, 0, 0 }; rgbColor noColor = { 0, 0, 0 };
memcpy(_color, noColor, sizeof(_color)); memcpy(_color, noColor, sizeof(_color));
_shouldDie = false; _shouldBeDeleted = false;
_modelURL = MODEL_DEFAULT_MODEL_URL; _modelURL = MODEL_DEFAULT_MODEL_URL;
_rotation = MODEL_DEFAULT_MODEL_ROTATION; _rotation = MODEL_DEFAULT_MODEL_ROTATION;
@ -98,12 +98,12 @@ void EntityItem::initFromEntityItemID(const EntityItemID& modelItemID) {
_lastAnimated = now; _lastAnimated = now;
} }
EntityItem::EntityItem(const EntityItemID& modelItemID) { EntityItem::EntityItem(const EntityItemID& entityItemID) {
initFromEntityItemID(modelItemID); initFromEntityItemID(entityItemID);
} }
EntityItem::EntityItem(const EntityItemID& modelItemID, const EntityItemProperties& properties) { EntityItem::EntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) {
initFromEntityItemID(modelItemID); initFromEntityItemID(entityItemID);
setProperties(properties, true); // force copy setProperties(properties, true); // force copy
} }
@ -124,7 +124,7 @@ void EntityItem::init(glm::vec3 position, float radius, rgbColor color, uint32_t
_position = position; _position = position;
_radius = radius; _radius = radius;
memcpy(_color, color, sizeof(_color)); memcpy(_color, color, sizeof(_color));
_shouldDie = false; _shouldBeDeleted = false;
_modelURL = MODEL_DEFAULT_MODEL_URL; _modelURL = MODEL_DEFAULT_MODEL_URL;
_rotation = MODEL_DEFAULT_MODEL_ROTATION; _rotation = MODEL_DEFAULT_MODEL_ROTATION;
@ -394,7 +394,7 @@ OctreeElement::AppendState EntityItem::appendEntityData(OctreePacketData* packet
if (requestedProperties.getHasProperty(PROP_SHOULD_BE_DELETED)) { if (requestedProperties.getHasProperty(PROP_SHOULD_BE_DELETED)) {
//qDebug() << "PROP_SHOULD_BE_DELETED requested..."; //qDebug() << "PROP_SHOULD_BE_DELETED requested...";
LevelDetails propertyLevel = packetData->startLevel(); LevelDetails propertyLevel = packetData->startLevel();
successPropertyFits = packetData->appendValue(getShouldDie()); successPropertyFits = packetData->appendValue(getShouldBeDeleted());
if (successPropertyFits) { if (successPropertyFits) {
propertyFlags |= PROP_SHOULD_BE_DELETED; propertyFlags |= PROP_SHOULD_BE_DELETED;
propertiesDidntFit -= PROP_SHOULD_BE_DELETED; propertiesDidntFit -= PROP_SHOULD_BE_DELETED;
@ -507,10 +507,10 @@ int EntityItem::oldVersionReadEntityDataFromBuffer(const unsigned char* data, in
dataAt += sizeof(_color); dataAt += sizeof(_color);
bytesRead += sizeof(_color); bytesRead += sizeof(_color);
// shouldDie // shouldBeDeleted
memcpy(&_shouldDie, dataAt, sizeof(_shouldDie)); memcpy(&_shouldBeDeleted, dataAt, sizeof(_shouldBeDeleted));
dataAt += sizeof(_shouldDie); dataAt += sizeof(_shouldBeDeleted);
bytesRead += sizeof(_shouldDie); bytesRead += sizeof(_shouldBeDeleted);
// modelURL // modelURL
uint16_t modelURLLength; uint16_t modelURLLength;
@ -713,9 +713,9 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef
// PROP_SHOULD_BE_DELETED // PROP_SHOULD_BE_DELETED
if (propertyFlags.getHasProperty(PROP_SHOULD_BE_DELETED)) { if (propertyFlags.getHasProperty(PROP_SHOULD_BE_DELETED)) {
memcpy(&_shouldDie, dataAt, sizeof(_shouldDie)); memcpy(&_shouldBeDeleted, dataAt, sizeof(_shouldBeDeleted));
dataAt += sizeof(_shouldDie); dataAt += sizeof(_shouldBeDeleted);
bytesRead += sizeof(_shouldDie); bytesRead += sizeof(_shouldBeDeleted);
} }
} }
return bytesRead; return bytesRead;
@ -831,11 +831,11 @@ EntityItem EntityItem::fromEditPacket(const unsigned char* data, int length, int
processedBytes += sizeof(newEntityItem._color); processedBytes += sizeof(newEntityItem._color);
} }
// shouldDie // shouldBeDeleted
if (isNewEntityItem || ((packetContainsBits & MODEL_PACKET_CONTAINS_SHOULDDIE) == MODEL_PACKET_CONTAINS_SHOULDDIE)) { if (isNewEntityItem || ((packetContainsBits & MODEL_PACKET_CONTAINS_SHOULDDIE) == MODEL_PACKET_CONTAINS_SHOULDDIE)) {
memcpy(&newEntityItem._shouldDie, dataAt, sizeof(newEntityItem._shouldDie)); memcpy(&newEntityItem._shouldBeDeleted, dataAt, sizeof(newEntityItem._shouldBeDeleted));
dataAt += sizeof(newEntityItem._shouldDie); dataAt += sizeof(newEntityItem._shouldBeDeleted);
processedBytes += sizeof(newEntityItem._shouldDie); processedBytes += sizeof(newEntityItem._shouldBeDeleted);
} }
// modelURL // modelURL
@ -910,7 +910,7 @@ EntityItem EntityItem::fromEditPacket(const unsigned char* data, int length, int
void EntityItem::debugDump() const { void EntityItem::debugDump() const {
qDebug("EntityItem id :%u", _id); qDebug("EntityItem id :%u", _id);
qDebug(" edited ago:%f", getEditedAgo()); qDebug(" edited ago:%f", getEditedAgo());
qDebug(" should die:%s", debug::valueOf(getShouldDie())); qDebug(" should die:%s", debug::valueOf(getShouldBeDeleted()));
qDebug(" position:%f,%f,%f", _position.x, _position.y, _position.z); qDebug(" position:%f,%f,%f", _position.x, _position.y, _position.z);
qDebug(" radius:%f", getRadius()); qDebug(" radius:%f", getRadius());
qDebug(" color:%d,%d,%d", _color[0], _color[1], _color[2]); qDebug(" color:%d,%d,%d", _color[0], _color[1], _color[2]);
@ -1004,10 +1004,10 @@ bool EntityItem::encodeEntityEditMessageDetails(PacketType command, EntityItemID
// shoulDie // shoulDie
if (isNewEntityItem || ((packetContainsBits & MODEL_PACKET_CONTAINS_SHOULDDIE) == MODEL_PACKET_CONTAINS_SHOULDDIE)) { if (isNewEntityItem || ((packetContainsBits & MODEL_PACKET_CONTAINS_SHOULDDIE) == MODEL_PACKET_CONTAINS_SHOULDDIE)) {
bool shouldDie = properties.getShouldDie(); bool shouldBeDeleted = properties.getShouldBeDeleted();
memcpy(copyAt, &shouldDie, sizeof(shouldDie)); memcpy(copyAt, &shouldBeDeleted, sizeof(shouldBeDeleted));
copyAt += sizeof(shouldDie); copyAt += sizeof(shouldBeDeleted);
sizeOut += sizeof(shouldDie); sizeOut += sizeof(shouldBeDeleted);
} }
// modelURL // modelURL
@ -1193,7 +1193,7 @@ QVector<glm::quat> EntityItem::getAnimationFrame() {
void EntityItem::update(const quint64& updateTime) { void EntityItem::update(const quint64& updateTime) {
_lastUpdated = updateTime; _lastUpdated = updateTime;
setShouldDie(getShouldDie()); setShouldBeDeleted(getShouldBeDeleted());
quint64 now = usecTimestampNow(); quint64 now = usecTimestampNow();
@ -1239,7 +1239,7 @@ EntityItemProperties::EntityItemProperties() :
_position(0), _position(0),
_color(), _color(),
_radius(MODEL_DEFAULT_RADIUS), _radius(MODEL_DEFAULT_RADIUS),
_shouldDie(false), _shouldBeDeleted(false),
_modelURL(""), _modelURL(""),
_rotation(MODEL_DEFAULT_MODEL_ROTATION), _rotation(MODEL_DEFAULT_MODEL_ROTATION),
_animationURL(""), _animationURL(""),
@ -1255,7 +1255,7 @@ EntityItemProperties::EntityItemProperties() :
_positionChanged(false), _positionChanged(false),
_colorChanged(false), _colorChanged(false),
_radiusChanged(false), _radiusChanged(false),
_shouldDieChanged(false), _shouldBeDeletedChanged(false),
_modelURLChanged(false), _modelURLChanged(false),
_rotationChanged(false), _rotationChanged(false),
_animationURLChanged(false), _animationURLChanged(false),
@ -1292,7 +1292,7 @@ uint16_t EntityItemProperties::getChangedBits() const {
changedBits += MODEL_PACKET_CONTAINS_COLOR; changedBits += MODEL_PACKET_CONTAINS_COLOR;
} }
if (_shouldDieChanged) { if (_shouldBeDeletedChanged) {
changedBits += MODEL_PACKET_CONTAINS_SHOULDDIE; changedBits += MODEL_PACKET_CONTAINS_SHOULDDIE;
} }
@ -1335,7 +1335,7 @@ QScriptValue EntityItemProperties::copyToScriptValue(QScriptEngine* engine) cons
properties.setProperty("radius", _radius); properties.setProperty("radius", _radius);
properties.setProperty("shouldDie", _shouldDie); properties.setProperty("shouldBeDeleted", _shouldBeDeleted);
properties.setProperty("modelURL", _modelURL); properties.setProperty("modelURL", _modelURL);
@ -1404,13 +1404,13 @@ void EntityItemProperties::copyFromScriptValue(const QScriptValue &object) {
} }
} }
QScriptValue shouldDie = object.property("shouldDie"); QScriptValue shouldBeDeleted = object.property("shouldBeDeleted");
if (shouldDie.isValid()) { if (shouldBeDeleted.isValid()) {
bool newShouldDie; bool newShouldBeDeleted;
newShouldDie = shouldDie.toVariant().toBool(); newShouldBeDeleted = shouldBeDeleted.toVariant().toBool();
if (_defaultSettings || newShouldDie != _shouldDie) { if (_defaultSettings || newShouldBeDeleted != _shouldBeDeleted) {
_shouldDie = newShouldDie; _shouldBeDeleted = newShouldBeDeleted;
_shouldDieChanged = true; _shouldBeDeletedChanged = true;
} }
} }
@ -1513,8 +1513,8 @@ void EntityItemProperties::copyToEntityItem(EntityItem& modelItem, bool forceCop
somethingChanged = true; somethingChanged = true;
} }
if (_shouldDieChanged || forceCopy) { if (_shouldBeDeletedChanged || forceCopy) {
modelItem.setShouldDie(_shouldDie); modelItem.setShouldBeDeleted(_shouldBeDeleted);
somethingChanged = true; somethingChanged = true;
} }
@ -1569,7 +1569,7 @@ void EntityItemProperties::copyFromEntityItem(const EntityItem& modelItem) {
_position = modelItem.getPosition() * (float) TREE_SCALE; _position = modelItem.getPosition() * (float) TREE_SCALE;
_color = modelItem.getXColor(); _color = modelItem.getXColor();
_radius = modelItem.getRadius() * (float) TREE_SCALE; _radius = modelItem.getRadius() * (float) TREE_SCALE;
_shouldDie = modelItem.getShouldDie(); _shouldBeDeleted = modelItem.getShouldBeDeleted();
_modelURL = modelItem.getModelURL(); _modelURL = modelItem.getModelURL();
_rotation = modelItem.getRotation(); _rotation = modelItem.getRotation();
_animationURL = modelItem.getAnimationURL(); _animationURL = modelItem.getAnimationURL();
@ -1585,7 +1585,7 @@ void EntityItemProperties::copyFromEntityItem(const EntityItem& modelItem) {
_colorChanged = false; _colorChanged = false;
_radiusChanged = false; _radiusChanged = false;
_shouldDieChanged = false; _shouldBeDeletedChanged = false;
_modelURLChanged = false; _modelURLChanged = false;
_rotationChanged = false; _rotationChanged = false;
_animationURLChanged = false; _animationURLChanged = false;

View file

@ -96,7 +96,7 @@ public:
const glm::vec3& getPosition() const { return _position; } const glm::vec3& getPosition() const { return _position; }
xColor getColor() const { return _color; } xColor getColor() const { return _color; }
float getRadius() const { return _radius; } float getRadius() const { return _radius; }
bool getShouldDie() const { return _shouldDie; } bool getShouldBeDeleted() const { return _shouldBeDeleted; }
const QString& getModelURL() const { return _modelURL; } const QString& getModelURL() const { return _modelURL; }
const glm::quat& getRotation() const { return _rotation; } const glm::quat& getRotation() const { return _rotation; }
@ -113,7 +113,7 @@ public:
void setPosition(const glm::vec3& value) { _position = value; _positionChanged = true; } void setPosition(const glm::vec3& value) { _position = value; _positionChanged = true; }
void setColor(const xColor& value) { _color = value; _colorChanged = true; } void setColor(const xColor& value) { _color = value; _colorChanged = true; }
void setRadius(float value) { _radius = value; _radiusChanged = true; } void setRadius(float value) { _radius = value; _radiusChanged = true; }
void setShouldDie(bool shouldDie) { _shouldDie = shouldDie; _shouldDieChanged = true; } void setShouldBeDeleted(bool shouldBeDeleted) { _shouldBeDeleted = shouldBeDeleted; _shouldBeDeletedChanged = true; }
// model related properties // model related properties
void setModelURL(const QString& url) { _modelURL = url; _modelURLChanged = true; } void setModelURL(const QString& url) { _modelURL = url; _modelURLChanged = true; }
@ -136,7 +136,7 @@ private:
glm::vec3 _position; glm::vec3 _position;
xColor _color; xColor _color;
float _radius; float _radius;
bool _shouldDie; /// to delete it bool _shouldBeDeleted; /// to delete it
QString _modelURL; QString _modelURL;
glm::quat _rotation; glm::quat _rotation;
@ -153,7 +153,7 @@ private:
bool _positionChanged; bool _positionChanged;
bool _colorChanged; bool _colorChanged;
bool _radiusChanged; bool _radiusChanged;
bool _shouldDieChanged; bool _shouldBeDeletedChanged;
bool _modelURLChanged; bool _modelURLChanged;
bool _rotationChanged; bool _rotationChanged;
@ -226,8 +226,8 @@ class EntityItem {
public: public:
EntityItem(); EntityItem();
EntityItem(const EntityItemID& modelItemID); EntityItem(const EntityItemID& entityItemID);
EntityItem(const EntityItemID& modelItemID, const EntityItemProperties& properties); EntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties);
/// creates an NEW model from an model add or edit message data buffer /// creates an NEW model from an model add or edit message data buffer
static EntityItem fromEditPacket(const unsigned char* data, int length, int& processedBytes, EntityTree* tree, bool& valid); static EntityItem fromEditPacket(const unsigned char* data, int length, int& processedBytes, EntityTree* tree, bool& valid);
@ -276,7 +276,7 @@ public:
float getEditedAgo() const { return static_cast<float>(usecTimestampNow() - _lastEdited) / static_cast<float>(USECS_PER_SECOND); } float getEditedAgo() const { return static_cast<float>(usecTimestampNow() - _lastEdited) / static_cast<float>(USECS_PER_SECOND); }
uint32_t getID() const { return _id; } uint32_t getID() const { return _id; }
void setID(uint32_t id) { _id = id; } void setID(uint32_t id) { _id = id; }
bool getShouldDie() const { return _shouldDie; } bool getShouldBeDeleted() const { return _shouldBeDeleted; }
uint32_t getCreatorTokenID() const { return _creatorTokenID; } uint32_t getCreatorTokenID() const { return _creatorTokenID; }
bool isNewlyCreated() const { return _newlyCreated; } bool isNewlyCreated() const { return _newlyCreated; }
bool isKnownID() const { return getID() != UNKNOWN_MODEL_ID; } bool isKnownID() const { return getID() != UNKNOWN_MODEL_ID; }
@ -293,7 +293,7 @@ public:
/// set radius in domain scale units (0.0 - 1.0) /// set radius in domain scale units (0.0 - 1.0)
void setRadius(float value) { _radius = value; } void setRadius(float value) { _radius = value; }
void setShouldDie(bool shouldDie) { _shouldDie = shouldDie; } void setShouldBeDeleted(bool shouldBeDeleted) { _shouldBeDeleted = shouldBeDeleted; }
void setCreatorTokenID(uint32_t creatorTokenID) { _creatorTokenID = creatorTokenID; } void setCreatorTokenID(uint32_t creatorTokenID) { _creatorTokenID = creatorTokenID; }
// model related properties // model related properties
@ -346,7 +346,7 @@ public:
static void cleanupLoadedAnimations(); static void cleanupLoadedAnimations();
protected: protected:
void initFromEntityItemID(const EntityItemID& modelItemID); 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_MODEL);
glm::vec3 _position; glm::vec3 _position;
@ -354,7 +354,7 @@ protected:
float _radius; float _radius;
uint32_t _id; uint32_t _id;
static uint32_t _nextID; static uint32_t _nextID;
bool _shouldDie; bool _shouldBeDeleted;
// model related items // model related items
QString _modelURL; QString _modelURL;

View file

@ -117,7 +117,7 @@ void EntityScriptingInterface::deleteEntity(EntityItemID entityID) {
// setup properties to kill the model // setup properties to kill the model
EntityItemProperties properties; EntityItemProperties properties;
properties.setShouldDie(true); properties.setShouldBeDeleted(true);
uint32_t actualID = entityID.id; uint32_t actualID = entityID.id;

View file

@ -385,9 +385,9 @@ bool DeleteEntityOperator::PreRecursion(OctreeElement* element) {
if (modelTreeElement == details.containingElement) { if (modelTreeElement == details.containingElement) {
// This is a good place to delete it!!! // This is a good place to delete it!!!
EntityItemID modelItemID = details.model->getEntityItemID(); EntityItemID entityItemID = details.model->getEntityItemID();
modelTreeElement->removeEntityWithEntityItemID(modelItemID); modelTreeElement->removeEntityWithEntityItemID(entityItemID);
_tree->setContainingElement(modelItemID, NULL); _tree->setContainingElement(entityItemID, NULL);
_foundCount++; _foundCount++;
} }
} }
@ -589,7 +589,7 @@ bool EntityTree::findInSphereOperation(OctreeElement* element, void* extraData)
// If this element contains the point, then search it... // If this element contains the point, then search it...
if (sphereIntersection) { if (sphereIntersection) {
EntityTreeElement* modelTreeElement = static_cast<EntityTreeElement*>(element); EntityTreeElement* modelTreeElement = static_cast<EntityTreeElement*>(element);
modelTreeElement->getEntitys(args->position, args->targetRadius, args->models); modelTreeElement->getEntities(args->position, args->targetRadius, args->models);
return true; // keep searching in case children have closer models return true; // keep searching in case children have closer models
} }
@ -622,7 +622,7 @@ bool EntityTree::findInCubeOperation(OctreeElement* element, void* extraData) {
const AACube& elementCube = element->getAACube(); const AACube& elementCube = element->getAACube();
if (elementCube.touches(args->_cube)) { if (elementCube.touches(args->_cube)) {
EntityTreeElement* modelTreeElement = static_cast<EntityTreeElement*>(element); EntityTreeElement* modelTreeElement = static_cast<EntityTreeElement*>(element);
modelTreeElement->getEntitys(args->_cube, args->_foundEntitys); modelTreeElement->getEntities(args->_cube, args->_foundEntitys);
return true; return true;
} }
return false; return false;
@ -740,21 +740,21 @@ void EntityTree::update() {
recurseTreeWithOperation(updateOperation, &args); recurseTreeWithOperation(updateOperation, &args);
// now add back any of the particles that moved elements.... // now add back any of the particles that moved elements....
int movingEntitys = args._movingEntitys.size(); int movingEntitys = args._movingEntities.size();
for (int i = 0; i < movingEntitys; i++) { for (int i = 0; i < movingEntitys; i++) {
bool shouldDie = args._movingEntitys[i].getShouldDie(); bool shouldDie = args._movingEntities[i].getShouldBeDeleted();
// if the particle is still inside our total bounds, then re-add it // if the particle is still inside our total bounds, then re-add it
AACube treeBounds = getRoot()->getAACube(); AACube treeBounds = getRoot()->getAACube();
if (!shouldDie && treeBounds.contains(args._movingEntitys[i].getPosition())) { if (!shouldDie && treeBounds.contains(args._movingEntities[i].getPosition())) {
storeEntity(args._movingEntitys[i]); storeEntity(args._movingEntities[i]);
} else { } else {
uint32_t modelItemID = args._movingEntitys[i].getID(); uint32_t entityItemID = args._movingEntities[i].getID();
quint64 deletedAt = usecTimestampNow(); quint64 deletedAt = usecTimestampNow();
_recentlyDeletedEntitysLock.lockForWrite(); _recentlyDeletedEntitysLock.lockForWrite();
_recentlyDeletedEntityItemIDs.insert(deletedAt, modelItemID); _recentlyDeletedEntityItemIDs.insert(deletedAt, entityItemID);
_recentlyDeletedEntitysLock.unlock(); _recentlyDeletedEntitysLock.unlock();
} }
} }
@ -922,33 +922,33 @@ void EntityTree::processEraseMessage(const QByteArray& dataByteArray, const Shar
dataAt += sizeof(modelID); dataAt += sizeof(modelID);
processedBytes += sizeof(modelID); processedBytes += sizeof(modelID);
EntityItemID modelItemID(modelID); EntityItemID entityItemID(modelID);
modelItemIDsToDelete << modelItemID; modelItemIDsToDelete << entityItemID;
} }
deleteEntitys(modelItemIDsToDelete); deleteEntitys(modelItemIDsToDelete);
} }
} }
EntityTreeElement* EntityTree::getContainingElement(const EntityItemID& modelItemID) const { EntityTreeElement* EntityTree::getContainingElement(const EntityItemID& entityItemID) const {
//qDebug() << "_modelToElementMap=" << _modelToElementMap; //qDebug() << "_modelToElementMap=" << _modelToElementMap;
// TODO: do we need to make this thread safe? Or is it acceptable as is // TODO: do we need to make this thread safe? Or is it acceptable as is
if (_modelToElementMap.contains(modelItemID)) { if (_modelToElementMap.contains(entityItemID)) {
return _modelToElementMap.value(modelItemID); return _modelToElementMap.value(entityItemID);
} }
return NULL; return NULL;
} }
void EntityTree::setContainingElement(const EntityItemID& modelItemID, EntityTreeElement* element) { void EntityTree::setContainingElement(const EntityItemID& entityItemID, EntityTreeElement* element) {
// TODO: do we need to make this thread safe? Or is it acceptable as is // TODO: do we need to make this thread safe? Or is it acceptable as is
if (element) { if (element) {
_modelToElementMap[modelItemID] = element; _modelToElementMap[entityItemID] = element;
} else { } else {
_modelToElementMap.remove(modelItemID); _modelToElementMap.remove(entityItemID);
} }
//qDebug() << "setContainingElement() modelItemID=" << modelItemID << "element=" << element; //qDebug() << "setContainingElement() entityItemID=" << entityItemID << "element=" << element;
//qDebug() << "AFTER _modelToElementMap=" << _modelToElementMap; //qDebug() << "AFTER _modelToElementMap=" << _modelToElementMap;
} }

View file

@ -50,7 +50,6 @@ public:
virtual bool rootElementHasData() const { return true; } virtual bool rootElementHasData() const { return true; }
virtual void update(); virtual void update();
void OLD__storeEntity(const EntityItem& model, const SharedNodePointer& senderNode = SharedNodePointer());
void storeEntity(const EntityItem& model, const SharedNodePointer& senderNode = SharedNodePointer()); void storeEntity(const EntityItem& model, const SharedNodePointer& senderNode = SharedNodePointer());
void updateEntity(const EntityItemID& modelID, const EntityItemProperties& properties); void updateEntity(const EntityItemID& modelID, const EntityItemProperties& properties);
void addEntity(const EntityItemID& modelID, const EntityItemProperties& properties); void addEntity(const EntityItemID& modelID, const EntityItemProperties& properties);
@ -90,8 +89,8 @@ public:
return _fbxService ? _fbxService->getGeometryForEntity(modelItem) : NULL; return _fbxService ? _fbxService->getGeometryForEntity(modelItem) : NULL;
} }
EntityTreeElement* getContainingElement(const EntityItemID& modelItemID) const; EntityTreeElement* getContainingElement(const EntityItemID& entityItemID) const;
void setContainingElement(const EntityItemID& modelItemID, EntityTreeElement* element); void setContainingElement(const EntityItemID& entityItemID, EntityTreeElement* element);
void debugDumpMap(); void debugDumpMap();
private: private:

View file

@ -75,9 +75,9 @@ OctreeElement::AppendState EntityTreeElement::appendElementData(OctreePacketData
LevelDetails elementLevel = packetData->startLevel(); LevelDetails elementLevel = packetData->startLevel();
// write our models out... first determine which of the models are in view based on our params // write our models out... first determine which of the models are in view based on our params
uint16_t numberOfEntitys = 0; uint16_t numberOfEntities = 0;
uint16_t actualNumberOfEntitys = 0; uint16_t actualNumberOfEntities = 0;
QVector<uint16_t> indexesOfEntitysToInclude; QVector<uint16_t> indexesOfEntitiesToInclude;
for (uint16_t i = 0; i < _entityItems->size(); i++) { for (uint16_t i = 0; i < _entityItems->size(); i++) {
const EntityItem& model = (*_entityItems)[i]; const EntityItem& model = (*_entityItems)[i];
@ -96,16 +96,16 @@ OctreeElement::AppendState EntityTreeElement::appendElementData(OctreePacketData
} }
if (includeThisEntity) { if (includeThisEntity) {
indexesOfEntitysToInclude << i; indexesOfEntitiesToInclude << i;
numberOfEntitys++; numberOfEntities++;
} }
} }
int numberOfEntitysOffset = packetData->getUncompressedByteOffset(); int numberOfEntitiesOffset = packetData->getUncompressedByteOffset();
bool successAppendEntityCount = packetData->appendValue(numberOfEntitys); bool successAppendEntityCount = packetData->appendValue(numberOfEntities);
if (successAppendEntityCount) { if (successAppendEntityCount) {
foreach (uint16_t i, indexesOfEntitysToInclude) { foreach (uint16_t i, indexesOfEntitiesToInclude) {
const EntityItem& model = (*_entityItems)[i]; const EntityItem& model = (*_entityItems)[i];
LevelDetails modelLevel = packetData->startLevel(); LevelDetails modelLevel = packetData->startLevel();
@ -120,7 +120,7 @@ OctreeElement::AppendState EntityTreeElement::appendElementData(OctreePacketData
// If either ALL or some of it got appended, then end the level (commit it) // 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 // and include the model in our final count of models
packetData->endLevel(modelLevel); packetData->endLevel(modelLevel);
actualNumberOfEntitys++; actualNumberOfEntities++;
} }
// If the model item got completely appended, then we can remove it from the extra encode data // If the model item got completely appended, then we can remove it from the extra encode data
@ -153,18 +153,18 @@ OctreeElement::AppendState EntityTreeElement::appendElementData(OctreePacketData
} }
// Determine if no models at all were able to fit // Determine if no models at all were able to fit
bool noEntitysFit = (numberOfEntitys > 0 && actualNumberOfEntitys == 0); 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 models than we expected, update the number of models in our packet
bool successUpdateEntityCount = true; bool successUpdateEntityCount = true;
if (!noEntitysFit && numberOfEntitys != actualNumberOfEntitys) { if (!noEntitiesFit && numberOfEntities != actualNumberOfEntities) {
successUpdateEntityCount = packetData->updatePriorBytes(numberOfEntitysOffset, successUpdateEntityCount = packetData->updatePriorBytes(numberOfEntitiesOffset,
(const unsigned char*)&actualNumberOfEntitys, sizeof(actualNumberOfEntitys)); (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 model count, or we couldn't fit any models, then
// we should discard our element and return a result of NONE // we should discard our element and return a result of NONE
if (!successUpdateEntityCount || noEntitysFit) { if (!successUpdateEntityCount || noEntitiesFit) {
packetData->discardLevel(elementLevel); packetData->discardLevel(elementLevel);
appendElementState = OctreeElement::NONE; appendElementState = OctreeElement::NONE;
} else { } else {
@ -215,8 +215,8 @@ void EntityTreeElement::update(EntityTreeUpdateArgs& args) {
// If the model wants to die, or if it's left our bounding box, then move it // 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 // into the arguments moving models. These will be added back or deleted completely
if (model.getShouldDie() || !bestFitEntityBounds(model)) { if (model.getShouldBeDeleted() || !bestFitEntityBounds(model)) {
args._movingEntitys.push_back(model); args._movingEntities.push_back(model);
// erase this model // erase this model
modelItr = _entityItems->erase(modelItr); modelItr = _entityItems->erase(modelItr);
@ -242,32 +242,32 @@ bool EntityTreeElement::findDetailedRayIntersection(const glm::vec3& origin, con
// 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 models...
QList<EntityItem>::iterator modelItr = _entityItems->begin(); QList<EntityItem>::iterator entityItr = _entityItems->begin();
QList<EntityItem>::const_iterator modelEnd = _entityItems->end(); QList<EntityItem>::const_iterator entityEnd = _entityItems->end();
bool somethingIntersected = false; bool somethingIntersected = false;
while(modelItr != modelEnd) { while(entityItr != entityEnd) {
EntityItem& model = (*modelItr); EntityItem& entity = (*entityItr);
AACube modelCube = model.getAACube(); AACube entityCube = entity.getAACube();
float localDistance; float localDistance;
BoxFace localFace; BoxFace localFace;
// if the ray doesn't intersect with our cube, we can stop searching! // if the ray doesn't intersect with our cube, we can stop searching!
if (modelCube.findRayIntersection(origin, direction, localDistance, localFace)) { if (entityCube.findRayIntersection(origin, direction, localDistance, localFace)) {
const FBXGeometry* fbxGeometry = _myTree->getGeometryForEntity(model); const FBXGeometry* fbxGeometry = _myTree->getGeometryForEntity(entity);
if (fbxGeometry && fbxGeometry->meshExtents.isValid()) { if (fbxGeometry && fbxGeometry->meshExtents.isValid()) {
Extents extents = fbxGeometry->meshExtents; Extents extents = fbxGeometry->meshExtents;
// NOTE: If the model has a bad mesh, then extents will be 0,0,0 & 0,0,0 // NOTE: If the entity has a bad mesh, then extents will be 0,0,0 & 0,0,0
if (extents.minimum == extents.maximum && extents.minimum == glm::vec3(0,0,0)) { if (extents.minimum == extents.maximum && extents.minimum == glm::vec3(0,0,0)) {
extents.maximum = glm::vec3(1.0f,1.0f,1.0f); // in this case we will simulate the unit cube extents.maximum = glm::vec3(1.0f,1.0f,1.0f); // in this case we will simulate the unit cube
} }
// NOTE: these extents are model space, so we need to scale and center them accordingly // NOTE: these extents are entity space, so we need to scale and center them accordingly
// size is our "target size in world space" // size is our "target size in world space"
// we need to set our model scale so that the extents of the mesh, fit in a cube that size... // we need to set our entity scale so that the extents of the mesh, fit in a cube that size...
float maxDimension = glm::distance(extents.maximum, extents.minimum); float maxDimension = glm::distance(extents.maximum, extents.minimum);
float scale = model.getSize() / maxDimension; float scale = entity.getSize() / maxDimension;
glm::vec3 halfDimensions = (extents.maximum - extents.minimum) * 0.5f; glm::vec3 halfDimensions = (extents.maximum - extents.minimum) * 0.5f;
glm::vec3 offset = -extents.minimum - halfDimensions; glm::vec3 offset = -extents.minimum - halfDimensions;
@ -280,10 +280,10 @@ bool EntityTreeElement::findDetailedRayIntersection(const glm::vec3& origin, con
Extents rotatedExtents = extents; Extents rotatedExtents = extents;
calculateRotatedExtents(rotatedExtents, model.getRotation()); calculateRotatedExtents(rotatedExtents, entity.getRotation());
rotatedExtents.minimum += model.getPosition(); rotatedExtents.minimum += entity.getPosition();
rotatedExtents.maximum += model.getPosition(); rotatedExtents.maximum += entity.getPosition();
AABox rotatedExtentsBox(rotatedExtents.minimum, (rotatedExtents.maximum - rotatedExtents.minimum)); AABox rotatedExtentsBox(rotatedExtents.minimum, (rotatedExtents.maximum - rotatedExtents.minimum));
@ -291,24 +291,24 @@ bool EntityTreeElement::findDetailedRayIntersection(const glm::vec3& origin, con
// if it's in our AABOX for our rotated extents, then check to see if it's in our non-AABox // if it's in our AABOX for our rotated extents, then check to see if it's in our non-AABox
if (rotatedExtentsBox.findRayIntersection(origin, direction, localDistance, localFace)) { if (rotatedExtentsBox.findRayIntersection(origin, direction, localDistance, localFace)) {
// extents is the model relative, scaled, centered extents of the model // extents is the entity relative, scaled, centered extents of the entity
glm::mat4 rotation = glm::mat4_cast(model.getRotation()); glm::mat4 rotation = glm::mat4_cast(entity.getRotation());
glm::mat4 translation = glm::translate(model.getPosition()); glm::mat4 translation = glm::translate(entity.getPosition());
glm::mat4 modelToWorldMatrix = translation * rotation; glm::mat4 entityToWorldMatrix = translation * rotation;
glm::mat4 worldToEntityMatrix = glm::inverse(modelToWorldMatrix); glm::mat4 worldToEntityMatrix = glm::inverse(entityToWorldMatrix);
AABox modelFrameBox(extents.minimum, (extents.maximum - extents.minimum)); AABox entityFrameBox(extents.minimum, (extents.maximum - extents.minimum));
glm::vec3 modelFrameOrigin = glm::vec3(worldToEntityMatrix * glm::vec4(origin, 1.0f)); glm::vec3 entityFrameOrigin = glm::vec3(worldToEntityMatrix * glm::vec4(origin, 1.0f));
glm::vec3 modelFrameDirection = glm::vec3(worldToEntityMatrix * glm::vec4(direction, 0.0f)); glm::vec3 entityFrameDirection = glm::vec3(worldToEntityMatrix * glm::vec4(direction, 0.0f));
// we can use the AABox's ray intersection by mapping our origin and direction into the model frame // we can use the AABox's ray intersection by mapping our origin and direction into the entity frame
// and testing intersection there. // and testing intersection there.
if (modelFrameBox.findRayIntersection(modelFrameOrigin, modelFrameDirection, localDistance, localFace)) { if (entityFrameBox.findRayIntersection(entityFrameOrigin, entityFrameDirection, localDistance, localFace)) {
if (localDistance < distance) { if (localDistance < distance) {
distance = localDistance; distance = localDistance;
face = localFace; face = localFace;
*intersectedObject = (void*)(&model); *intersectedObject = (void*)(&entity);
somethingIntersected = true; somethingIntersected = true;
} }
} }
@ -316,93 +316,93 @@ bool EntityTreeElement::findDetailedRayIntersection(const glm::vec3& origin, con
} else if (localDistance < distance) { } else if (localDistance < distance) {
distance = localDistance; distance = localDistance;
face = localFace; face = localFace;
*intersectedObject = (void*)(&model); *intersectedObject = (void*)(&entity);
somethingIntersected = true; somethingIntersected = true;
} }
} }
++modelItr; ++entityItr;
} }
return somethingIntersected; return somethingIntersected;
} }
bool EntityTreeElement::findSpherePenetration(const glm::vec3& center, float radius, bool EntityTreeElement::findSpherePenetration(const glm::vec3& center, float radius,
glm::vec3& penetration, void** penetratedObject) const { glm::vec3& penetration, void** penetratedObject) const {
QList<EntityItem>::iterator modelItr = _entityItems->begin(); QList<EntityItem>::iterator entityItr = _entityItems->begin();
QList<EntityItem>::const_iterator modelEnd = _entityItems->end(); QList<EntityItem>::const_iterator entityEnd = _entityItems->end();
while(modelItr != modelEnd) { while(entityItr != entityEnd) {
EntityItem& model = (*modelItr); EntityItem& entity = (*entityItr);
glm::vec3 modelCenter = model.getPosition(); glm::vec3 entityCenter = entity.getPosition();
float modelRadius = model.getRadius(); float entityRadius = entity.getRadius();
// don't penetrate yourself // don't penetrate yourself
if (modelCenter == center && modelRadius == radius) { if (entityCenter == center && entityRadius == radius) {
return false; return false;
} }
if (findSphereSpherePenetration(center, radius, modelCenter, modelRadius, penetration)) { if (findSphereSpherePenetration(center, radius, entityCenter, entityRadius, penetration)) {
// return true on first valid model penetration // return true on first valid entity penetration
*penetratedObject = (void*)(&model); *penetratedObject = (void*)(&entity);
return true; return true;
} }
++modelItr; ++entityItr;
} }
return false; return false;
} }
bool EntityTreeElement::updateEntity(const EntityItem& model) { bool EntityTreeElement::updateEntity(const EntityItem& entity) {
const bool wantDebug = false; const bool wantDebug = false;
if (wantDebug) { if (wantDebug) {
EntityItemID modelItemID = model.getEntityItemID(); EntityItemID entityItemID = entity.getEntityItemID();
qDebug() << "EntityTreeElement::updateEntity(model) modelID.id=" qDebug() << "EntityTreeElement::updateEntity(entity) entityID.id="
<< modelItemID.id << "creatorTokenID=" << modelItemID.creatorTokenID; << entityItemID.id << "creatorTokenID=" << entityItemID.creatorTokenID;
} }
// NOTE: this method must first lookup the model by ID, hence it is O(N) // NOTE: this method must first lookup the entity by ID, hence it is O(N)
// and "model is not found" is worst-case (full N) but maybe we don't care? // and "entity is not found" is worst-case (full N) but maybe we don't care?
// (guaranteed that num models per elemen is small?) // (guaranteed that num entitys per elemen is small?)
uint16_t numberOfEntitys = _entityItems->size(); uint16_t numberOfEntities = _entityItems->size();
for (uint16_t i = 0; i < numberOfEntitys; i++) { for (uint16_t i = 0; i < numberOfEntities; i++) {
EntityItem& thisEntity = (*_entityItems)[i]; EntityItem& thisEntity = (*_entityItems)[i];
if (thisEntity.getID() == model.getID()) { if (thisEntity.getID() == entity.getID()) {
if (wantDebug) { if (wantDebug) {
qDebug() << "found model with id"; qDebug() << "found entity with id";
} }
int difference = thisEntity.getLastUpdated() - model.getLastUpdated(); int difference = thisEntity.getLastUpdated() - entity.getLastUpdated();
bool changedOnServer = thisEntity.getLastEdited() <= model.getLastEdited(); bool changedOnServer = thisEntity.getLastEdited() <= entity.getLastEdited();
bool localOlder = thisEntity.getLastUpdated() < model.getLastUpdated(); bool localOlder = thisEntity.getLastUpdated() < entity.getLastUpdated();
if (changedOnServer || localOlder) { if (changedOnServer || localOlder) {
if (wantDebug) { if (wantDebug) {
qDebug("local model [id:%d] %s and %s than server model by %d, model.isNewlyCreated()=%s", qDebug("local entity [id:%d] %s and %s than server entity by %d, entity.isNewlyCreated()=%s",
model.getID(), (changedOnServer ? "CHANGED" : "same"), entity.getID(), (changedOnServer ? "CHANGED" : "same"),
(localOlder ? "OLDER" : "NEWER"), (localOlder ? "OLDER" : "NEWER"),
difference, debug::valueOf(model.isNewlyCreated()) ); difference, debug::valueOf(entity.isNewlyCreated()) );
} }
thisEntity.copyChangedProperties(model); thisEntity.copyChangedProperties(entity);
markWithChangedTime(); markWithChangedTime();
// seems like we shouldn't need this // seems like we shouldn't need this
_myTree->setContainingElement(model.getEntityItemID(), this); _myTree->setContainingElement(entity.getEntityItemID(), this);
} else { } else {
if (wantDebug) { if (wantDebug) {
qDebug(">>> IGNORING SERVER!!! Would've caused jutter! <<< " qDebug(">>> IGNORING SERVER!!! Would've caused jutter! <<< "
"local model [id:%d] %s and %s than server model by %d, model.isNewlyCreated()=%s", "local entity [id:%d] %s and %s than server entity by %d, entity.isNewlyCreated()=%s",
model.getID(), (changedOnServer ? "CHANGED" : "same"), entity.getID(), (changedOnServer ? "CHANGED" : "same"),
(localOlder ? "OLDER" : "NEWER"), (localOlder ? "OLDER" : "NEWER"),
difference, debug::valueOf(model.isNewlyCreated()) ); difference, debug::valueOf(entity.isNewlyCreated()) );
} }
} }
return true; return true;
} }
} }
// If we didn't find the model here, then let's check to see if we should add it... // If we didn't find the entity here, then let's check to see if we should add it...
if (bestFitEntityBounds(model)) { if (bestFitEntityBounds(entity)) {
_entityItems->push_back(model); _entityItems->push_back(entity);
markWithChangedTime(); markWithChangedTime();
// Since we're adding this item to this element, we need to let the tree know about it // Since we're adding this item to this element, we need to let the tree know about it
_myTree->setContainingElement(model.getEntityItemID(), this); _myTree->setContainingElement(entity.getEntityItemID(), this);
return true; return true;
} }
@ -411,37 +411,37 @@ bool EntityTreeElement::updateEntity(const EntityItem& model) {
void EntityTreeElement::updateEntityItemID(FindAndUpdateEntityItemIDArgs* args) { void EntityTreeElement::updateEntityItemID(FindAndUpdateEntityItemIDArgs* args) {
bool wantDebug = false; bool wantDebug = false;
uint16_t numberOfEntitys = _entityItems->size(); uint16_t numberOfEntities = _entityItems->size();
for (uint16_t i = 0; i < numberOfEntitys; i++) { for (uint16_t i = 0; i < numberOfEntities; i++) {
EntityItem& thisEntity = (*_entityItems)[i]; EntityItem& thisEntity = (*_entityItems)[i];
if (!args->creatorTokenFound) { if (!args->creatorTokenFound) {
// first, we're looking for matching creatorTokenIDs, if we find that, then we fix it to know the actual ID // first, we're looking for matching creatorTokenIDs, if we find that, then we fix it to know the actual ID
if (thisEntity.getCreatorTokenID() == args->creatorTokenID) { if (thisEntity.getCreatorTokenID() == args->creatorTokenID) {
if (wantDebug) { if (wantDebug) {
qDebug() << "EntityTreeElement::updateEntityItemID()... found the model... updating it's ID... " qDebug() << "EntityTreeElement::updateEntityItemID()... found the entity... updating it's ID... "
<< "creatorTokenID=" << args->creatorTokenID << "creatorTokenID=" << args->creatorTokenID
<< "modelID=" << args->modelID; << "entityID=" << args->entityID;
} }
thisEntity.setID(args->modelID); thisEntity.setID(args->entityID);
args->creatorTokenFound = true; args->creatorTokenFound = true;
} }
} }
// if we're in an isViewing tree, we also need to look for an kill any viewed models // if we're in an isViewing tree, we also need to look for an kill any viewed entitys
if (!args->viewedEntityFound && args->isViewing) { if (!args->viewedEntityFound && args->isViewing) {
if (thisEntity.getCreatorTokenID() == UNKNOWN_MODEL_TOKEN && thisEntity.getID() == args->modelID) { if (thisEntity.getCreatorTokenID() == UNKNOWN_MODEL_TOKEN && thisEntity.getID() == args->entityID) {
if (wantDebug) { if (wantDebug) {
qDebug() << "EntityTreeElement::updateEntityItemID()... VIEWED MODEL FOUND??? " qDebug() << "EntityTreeElement::updateEntityItemID()... VIEWED entity FOUND??? "
<< "args->creatorTokenID=" << args->creatorTokenID << "args->creatorTokenID=" << args->creatorTokenID
<< "thisEntity.getCreatorTokenID()=" << thisEntity.getCreatorTokenID() << "thisEntity.getCreatorTokenID()=" << thisEntity.getCreatorTokenID()
<< "args->modelID=" << args->modelID; << "args->entityID=" << args->entityID;
} }
_entityItems->removeAt(i); // remove the model at this index _entityItems->removeAt(i); // remove the entity at this index
numberOfEntitys--; // this means we have 1 fewer model in this list numberOfEntities--; // this means we have 1 fewer entity in this list
i--; // and we actually want to back up i as well. i--; // and we actually want to back up i as well.
args->viewedEntityFound = true; args->viewedEntityFound = true;
} }
@ -454,8 +454,8 @@ void EntityTreeElement::updateEntityItemID(FindAndUpdateEntityItemIDArgs* args)
const EntityItem* EntityTreeElement::getClosestEntity(glm::vec3 position) const { const EntityItem* EntityTreeElement::getClosestEntity(glm::vec3 position) const {
const EntityItem* closestEntity = NULL; const EntityItem* closestEntity = NULL;
float closestEntityDistance = FLT_MAX; float closestEntityDistance = FLT_MAX;
uint16_t numberOfEntitys = _entityItems->size(); uint16_t numberOfEntities = _entityItems->size();
for (uint16_t i = 0; i < numberOfEntitys; i++) { for (uint16_t i = 0; i < numberOfEntities; i++) {
float distanceToEntity = glm::distance(position, (*_entityItems)[i].getPosition()); float distanceToEntity = glm::distance(position, (*_entityItems)[i].getPosition());
if (distanceToEntity < closestEntityDistance) { if (distanceToEntity < closestEntityDistance) {
closestEntity = &(*_entityItems)[i]; closestEntity = &(*_entityItems)[i];
@ -464,40 +464,40 @@ const EntityItem* EntityTreeElement::getClosestEntity(glm::vec3 position) const
return closestEntity; return closestEntity;
} }
void EntityTreeElement::getEntitys(const glm::vec3& searchPosition, float searchRadius, QVector<const EntityItem*>& foundEntitys) const { void EntityTreeElement::getEntities(const glm::vec3& searchPosition, float searchRadius, QVector<const EntityItem*>& foundEntities) const {
uint16_t numberOfEntitys = _entityItems->size(); uint16_t numberOfEntities = _entityItems->size();
for (uint16_t i = 0; i < numberOfEntitys; i++) { for (uint16_t i = 0; i < numberOfEntities; i++) {
const EntityItem* model = &(*_entityItems)[i]; const EntityItem* entity = &(*_entityItems)[i];
float distance = glm::length(model->getPosition() - searchPosition); float distance = glm::length(entity->getPosition() - searchPosition);
if (distance < searchRadius + model->getRadius()) { if (distance < searchRadius + entity->getRadius()) {
foundEntitys.push_back(model); foundEntities.push_back(entity);
} }
} }
} }
void EntityTreeElement::getEntitys(const AACube& box, QVector<EntityItem*>& foundEntitys) { void EntityTreeElement::getEntities(const AACube& box, QVector<EntityItem*>& foundEntities) {
QList<EntityItem>::iterator modelItr = _entityItems->begin(); QList<EntityItem>::iterator entityItr = _entityItems->begin();
QList<EntityItem>::iterator modelEnd = _entityItems->end(); QList<EntityItem>::iterator entityEnd = _entityItems->end();
AACube modelCube; AACube entityCube;
while(modelItr != modelEnd) { while(entityItr != entityEnd) {
EntityItem* model = &(*modelItr); EntityItem* entity = &(*entityItr);
float radius = model->getRadius(); float radius = entity->getRadius();
// NOTE: we actually do cube-cube collision queries here, which is sloppy but good enough for now // NOTE: we actually do cube-cube collision queries here, which is sloppy but good enough for now
// TODO: decide whether to replace modelCube-cube query with sphere-cube (requires a square root // TODO: decide whether to replace entityCube-cube query with sphere-cube (requires a square root
// but will be slightly more accurate). // but will be slightly more accurate).
modelCube.setBox(model->getPosition() - glm::vec3(radius), 2.f * radius); entityCube.setBox(entity->getPosition() - glm::vec3(radius), 2.f * radius);
if (modelCube.touches(_cube)) { if (entityCube.touches(_cube)) {
foundEntitys.push_back(model); foundEntities.push_back(entity);
} }
++modelItr; ++entityItr;
} }
} }
const EntityItem* EntityTreeElement::getEntityWithID(uint32_t id) const { const EntityItem* EntityTreeElement::getEntityWithID(uint32_t id) const {
// NOTE: this lookup is O(N) but maybe we don't care? (guaranteed that num models per elemen is small?) // NOTE: this lookup is O(N) but maybe we don't care? (guaranteed that num entitys per elemen is small?)
const EntityItem* foundEntity = NULL; const EntityItem* foundEntity = NULL;
uint16_t numberOfEntitys = _entityItems->size(); uint16_t numberOfEntities = _entityItems->size();
for (uint16_t i = 0; i < numberOfEntitys; i++) { for (uint16_t i = 0; i < numberOfEntities; i++) {
if ((*_entityItems)[i].getID() == id) { if ((*_entityItems)[i].getID() == id) {
foundEntity = &(*_entityItems)[i]; foundEntity = &(*_entityItems)[i];
break; break;
@ -507,10 +507,10 @@ const EntityItem* EntityTreeElement::getEntityWithID(uint32_t id) const {
} }
const EntityItem* EntityTreeElement::getEntityWithEntityItemID(const EntityItemID& 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 models per elemen is small?) // NOTE: this lookup is O(N) but maybe we don't care? (guaranteed that num entitys per elemen is small?)
const EntityItem* foundEntity = NULL; const EntityItem* foundEntity = NULL;
uint16_t numberOfEntitys = _entityItems->size(); uint16_t numberOfEntities = _entityItems->size();
for (uint16_t i = 0; i < numberOfEntitys; i++) { for (uint16_t i = 0; i < numberOfEntities; i++) {
if ((*_entityItems)[i].getEntityItemID() == id) { if ((*_entityItems)[i].getEntityItemID() == id) {
foundEntity = &(*_entityItems)[i]; foundEntity = &(*_entityItems)[i];
break; break;
@ -521,8 +521,8 @@ const EntityItem* EntityTreeElement::getEntityWithEntityItemID(const EntityItemI
bool EntityTreeElement::removeEntityWithID(uint32_t id) { bool EntityTreeElement::removeEntityWithID(uint32_t id) {
bool foundEntity = false; bool foundEntity = false;
uint16_t numberOfEntitys = _entityItems->size(); uint16_t numberOfEntities = _entityItems->size();
for (uint16_t i = 0; i < numberOfEntitys; i++) { for (uint16_t i = 0; i < numberOfEntities; i++) {
if ((*_entityItems)[i].getID() == id) { if ((*_entityItems)[i].getID() == id) {
foundEntity = true; foundEntity = true;
_entityItems->removeAt(i); _entityItems->removeAt(i);
@ -535,8 +535,8 @@ bool EntityTreeElement::removeEntityWithID(uint32_t id) {
bool EntityTreeElement::removeEntityWithEntityItemID(const EntityItemID& id) { bool EntityTreeElement::removeEntityWithEntityItemID(const EntityItemID& id) {
bool foundEntity = false; bool foundEntity = false;
uint16_t numberOfEntitys = _entityItems->size(); uint16_t numberOfEntities = _entityItems->size();
for (uint16_t i = 0; i < numberOfEntitys; i++) { for (uint16_t i = 0; i < numberOfEntities; i++) {
if ((*_entityItems)[i].getEntityItemID() == id) { if ((*_entityItems)[i].getEntityItemID() == id) {
foundEntity = true; foundEntity = true;
_entityItems->removeAt(i); _entityItems->removeAt(i);
@ -559,22 +559,22 @@ int EntityTreeElement::readElementDataFromBuffer(const unsigned char* data, int
const unsigned char* dataAt = data; const unsigned char* dataAt = data;
int bytesRead = 0; int bytesRead = 0;
uint16_t numberOfEntitys = 0; uint16_t numberOfEntities = 0;
int expectedBytesPerEntity = EntityItem::expectedBytes(); int expectedBytesPerEntity = EntityItem::expectedBytes();
if (bytesLeftToRead >= (int)sizeof(numberOfEntitys)) { if (bytesLeftToRead >= (int)sizeof(numberOfEntities)) {
// read our models in.... // read our entitys in....
numberOfEntitys = *(uint16_t*)dataAt; numberOfEntities = *(uint16_t*)dataAt;
dataAt += sizeof(numberOfEntitys); dataAt += sizeof(numberOfEntities);
bytesLeftToRead -= (int)sizeof(numberOfEntitys); bytesLeftToRead -= (int)sizeof(numberOfEntities);
bytesRead += sizeof(numberOfEntitys); bytesRead += sizeof(numberOfEntities);
if (bytesLeftToRead >= (int)(numberOfEntitys * expectedBytesPerEntity)) { if (bytesLeftToRead >= (int)(numberOfEntities * expectedBytesPerEntity)) {
for (uint16_t i = 0; i < numberOfEntitys; i++) { for (uint16_t i = 0; i < numberOfEntities; i++) {
EntityItem tempEntity; // we will read into this EntityItem tempEntity; // we will read into this
EntityItemID modelItemID = EntityItem::readEntityItemIDFromBuffer(dataAt, bytesLeftToRead, args); EntityItemID entityItemID = EntityItem::readEntityItemIDFromBuffer(dataAt, bytesLeftToRead, args);
const EntityItem* existingEntityItem = _myTree->findEntityByEntityItemID(modelItemID); const EntityItem* existingEntityItem = _myTree->findEntityByEntityItemID(entityItemID);
if (existingEntityItem) { if (existingEntityItem) {
// copy original properties... // copy original properties...
tempEntity.copyChangedProperties(*existingEntityItem); tempEntity.copyChangedProperties(*existingEntityItem);

View file

@ -1,6 +1,6 @@
// //
// EntityTreeElement.h // EntityTreeElement.h
// libraries/models/src // libraries/entities/src
// //
// Created by Brad Hefta-Gaub on 12/4/13. // Created by Brad Hefta-Gaub on 12/4/13.
// Copyright 2013 High Fidelity, Inc. // Copyright 2013 High Fidelity, Inc.
@ -29,7 +29,7 @@ public:
_movingItems(0) _movingItems(0)
{ } { }
QList<EntityItem> _movingEntitys; QList<EntityItem> _movingEntities;
int _totalElements; int _totalElements;
int _totalItems; int _totalItems;
int _movingItems; int _movingItems;
@ -37,7 +37,7 @@ public:
class FindAndUpdateEntityItemIDArgs { class FindAndUpdateEntityItemIDArgs {
public: public:
uint32_t modelID; uint32_t entityID;
uint32_t creatorTokenID; uint32_t creatorTokenID;
bool creatorTokenFound; bool creatorTokenFound;
bool viewedEntityFound; bool viewedEntityFound;
@ -120,21 +120,21 @@ public:
void update(EntityTreeUpdateArgs& args); void update(EntityTreeUpdateArgs& args);
void setTree(EntityTree* tree) { _myTree = tree; } void setTree(EntityTree* tree) { _myTree = tree; }
bool updateEntity(const EntityItem& model); bool updateEntity(const EntityItem& entity);
void updateEntityItemID(FindAndUpdateEntityItemIDArgs* args); void updateEntityItemID(FindAndUpdateEntityItemIDArgs* args);
const EntityItem* getClosestEntity(glm::vec3 position) const; const EntityItem* getClosestEntity(glm::vec3 position) const;
/// finds all models that touch a sphere /// finds all entities that touch a sphere
/// \param position the center of the query sphere /// \param position the center of the query sphere
/// \param radius the radius of the query sphere /// \param radius the radius of the query sphere
/// \param models[out] vector of const EntityItem* /// \param entities[out] vector of const EntityItem*
void getEntitys(const glm::vec3& position, float radius, QVector<const EntityItem*>& foundEntitys) const; void getEntities(const glm::vec3& position, float radius, QVector<const EntityItem*>& foundEntities) const;
/// finds all models that touch a box /// finds all entities that touch a box
/// \param box the query box /// \param box the query box
/// \param models[out] vector of non-const EntityItem* /// \param entities[out] vector of non-const EntityItem*
void getEntitys(const AACube& box, QVector<EntityItem*>& foundEntitys); void getEntities(const AACube& box, QVector<EntityItem*>& foundEntities);
const EntityItem* getEntityWithID(uint32_t id) const; const EntityItem* getEntityWithID(uint32_t id) const;
const EntityItem* getEntityWithEntityItemID(const EntityItemID& id) const; const EntityItem* getEntityWithEntityItemID(const EntityItemID& id) const;
@ -142,8 +142,8 @@ public:
bool removeEntityWithID(uint32_t id); bool removeEntityWithID(uint32_t id);
bool removeEntityWithEntityItemID(const EntityItemID& id); bool removeEntityWithEntityItemID(const EntityItemID& id);
bool containsEntityBounds(const EntityItem& model) const; bool containsEntityBounds(const EntityItem& entity) const;
bool bestFitEntityBounds(const EntityItem& model) const; bool bestFitEntityBounds(const EntityItem& entity) const;
protected: protected:
virtual void init(unsigned char * octalCode); virtual void init(unsigned char * octalCode);