mirror of
https://github.com/lubosz/overte.git
synced 2025-04-13 13:13:19 +02:00
hook up prototype PhysicsBoundary job
This commit is contained in:
parent
d9ab166aac
commit
4f0980b94b
10 changed files with 68 additions and 109 deletions
|
@ -2495,8 +2495,6 @@ void Application::initializeGL() {
|
|||
DependencyManager::get<GeometryCache>()->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 {
|
||||
|
|
|
@ -10,8 +10,15 @@
|
|||
#include "GameWorkload.h"
|
||||
#include "GameWorkloadRenderer.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() {
|
||||
|
@ -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<GameWorkloadContext>(space, scene)));
|
||||
void GameWorkload::startup(const workload::SpacePointer& space,
|
||||
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");
|
||||
|
||||
|
||||
const auto regionChanges = _engine->getOutput();
|
||||
_engine->addJob<PhysicsBoundary>("PhysicsBoundary", regionChanges);
|
||||
}
|
||||
|
||||
void GameWorkload::shutdown() {
|
||||
|
|
|
@ -10,17 +10,21 @@
|
|||
#ifndef hifi_GameWorkload_h
|
||||
#define hifi_GameWorkload_h
|
||||
|
||||
#include "workload/Space.h"
|
||||
#include "workload/Engine.h"
|
||||
#include <workload/Space.h>
|
||||
#include <workload/Engine.h>
|
||||
|
||||
#include "render/Scene.h"
|
||||
#include <render/Scene.h>
|
||||
#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
|
||||
#endif // hifi_GameWorkload_h
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<EngineBuilder, Inputs>;
|
||||
using Outputs = RegionTracker::Outputs;
|
||||
using JobModel = Task::ModelIO<EngineBuilder, Inputs, Outputs>;
|
||||
void build(JobModel& model, const Varying& in, Varying& out) {
|
||||
model.addJob<SetupViews>("setupViews", in);
|
||||
model.addJob<PerformSpaceTransaction>("updateSpace");
|
||||
const auto regionChanges = model.addJob<RegionTracker>("regionTracker");
|
||||
model.addJob<RegionState>("regionState", regionChanges);
|
||||
|
||||
out = regionChanges;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -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) {}
|
||||
|
|
|
@ -21,10 +21,8 @@
|
|||
using namespace workload;
|
||||
|
||||
Space::Space() : Collection() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
void Space::processTransactionFrame(const Transaction& transaction) {
|
||||
std::unique_lock<std::mutex> 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<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) {
|
||||
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 {
|
||||
std::unique_lock<std::mutex> 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<std::mutex> lock(_proxiesMutex);
|
||||
if (_IDAllocator.checkIndex(proxyID)) {
|
||||
return _owners[proxyID];
|
||||
}
|
||||
}*/
|
||||
return Owner();
|
||||
}
|
||||
|
||||
void Space::clear() {
|
||||
std::unique_lock<std::mutex> lock(_proxiesMutex);
|
||||
_IDAllocator.clear();
|
||||
_proxies.clear();
|
||||
_owners.clear();
|
||||
_views.clear();
|
||||
}
|
||||
|
||||
|
||||
void Space::setViews(const Views& views) {
|
||||
_views = views;
|
||||
}
|
||||
|
|
|
@ -48,6 +48,8 @@ public:
|
|||
void categorizeAndGetChanges(std::vector<Change>& 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<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
|
||||
mutable std::mutex _proxiesMutex;
|
||||
Proxy::Vector _proxies;
|
||||
std::vector<Owner> _owners;
|
||||
|
||||
Views _views;
|
||||
};
|
||||
|
|
|
@ -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));
|
||||
}*/
|
||||
//}
|
||||
//}
|
||||
|
|
|
@ -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<ProxyID, ProxyPayload>;
|
||||
using Reset = std::tuple<ProxyID, ProxyPayload, Owner>;
|
||||
using Remove = ProxyID;
|
||||
using Update = std::tuple<ProxyID, ProxyPayload>;
|
||||
|
||||
|
@ -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
|
||||
#endif // hifi_workload_Transaction_h
|
||||
|
|
Loading…
Reference in a new issue