Merging with the actual worloadspace managed from the EntityTreeRenderer

This commit is contained in:
samcake 2018-02-21 10:34:58 -08:00
parent 34db56c50c
commit 33b47f9ae2
6 changed files with 18 additions and 8 deletions

View file

@ -2400,7 +2400,7 @@ void Application::initializeGL() {
DependencyManager::get<GeometryCache>()->initializeShapePipelines(); DependencyManager::get<GeometryCache>()->initializeShapePipelines();
}); });
_gameWorkload.startup(_workloadSpace, _main3DScene); _gameWorkload.startup(getEntities()->getWorkloadSpace(), _main3DScene);
_offscreenContext = new OffscreenGLCanvas(); _offscreenContext = new OffscreenGLCanvas();
_offscreenContext->setObjectName("MainThreadContext"); _offscreenContext->setObjectName("MainThreadContext");

View file

@ -616,7 +616,6 @@ private:
gpu::ContextPointer _gpuContext; // initialized during window creation gpu::ContextPointer _gpuContext; // initialized during window creation
GameWorkload _gameWorkload; GameWorkload _gameWorkload;
workload::SpacePointer _workloadSpace{ new workload::Space() };
mutable QMutex _renderArgsMutex{ QMutex::Recursive }; mutable QMutex _renderArgsMutex{ QMutex::Recursive };
struct AppRenderArgs { struct AppRenderArgs {

View file

@ -30,17 +30,23 @@ void GameSpaceToRender::run(const workload::WorkloadContextPointer& runContext,
auto renderItem = std::make_shared<GameWorkloadRenderItem>(); auto renderItem = std::make_shared<GameWorkloadRenderItem>();
renderItem->editBound().expandedContains(glm::vec3(0.0), 32000.0); renderItem->editBound().expandedContains(glm::vec3(0.0), 32000.0);
transaction.resetItem(_spaceRenderItemID, std::make_shared<GameWorkloadRenderItem::Payload>(std::make_shared<GameWorkloadRenderItem>())); transaction.resetItem(_spaceRenderItemID, std::make_shared<GameWorkloadRenderItem::Payload>(std::make_shared<GameWorkloadRenderItem>()));
scene->enqueueTransaction(transaction);
} }
scene->enqueueTransaction(transaction);
auto space = gameWorkloadContext->_space; auto space = gameWorkloadContext->_space;
if (!space) { if (!space) {
return; return;
} }
space->getNumObjects(); std::vector<workload::Space::Proxy> proxies(space->getNumAllocatedProxies());
space->copyProxyValues(proxies.data(), proxies.size());
transaction.updateItem<GameWorkloadRenderItem>(_spaceRenderItemID, [proxies](GameWorkloadRenderItem& item) {
item.setAllProxies(proxies);
});
scene->enqueueTransaction(transaction);
} }
namespace render { namespace render {

View file

@ -281,7 +281,7 @@ void EntityTreeRenderer::addPendingEntities(const render::ScenePointer& scene, r
if (entity->getSpaceIndex() == -1) { if (entity->getSpaceIndex() == -1) {
std::unique_lock<std::mutex> lock(_spaceLock); std::unique_lock<std::mutex> lock(_spaceLock);
workload::Space::Sphere sphere(entity->getWorldPosition(), entity->getBoundingRadius()); workload::Space::Sphere sphere(entity->getWorldPosition(), entity->getBoundingRadius());
int32_t spaceIndex = _space.createProxy(sphere); int32_t spaceIndex = _space->createProxy(sphere);
entity->setSpaceIndex(spaceIndex); entity->setSpaceIndex(spaceIndex);
connect(entity.get(), &EntityItem::spaceUpdate, this, &EntityTreeRenderer::handleSpaceUpdate, Qt::QueuedConnection); 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 { // update proxies in the workload::Space
std::unique_lock<std::mutex> lock(_spaceLock); std::unique_lock<std::mutex> lock(_spaceLock);
_space.updateProxies(_spaceUpdates); _space->updateProxies(_spaceUpdates);
_spaceUpdates.clear(); _spaceUpdates.clear();
} }
{ // flush final EntityTree references to removed entities { // flush final EntityTree references to removed entities
@ -442,7 +442,7 @@ void EntityTreeRenderer::update(bool simulate) {
disconnect(entity.get(), &EntityItem::spaceUpdate, this, &EntityTreeRenderer::handleSpaceUpdate); disconnect(entity.get(), &EntityItem::spaceUpdate, this, &EntityTreeRenderer::handleSpaceUpdate);
deadProxies.push_back(spaceIndex); deadProxies.push_back(spaceIndex);
} }
_space.deleteProxies(deadProxies); _space->deleteProxies(deadProxies);
} }
} }

View file

@ -120,6 +120,9 @@ public:
static void setRenderDebugHullsOperator(std::function<bool()> renderDebugHullsOperator) { _renderDebugHullsOperator = renderDebugHullsOperator; } static void setRenderDebugHullsOperator(std::function<bool()> renderDebugHullsOperator) { _renderDebugHullsOperator = renderDebugHullsOperator; }
static bool shouldRenderDebugHulls() { return _renderDebugHullsOperator(); } static bool shouldRenderDebugHulls() { return _renderDebugHullsOperator(); }
// Access the workload Space
const workload::SpacePointer getWorkloadSpace() const { return _space; }
signals: signals:
void enterEntity(const EntityItemID& entityItemID); void enterEntity(const EntityItemID& entityItemID);
void leaveEntity(const EntityItemID& entityItemID); void leaveEntity(const EntityItemID& entityItemID);
@ -266,7 +269,7 @@ private:
static std::function<bool()> _renderDebugHullsOperator; static std::function<bool()> _renderDebugHullsOperator;
mutable std::mutex _spaceLock; mutable std::mutex _spaceLock;
workload::Space _space; workload::SpacePointer _space{ new workload::Space() };
std::vector<workload::Space::ProxyUpdate> _spaceUpdates; std::vector<workload::Space::ProxyUpdate> _spaceUpdates;
}; };

View file

@ -35,6 +35,7 @@ public:
class Proxy { class Proxy {
public: public:
Proxy() : sphere(0.0f) {}
Proxy(const Sphere& s) : sphere(s) {} Proxy(const Sphere& s) : sphere(s) {}
Sphere sphere; Sphere sphere;
uint8_t region { REGION_UNKNOWN }; uint8_t region { REGION_UNKNOWN };
@ -68,6 +69,7 @@ public:
void setViews(const std::vector<View>& views); void setViews(const std::vector<View>& views);
uint32_t getNumObjects() const { return (uint32_t)(_proxies.size() - _freeIndices.size()); } uint32_t getNumObjects() const { return (uint32_t)(_proxies.size() - _freeIndices.size()); }
uint32_t getNumAllocatedProxies() const { return (uint32_t)(_proxies.size()); }
void categorizeAndGetChanges(std::vector<Change>& changes); void categorizeAndGetChanges(std::vector<Change>& changes);