From 67ff05739a2c7d4593081d954391f40e76a60d59 Mon Sep 17 00:00:00 2001 From: sabrina-shanman Date: Wed, 15 Aug 2018 11:05:52 -0700 Subject: [PATCH] Take advantage of CollisionPickResult intersections being shared pointers to avoid copying on result comparison --- interface/src/raypick/CollisionPick.cpp | 27 +++++++++++++++++++++++++ interface/src/raypick/CollisionPick.h | 18 +---------------- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/interface/src/raypick/CollisionPick.cpp b/interface/src/raypick/CollisionPick.cpp index f05fb208f1..d763fc5c27 100644 --- a/interface/src/raypick/CollisionPick.cpp +++ b/interface/src/raypick/CollisionPick.cpp @@ -15,6 +15,33 @@ #include "ScriptEngineLogging.h" #include "UUIDHasher.h" +PickResultPointer CollisionPickResult::compareAndProcessNewResult(const PickResultPointer& newRes) { + const std::shared_ptr newCollisionResult = std::static_pointer_cast(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(*this); +} + void buildObjectIntersectionsMap(IntersectionType intersectionType, const std::shared_ptr> objectIntersections, std::unordered_map& intersections, std::unordered_map& collisionPointPairs) { for (auto& objectIntersection : *objectIntersections) { auto at = intersections.find(objectIntersection.foundID); diff --git a/interface/src/raypick/CollisionPick.h b/interface/src/raypick/CollisionPick.h index 2f383f3a58..40f2450776 100644 --- a/interface/src/raypick/CollisionPick.h +++ b/interface/src/raypick/CollisionPick.h @@ -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 newCollisionResult = std::static_pointer_cast(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(*this); - } + PickResultPointer compareAndProcessNewResult(const PickResultPointer& newRes) override; }; class CollisionPick : public Pick {