This commit is contained in:
Andrew Meadows 2018-02-07 16:25:06 -08:00
parent be38a4bc71
commit a8ad846f2b
3 changed files with 12 additions and 16 deletions

View file

@ -60,15 +60,13 @@ void Space::updateProxy(int32_t proxyId, const Space::Sphere& newSphere) {
return; return;
} }
_proxies[proxyId].sphere = newSphere; _proxies[proxyId].sphere = newSphere;
// TODO: when view is not changing it would be faster to recategorize each Proxy that changes.
// Otherwise, we would want to just update all changed objects, adjust the view, and then comute changes.
} }
void Space::setViews(const std::vector<Space::View>& views) { void Space::setViews(const std::vector<Space::View>& views) {
_views = views; _views = views;
} }
void Space::recategorizeProxiesAndGetChanges(std::vector<Space::Change>& changes) { void Space::categorizeAndGetChanges(std::vector<Space::Change>& changes) {
uint32_t numProxies = _proxies.size(); uint32_t numProxies = _proxies.size();
uint32_t numViews = _views.size(); uint32_t numViews = _views.size();
for (uint32_t i = 0; i < numProxies; ++i) { for (uint32_t i = 0; i < numProxies; ++i) {

View file

@ -45,8 +45,8 @@ public:
radiuses[1] = midRadius; radiuses[1] = midRadius;
radiuses[2] = farRadius; radiuses[2] = farRadius;
} }
glm::vec3 center { 0.0f, 0.0f, 0.0f }; // these init values are not important glm::vec3 center { 0.0f, 0.0f, 0.0f };
float radiuses[3] { 1.0f, 2.0f, 3.0f }; // these init values are not important float radiuses[3] { 0.0f, 0.0f, 0.0f };
}; };
class Change { class Change {
@ -66,11 +66,9 @@ public:
uint32_t getNumObjects() const { return (uint32_t)(_proxies.size() - _freeIndices.size()); } uint32_t getNumObjects() const { return (uint32_t)(_proxies.size() - _freeIndices.size()); }
void recategorizeProxiesAndGetChanges(std::vector<Change>& changes); void categorizeAndGetChanges(std::vector<Change>& changes);
private: private:
// NOTE: double-buffering proxy.category and .prevRegion in their own arrays is NOT faster
// (performance is within the noise) than leaving them as data members of Proxy.
std::vector<Proxy> _proxies; std::vector<Proxy> _proxies;
std::vector<View> _views; std::vector<View> _views;
std::vector<int32_t> _freeIndices; std::vector<int32_t> _freeIndices;

View file

@ -47,7 +47,7 @@ void SpaceTests::testOverlaps() {
QVERIFY(space.getNumObjects() == 1); QVERIFY(space.getNumObjects() == 1);
Changes changes; Changes changes;
space.recategorizeProxiesAndGetChanges(changes); space.categorizeAndGetChanges(changes);
QVERIFY(changes.size() == 0); QVERIFY(changes.size() == 0);
} }
@ -57,7 +57,7 @@ void SpaceTests::testOverlaps() {
workload::Space::Sphere newSphere(newPosition, newRadius); workload::Space::Sphere newSphere(newPosition, newRadius);
space.updateProxy(proxyId, newSphere); space.updateProxy(proxyId, newSphere);
Changes changes; Changes changes;
space.recategorizeProxiesAndGetChanges(changes); space.categorizeAndGetChanges(changes);
QVERIFY(changes.size() == 1); QVERIFY(changes.size() == 1);
QVERIFY(changes[0].proxyId == proxyId); QVERIFY(changes[0].proxyId == proxyId);
QVERIFY(changes[0].region == workload::Space::REGION_FAR); QVERIFY(changes[0].region == workload::Space::REGION_FAR);
@ -70,7 +70,7 @@ void SpaceTests::testOverlaps() {
workload::Space::Sphere newSphere(newPosition, newRadius); workload::Space::Sphere newSphere(newPosition, newRadius);
space.updateProxy(proxyId, newSphere); space.updateProxy(proxyId, newSphere);
Changes changes; Changes changes;
space.recategorizeProxiesAndGetChanges(changes); space.categorizeAndGetChanges(changes);
QVERIFY(changes.size() == 1); QVERIFY(changes.size() == 1);
QVERIFY(changes[0].proxyId == proxyId); QVERIFY(changes[0].proxyId == proxyId);
QVERIFY(changes[0].region == workload::Space::REGION_MIDDLE); QVERIFY(changes[0].region == workload::Space::REGION_MIDDLE);
@ -83,7 +83,7 @@ void SpaceTests::testOverlaps() {
workload::Space::Sphere newSphere(newPosition, newRadius); workload::Space::Sphere newSphere(newPosition, newRadius);
space.updateProxy(proxyId, newSphere); space.updateProxy(proxyId, newSphere);
Changes changes; Changes changes;
space.recategorizeProxiesAndGetChanges(changes); space.categorizeAndGetChanges(changes);
QVERIFY(changes.size() == 1); QVERIFY(changes.size() == 1);
QVERIFY(changes[0].proxyId == proxyId); QVERIFY(changes[0].proxyId == proxyId);
QVERIFY(changes[0].region == workload::Space::REGION_NEAR); QVERIFY(changes[0].region == workload::Space::REGION_NEAR);
@ -94,7 +94,7 @@ void SpaceTests::testOverlaps() {
// NOTE: atm deleting a proxy doesn't result in a "Change" // NOTE: atm deleting a proxy doesn't result in a "Change"
space.deleteProxy(proxyId); space.deleteProxy(proxyId);
Changes changes; Changes changes;
space.recategorizeProxiesAndGetChanges(changes); space.categorizeAndGetChanges(changes);
QVERIFY(changes.size() == 0); QVERIFY(changes.size() == 0);
QVERIFY(space.getNumObjects() == 0); QVERIFY(space.getNumObjects() == 0);
} }
@ -195,10 +195,10 @@ void SpaceTests::benchmark() {
space.setViews(views); space.setViews(views);
} }
// measure time to recategorize everything // measure time to categorizeAndGetChanges everything
std::vector<workload::Space::Change> changes; std::vector<workload::Space::Change> changes;
startTime = usecTimestampNow(); startTime = usecTimestampNow();
space.recategorizeProxiesAndGetChanges(changes); space.categorizeAndGetChanges(changes);
usec = usecTimestampNow() - startTime; usec = usecTimestampNow() - startTime;
timeToMoveView.push_back(usec); timeToMoveView.push_back(usec);
@ -227,7 +227,7 @@ void SpaceTests::benchmark() {
space.updateProxy(proxyKeys[j], newSpheres[k++]); space.updateProxy(proxyKeys[j], newSpheres[k++]);
} }
changes.clear(); changes.clear();
space.recategorizeProxiesAndGetChanges(changes); space.categorizeAndGetChanges(changes);
usec = usecTimestampNow() - startTime; usec = usecTimestampNow() - startTime;
timeToMoveProxies.push_back(usec); timeToMoveProxies.push_back(usec);