mirror of
https://thingvellir.net/git/overte
synced 2025-03-27 23:52:03 +01:00
more renaming work
This commit is contained in:
parent
d25ba66b21
commit
ad7a768fff
7 changed files with 224 additions and 225 deletions
|
@ -57,12 +57,12 @@ void EntityItem::handleAddEntityResponse(const QByteArray& packet) {
|
|||
memcpy(&creatorTokenID, dataAt, sizeof(creatorTokenID));
|
||||
dataAt += sizeof(creatorTokenID);
|
||||
|
||||
uint32_t modelItemID;
|
||||
memcpy(&modelItemID, dataAt, sizeof(modelItemID));
|
||||
dataAt += sizeof(modelItemID);
|
||||
uint32_t entityItemID;
|
||||
memcpy(&entityItemID, dataAt, sizeof(entityItemID));
|
||||
dataAt += sizeof(entityItemID);
|
||||
|
||||
// add our token to id mapping
|
||||
_tokenIDsToIDs[creatorTokenID] = modelItemID;
|
||||
_tokenIDsToIDs[creatorTokenID] = entityItemID;
|
||||
}
|
||||
|
||||
EntityItem::EntityItem() {
|
||||
|
@ -70,9 +70,9 @@ EntityItem::EntityItem() {
|
|||
init(glm::vec3(0,0,0), 0, noColor, NEW_MODEL);
|
||||
}
|
||||
|
||||
void EntityItem::initFromEntityItemID(const EntityItemID& modelItemID) {
|
||||
_id = modelItemID.id;
|
||||
_creatorTokenID = modelItemID.creatorTokenID;
|
||||
void EntityItem::initFromEntityItemID(const EntityItemID& entityItemID) {
|
||||
_id = entityItemID.id;
|
||||
_creatorTokenID = entityItemID.creatorTokenID;
|
||||
|
||||
// init values with defaults before calling setProperties
|
||||
uint64_t now = usecTimestampNow();
|
||||
|
@ -83,7 +83,7 @@ void EntityItem::initFromEntityItemID(const EntityItemID& modelItemID) {
|
|||
_radius = 0;
|
||||
rgbColor noColor = { 0, 0, 0 };
|
||||
memcpy(_color, noColor, sizeof(_color));
|
||||
_shouldDie = false;
|
||||
_shouldBeDeleted = false;
|
||||
_modelURL = MODEL_DEFAULT_MODEL_URL;
|
||||
_rotation = MODEL_DEFAULT_MODEL_ROTATION;
|
||||
|
||||
|
@ -98,12 +98,12 @@ void EntityItem::initFromEntityItemID(const EntityItemID& modelItemID) {
|
|||
_lastAnimated = now;
|
||||
}
|
||||
|
||||
EntityItem::EntityItem(const EntityItemID& modelItemID) {
|
||||
initFromEntityItemID(modelItemID);
|
||||
EntityItem::EntityItem(const EntityItemID& entityItemID) {
|
||||
initFromEntityItemID(entityItemID);
|
||||
}
|
||||
|
||||
EntityItem::EntityItem(const EntityItemID& modelItemID, const EntityItemProperties& properties) {
|
||||
initFromEntityItemID(modelItemID);
|
||||
EntityItem::EntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) {
|
||||
initFromEntityItemID(entityItemID);
|
||||
setProperties(properties, true); // force copy
|
||||
}
|
||||
|
||||
|
@ -124,7 +124,7 @@ void EntityItem::init(glm::vec3 position, float radius, rgbColor color, uint32_t
|
|||
_position = position;
|
||||
_radius = radius;
|
||||
memcpy(_color, color, sizeof(_color));
|
||||
_shouldDie = false;
|
||||
_shouldBeDeleted = false;
|
||||
_modelURL = MODEL_DEFAULT_MODEL_URL;
|
||||
_rotation = MODEL_DEFAULT_MODEL_ROTATION;
|
||||
|
||||
|
@ -394,7 +394,7 @@ OctreeElement::AppendState EntityItem::appendEntityData(OctreePacketData* packet
|
|||
if (requestedProperties.getHasProperty(PROP_SHOULD_BE_DELETED)) {
|
||||
//qDebug() << "PROP_SHOULD_BE_DELETED requested...";
|
||||
LevelDetails propertyLevel = packetData->startLevel();
|
||||
successPropertyFits = packetData->appendValue(getShouldDie());
|
||||
successPropertyFits = packetData->appendValue(getShouldBeDeleted());
|
||||
if (successPropertyFits) {
|
||||
propertyFlags |= PROP_SHOULD_BE_DELETED;
|
||||
propertiesDidntFit -= PROP_SHOULD_BE_DELETED;
|
||||
|
@ -507,10 +507,10 @@ int EntityItem::oldVersionReadEntityDataFromBuffer(const unsigned char* data, in
|
|||
dataAt += sizeof(_color);
|
||||
bytesRead += sizeof(_color);
|
||||
|
||||
// shouldDie
|
||||
memcpy(&_shouldDie, dataAt, sizeof(_shouldDie));
|
||||
dataAt += sizeof(_shouldDie);
|
||||
bytesRead += sizeof(_shouldDie);
|
||||
// shouldBeDeleted
|
||||
memcpy(&_shouldBeDeleted, dataAt, sizeof(_shouldBeDeleted));
|
||||
dataAt += sizeof(_shouldBeDeleted);
|
||||
bytesRead += sizeof(_shouldBeDeleted);
|
||||
|
||||
// modelURL
|
||||
uint16_t modelURLLength;
|
||||
|
@ -713,9 +713,9 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef
|
|||
|
||||
// PROP_SHOULD_BE_DELETED
|
||||
if (propertyFlags.getHasProperty(PROP_SHOULD_BE_DELETED)) {
|
||||
memcpy(&_shouldDie, dataAt, sizeof(_shouldDie));
|
||||
dataAt += sizeof(_shouldDie);
|
||||
bytesRead += sizeof(_shouldDie);
|
||||
memcpy(&_shouldBeDeleted, dataAt, sizeof(_shouldBeDeleted));
|
||||
dataAt += sizeof(_shouldBeDeleted);
|
||||
bytesRead += sizeof(_shouldBeDeleted);
|
||||
}
|
||||
}
|
||||
return bytesRead;
|
||||
|
@ -831,11 +831,11 @@ EntityItem EntityItem::fromEditPacket(const unsigned char* data, int length, int
|
|||
processedBytes += sizeof(newEntityItem._color);
|
||||
}
|
||||
|
||||
// shouldDie
|
||||
// shouldBeDeleted
|
||||
if (isNewEntityItem || ((packetContainsBits & MODEL_PACKET_CONTAINS_SHOULDDIE) == MODEL_PACKET_CONTAINS_SHOULDDIE)) {
|
||||
memcpy(&newEntityItem._shouldDie, dataAt, sizeof(newEntityItem._shouldDie));
|
||||
dataAt += sizeof(newEntityItem._shouldDie);
|
||||
processedBytes += sizeof(newEntityItem._shouldDie);
|
||||
memcpy(&newEntityItem._shouldBeDeleted, dataAt, sizeof(newEntityItem._shouldBeDeleted));
|
||||
dataAt += sizeof(newEntityItem._shouldBeDeleted);
|
||||
processedBytes += sizeof(newEntityItem._shouldBeDeleted);
|
||||
}
|
||||
|
||||
// modelURL
|
||||
|
@ -910,7 +910,7 @@ EntityItem EntityItem::fromEditPacket(const unsigned char* data, int length, int
|
|||
void EntityItem::debugDump() const {
|
||||
qDebug("EntityItem id :%u", _id);
|
||||
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(" radius:%f", getRadius());
|
||||
qDebug(" color:%d,%d,%d", _color[0], _color[1], _color[2]);
|
||||
|
@ -1004,10 +1004,10 @@ bool EntityItem::encodeEntityEditMessageDetails(PacketType command, EntityItemID
|
|||
|
||||
// shoulDie
|
||||
if (isNewEntityItem || ((packetContainsBits & MODEL_PACKET_CONTAINS_SHOULDDIE) == MODEL_PACKET_CONTAINS_SHOULDDIE)) {
|
||||
bool shouldDie = properties.getShouldDie();
|
||||
memcpy(copyAt, &shouldDie, sizeof(shouldDie));
|
||||
copyAt += sizeof(shouldDie);
|
||||
sizeOut += sizeof(shouldDie);
|
||||
bool shouldBeDeleted = properties.getShouldBeDeleted();
|
||||
memcpy(copyAt, &shouldBeDeleted, sizeof(shouldBeDeleted));
|
||||
copyAt += sizeof(shouldBeDeleted);
|
||||
sizeOut += sizeof(shouldBeDeleted);
|
||||
}
|
||||
|
||||
// modelURL
|
||||
|
@ -1193,7 +1193,7 @@ QVector<glm::quat> EntityItem::getAnimationFrame() {
|
|||
|
||||
void EntityItem::update(const quint64& updateTime) {
|
||||
_lastUpdated = updateTime;
|
||||
setShouldDie(getShouldDie());
|
||||
setShouldBeDeleted(getShouldBeDeleted());
|
||||
|
||||
quint64 now = usecTimestampNow();
|
||||
|
||||
|
@ -1239,7 +1239,7 @@ EntityItemProperties::EntityItemProperties() :
|
|||
_position(0),
|
||||
_color(),
|
||||
_radius(MODEL_DEFAULT_RADIUS),
|
||||
_shouldDie(false),
|
||||
_shouldBeDeleted(false),
|
||||
_modelURL(""),
|
||||
_rotation(MODEL_DEFAULT_MODEL_ROTATION),
|
||||
_animationURL(""),
|
||||
|
@ -1255,7 +1255,7 @@ EntityItemProperties::EntityItemProperties() :
|
|||
_positionChanged(false),
|
||||
_colorChanged(false),
|
||||
_radiusChanged(false),
|
||||
_shouldDieChanged(false),
|
||||
_shouldBeDeletedChanged(false),
|
||||
_modelURLChanged(false),
|
||||
_rotationChanged(false),
|
||||
_animationURLChanged(false),
|
||||
|
@ -1292,7 +1292,7 @@ uint16_t EntityItemProperties::getChangedBits() const {
|
|||
changedBits += MODEL_PACKET_CONTAINS_COLOR;
|
||||
}
|
||||
|
||||
if (_shouldDieChanged) {
|
||||
if (_shouldBeDeletedChanged) {
|
||||
changedBits += MODEL_PACKET_CONTAINS_SHOULDDIE;
|
||||
}
|
||||
|
||||
|
@ -1335,7 +1335,7 @@ QScriptValue EntityItemProperties::copyToScriptValue(QScriptEngine* engine) cons
|
|||
|
||||
properties.setProperty("radius", _radius);
|
||||
|
||||
properties.setProperty("shouldDie", _shouldDie);
|
||||
properties.setProperty("shouldBeDeleted", _shouldBeDeleted);
|
||||
|
||||
properties.setProperty("modelURL", _modelURL);
|
||||
|
||||
|
@ -1404,13 +1404,13 @@ void EntityItemProperties::copyFromScriptValue(const QScriptValue &object) {
|
|||
}
|
||||
}
|
||||
|
||||
QScriptValue shouldDie = object.property("shouldDie");
|
||||
if (shouldDie.isValid()) {
|
||||
bool newShouldDie;
|
||||
newShouldDie = shouldDie.toVariant().toBool();
|
||||
if (_defaultSettings || newShouldDie != _shouldDie) {
|
||||
_shouldDie = newShouldDie;
|
||||
_shouldDieChanged = true;
|
||||
QScriptValue shouldBeDeleted = object.property("shouldBeDeleted");
|
||||
if (shouldBeDeleted.isValid()) {
|
||||
bool newShouldBeDeleted;
|
||||
newShouldBeDeleted = shouldBeDeleted.toVariant().toBool();
|
||||
if (_defaultSettings || newShouldBeDeleted != _shouldBeDeleted) {
|
||||
_shouldBeDeleted = newShouldBeDeleted;
|
||||
_shouldBeDeletedChanged = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1513,8 +1513,8 @@ void EntityItemProperties::copyToEntityItem(EntityItem& modelItem, bool forceCop
|
|||
somethingChanged = true;
|
||||
}
|
||||
|
||||
if (_shouldDieChanged || forceCopy) {
|
||||
modelItem.setShouldDie(_shouldDie);
|
||||
if (_shouldBeDeletedChanged || forceCopy) {
|
||||
modelItem.setShouldBeDeleted(_shouldBeDeleted);
|
||||
somethingChanged = true;
|
||||
}
|
||||
|
||||
|
@ -1569,7 +1569,7 @@ void EntityItemProperties::copyFromEntityItem(const EntityItem& modelItem) {
|
|||
_position = modelItem.getPosition() * (float) TREE_SCALE;
|
||||
_color = modelItem.getXColor();
|
||||
_radius = modelItem.getRadius() * (float) TREE_SCALE;
|
||||
_shouldDie = modelItem.getShouldDie();
|
||||
_shouldBeDeleted = modelItem.getShouldBeDeleted();
|
||||
_modelURL = modelItem.getModelURL();
|
||||
_rotation = modelItem.getRotation();
|
||||
_animationURL = modelItem.getAnimationURL();
|
||||
|
@ -1585,7 +1585,7 @@ void EntityItemProperties::copyFromEntityItem(const EntityItem& modelItem) {
|
|||
_colorChanged = false;
|
||||
_radiusChanged = false;
|
||||
|
||||
_shouldDieChanged = false;
|
||||
_shouldBeDeletedChanged = false;
|
||||
_modelURLChanged = false;
|
||||
_rotationChanged = false;
|
||||
_animationURLChanged = false;
|
||||
|
|
|
@ -96,7 +96,7 @@ public:
|
|||
const glm::vec3& getPosition() const { return _position; }
|
||||
xColor getColor() const { return _color; }
|
||||
float getRadius() const { return _radius; }
|
||||
bool getShouldDie() const { return _shouldDie; }
|
||||
bool getShouldBeDeleted() const { return _shouldBeDeleted; }
|
||||
|
||||
const QString& getModelURL() const { return _modelURL; }
|
||||
const glm::quat& getRotation() const { return _rotation; }
|
||||
|
@ -113,7 +113,7 @@ public:
|
|||
void setPosition(const glm::vec3& value) { _position = value; _positionChanged = true; }
|
||||
void setColor(const xColor& value) { _color = value; _colorChanged = 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
|
||||
void setModelURL(const QString& url) { _modelURL = url; _modelURLChanged = true; }
|
||||
|
@ -136,7 +136,7 @@ private:
|
|||
glm::vec3 _position;
|
||||
xColor _color;
|
||||
float _radius;
|
||||
bool _shouldDie; /// to delete it
|
||||
bool _shouldBeDeleted; /// to delete it
|
||||
|
||||
QString _modelURL;
|
||||
glm::quat _rotation;
|
||||
|
@ -153,7 +153,7 @@ private:
|
|||
bool _positionChanged;
|
||||
bool _colorChanged;
|
||||
bool _radiusChanged;
|
||||
bool _shouldDieChanged;
|
||||
bool _shouldBeDeletedChanged;
|
||||
|
||||
bool _modelURLChanged;
|
||||
bool _rotationChanged;
|
||||
|
@ -226,8 +226,8 @@ class EntityItem {
|
|||
|
||||
public:
|
||||
EntityItem();
|
||||
EntityItem(const EntityItemID& modelItemID);
|
||||
EntityItem(const EntityItemID& modelItemID, const EntityItemProperties& properties);
|
||||
EntityItem(const EntityItemID& entityItemID);
|
||||
EntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties);
|
||||
|
||||
/// 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);
|
||||
|
@ -276,7 +276,7 @@ public:
|
|||
float getEditedAgo() const { return static_cast<float>(usecTimestampNow() - _lastEdited) / static_cast<float>(USECS_PER_SECOND); }
|
||||
uint32_t getID() const { return _id; }
|
||||
void setID(uint32_t id) { _id = id; }
|
||||
bool getShouldDie() const { return _shouldDie; }
|
||||
bool getShouldBeDeleted() const { return _shouldBeDeleted; }
|
||||
uint32_t getCreatorTokenID() const { return _creatorTokenID; }
|
||||
bool isNewlyCreated() const { return _newlyCreated; }
|
||||
bool isKnownID() const { return getID() != UNKNOWN_MODEL_ID; }
|
||||
|
@ -293,7 +293,7 @@ public:
|
|||
/// set radius in domain scale units (0.0 - 1.0)
|
||||
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; }
|
||||
|
||||
// model related properties
|
||||
|
@ -346,7 +346,7 @@ public:
|
|||
static void cleanupLoadedAnimations();
|
||||
|
||||
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);
|
||||
|
||||
glm::vec3 _position;
|
||||
|
@ -354,7 +354,7 @@ protected:
|
|||
float _radius;
|
||||
uint32_t _id;
|
||||
static uint32_t _nextID;
|
||||
bool _shouldDie;
|
||||
bool _shouldBeDeleted;
|
||||
|
||||
// model related items
|
||||
QString _modelURL;
|
||||
|
|
|
@ -117,7 +117,7 @@ void EntityScriptingInterface::deleteEntity(EntityItemID entityID) {
|
|||
|
||||
// setup properties to kill the model
|
||||
EntityItemProperties properties;
|
||||
properties.setShouldDie(true);
|
||||
properties.setShouldBeDeleted(true);
|
||||
|
||||
uint32_t actualID = entityID.id;
|
||||
|
||||
|
|
|
@ -385,9 +385,9 @@ bool DeleteEntityOperator::PreRecursion(OctreeElement* element) {
|
|||
if (modelTreeElement == details.containingElement) {
|
||||
|
||||
// This is a good place to delete it!!!
|
||||
EntityItemID modelItemID = details.model->getEntityItemID();
|
||||
modelTreeElement->removeEntityWithEntityItemID(modelItemID);
|
||||
_tree->setContainingElement(modelItemID, NULL);
|
||||
EntityItemID entityItemID = details.model->getEntityItemID();
|
||||
modelTreeElement->removeEntityWithEntityItemID(entityItemID);
|
||||
_tree->setContainingElement(entityItemID, NULL);
|
||||
_foundCount++;
|
||||
}
|
||||
}
|
||||
|
@ -589,7 +589,7 @@ bool EntityTree::findInSphereOperation(OctreeElement* element, void* extraData)
|
|||
// If this element contains the point, then search it...
|
||||
if (sphereIntersection) {
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -622,7 +622,7 @@ bool EntityTree::findInCubeOperation(OctreeElement* element, void* extraData) {
|
|||
const AACube& elementCube = element->getAACube();
|
||||
if (elementCube.touches(args->_cube)) {
|
||||
EntityTreeElement* modelTreeElement = static_cast<EntityTreeElement*>(element);
|
||||
modelTreeElement->getEntitys(args->_cube, args->_foundEntitys);
|
||||
modelTreeElement->getEntities(args->_cube, args->_foundEntitys);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -740,21 +740,21 @@ void EntityTree::update() {
|
|||
recurseTreeWithOperation(updateOperation, &args);
|
||||
|
||||
// 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++) {
|
||||
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
|
||||
AACube treeBounds = getRoot()->getAACube();
|
||||
|
||||
if (!shouldDie && treeBounds.contains(args._movingEntitys[i].getPosition())) {
|
||||
storeEntity(args._movingEntitys[i]);
|
||||
if (!shouldDie && treeBounds.contains(args._movingEntities[i].getPosition())) {
|
||||
storeEntity(args._movingEntities[i]);
|
||||
} else {
|
||||
uint32_t modelItemID = args._movingEntitys[i].getID();
|
||||
uint32_t entityItemID = args._movingEntities[i].getID();
|
||||
quint64 deletedAt = usecTimestampNow();
|
||||
_recentlyDeletedEntitysLock.lockForWrite();
|
||||
_recentlyDeletedEntityItemIDs.insert(deletedAt, modelItemID);
|
||||
_recentlyDeletedEntityItemIDs.insert(deletedAt, entityItemID);
|
||||
_recentlyDeletedEntitysLock.unlock();
|
||||
}
|
||||
}
|
||||
|
@ -922,33 +922,33 @@ void EntityTree::processEraseMessage(const QByteArray& dataByteArray, const Shar
|
|||
dataAt += sizeof(modelID);
|
||||
processedBytes += sizeof(modelID);
|
||||
|
||||
EntityItemID modelItemID(modelID);
|
||||
modelItemIDsToDelete << modelItemID;
|
||||
EntityItemID entityItemID(modelID);
|
||||
modelItemIDsToDelete << entityItemID;
|
||||
}
|
||||
deleteEntitys(modelItemIDsToDelete);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
EntityTreeElement* EntityTree::getContainingElement(const EntityItemID& modelItemID) const {
|
||||
EntityTreeElement* EntityTree::getContainingElement(const EntityItemID& entityItemID) const {
|
||||
//qDebug() << "_modelToElementMap=" << _modelToElementMap;
|
||||
|
||||
// TODO: do we need to make this thread safe? Or is it acceptable as is
|
||||
if (_modelToElementMap.contains(modelItemID)) {
|
||||
return _modelToElementMap.value(modelItemID);
|
||||
if (_modelToElementMap.contains(entityItemID)) {
|
||||
return _modelToElementMap.value(entityItemID);
|
||||
}
|
||||
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
|
||||
if (element) {
|
||||
_modelToElementMap[modelItemID] = element;
|
||||
_modelToElementMap[entityItemID] = element;
|
||||
} else {
|
||||
_modelToElementMap.remove(modelItemID);
|
||||
_modelToElementMap.remove(entityItemID);
|
||||
}
|
||||
|
||||
//qDebug() << "setContainingElement() modelItemID=" << modelItemID << "element=" << element;
|
||||
//qDebug() << "setContainingElement() entityItemID=" << entityItemID << "element=" << element;
|
||||
//qDebug() << "AFTER _modelToElementMap=" << _modelToElementMap;
|
||||
}
|
||||
|
||||
|
|
|
@ -50,7 +50,6 @@ public:
|
|||
virtual bool rootElementHasData() const { return true; }
|
||||
virtual void update();
|
||||
|
||||
void OLD__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 addEntity(const EntityItemID& modelID, const EntityItemProperties& properties);
|
||||
|
@ -90,8 +89,8 @@ public:
|
|||
return _fbxService ? _fbxService->getGeometryForEntity(modelItem) : NULL;
|
||||
}
|
||||
|
||||
EntityTreeElement* getContainingElement(const EntityItemID& modelItemID) const;
|
||||
void setContainingElement(const EntityItemID& modelItemID, EntityTreeElement* element);
|
||||
EntityTreeElement* getContainingElement(const EntityItemID& entityItemID) const;
|
||||
void setContainingElement(const EntityItemID& entityItemID, EntityTreeElement* element);
|
||||
void debugDumpMap();
|
||||
|
||||
private:
|
||||
|
|
|
@ -75,9 +75,9 @@ OctreeElement::AppendState EntityTreeElement::appendElementData(OctreePacketData
|
|||
LevelDetails elementLevel = packetData->startLevel();
|
||||
|
||||
// write our models out... first determine which of the models are in view based on our params
|
||||
uint16_t numberOfEntitys = 0;
|
||||
uint16_t actualNumberOfEntitys = 0;
|
||||
QVector<uint16_t> indexesOfEntitysToInclude;
|
||||
uint16_t numberOfEntities = 0;
|
||||
uint16_t actualNumberOfEntities = 0;
|
||||
QVector<uint16_t> indexesOfEntitiesToInclude;
|
||||
|
||||
for (uint16_t i = 0; i < _entityItems->size(); i++) {
|
||||
const EntityItem& model = (*_entityItems)[i];
|
||||
|
@ -96,16 +96,16 @@ OctreeElement::AppendState EntityTreeElement::appendElementData(OctreePacketData
|
|||
}
|
||||
|
||||
if (includeThisEntity) {
|
||||
indexesOfEntitysToInclude << i;
|
||||
numberOfEntitys++;
|
||||
indexesOfEntitiesToInclude << i;
|
||||
numberOfEntities++;
|
||||
}
|
||||
}
|
||||
|
||||
int numberOfEntitysOffset = packetData->getUncompressedByteOffset();
|
||||
bool successAppendEntityCount = packetData->appendValue(numberOfEntitys);
|
||||
int numberOfEntitiesOffset = packetData->getUncompressedByteOffset();
|
||||
bool successAppendEntityCount = packetData->appendValue(numberOfEntities);
|
||||
|
||||
if (successAppendEntityCount) {
|
||||
foreach (uint16_t i, indexesOfEntitysToInclude) {
|
||||
foreach (uint16_t i, indexesOfEntitiesToInclude) {
|
||||
const EntityItem& model = (*_entityItems)[i];
|
||||
|
||||
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)
|
||||
// and include the model in our final count of models
|
||||
packetData->endLevel(modelLevel);
|
||||
actualNumberOfEntitys++;
|
||||
actualNumberOfEntities++;
|
||||
}
|
||||
|
||||
// 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
|
||||
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
|
||||
bool successUpdateEntityCount = true;
|
||||
if (!noEntitysFit && numberOfEntitys != actualNumberOfEntitys) {
|
||||
successUpdateEntityCount = packetData->updatePriorBytes(numberOfEntitysOffset,
|
||||
(const unsigned char*)&actualNumberOfEntitys, sizeof(actualNumberOfEntitys));
|
||||
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
|
||||
// we should discard our element and return a result of NONE
|
||||
if (!successUpdateEntityCount || noEntitysFit) {
|
||||
if (!successUpdateEntityCount || noEntitiesFit) {
|
||||
packetData->discardLevel(elementLevel);
|
||||
appendElementState = OctreeElement::NONE;
|
||||
} 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
|
||||
// into the arguments moving models. These will be added back or deleted completely
|
||||
if (model.getShouldDie() || !bestFitEntityBounds(model)) {
|
||||
args._movingEntitys.push_back(model);
|
||||
if (model.getShouldBeDeleted() || !bestFitEntityBounds(model)) {
|
||||
args._movingEntities.push_back(model);
|
||||
|
||||
// erase this model
|
||||
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...
|
||||
|
||||
QList<EntityItem>::iterator modelItr = _entityItems->begin();
|
||||
QList<EntityItem>::const_iterator modelEnd = _entityItems->end();
|
||||
QList<EntityItem>::iterator entityItr = _entityItems->begin();
|
||||
QList<EntityItem>::const_iterator entityEnd = _entityItems->end();
|
||||
bool somethingIntersected = false;
|
||||
while(modelItr != modelEnd) {
|
||||
EntityItem& model = (*modelItr);
|
||||
while(entityItr != entityEnd) {
|
||||
EntityItem& entity = (*entityItr);
|
||||
|
||||
AACube modelCube = model.getAACube();
|
||||
AACube entityCube = entity.getAACube();
|
||||
float localDistance;
|
||||
BoxFace localFace;
|
||||
|
||||
// if the ray doesn't intersect with our cube, we can stop searching!
|
||||
if (modelCube.findRayIntersection(origin, direction, localDistance, localFace)) {
|
||||
const FBXGeometry* fbxGeometry = _myTree->getGeometryForEntity(model);
|
||||
if (entityCube.findRayIntersection(origin, direction, localDistance, localFace)) {
|
||||
const FBXGeometry* fbxGeometry = _myTree->getGeometryForEntity(entity);
|
||||
if (fbxGeometry && fbxGeometry->meshExtents.isValid()) {
|
||||
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)) {
|
||||
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"
|
||||
// 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 scale = model.getSize() / maxDimension;
|
||||
float scale = entity.getSize() / maxDimension;
|
||||
|
||||
glm::vec3 halfDimensions = (extents.maximum - extents.minimum) * 0.5f;
|
||||
glm::vec3 offset = -extents.minimum - halfDimensions;
|
||||
|
@ -280,10 +280,10 @@ bool EntityTreeElement::findDetailedRayIntersection(const glm::vec3& origin, con
|
|||
|
||||
Extents rotatedExtents = extents;
|
||||
|
||||
calculateRotatedExtents(rotatedExtents, model.getRotation());
|
||||
calculateRotatedExtents(rotatedExtents, entity.getRotation());
|
||||
|
||||
rotatedExtents.minimum += model.getPosition();
|
||||
rotatedExtents.maximum += model.getPosition();
|
||||
rotatedExtents.minimum += entity.getPosition();
|
||||
rotatedExtents.maximum += entity.getPosition();
|
||||
|
||||
|
||||
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 (rotatedExtentsBox.findRayIntersection(origin, direction, localDistance, localFace)) {
|
||||
|
||||
// extents is the model relative, scaled, centered extents of the model
|
||||
glm::mat4 rotation = glm::mat4_cast(model.getRotation());
|
||||
glm::mat4 translation = glm::translate(model.getPosition());
|
||||
glm::mat4 modelToWorldMatrix = translation * rotation;
|
||||
glm::mat4 worldToEntityMatrix = glm::inverse(modelToWorldMatrix);
|
||||
// extents is the entity relative, scaled, centered extents of the entity
|
||||
glm::mat4 rotation = glm::mat4_cast(entity.getRotation());
|
||||
glm::mat4 translation = glm::translate(entity.getPosition());
|
||||
glm::mat4 entityToWorldMatrix = translation * rotation;
|
||||
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 modelFrameDirection = glm::vec3(worldToEntityMatrix * glm::vec4(direction, 0.0f));
|
||||
glm::vec3 entityFrameOrigin = glm::vec3(worldToEntityMatrix * glm::vec4(origin, 1.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.
|
||||
if (modelFrameBox.findRayIntersection(modelFrameOrigin, modelFrameDirection, localDistance, localFace)) {
|
||||
if (entityFrameBox.findRayIntersection(entityFrameOrigin, entityFrameDirection, localDistance, localFace)) {
|
||||
if (localDistance < distance) {
|
||||
distance = localDistance;
|
||||
face = localFace;
|
||||
*intersectedObject = (void*)(&model);
|
||||
*intersectedObject = (void*)(&entity);
|
||||
somethingIntersected = true;
|
||||
}
|
||||
}
|
||||
|
@ -316,93 +316,93 @@ bool EntityTreeElement::findDetailedRayIntersection(const glm::vec3& origin, con
|
|||
} else if (localDistance < distance) {
|
||||
distance = localDistance;
|
||||
face = localFace;
|
||||
*intersectedObject = (void*)(&model);
|
||||
*intersectedObject = (void*)(&entity);
|
||||
somethingIntersected = true;
|
||||
}
|
||||
}
|
||||
|
||||
++modelItr;
|
||||
++entityItr;
|
||||
}
|
||||
return somethingIntersected;
|
||||
}
|
||||
|
||||
bool EntityTreeElement::findSpherePenetration(const glm::vec3& center, float radius,
|
||||
glm::vec3& penetration, void** penetratedObject) const {
|
||||
QList<EntityItem>::iterator modelItr = _entityItems->begin();
|
||||
QList<EntityItem>::const_iterator modelEnd = _entityItems->end();
|
||||
while(modelItr != modelEnd) {
|
||||
EntityItem& model = (*modelItr);
|
||||
glm::vec3 modelCenter = model.getPosition();
|
||||
float modelRadius = model.getRadius();
|
||||
QList<EntityItem>::iterator entityItr = _entityItems->begin();
|
||||
QList<EntityItem>::const_iterator entityEnd = _entityItems->end();
|
||||
while(entityItr != entityEnd) {
|
||||
EntityItem& entity = (*entityItr);
|
||||
glm::vec3 entityCenter = entity.getPosition();
|
||||
float entityRadius = entity.getRadius();
|
||||
|
||||
// don't penetrate yourself
|
||||
if (modelCenter == center && modelRadius == radius) {
|
||||
if (entityCenter == center && entityRadius == radius) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (findSphereSpherePenetration(center, radius, modelCenter, modelRadius, penetration)) {
|
||||
// return true on first valid model penetration
|
||||
*penetratedObject = (void*)(&model);
|
||||
if (findSphereSpherePenetration(center, radius, entityCenter, entityRadius, penetration)) {
|
||||
// return true on first valid entity penetration
|
||||
*penetratedObject = (void*)(&entity);
|
||||
return true;
|
||||
}
|
||||
++modelItr;
|
||||
++entityItr;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool EntityTreeElement::updateEntity(const EntityItem& model) {
|
||||
bool EntityTreeElement::updateEntity(const EntityItem& entity) {
|
||||
const bool wantDebug = false;
|
||||
if (wantDebug) {
|
||||
EntityItemID modelItemID = model.getEntityItemID();
|
||||
qDebug() << "EntityTreeElement::updateEntity(model) modelID.id="
|
||||
<< modelItemID.id << "creatorTokenID=" << modelItemID.creatorTokenID;
|
||||
EntityItemID entityItemID = entity.getEntityItemID();
|
||||
qDebug() << "EntityTreeElement::updateEntity(entity) entityID.id="
|
||||
<< entityItemID.id << "creatorTokenID=" << entityItemID.creatorTokenID;
|
||||
}
|
||||
|
||||
// NOTE: this method must first lookup the model by ID, hence it is O(N)
|
||||
// and "model is not found" is worst-case (full N) but maybe we don't care?
|
||||
// (guaranteed that num models per elemen is small?)
|
||||
uint16_t numberOfEntitys = _entityItems->size();
|
||||
for (uint16_t i = 0; i < numberOfEntitys; i++) {
|
||||
// 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?)
|
||||
uint16_t numberOfEntities = _entityItems->size();
|
||||
for (uint16_t i = 0; i < numberOfEntities; i++) {
|
||||
EntityItem& thisEntity = (*_entityItems)[i];
|
||||
if (thisEntity.getID() == model.getID()) {
|
||||
if (thisEntity.getID() == entity.getID()) {
|
||||
if (wantDebug) {
|
||||
qDebug() << "found model with id";
|
||||
qDebug() << "found entity with id";
|
||||
}
|
||||
int difference = thisEntity.getLastUpdated() - model.getLastUpdated();
|
||||
bool changedOnServer = thisEntity.getLastEdited() <= model.getLastEdited();
|
||||
bool localOlder = thisEntity.getLastUpdated() < model.getLastUpdated();
|
||||
int difference = thisEntity.getLastUpdated() - entity.getLastUpdated();
|
||||
bool changedOnServer = thisEntity.getLastEdited() <= entity.getLastEdited();
|
||||
bool localOlder = thisEntity.getLastUpdated() < entity.getLastUpdated();
|
||||
if (changedOnServer || localOlder) {
|
||||
if (wantDebug) {
|
||||
qDebug("local model [id:%d] %s and %s than server model by %d, model.isNewlyCreated()=%s",
|
||||
model.getID(), (changedOnServer ? "CHANGED" : "same"),
|
||||
qDebug("local entity [id:%d] %s and %s than server entity by %d, entity.isNewlyCreated()=%s",
|
||||
entity.getID(), (changedOnServer ? "CHANGED" : "same"),
|
||||
(localOlder ? "OLDER" : "NEWER"),
|
||||
difference, debug::valueOf(model.isNewlyCreated()) );
|
||||
difference, debug::valueOf(entity.isNewlyCreated()) );
|
||||
}
|
||||
|
||||
thisEntity.copyChangedProperties(model);
|
||||
thisEntity.copyChangedProperties(entity);
|
||||
markWithChangedTime();
|
||||
|
||||
// seems like we shouldn't need this
|
||||
_myTree->setContainingElement(model.getEntityItemID(), this);
|
||||
_myTree->setContainingElement(entity.getEntityItemID(), this);
|
||||
} else {
|
||||
if (wantDebug) {
|
||||
qDebug(">>> IGNORING SERVER!!! Would've caused jutter! <<< "
|
||||
"local model [id:%d] %s and %s than server model by %d, model.isNewlyCreated()=%s",
|
||||
model.getID(), (changedOnServer ? "CHANGED" : "same"),
|
||||
"local entity [id:%d] %s and %s than server entity by %d, entity.isNewlyCreated()=%s",
|
||||
entity.getID(), (changedOnServer ? "CHANGED" : "same"),
|
||||
(localOlder ? "OLDER" : "NEWER"),
|
||||
difference, debug::valueOf(model.isNewlyCreated()) );
|
||||
difference, debug::valueOf(entity.isNewlyCreated()) );
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// If we didn't find the model here, then let's check to see if we should add it...
|
||||
if (bestFitEntityBounds(model)) {
|
||||
_entityItems->push_back(model);
|
||||
// If we didn't find the entity here, then let's check to see if we should add it...
|
||||
if (bestFitEntityBounds(entity)) {
|
||||
_entityItems->push_back(entity);
|
||||
markWithChangedTime();
|
||||
// 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;
|
||||
}
|
||||
|
||||
|
@ -411,37 +411,37 @@ bool EntityTreeElement::updateEntity(const EntityItem& model) {
|
|||
|
||||
void EntityTreeElement::updateEntityItemID(FindAndUpdateEntityItemIDArgs* args) {
|
||||
bool wantDebug = false;
|
||||
uint16_t numberOfEntitys = _entityItems->size();
|
||||
for (uint16_t i = 0; i < numberOfEntitys; i++) {
|
||||
uint16_t numberOfEntities = _entityItems->size();
|
||||
for (uint16_t i = 0; i < numberOfEntities; i++) {
|
||||
EntityItem& thisEntity = (*_entityItems)[i];
|
||||
|
||||
if (!args->creatorTokenFound) {
|
||||
// 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 (wantDebug) {
|
||||
qDebug() << "EntityTreeElement::updateEntityItemID()... found the model... updating it's ID... "
|
||||
qDebug() << "EntityTreeElement::updateEntityItemID()... found the entity... updating it's ID... "
|
||||
<< "creatorTokenID=" << args->creatorTokenID
|
||||
<< "modelID=" << args->modelID;
|
||||
<< "entityID=" << args->entityID;
|
||||
}
|
||||
|
||||
thisEntity.setID(args->modelID);
|
||||
thisEntity.setID(args->entityID);
|
||||
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 (thisEntity.getCreatorTokenID() == UNKNOWN_MODEL_TOKEN && thisEntity.getID() == args->modelID) {
|
||||
if (thisEntity.getCreatorTokenID() == UNKNOWN_MODEL_TOKEN && thisEntity.getID() == args->entityID) {
|
||||
|
||||
if (wantDebug) {
|
||||
qDebug() << "EntityTreeElement::updateEntityItemID()... VIEWED MODEL FOUND??? "
|
||||
qDebug() << "EntityTreeElement::updateEntityItemID()... VIEWED entity FOUND??? "
|
||||
<< "args->creatorTokenID=" << args->creatorTokenID
|
||||
<< "thisEntity.getCreatorTokenID()=" << thisEntity.getCreatorTokenID()
|
||||
<< "args->modelID=" << args->modelID;
|
||||
<< "args->entityID=" << args->entityID;
|
||||
}
|
||||
|
||||
_entityItems->removeAt(i); // remove the model at this index
|
||||
numberOfEntitys--; // this means we have 1 fewer model in this list
|
||||
_entityItems->removeAt(i); // remove the entity at this index
|
||||
numberOfEntities--; // this means we have 1 fewer entity in this list
|
||||
i--; // and we actually want to back up i as well.
|
||||
args->viewedEntityFound = true;
|
||||
}
|
||||
|
@ -454,8 +454,8 @@ void EntityTreeElement::updateEntityItemID(FindAndUpdateEntityItemIDArgs* args)
|
|||
const EntityItem* EntityTreeElement::getClosestEntity(glm::vec3 position) const {
|
||||
const EntityItem* closestEntity = NULL;
|
||||
float closestEntityDistance = FLT_MAX;
|
||||
uint16_t numberOfEntitys = _entityItems->size();
|
||||
for (uint16_t i = 0; i < numberOfEntitys; i++) {
|
||||
uint16_t numberOfEntities = _entityItems->size();
|
||||
for (uint16_t i = 0; i < numberOfEntities; i++) {
|
||||
float distanceToEntity = glm::distance(position, (*_entityItems)[i].getPosition());
|
||||
if (distanceToEntity < closestEntityDistance) {
|
||||
closestEntity = &(*_entityItems)[i];
|
||||
|
@ -464,40 +464,40 @@ const EntityItem* EntityTreeElement::getClosestEntity(glm::vec3 position) const
|
|||
return closestEntity;
|
||||
}
|
||||
|
||||
void EntityTreeElement::getEntitys(const glm::vec3& searchPosition, float searchRadius, QVector<const EntityItem*>& foundEntitys) const {
|
||||
uint16_t numberOfEntitys = _entityItems->size();
|
||||
for (uint16_t i = 0; i < numberOfEntitys; i++) {
|
||||
const EntityItem* model = &(*_entityItems)[i];
|
||||
float distance = glm::length(model->getPosition() - searchPosition);
|
||||
if (distance < searchRadius + model->getRadius()) {
|
||||
foundEntitys.push_back(model);
|
||||
void EntityTreeElement::getEntities(const glm::vec3& searchPosition, float searchRadius, QVector<const EntityItem*>& foundEntities) const {
|
||||
uint16_t numberOfEntities = _entityItems->size();
|
||||
for (uint16_t i = 0; i < numberOfEntities; i++) {
|
||||
const EntityItem* entity = &(*_entityItems)[i];
|
||||
float distance = glm::length(entity->getPosition() - searchPosition);
|
||||
if (distance < searchRadius + entity->getRadius()) {
|
||||
foundEntities.push_back(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EntityTreeElement::getEntitys(const AACube& box, QVector<EntityItem*>& foundEntitys) {
|
||||
QList<EntityItem>::iterator modelItr = _entityItems->begin();
|
||||
QList<EntityItem>::iterator modelEnd = _entityItems->end();
|
||||
AACube modelCube;
|
||||
while(modelItr != modelEnd) {
|
||||
EntityItem* model = &(*modelItr);
|
||||
float radius = model->getRadius();
|
||||
void EntityTreeElement::getEntities(const AACube& box, QVector<EntityItem*>& foundEntities) {
|
||||
QList<EntityItem>::iterator entityItr = _entityItems->begin();
|
||||
QList<EntityItem>::iterator entityEnd = _entityItems->end();
|
||||
AACube entityCube;
|
||||
while(entityItr != entityEnd) {
|
||||
EntityItem* entity = &(*entityItr);
|
||||
float radius = entity->getRadius();
|
||||
// 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).
|
||||
modelCube.setBox(model->getPosition() - glm::vec3(radius), 2.f * radius);
|
||||
if (modelCube.touches(_cube)) {
|
||||
foundEntitys.push_back(model);
|
||||
entityCube.setBox(entity->getPosition() - glm::vec3(radius), 2.f * radius);
|
||||
if (entityCube.touches(_cube)) {
|
||||
foundEntities.push_back(entity);
|
||||
}
|
||||
++modelItr;
|
||||
++entityItr;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
uint16_t numberOfEntitys = _entityItems->size();
|
||||
for (uint16_t i = 0; i < numberOfEntitys; i++) {
|
||||
uint16_t numberOfEntities = _entityItems->size();
|
||||
for (uint16_t i = 0; i < numberOfEntities; i++) {
|
||||
if ((*_entityItems)[i].getID() == id) {
|
||||
foundEntity = &(*_entityItems)[i];
|
||||
break;
|
||||
|
@ -507,10 +507,10 @@ 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 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;
|
||||
uint16_t numberOfEntitys = _entityItems->size();
|
||||
for (uint16_t i = 0; i < numberOfEntitys; i++) {
|
||||
uint16_t numberOfEntities = _entityItems->size();
|
||||
for (uint16_t i = 0; i < numberOfEntities; i++) {
|
||||
if ((*_entityItems)[i].getEntityItemID() == id) {
|
||||
foundEntity = &(*_entityItems)[i];
|
||||
break;
|
||||
|
@ -521,8 +521,8 @@ const EntityItem* EntityTreeElement::getEntityWithEntityItemID(const EntityItemI
|
|||
|
||||
bool EntityTreeElement::removeEntityWithID(uint32_t id) {
|
||||
bool foundEntity = false;
|
||||
uint16_t numberOfEntitys = _entityItems->size();
|
||||
for (uint16_t i = 0; i < numberOfEntitys; i++) {
|
||||
uint16_t numberOfEntities = _entityItems->size();
|
||||
for (uint16_t i = 0; i < numberOfEntities; i++) {
|
||||
if ((*_entityItems)[i].getID() == id) {
|
||||
foundEntity = true;
|
||||
_entityItems->removeAt(i);
|
||||
|
@ -535,8 +535,8 @@ bool EntityTreeElement::removeEntityWithID(uint32_t id) {
|
|||
|
||||
bool EntityTreeElement::removeEntityWithEntityItemID(const EntityItemID& id) {
|
||||
bool foundEntity = false;
|
||||
uint16_t numberOfEntitys = _entityItems->size();
|
||||
for (uint16_t i = 0; i < numberOfEntitys; i++) {
|
||||
uint16_t numberOfEntities = _entityItems->size();
|
||||
for (uint16_t i = 0; i < numberOfEntities; i++) {
|
||||
if ((*_entityItems)[i].getEntityItemID() == id) {
|
||||
foundEntity = true;
|
||||
_entityItems->removeAt(i);
|
||||
|
@ -559,22 +559,22 @@ int EntityTreeElement::readElementDataFromBuffer(const unsigned char* data, int
|
|||
|
||||
const unsigned char* dataAt = data;
|
||||
int bytesRead = 0;
|
||||
uint16_t numberOfEntitys = 0;
|
||||
uint16_t numberOfEntities = 0;
|
||||
int expectedBytesPerEntity = EntityItem::expectedBytes();
|
||||
|
||||
if (bytesLeftToRead >= (int)sizeof(numberOfEntitys)) {
|
||||
// read our models in....
|
||||
numberOfEntitys = *(uint16_t*)dataAt;
|
||||
if (bytesLeftToRead >= (int)sizeof(numberOfEntities)) {
|
||||
// read our entitys in....
|
||||
numberOfEntities = *(uint16_t*)dataAt;
|
||||
|
||||
dataAt += sizeof(numberOfEntitys);
|
||||
bytesLeftToRead -= (int)sizeof(numberOfEntitys);
|
||||
bytesRead += sizeof(numberOfEntitys);
|
||||
dataAt += sizeof(numberOfEntities);
|
||||
bytesLeftToRead -= (int)sizeof(numberOfEntities);
|
||||
bytesRead += sizeof(numberOfEntities);
|
||||
|
||||
if (bytesLeftToRead >= (int)(numberOfEntitys * expectedBytesPerEntity)) {
|
||||
for (uint16_t i = 0; i < numberOfEntitys; i++) {
|
||||
if (bytesLeftToRead >= (int)(numberOfEntities * expectedBytesPerEntity)) {
|
||||
for (uint16_t i = 0; i < numberOfEntities; i++) {
|
||||
EntityItem tempEntity; // we will read into this
|
||||
EntityItemID modelItemID = EntityItem::readEntityItemIDFromBuffer(dataAt, bytesLeftToRead, args);
|
||||
const EntityItem* existingEntityItem = _myTree->findEntityByEntityItemID(modelItemID);
|
||||
EntityItemID entityItemID = EntityItem::readEntityItemIDFromBuffer(dataAt, bytesLeftToRead, args);
|
||||
const EntityItem* existingEntityItem = _myTree->findEntityByEntityItemID(entityItemID);
|
||||
if (existingEntityItem) {
|
||||
// copy original properties...
|
||||
tempEntity.copyChangedProperties(*existingEntityItem);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
//
|
||||
// EntityTreeElement.h
|
||||
// libraries/models/src
|
||||
// libraries/entities/src
|
||||
//
|
||||
// Created by Brad Hefta-Gaub on 12/4/13.
|
||||
// Copyright 2013 High Fidelity, Inc.
|
||||
|
@ -29,7 +29,7 @@ public:
|
|||
_movingItems(0)
|
||||
{ }
|
||||
|
||||
QList<EntityItem> _movingEntitys;
|
||||
QList<EntityItem> _movingEntities;
|
||||
int _totalElements;
|
||||
int _totalItems;
|
||||
int _movingItems;
|
||||
|
@ -37,7 +37,7 @@ public:
|
|||
|
||||
class FindAndUpdateEntityItemIDArgs {
|
||||
public:
|
||||
uint32_t modelID;
|
||||
uint32_t entityID;
|
||||
uint32_t creatorTokenID;
|
||||
bool creatorTokenFound;
|
||||
bool viewedEntityFound;
|
||||
|
@ -120,21 +120,21 @@ public:
|
|||
void update(EntityTreeUpdateArgs& args);
|
||||
void setTree(EntityTree* tree) { _myTree = tree; }
|
||||
|
||||
bool updateEntity(const EntityItem& model);
|
||||
bool updateEntity(const EntityItem& entity);
|
||||
void updateEntityItemID(FindAndUpdateEntityItemIDArgs* args);
|
||||
|
||||
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 radius the radius of the query sphere
|
||||
/// \param models[out] vector of const EntityItem*
|
||||
void getEntitys(const glm::vec3& position, float radius, QVector<const EntityItem*>& foundEntitys) const;
|
||||
/// \param entities[out] vector of const EntityItem*
|
||||
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 models[out] vector of non-const EntityItem*
|
||||
void getEntitys(const AACube& box, QVector<EntityItem*>& foundEntitys);
|
||||
/// \param entities[out] vector of non-const EntityItem*
|
||||
void getEntities(const AACube& box, QVector<EntityItem*>& foundEntities);
|
||||
|
||||
const EntityItem* getEntityWithID(uint32_t id) const;
|
||||
const EntityItem* getEntityWithEntityItemID(const EntityItemID& id) const;
|
||||
|
@ -142,8 +142,8 @@ public:
|
|||
bool removeEntityWithID(uint32_t id);
|
||||
bool removeEntityWithEntityItemID(const EntityItemID& id);
|
||||
|
||||
bool containsEntityBounds(const EntityItem& model) const;
|
||||
bool bestFitEntityBounds(const EntityItem& model) const;
|
||||
bool containsEntityBounds(const EntityItem& entity) const;
|
||||
bool bestFitEntityBounds(const EntityItem& entity) const;
|
||||
|
||||
protected:
|
||||
virtual void init(unsigned char * octalCode);
|
||||
|
|
Loading…
Reference in a new issue