Take advantage of CollisionPickResult intersections being shared pointers to avoid copying on result comparison

This commit is contained in:
sabrina-shanman 2018-08-15 11:05:52 -07:00
parent aa4a6b2eae
commit 67ff05739a
2 changed files with 28 additions and 17 deletions

View file

@ -15,6 +15,33 @@
#include "ScriptEngineLogging.h"
#include "UUIDHasher.h"
PickResultPointer CollisionPickResult::compareAndProcessNewResult(const PickResultPointer& newRes) {
const std::shared_ptr<CollisionPickResult> newCollisionResult = std::static_pointer_cast<CollisionPickResult>(newRes);
if (entityIntersections->size()) {
for (ContactTestResult& entityIntersection : *(newCollisionResult->entityIntersections)) {
entityIntersections->push_back(entityIntersection);
}
} else {
entityIntersections = newCollisionResult->entityIntersections;
}
if (avatarIntersections->size()) {
for (ContactTestResult& avatarIntersection : *(newCollisionResult->avatarIntersections)) {
avatarIntersections->push_back(avatarIntersection);
}
} else {
avatarIntersections = newCollisionResult->avatarIntersections;
}
intersects = entityIntersections->size() || avatarIntersections->size();
if (newCollisionResult->loadState == LOAD_STATE_NOT_LOADED || loadState == LOAD_STATE_UNKNOWN) {
loadState = (LoadState)newCollisionResult->loadState;
}
return std::make_shared<CollisionPickResult>(*this);
}
void buildObjectIntersectionsMap(IntersectionType intersectionType, const std::shared_ptr<std::vector<ContactTestResult>> objectIntersections, std::unordered_map<QUuid, QVariantMap>& intersections, std::unordered_map<QUuid, QVariantList>& collisionPointPairs) {
for (auto& objectIntersection : *objectIntersections) {
auto at = intersections.find(objectIntersection.foundID);

View file

@ -53,23 +53,7 @@ public:
bool doesIntersect() const override { return intersects; }
bool checkOrFilterAgainstMaxDistance(float maxDistance) override { return true; }
PickResultPointer compareAndProcessNewResult(const PickResultPointer& newRes) override {
const std::shared_ptr<CollisionPickResult> newCollisionResult = std::static_pointer_cast<CollisionPickResult>(newRes);
for (ContactTestResult& entityIntersection : *(newCollisionResult->entityIntersections)) {
entityIntersections->push_back(entityIntersection);
}
for (ContactTestResult& avatarIntersection : *(newCollisionResult->avatarIntersections)) {
avatarIntersections->push_back(avatarIntersection);
}
intersects = entityIntersections->size() || avatarIntersections->size();
if (newCollisionResult->loadState == LOAD_STATE_NOT_LOADED || loadState == LOAD_STATE_UNKNOWN) {
loadState = (LoadState)newCollisionResult->loadState;
}
return std::make_shared<CollisionPickResult>(*this);
}
PickResultPointer compareAndProcessNewResult(const PickResultPointer& newRes) override;
};
class CollisionPick : public Pick<CollisionRegion> {