mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 23:16:50 +02:00
Take advantage of CollisionPickResult intersections being shared pointers to avoid copying on result comparison
This commit is contained in:
parent
aa4a6b2eae
commit
67ff05739a
2 changed files with 28 additions and 17 deletions
|
@ -15,6 +15,33 @@
|
||||||
#include "ScriptEngineLogging.h"
|
#include "ScriptEngineLogging.h"
|
||||||
#include "UUIDHasher.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) {
|
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) {
|
for (auto& objectIntersection : *objectIntersections) {
|
||||||
auto at = intersections.find(objectIntersection.foundID);
|
auto at = intersections.find(objectIntersection.foundID);
|
||||||
|
|
|
@ -53,23 +53,7 @@ public:
|
||||||
bool doesIntersect() const override { return intersects; }
|
bool doesIntersect() const override { return intersects; }
|
||||||
bool checkOrFilterAgainstMaxDistance(float maxDistance) override { return true; }
|
bool checkOrFilterAgainstMaxDistance(float maxDistance) override { return true; }
|
||||||
|
|
||||||
PickResultPointer compareAndProcessNewResult(const PickResultPointer& newRes) override {
|
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);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class CollisionPick : public Pick<CollisionRegion> {
|
class CollisionPick : public Pick<CollisionRegion> {
|
||||||
|
|
Loading…
Reference in a new issue