diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 634511b5ce..3cd6a4199a 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -4170,6 +4170,14 @@ void Application::idle() { } { + // TEMP HACK: one view with static radiuses + float r0 = 10.0f; + float r1 = 20.0f; + float r2 = 30.0f; + workload::Space::View view(_viewFrustum.getPosition(), r0, r1, r2); + std::vector views; + views.push_back(view); + getEntities()->getWorkloadSpace()->setViews(views); _gameWorkload._engine->run(); } { diff --git a/libraries/workload/src/workload/ClassificationTracker.cpp b/libraries/workload/src/workload/ClassificationTracker.cpp index 009549737f..15066b1050 100644 --- a/libraries/workload/src/workload/ClassificationTracker.cpp +++ b/libraries/workload/src/workload/ClassificationTracker.cpp @@ -18,7 +18,17 @@ using namespace workload; void ClassificationTracker::configure(const Config& config) { } -void ClassificationTracker::run(const workload::WorkloadContextPointer& renderContext, Outputs& outputs) { - +void ClassificationTracker::run(const WorkloadContextPointer& context, Outputs& outputs) { + auto space = context->_space; + if (space) { + Changes changes; + space->categorizeAndGetChanges(changes); + outputs.resize(workload::Space::NUM_TRANSITIONS); + for (uint32_t i = 0; i < changes.size(); ++i) { + int32_t j = Space::computeTransitionIndex(changes[i].prevRegion, changes[i].region); + assert(j >= 0 && j < workload::Space::NUM_TRANSITIONS); + outputs[j].push_back(changes[i].proxyId); + } + } } diff --git a/libraries/workload/src/workload/ClassificationTracker.h b/libraries/workload/src/workload/ClassificationTracker.h index ca7a919769..e3364950da 100644 --- a/libraries/workload/src/workload/ClassificationTracker.h +++ b/libraries/workload/src/workload/ClassificationTracker.h @@ -29,7 +29,7 @@ namespace workload { class ClassificationTracker { public: using Config = ClassificationTrackerConfig; - using Outputs = Classifications; + using Outputs = SortedChanges; using JobModel = workload::Job::ModelO; ClassificationTracker() {} diff --git a/libraries/workload/src/workload/Space.h b/libraries/workload/src/workload/Space.h index ede074df4e..fb102d49a0 100644 --- a/libraries/workload/src/workload/Space.h +++ b/libraries/workload/src/workload/Space.h @@ -24,6 +24,11 @@ namespace workload { class Space { public: + static const int32_t NUM_CLASSIFICATIONS = 4; + static const int32_t NUM_TRANSITIONS = NUM_CLASSIFICATIONS * (NUM_CLASSIFICATIONS - 1); + + static int32_t computeTransitionIndex(int32_t prevIndex, int32_t newIndex); + static const uint8_t REGION_NEAR = 0; static const uint8_t REGION_MIDDLE = 1; static const uint8_t REGION_FAR = 2; @@ -47,12 +52,12 @@ public: class View { public: View(const glm::vec3& pos, float nearRadius, float midRadius, float farRadius) : center(pos) { - radiuses[0] = nearRadius; - radiuses[1] = midRadius; - radiuses[2] = farRadius; + radiuses[REGION_NEAR] = nearRadius; + radiuses[REGION_MIDDLE] = midRadius; + radiuses[REGION_FAR] = farRadius; } - glm::vec3 center { 0.0f, 0.0f, 0.0f }; - float radiuses[3] { 0.0f, 0.0f, 0.0f }; + glm::vec3 center; + float radiuses[NUM_CLASSIFICATIONS - 1]; }; class Change { @@ -86,8 +91,44 @@ private: std::vector _freeIndices; }; +inline int32_t Space::computeTransitionIndex(int32_t prevIndex, int32_t newIndex) { + // given prevIndex and newIndex compute an index into the transition list, + // where the lists between unchanged indices don't exist (signaled by index = -1). + // + // Given an NxN array + // let p = i + N * j + // + // then k = -1 when i == j + // = p - (1 + p/(N+1)) when i != j + // + // i 0 1 2 3 + // j +-------+-------+-------+-------+ + // |p = 0 | 1 | 2 | 3 | + // 0 | | | | | + // |k = -1 | 0 | 1 | 2 | + // +-------+-------+-------+-------+ + // | 4 | 5 | 6 | 7 | + // 1 | | | | | + // | 3 | -1 | 4 | 5 | + // +-------+-------+-------+-------+ + // | 8 | 9 | 10 | 11 | + // 2 | | | | | + // | 6 | 7 | -1 | 8 | + // +-------+-------+-------+-------+ + // | 12 | 13 | 14 | 15 | + // 3 | | | | | + // | 9 | 10 | 11 | -1 | + // +-------+-------+-------+-------+ + int32_t p = prevIndex + Space::NUM_CLASSIFICATIONS * newIndex; + if (0 == (p % (Space::NUM_CLASSIFICATIONS + 1))) { + return -1; + } + return p - (1 + p / (Space::NUM_CLASSIFICATIONS + 1)); +} + using SpacePointer = std::shared_ptr; -using Classifications = std::vector; +using Changes = std::vector; +using SortedChanges = std::vector>; } // namespace workload diff --git a/tests/workload/src/SpaceTests.cpp b/tests/workload/src/SpaceTests.cpp index 1c6b0491a7..23e12074ea 100644 --- a/tests/workload/src/SpaceTests.cpp +++ b/tests/workload/src/SpaceTests.cpp @@ -55,7 +55,9 @@ void SpaceTests::testOverlaps() { float newRadius = 1.0f; glm::vec3 newPosition = viewCenter + glm::vec3(0.0f, 0.0f, far + newRadius - DELTA); workload::Space::Sphere newSphere(newPosition, newRadius); - space.updateProxy(proxyId, newSphere); + std::vector updates; + updates.push_back(workload::Space::ProxyUpdate(proxyId, newSphere)); + space.updateProxies(updates); Changes changes; space.categorizeAndGetChanges(changes); QVERIFY(changes.size() == 1); @@ -68,7 +70,9 @@ void SpaceTests::testOverlaps() { float newRadius = 1.0f; glm::vec3 newPosition = viewCenter + glm::vec3(0.0f, 0.0f, mid + newRadius - DELTA); workload::Space::Sphere newSphere(newPosition, newRadius); - space.updateProxy(proxyId, newSphere); + std::vector updates; + updates.push_back(workload::Space::ProxyUpdate(proxyId, newSphere)); + space.updateProxies(updates); Changes changes; space.categorizeAndGetChanges(changes); QVERIFY(changes.size() == 1); @@ -81,7 +85,9 @@ void SpaceTests::testOverlaps() { float newRadius = 1.0f; glm::vec3 newPosition = viewCenter + glm::vec3(0.0f, 0.0f, near + newRadius - DELTA); workload::Space::Sphere newSphere(newPosition, newRadius); - space.updateProxy(proxyId, newSphere); + std::vector updates; + updates.push_back(workload::Space::ProxyUpdate(proxyId, newSphere)); + space.updateProxies(updates); Changes changes; space.categorizeAndGetChanges(changes); QVERIFY(changes.size() == 1); @@ -92,7 +98,9 @@ void SpaceTests::testOverlaps() { { // delete proxy // NOTE: atm deleting a proxy doesn't result in a "Change" - space.deleteProxy(proxyId); + std::vector deadProxies; + deadProxies.push_back(proxyId); + space.deleteProxies(deadProxies); Changes changes; space.categorizeAndGetChanges(changes); QVERIFY(changes.size() == 0); @@ -145,9 +153,9 @@ void SpaceTests::benchmark() { uint32_t numProxies[] = { 100, 1000, 10000, 100000 }; uint32_t numTests = 4; std::vector timeToAddAll; - std::vector timeToRemoveAll; std::vector timeToMoveView; std::vector timeToMoveProxies; + std::vector timeToRemoveAll; for (uint32_t i = 0; i < numTests; ++i) { workload::Space space;