hook up prototype PhysicsBoundary job

This commit is contained in:
Andrew Meadows 2018-04-05 12:11:57 -07:00
parent d9ab166aac
commit 4f0980b94b
10 changed files with 68 additions and 109 deletions

View file

@ -2495,8 +2495,6 @@ void Application::initializeGL() {
DependencyManager::get<GeometryCache>()->initializeShapePipelines(); DependencyManager::get<GeometryCache>()->initializeShapePipelines();
}); });
_gameWorkload.startup(getEntities()->getWorkloadSpace(), _main3DScene);
_offscreenContext = new OffscreenGLCanvas(); _offscreenContext = new OffscreenGLCanvas();
_offscreenContext->setObjectName("MainThreadContext"); _offscreenContext->setObjectName("MainThreadContext");
_offscreenContext->create(_glWidget->qglContext()); _offscreenContext->create(_glWidget->qglContext());
@ -4705,6 +4703,8 @@ void Application::init() {
avatar->setCollisionSound(sound); avatar->setCollisionSound(sound);
} }
}, Qt::QueuedConnection); }, Qt::QueuedConnection);
_gameWorkload.startup(getEntities()->getWorkloadSpace(), _main3DScene, _entitySimulation);
} }
void Application::updateLOD(float deltaTime) const { void Application::updateLOD(float deltaTime) const {

View file

@ -10,8 +10,15 @@
#include "GameWorkload.h" #include "GameWorkload.h"
#include "GameWorkloadRenderer.h" #include "GameWorkloadRenderer.h"
#include <ViewFrustum.h> #include <ViewFrustum.h>
#include <workload/RegionTracker.h>
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() { GameWorkloadContext::~GameWorkloadContext() {
@ -19,19 +26,22 @@ GameWorkloadContext::~GameWorkloadContext() {
GameWorkload::GameWorkload() { GameWorkload::GameWorkload() {
} }
GameWorkload::~GameWorkload() { GameWorkload::~GameWorkload() {
shutdown(); shutdown();
} }
void GameWorkload::startup(const workload::SpacePointer& space, const render::ScenePointer& scene) { void GameWorkload::startup(const workload::SpacePointer& space,
_engine.reset(new workload::Engine(std::make_shared<GameWorkloadContext>(space, scene))); const render::ScenePointer& scene,
const PhysicalEntitySimulationPointer& simulation) {
_engine.reset(new workload::Engine(std::make_shared<GameWorkloadContext>(space, scene, simulation)));
auto output = _engine->getOutput();
_engine->addJob<GameSpaceToRender>("SpaceToRender"); _engine->addJob<GameSpaceToRender>("SpaceToRender");
const auto regionChanges = _engine->getOutput();
_engine->addJob<PhysicsBoundary>("PhysicsBoundary", regionChanges);
} }
void GameWorkload::shutdown() { void GameWorkload::shutdown() {

View file

@ -10,17 +10,21 @@
#ifndef hifi_GameWorkload_h #ifndef hifi_GameWorkload_h
#define hifi_GameWorkload_h #define hifi_GameWorkload_h
#include "workload/Space.h" #include <workload/Space.h>
#include "workload/Engine.h" #include <workload/Engine.h>
#include "render/Scene.h" #include <render/Scene.h>
#include "PhysicalEntitySimulation.h"
class GameWorkloadContext : public workload::WorkloadContext { class GameWorkloadContext : public workload::WorkloadContext {
public: public:
GameWorkloadContext(const workload::SpacePointer& space, const render::ScenePointer& scene); GameWorkloadContext(const workload::SpacePointer& space,
const render::ScenePointer& scene,
const PhysicalEntitySimulationPointer& simulation);
virtual ~GameWorkloadContext(); virtual ~GameWorkloadContext();
render::ScenePointer _scene; render::ScenePointer _scene;
PhysicalEntitySimulationPointer _simulation;
}; };
class GameWorkload { class GameWorkload {
@ -28,7 +32,9 @@ public:
GameWorkload(); GameWorkload();
~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 shutdown();
void updateViews(const ViewFrustum& frustum); void updateViews(const ViewFrustum& frustum);
@ -36,4 +42,4 @@ public:
workload::EnginePointer _engine; workload::EnginePointer _engine;
}; };
#endif #endif // hifi_GameWorkload_h

View file

@ -284,7 +284,7 @@ void EntityTreeRenderer::addPendingEntities(const render::ScenePointer& scene, r
auto spaceIndex = _space->allocateID(); auto spaceIndex = _space->allocateID();
workload::Sphere sphere(entity->getWorldPosition(), entity->getBoundingRadius()); workload::Sphere sphere(entity->getWorldPosition(), entity->getBoundingRadius());
workload::Transaction transaction; workload::Transaction transaction;
transaction.reset(spaceIndex, sphere); transaction.reset(spaceIndex, sphere, workload::Owner(entity.get()));
_space->enqueueTransaction(transaction); _space->enqueueTransaction(transaction);
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);

View file

@ -5,9 +5,6 @@
// Created by Andrew Meadows 2018.02.08 // Created by Andrew Meadows 2018.02.08
// Copyright 2018 High Fidelity, Inc. // 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. // Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
@ -26,13 +23,14 @@ namespace workload {
class EngineBuilder { class EngineBuilder {
public: public:
using Inputs = Views; using Inputs = Views;
using JobModel = Task::ModelI<EngineBuilder, Inputs>; using Outputs = RegionTracker::Outputs;
using JobModel = Task::ModelIO<EngineBuilder, Inputs, Outputs>;
void build(JobModel& model, const Varying& in, Varying& out) { void build(JobModel& model, const Varying& in, Varying& out) {
model.addJob<SetupViews>("setupViews", in); model.addJob<SetupViews>("setupViews", in);
model.addJob<PerformSpaceTransaction>("updateSpace"); model.addJob<PerformSpaceTransaction>("updateSpace");
const auto regionChanges = model.addJob<RegionTracker>("regionTracker"); const auto regionChanges = model.addJob<RegionTracker>("regionTracker");
model.addJob<RegionState>("regionState", regionChanges); model.addJob<RegionState>("regionState", regionChanges);
out = regionChanges;
} }
}; };

View file

@ -15,6 +15,18 @@
namespace workload { 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 { class Proxy {
public: public:
Proxy() : sphere(0.0f) {} Proxy() : sphere(0.0f) {}

View file

@ -21,10 +21,8 @@
using namespace workload; using namespace workload;
Space::Space() : Collection() { Space::Space() : Collection() {
} }
void Space::processTransactionFrame(const Transaction& transaction) { void Space::processTransactionFrame(const Transaction& transaction) {
std::unique_lock<std::mutex> lock(_proxiesMutex); std::unique_lock<std::mutex> lock(_proxiesMutex);
// Here we should be able to check the value of last ProxyID allocated // 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(); ProxyID maxID = _IDAllocator.getNumAllocatedIndices();
if (maxID > (Index) _proxies.size()) { if (maxID > (Index) _proxies.size()) {
_proxies.resize(maxID + 100); // allocate the maxId and more _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 // Now we know for sure that we have enough items in the array to
// capture anything coming from the transaction // capture anything coming from the transaction
// resets and potential NEW items
processResets(transaction._resetItems); processResets(transaction._resetItems);
// Update the numItemsAtomic counter AFTER the reset changes went through
// _numAllocatedItems.exchange(maxID);
// updates
processUpdates(transaction._updatedItems); processUpdates(transaction._updatedItems);
// removes
processRemoves(transaction._removedItems); processRemoves(transaction._removedItems);
// Update the numItemsAtomic counter AFTER the pending changes went through
// _numAllocatedItems.exchange(maxID);
} }
void Space::processResets(const Transaction::Resets& transactions) { 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 // Reset the item with a new payload
item.sphere = (std::get<1>(reset)); item.sphere = (std::get<1>(reset));
item.prevRegion = item.region = Region::UNKNOWN; 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 // Kill it
item.prevRegion = item.region = Region::INVALID; item.prevRegion = item.region = Region::INVALID;
_owners[removedID] = Owner();
} }
} }
@ -88,40 +78,9 @@ void Space::processUpdates(const Transaction::Updates& transactions) {
auto& item = _proxies[updateID]; auto& item = _proxies[updateID];
// Update the item // Update the item
// item.update(std::get<1>(update));
item.sphere = (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<int32_t>& deadIndices) {
for (uint32_t i = 0; i < deadIndices.size(); ++i) {
deleteProxy(deadIndices[i]);
}
}
*/
/*void Space::updateProxies(const std::vector<ProxyUpdate>& 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<Space::Change>& changes) { void Space::categorizeAndGetChanges(std::vector<Space::Change>& changes) {
std::unique_lock<std::mutex> lock(_proxiesMutex); std::unique_lock<std::mutex> lock(_proxiesMutex);
@ -153,27 +112,6 @@ void Space::categorizeAndGetChanges(std::vector<Space::Change>& 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 { uint32_t Space::copyProxyValues(Proxy* proxies, uint32_t numDestProxies) const {
std::unique_lock<std::mutex> lock(_proxiesMutex); std::unique_lock<std::mutex> lock(_proxiesMutex);
auto numCopied = std::min(numDestProxies, (uint32_t)_proxies.size()); 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; return numCopied;
} }
const Owner Space::getOwner(int32_t proxyID) const {
// private std::unique_lock<std::mutex> lock(_proxiesMutex);
/*void Space::updateProxy(int32_t proxyId, const Space::Sphere& newSphere) { if (_IDAllocator.checkIndex(proxyID)) {
if (proxyId > -1 && proxyId < (int32_t)_proxies.size()) { return _owners[proxyID];
_proxies[proxyId].sphere = newSphere;
} }
}*/ return Owner();
}
void Space::clear() { void Space::clear() {
std::unique_lock<std::mutex> lock(_proxiesMutex); std::unique_lock<std::mutex> lock(_proxiesMutex);
_IDAllocator.clear(); _IDAllocator.clear();
_proxies.clear(); _proxies.clear();
_owners.clear();
_views.clear(); _views.clear();
} }
void Space::setViews(const Views& views) { void Space::setViews(const Views& views) {
_views = views; _views = views;
} }

View file

@ -48,6 +48,8 @@ public:
void categorizeAndGetChanges(std::vector<Change>& changes); void categorizeAndGetChanges(std::vector<Change>& changes);
uint32_t copyProxyValues(Proxy* proxies, uint32_t numDestProxies) const; uint32_t copyProxyValues(Proxy* proxies, uint32_t numDestProxies) const;
const Owner getOwner(int32_t proxyID) const;
void clear(); void clear();
private: private:
@ -56,17 +58,10 @@ private:
void processRemoves(const Transaction::Removes& transactions); void processRemoves(const Transaction::Removes& transactions);
void processUpdates(const Transaction::Updates& transactions); void processUpdates(const Transaction::Updates& transactions);
// int32_t createProxy(const Sphere& sphere);
// void deleteProxies(const IndexVector& deadIndices);
// void updateProxies(const std::vector<ProxyUpdate>& 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 // The database of proxies is protected for editing by a mutex
mutable std::mutex _proxiesMutex; mutable std::mutex _proxiesMutex;
Proxy::Vector _proxies; Proxy::Vector _proxies;
std::vector<Owner> _owners;
Views _views; Views _views;
}; };

View file

@ -13,8 +13,8 @@
using namespace workload; using namespace workload;
void Transaction::reset(ProxyID id, const ProxyPayload& payload) { void Transaction::reset(ProxyID id, const ProxyPayload& payload, const Owner& owner) {
_resetItems.emplace_back(Reset{ id, payload }); _resetItems.emplace_back(Reset{ id, payload, owner });
} }
void Transaction::remove(ProxyID id) { void Transaction::remove(ProxyID id) {
@ -234,4 +234,4 @@ void Collection::processTransactionQueue() {
// Update the item // Update the item
item.update(std::get<1>(update)); item.update(std::get<1>(update));
}*/ }*/
//} //}

View file

@ -89,13 +89,13 @@ namespace workload {
// These changes must be expressed through the corresponding command from the Transaction // 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 // 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. // of updating the space at the Frame boundary.
// //
class Transaction { class Transaction {
friend class Space; friend class Space;
public: public:
using ProxyPayload = Sphere; using ProxyPayload = Sphere;
using Reset = std::tuple<ProxyID, ProxyPayload>; using Reset = std::tuple<ProxyID, ProxyPayload, Owner>;
using Remove = ProxyID; using Remove = ProxyID;
using Update = std::tuple<ProxyID, ProxyPayload>; using Update = std::tuple<ProxyID, ProxyPayload>;
@ -107,7 +107,7 @@ public:
~Transaction() {} ~Transaction() {}
// Proxy transactions // 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 reset(const Resets& resets);
void remove(ProxyID id); void remove(ProxyID id);
void remove(const Removes& removes); void remove(const Removes& removes);
@ -122,7 +122,7 @@ public:
void merge(const Transaction& transaction); void merge(const Transaction& transaction);
void merge(Transaction&& transaction); void merge(Transaction&& transaction);
void clear(); void clear();
protected: protected:
@ -174,10 +174,10 @@ protected:
TransactionFrames _transactionFrames; TransactionFrames _transactionFrames;
uint32_t _transactionFrameNumber{ 0 }; uint32_t _transactionFrameNumber{ 0 };
// Process one transaction frame // Process one transaction frame
virtual void processTransactionFrame(const Transaction& transaction) = 0; virtual void processTransactionFrame(const Transaction& transaction) = 0;
}; };
} // namespace workload } // namespace workload
#endif // hifi_workload_Transaction_h #endif // hifi_workload_Transaction_h