From 4f0980b94b78accaf480abb9888d931a49799cbd Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Thu, 5 Apr 2018 12:11:57 -0700 Subject: [PATCH] hook up prototype PhysicsBoundary job --- interface/src/Application.cpp | 4 +- interface/src/workload/GameWorkload.cpp | 20 +++-- interface/src/workload/GameWorkload.h | 18 ++-- .../src/EntityTreeRenderer.cpp | 2 +- libraries/workload/src/workload/Engine.cpp | 8 +- libraries/workload/src/workload/Proxy.h | 12 +++ libraries/workload/src/workload/Space.cpp | 84 +++---------------- libraries/workload/src/workload/Space.h | 11 +-- .../workload/src/workload/Transaction.cpp | 6 +- libraries/workload/src/workload/Transaction.h | 12 +-- 10 files changed, 68 insertions(+), 109 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 6576e035d1..1b85563969 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -2495,8 +2495,6 @@ void Application::initializeGL() { DependencyManager::get()->initializeShapePipelines(); }); - _gameWorkload.startup(getEntities()->getWorkloadSpace(), _main3DScene); - _offscreenContext = new OffscreenGLCanvas(); _offscreenContext->setObjectName("MainThreadContext"); _offscreenContext->create(_glWidget->qglContext()); @@ -4705,6 +4703,8 @@ void Application::init() { avatar->setCollisionSound(sound); } }, Qt::QueuedConnection); + + _gameWorkload.startup(getEntities()->getWorkloadSpace(), _main3DScene, _entitySimulation); } void Application::updateLOD(float deltaTime) const { diff --git a/interface/src/workload/GameWorkload.cpp b/interface/src/workload/GameWorkload.cpp index e71463d85a..86f6db7148 100644 --- a/interface/src/workload/GameWorkload.cpp +++ b/interface/src/workload/GameWorkload.cpp @@ -10,8 +10,15 @@ #include "GameWorkload.h" #include "GameWorkloadRenderer.h" #include +#include -GameWorkloadContext::GameWorkloadContext(const workload::SpacePointer& space, const render::ScenePointer& scene) : WorkloadContext(space), _scene(scene) { +#include "PhysicsBoundary.h" + +GameWorkloadContext::GameWorkloadContext(const workload::SpacePointer& space, + const render::ScenePointer& scene, + const PhysicalEntitySimulationPointer& simulation) +: WorkloadContext(space), _scene(scene), _simulation(simulation) +{ } GameWorkloadContext::~GameWorkloadContext() { @@ -19,19 +26,22 @@ GameWorkloadContext::~GameWorkloadContext() { GameWorkload::GameWorkload() { - } GameWorkload::~GameWorkload() { shutdown(); } -void GameWorkload::startup(const workload::SpacePointer& space, const render::ScenePointer& scene) { - _engine.reset(new workload::Engine(std::make_shared(space, scene))); +void GameWorkload::startup(const workload::SpacePointer& space, + const render::ScenePointer& scene, + const PhysicalEntitySimulationPointer& simulation) { + _engine.reset(new workload::Engine(std::make_shared(space, scene, simulation))); + auto output = _engine->getOutput(); _engine->addJob("SpaceToRender"); - + const auto regionChanges = _engine->getOutput(); + _engine->addJob("PhysicsBoundary", regionChanges); } void GameWorkload::shutdown() { diff --git a/interface/src/workload/GameWorkload.h b/interface/src/workload/GameWorkload.h index a89f8895c4..60b41c5c38 100644 --- a/interface/src/workload/GameWorkload.h +++ b/interface/src/workload/GameWorkload.h @@ -10,17 +10,21 @@ #ifndef hifi_GameWorkload_h #define hifi_GameWorkload_h -#include "workload/Space.h" -#include "workload/Engine.h" +#include +#include -#include "render/Scene.h" +#include +#include "PhysicalEntitySimulation.h" class GameWorkloadContext : public workload::WorkloadContext { public: - GameWorkloadContext(const workload::SpacePointer& space, const render::ScenePointer& scene); + GameWorkloadContext(const workload::SpacePointer& space, + const render::ScenePointer& scene, + const PhysicalEntitySimulationPointer& simulation); virtual ~GameWorkloadContext(); render::ScenePointer _scene; + PhysicalEntitySimulationPointer _simulation; }; class GameWorkload { @@ -28,7 +32,9 @@ public: GameWorkload(); ~GameWorkload(); - void startup(const workload::SpacePointer& space, const render::ScenePointer& scene); + void startup(const workload::SpacePointer& space, + const render::ScenePointer& scene, + const PhysicalEntitySimulationPointer& simulation); void shutdown(); void updateViews(const ViewFrustum& frustum); @@ -36,4 +42,4 @@ public: workload::EnginePointer _engine; }; -#endif \ No newline at end of file +#endif // hifi_GameWorkload_h diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.cpp b/libraries/entities-renderer/src/EntityTreeRenderer.cpp index dfb888f9cb..ac3afb3e2b 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.cpp +++ b/libraries/entities-renderer/src/EntityTreeRenderer.cpp @@ -284,7 +284,7 @@ void EntityTreeRenderer::addPendingEntities(const render::ScenePointer& scene, r auto spaceIndex = _space->allocateID(); workload::Sphere sphere(entity->getWorldPosition(), entity->getBoundingRadius()); workload::Transaction transaction; - transaction.reset(spaceIndex, sphere); + transaction.reset(spaceIndex, sphere, workload::Owner(entity.get())); _space->enqueueTransaction(transaction); entity->setSpaceIndex(spaceIndex); connect(entity.get(), &EntityItem::spaceUpdate, this, &EntityTreeRenderer::handleSpaceUpdate, Qt::QueuedConnection); diff --git a/libraries/workload/src/workload/Engine.cpp b/libraries/workload/src/workload/Engine.cpp index 0bb9c73fa0..03c04e6632 100644 --- a/libraries/workload/src/workload/Engine.cpp +++ b/libraries/workload/src/workload/Engine.cpp @@ -5,9 +5,6 @@ // Created by Andrew Meadows 2018.02.08 // Copyright 2018 High Fidelity, Inc. // -// Originally from lighthouse3d. Modified to utilize glm::vec3 and clean up to our coding standards -// Simple plane class. -// // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // @@ -26,13 +23,14 @@ namespace workload { class EngineBuilder { public: using Inputs = Views; - using JobModel = Task::ModelI; + using Outputs = RegionTracker::Outputs; + using JobModel = Task::ModelIO; void build(JobModel& model, const Varying& in, Varying& out) { model.addJob("setupViews", in); model.addJob("updateSpace"); const auto regionChanges = model.addJob("regionTracker"); model.addJob("regionState", regionChanges); - + out = regionChanges; } }; diff --git a/libraries/workload/src/workload/Proxy.h b/libraries/workload/src/workload/Proxy.h index 9248c2bb31..0c1c7363cd 100644 --- a/libraries/workload/src/workload/Proxy.h +++ b/libraries/workload/src/workload/Proxy.h @@ -15,6 +15,18 @@ namespace workload { +class Owner { +public: + Owner() = default; + Owner(void* data) : _data(data) {} + Owner(const Owner& other) = default; + Owner& operator=(const Owner& other) = default; + ~Owner() {} + void* get() const { return _data; } +private: + void* _data { nullptr }; +}; + class Proxy { public: Proxy() : sphere(0.0f) {} diff --git a/libraries/workload/src/workload/Space.cpp b/libraries/workload/src/workload/Space.cpp index 0e7b9a5ebc..ea18385c93 100644 --- a/libraries/workload/src/workload/Space.cpp +++ b/libraries/workload/src/workload/Space.cpp @@ -21,10 +21,8 @@ using namespace workload; Space::Space() : Collection() { - } - void Space::processTransactionFrame(const Transaction& transaction) { std::unique_lock lock(_proxiesMutex); // Here we should be able to check the value of last ProxyID allocated @@ -32,25 +30,14 @@ void Space::processTransactionFrame(const Transaction& transaction) { ProxyID maxID = _IDAllocator.getNumAllocatedIndices(); if (maxID > (Index) _proxies.size()) { _proxies.resize(maxID + 100); // allocate the maxId and more + _owners.resize(maxID + 100); } // Now we know for sure that we have enough items in the array to // capture anything coming from the transaction - // resets and potential NEW items processResets(transaction._resetItems); - - // Update the numItemsAtomic counter AFTER the reset changes went through - // _numAllocatedItems.exchange(maxID); - - // updates processUpdates(transaction._updatedItems); - - // removes processRemoves(transaction._removedItems); - - - // Update the numItemsAtomic counter AFTER the pending changes went through - // _numAllocatedItems.exchange(maxID); } void Space::processResets(const Transaction::Resets& transactions) { @@ -62,6 +49,8 @@ void Space::processResets(const Transaction::Resets& transactions) { // Reset the item with a new payload item.sphere = (std::get<1>(reset)); item.prevRegion = item.region = Region::UNKNOWN; + + _owners[ProxyID] = (std::get<2>(reset)); } } @@ -74,6 +63,7 @@ void Space::processRemoves(const Transaction::Removes& transactions) { // Kill it item.prevRegion = item.region = Region::INVALID; + _owners[removedID] = Owner(); } } @@ -88,40 +78,9 @@ void Space::processUpdates(const Transaction::Updates& transactions) { auto& item = _proxies[updateID]; // Update the item - // item.update(std::get<1>(update)); item.sphere = (std::get<1>(update)); - item.prevRegion = item.region = Region::UNKNOWN; } } -/* -int32_t Space::createProxy(const Space::Sphere& newSphere) { - if (_freeIndices.empty()) { - _proxies.emplace_back(Space::Proxy(newSphere)); - return (int32_t)_proxies.size() - 1; - } else { - int32_t index = _freeIndices.back(); - _freeIndices.pop_back(); - _proxies[index].sphere = newSphere; - _proxies[index].region = Region::UNKNOWN; - _proxies[index].prevRegion = Region::UNKNOWN; - return index; - } -}*/ -/* -void Space::deleteProxies(const std::vector& deadIndices) { - for (uint32_t i = 0; i < deadIndices.size(); ++i) { - deleteProxy(deadIndices[i]); - } -} -*/ -/*void Space::updateProxies(const std::vector& changedProxies) { - for (uint32_t i = 0; i < changedProxies.size(); ++i) { - int32_t proxyId = changedProxies[i].first; - if (proxyId > -1 && proxyId < (int32_t)_proxies.size()) { - updateProxy(changedProxies[i].first, changedProxies[i].second); - } - } -}*/ void Space::categorizeAndGetChanges(std::vector& changes) { std::unique_lock lock(_proxiesMutex); @@ -153,27 +112,6 @@ void Space::categorizeAndGetChanges(std::vector& changes) { } } -// private -/*void Space::deleteProxy(int32_t proxyId) { - if (proxyId > -1 && proxyId < (int32_t)_proxies.size()) { - if (proxyId == (int32_t)_proxies.size() - 1) { - // remove proxy on back - _proxies.pop_back(); - if (!_freeIndices.empty()) { - // remove any freeIndices on back - std::sort(_freeIndices.begin(), _freeIndices.end()); - while(!_freeIndices.empty() && _freeIndices.back() == (int32_t)_proxies.size() - 1) { - _freeIndices.pop_back(); - _proxies.pop_back(); - } - } - } else { - _proxies[proxyId].region = Region::INVALID; - _freeIndices.push_back(proxyId); - } - } -}*/ - uint32_t Space::copyProxyValues(Proxy* proxies, uint32_t numDestProxies) const { std::unique_lock lock(_proxiesMutex); auto numCopied = std::min(numDestProxies, (uint32_t)_proxies.size()); @@ -181,22 +119,22 @@ uint32_t Space::copyProxyValues(Proxy* proxies, uint32_t numDestProxies) const { return numCopied; } - -// private -/*void Space::updateProxy(int32_t proxyId, const Space::Sphere& newSphere) { - if (proxyId > -1 && proxyId < (int32_t)_proxies.size()) { - _proxies[proxyId].sphere = newSphere; +const Owner Space::getOwner(int32_t proxyID) const { + std::unique_lock lock(_proxiesMutex); + if (_IDAllocator.checkIndex(proxyID)) { + return _owners[proxyID]; } -}*/ + return Owner(); +} void Space::clear() { std::unique_lock lock(_proxiesMutex); _IDAllocator.clear(); _proxies.clear(); + _owners.clear(); _views.clear(); } - void Space::setViews(const Views& views) { _views = views; } diff --git a/libraries/workload/src/workload/Space.h b/libraries/workload/src/workload/Space.h index bed013cce9..d8d1659751 100644 --- a/libraries/workload/src/workload/Space.h +++ b/libraries/workload/src/workload/Space.h @@ -48,6 +48,8 @@ public: void categorizeAndGetChanges(std::vector& changes); uint32_t copyProxyValues(Proxy* proxies, uint32_t numDestProxies) const; + const Owner getOwner(int32_t proxyID) const; + void clear(); private: @@ -56,17 +58,10 @@ private: void processRemoves(const Transaction::Removes& transactions); void processUpdates(const Transaction::Updates& transactions); - // int32_t createProxy(const Sphere& sphere); - // void deleteProxies(const IndexVector& deadIndices); - // void updateProxies(const std::vector& changedProxies); - - // void deleteProxy(int32_t proxyId); - // void updateProxy(int32_t proxyId, const Sphere& sphere); - - // The database of proxies is protected for editing by a mutex mutable std::mutex _proxiesMutex; Proxy::Vector _proxies; + std::vector _owners; Views _views; }; diff --git a/libraries/workload/src/workload/Transaction.cpp b/libraries/workload/src/workload/Transaction.cpp index 063551763a..7dc7e7a3d2 100644 --- a/libraries/workload/src/workload/Transaction.cpp +++ b/libraries/workload/src/workload/Transaction.cpp @@ -13,8 +13,8 @@ using namespace workload; -void Transaction::reset(ProxyID id, const ProxyPayload& payload) { - _resetItems.emplace_back(Reset{ id, payload }); +void Transaction::reset(ProxyID id, const ProxyPayload& payload, const Owner& owner) { + _resetItems.emplace_back(Reset{ id, payload, owner }); } void Transaction::remove(ProxyID id) { @@ -234,4 +234,4 @@ void Collection::processTransactionQueue() { // Update the item item.update(std::get<1>(update)); }*/ -//} \ No newline at end of file +//} diff --git a/libraries/workload/src/workload/Transaction.h b/libraries/workload/src/workload/Transaction.h index d078989f48..506e3359e6 100644 --- a/libraries/workload/src/workload/Transaction.h +++ b/libraries/workload/src/workload/Transaction.h @@ -89,13 +89,13 @@ namespace workload { // These changes must be expressed through the corresponding command from the Transaction // The Transaction is then queued on the Space so all the pending transactions can be consolidated and processed at the time // of updating the space at the Frame boundary. -// +// class Transaction { friend class Space; public: using ProxyPayload = Sphere; - using Reset = std::tuple; + using Reset = std::tuple; using Remove = ProxyID; using Update = std::tuple; @@ -107,7 +107,7 @@ public: ~Transaction() {} // Proxy transactions - void reset(ProxyID id, const ProxyPayload& sphere); + void reset(ProxyID id, const ProxyPayload& sphere, const Owner& owner); void reset(const Resets& resets); void remove(ProxyID id); void remove(const Removes& removes); @@ -122,7 +122,7 @@ public: void merge(const Transaction& transaction); void merge(Transaction&& transaction); void clear(); - + protected: @@ -174,10 +174,10 @@ protected: TransactionFrames _transactionFrames; uint32_t _transactionFrameNumber{ 0 }; - // Process one transaction frame + // Process one transaction frame virtual void processTransactionFrame(const Transaction& transaction) = 0; }; } // namespace workload -#endif // hifi_workload_Transaction_h \ No newline at end of file +#endif // hifi_workload_Transaction_h