From 33b47f9ae29d0b7979f793e6b04b81459dcafa81 Mon Sep 17 00:00:00 2001 From: samcake Date: Wed, 21 Feb 2018 10:34:58 -0800 Subject: [PATCH] Merging with the actual worloadspace managed from the EntityTreeRenderer --- interface/src/Application.cpp | 2 +- interface/src/Application.h | 1 - interface/src/workload/GameWorkloadRenderer.cpp | 10 ++++++++-- libraries/entities-renderer/src/EntityTreeRenderer.cpp | 6 +++--- libraries/entities-renderer/src/EntityTreeRenderer.h | 5 ++++- libraries/workload/src/workload/Space.h | 2 ++ 6 files changed, 18 insertions(+), 8 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index e1d5ed7e29..0c654e9196 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -2400,7 +2400,7 @@ void Application::initializeGL() { DependencyManager::get()->initializeShapePipelines(); }); - _gameWorkload.startup(_workloadSpace, _main3DScene); + _gameWorkload.startup(getEntities()->getWorkloadSpace(), _main3DScene); _offscreenContext = new OffscreenGLCanvas(); _offscreenContext->setObjectName("MainThreadContext"); diff --git a/interface/src/Application.h b/interface/src/Application.h index 5617d0895d..8028dc8c68 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -616,7 +616,6 @@ private: gpu::ContextPointer _gpuContext; // initialized during window creation GameWorkload _gameWorkload; - workload::SpacePointer _workloadSpace{ new workload::Space() }; mutable QMutex _renderArgsMutex{ QMutex::Recursive }; struct AppRenderArgs { diff --git a/interface/src/workload/GameWorkloadRenderer.cpp b/interface/src/workload/GameWorkloadRenderer.cpp index dcc55e54b3..e10c28c36c 100644 --- a/interface/src/workload/GameWorkloadRenderer.cpp +++ b/interface/src/workload/GameWorkloadRenderer.cpp @@ -30,17 +30,23 @@ void GameSpaceToRender::run(const workload::WorkloadContextPointer& runContext, auto renderItem = std::make_shared(); renderItem->editBound().expandedContains(glm::vec3(0.0), 32000.0); transaction.resetItem(_spaceRenderItemID, std::make_shared(std::make_shared())); + scene->enqueueTransaction(transaction); } - scene->enqueueTransaction(transaction); auto space = gameWorkloadContext->_space; if (!space) { return; } - space->getNumObjects(); + std::vector proxies(space->getNumAllocatedProxies()); + space->copyProxyValues(proxies.data(), proxies.size()); + + transaction.updateItem(_spaceRenderItemID, [proxies](GameWorkloadRenderItem& item) { + item.setAllProxies(proxies); + }); + scene->enqueueTransaction(transaction); } namespace render { diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.cpp b/libraries/entities-renderer/src/EntityTreeRenderer.cpp index 879dd709e8..eecd21e5ac 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.cpp +++ b/libraries/entities-renderer/src/EntityTreeRenderer.cpp @@ -281,7 +281,7 @@ void EntityTreeRenderer::addPendingEntities(const render::ScenePointer& scene, r if (entity->getSpaceIndex() == -1) { std::unique_lock lock(_spaceLock); workload::Space::Sphere sphere(entity->getWorldPosition(), entity->getBoundingRadius()); - int32_t spaceIndex = _space.createProxy(sphere); + int32_t spaceIndex = _space->createProxy(sphere); entity->setSpaceIndex(spaceIndex); connect(entity.get(), &EntityItem::spaceUpdate, this, &EntityTreeRenderer::handleSpaceUpdate, Qt::QueuedConnection); } @@ -428,7 +428,7 @@ void EntityTreeRenderer::update(bool simulate) { } { // update proxies in the workload::Space std::unique_lock lock(_spaceLock); - _space.updateProxies(_spaceUpdates); + _space->updateProxies(_spaceUpdates); _spaceUpdates.clear(); } { // flush final EntityTree references to removed entities @@ -442,7 +442,7 @@ void EntityTreeRenderer::update(bool simulate) { disconnect(entity.get(), &EntityItem::spaceUpdate, this, &EntityTreeRenderer::handleSpaceUpdate); deadProxies.push_back(spaceIndex); } - _space.deleteProxies(deadProxies); + _space->deleteProxies(deadProxies); } } diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.h b/libraries/entities-renderer/src/EntityTreeRenderer.h index f034353347..5840dc6832 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.h +++ b/libraries/entities-renderer/src/EntityTreeRenderer.h @@ -120,6 +120,9 @@ public: static void setRenderDebugHullsOperator(std::function renderDebugHullsOperator) { _renderDebugHullsOperator = renderDebugHullsOperator; } static bool shouldRenderDebugHulls() { return _renderDebugHullsOperator(); } + // Access the workload Space + const workload::SpacePointer getWorkloadSpace() const { return _space; } + signals: void enterEntity(const EntityItemID& entityItemID); void leaveEntity(const EntityItemID& entityItemID); @@ -266,7 +269,7 @@ private: static std::function _renderDebugHullsOperator; mutable std::mutex _spaceLock; - workload::Space _space; + workload::SpacePointer _space{ new workload::Space() }; std::vector _spaceUpdates; }; diff --git a/libraries/workload/src/workload/Space.h b/libraries/workload/src/workload/Space.h index 4b8510ebae..d7478b6066 100644 --- a/libraries/workload/src/workload/Space.h +++ b/libraries/workload/src/workload/Space.h @@ -35,6 +35,7 @@ public: class Proxy { public: + Proxy() : sphere(0.0f) {} Proxy(const Sphere& s) : sphere(s) {} Sphere sphere; uint8_t region { REGION_UNKNOWN }; @@ -68,6 +69,7 @@ public: void setViews(const std::vector& views); uint32_t getNumObjects() const { return (uint32_t)(_proxies.size() - _freeIndices.size()); } + uint32_t getNumAllocatedProxies() const { return (uint32_t)(_proxies.size()); } void categorizeAndGetChanges(std::vector& changes);