mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 21:43:03 +02:00
optimized findModelByID
This commit is contained in:
parent
fb34d13305
commit
3ed0b34b63
2 changed files with 6 additions and 46 deletions
|
@ -492,52 +492,12 @@ void ModelTree::findModels(const AACube& cube, QVector<ModelItem*> foundModels)
|
||||||
foundModels.swap(args._foundModels);
|
foundModels.swap(args._foundModels);
|
||||||
}
|
}
|
||||||
|
|
||||||
class FindByIDArgs {
|
const ModelItem* ModelTree::findModelByID(uint32_t id, bool alreadyLocked) const {
|
||||||
public:
|
ModelItemID modelID(id);
|
||||||
uint32_t id;
|
return findModelByModelItemID(modelID);
|
||||||
bool found;
|
|
||||||
const ModelItem* foundModel;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
bool ModelTree::findByIDOperation(OctreeElement* element, void* extraData) {
|
|
||||||
//qDebug() << "ModelTree::findByIDOperation()....";
|
|
||||||
|
|
||||||
FindByIDArgs* args = static_cast<FindByIDArgs*>(extraData);
|
|
||||||
ModelTreeElement* modelTreeElement = static_cast<ModelTreeElement*>(element);
|
|
||||||
|
|
||||||
// if already found, stop looking
|
|
||||||
if (args->found) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// as the tree element if it has this model
|
|
||||||
const ModelItem* foundModel = modelTreeElement->getModelWithID(args->id);
|
|
||||||
if (foundModel) {
|
|
||||||
args->foundModel = foundModel;
|
|
||||||
args->found = true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// keep looking
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const ModelItem* ModelTree::findModelByModelItemID(const ModelItemID& modelID) const {
|
||||||
const ModelItem* ModelTree::findModelByID(uint32_t id, bool alreadyLocked) {
|
|
||||||
FindByIDArgs args = { id, false, NULL };
|
|
||||||
|
|
||||||
if (!alreadyLocked) {
|
|
||||||
lockForRead();
|
|
||||||
}
|
|
||||||
recurseTreeWithOperation(findByIDOperation, &args);
|
|
||||||
if (!alreadyLocked) {
|
|
||||||
unlock();
|
|
||||||
}
|
|
||||||
return args.foundModel;
|
|
||||||
}
|
|
||||||
|
|
||||||
const ModelItem* ModelTree::findModelByModelItemID(const ModelItemID& modelID) {
|
|
||||||
const ModelItem* foundModel = NULL;
|
const ModelItem* foundModel = NULL;
|
||||||
ModelTreeElement* containingElement = getContainingElement(modelID);
|
ModelTreeElement* containingElement = getContainingElement(modelID);
|
||||||
if (containingElement) {
|
if (containingElement) {
|
||||||
|
|
|
@ -55,8 +55,8 @@ public:
|
||||||
void addModel(const ModelItemID& modelID, const ModelItemProperties& properties);
|
void addModel(const ModelItemID& modelID, const ModelItemProperties& properties);
|
||||||
void deleteModel(const ModelItemID& modelID);
|
void deleteModel(const ModelItemID& modelID);
|
||||||
const ModelItem* findClosestModel(glm::vec3 position, float targetRadius);
|
const ModelItem* findClosestModel(glm::vec3 position, float targetRadius);
|
||||||
const ModelItem* findModelByID(uint32_t id, bool alreadyLocked = false);
|
const ModelItem* findModelByID(uint32_t id, bool alreadyLocked = false) const;
|
||||||
const ModelItem* findModelByModelItemID(const ModelItemID& modelID);
|
const ModelItem* findModelByModelItemID(const ModelItemID& modelID) const;
|
||||||
|
|
||||||
/// finds all models that touch a sphere
|
/// finds all models that touch a sphere
|
||||||
/// \param center the center of the sphere
|
/// \param center the center of the sphere
|
||||||
|
|
Loading…
Reference in a new issue