mirror of
https://github.com/overte-org/overte.git
synced 2025-04-07 15:34:05 +02:00
add/remove entities to physics using workload output
This commit is contained in:
parent
b96a4ed4be
commit
ed1761945c
8 changed files with 22 additions and 57 deletions
|
@ -4705,6 +4705,7 @@ void Application::init() {
|
|||
}, Qt::QueuedConnection);
|
||||
|
||||
_gameWorkload.startup(getEntities()->getWorkloadSpace(), _main3DScene, _entitySimulation);
|
||||
_entitySimulation->setWorkloadSpace(getEntities()->getWorkloadSpace());
|
||||
}
|
||||
|
||||
void Application::updateLOD(float deltaTime) const {
|
||||
|
|
|
@ -15,19 +15,6 @@
|
|||
|
||||
#include "render/Scene.h"
|
||||
|
||||
/*
|
||||
class FooJobConfig : public workload::Job::Config {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(bool fubar MEMBER fubar NOTIFY dirty)
|
||||
public:
|
||||
bool fubar{ false };
|
||||
signals:
|
||||
void dirty();
|
||||
protected:
|
||||
};
|
||||
*/
|
||||
|
||||
#include <iostream> // adebug
|
||||
#include <workload/RegionTracker.h>
|
||||
#include <EntityItem.h>
|
||||
#include "PhysicalEntitySimulation.h"
|
||||
|
@ -45,43 +32,20 @@ public:
|
|||
}
|
||||
|
||||
void run(const workload::WorkloadContextPointer& context, const Inputs& inputs) {
|
||||
const auto& regionChanges = inputs.get1();
|
||||
auto space = context->_space;
|
||||
if (!space) {
|
||||
return;
|
||||
}
|
||||
uint32_t listSize = (uint32_t)regionChanges.size();
|
||||
uint32_t totalTransitions = 0;
|
||||
for (uint32_t i = 0; i < listSize; ++i) {
|
||||
totalTransitions += (uint32_t)regionChanges[i].size();
|
||||
}
|
||||
// we're interested in things entering/leaving R3
|
||||
uint32_t regionIndex = workload::Region::R3;
|
||||
uint32_t exitIndex = 2 * regionIndex;
|
||||
uint32_t numExits = (uint32_t)regionChanges[exitIndex].size();
|
||||
for (uint32_t i = 0; i < numExits; ++i) {
|
||||
int32_t proxyID = regionChanges[exitIndex][i];
|
||||
auto owner = space->getOwner(proxyID).get<EntityItemPointer>();
|
||||
if (owner) {
|
||||
//EntityItem* entity = static_cast<EntityItem*>(owner);
|
||||
std::cout << "adebug - "
|
||||
//<< owner
|
||||
<< " '" << owner->getName().toStdString() << "'"
|
||||
<< std::endl; // adebug
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t enterIndex = exitIndex + 1;
|
||||
uint32_t numEntries = (uint32_t)regionChanges[enterIndex].size();
|
||||
for (uint32_t i = 0; i < numEntries; ++i) {
|
||||
int32_t proxyID = regionChanges[enterIndex][i];
|
||||
auto owner = space->getOwner(proxyID).get<EntityItemPointer>();
|
||||
if (owner) {
|
||||
// EntityItem* entity = static_cast<EntityItem*>(owner);
|
||||
std::cout << "adebug + "
|
||||
//<< owner
|
||||
<< " '" << owner->getName().toStdString() << "'"
|
||||
<< std::endl; // adebug
|
||||
GameWorkloadContext* gameContext = static_cast<GameWorkloadContext*>(context.get());
|
||||
PhysicalEntitySimulationPointer simulation = gameContext->_simulation;
|
||||
const auto& regionChanges = inputs.get0();
|
||||
for (uint32_t i = 0; i < (uint32_t)regionChanges.size(); ++i) {
|
||||
const workload::Space::Change& change = regionChanges[i];
|
||||
auto entity = space->getOwner(change.proxyId).get<EntityItemPointer>();
|
||||
if (entity) {
|
||||
simulation->changeEntity(entity);
|
||||
qCDebug("physics") << change.proxyId << " : " << "'" << entity->getName() << "' "
|
||||
<< (uint32_t)(change.prevRegion) << " --> " << (uint32_t)(change.region);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -121,7 +121,7 @@ public:
|
|||
static bool shouldRenderDebugHulls() { return _renderDebugHullsOperator(); }
|
||||
|
||||
// Access the workload Space
|
||||
const workload::SpacePointer getWorkloadSpace() const { return _space; }
|
||||
workload::SpacePointer getWorkloadSpace() const { return _space; }
|
||||
|
||||
signals:
|
||||
void enterEntity(const EntityItemID& entityItemID);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
set(TARGET_NAME physics)
|
||||
setup_hifi_library()
|
||||
link_hifi_libraries(shared fbx entities graphics)
|
||||
link_hifi_libraries(shared task workload fbx entities graphics)
|
||||
include_hifi_library_headers(networking)
|
||||
include_hifi_library_headers(gpu)
|
||||
include_hifi_library_headers(avatars)
|
||||
|
|
|
@ -120,8 +120,10 @@ void PhysicalEntitySimulation::changeEntityInternal(EntityItemPointer entity) {
|
|||
QMutexLocker lock(&_mutex);
|
||||
assert(entity);
|
||||
EntityMotionState* motionState = static_cast<EntityMotionState*>(entity->getPhysicsInfo());
|
||||
uint8_t region = _space->getRegion(entity->getSpaceIndex());
|
||||
bool shouldBePhysical = region < workload::Region::R3 && entity->shouldBePhysical();
|
||||
if (motionState) {
|
||||
if (!entity->shouldBePhysical()) {
|
||||
if (!shouldBePhysical) {
|
||||
// the entity should be removed from the physical simulation
|
||||
_incomingChanges.remove(motionState);
|
||||
_physicalObjects.remove(motionState);
|
||||
|
@ -133,7 +135,7 @@ void PhysicalEntitySimulation::changeEntityInternal(EntityItemPointer entity) {
|
|||
} else {
|
||||
_incomingChanges.insert(motionState);
|
||||
}
|
||||
} else if (entity->shouldBePhysical()) {
|
||||
} else if (shouldBePhysical) {
|
||||
// The intent is for this object to be in the PhysicsEngine, but it has no MotionState yet.
|
||||
// Perhaps it's shape has changed and it can now be added?
|
||||
_entitiesToAddToPhysics.insert(entity);
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
#include <EntityItem.h>
|
||||
#include <EntitySimulation.h>
|
||||
#include <workload/Space.h>
|
||||
|
||||
#include "PhysicsEngine.h"
|
||||
#include "EntityMotionState.h"
|
||||
|
@ -45,6 +46,7 @@ public:
|
|||
~PhysicalEntitySimulation();
|
||||
|
||||
void init(EntityTreePointer tree, PhysicsEnginePointer engine, EntityEditPacketSender* packetSender);
|
||||
void setWorkloadSpace(const workload::SpacePointer space) { _space = space; }
|
||||
|
||||
virtual void addDynamic(EntityDynamicPointer dynamic) override;
|
||||
virtual void applyDynamicChanges() override;
|
||||
|
@ -102,6 +104,7 @@ private:
|
|||
|
||||
VectorOfEntityMotionStates _owned;
|
||||
VectorOfEntityMotionStates _bids;
|
||||
workload::SpacePointer _space;
|
||||
uint64_t _nextBidExpiry;
|
||||
uint32_t _lastStepSendPackets { 0 };
|
||||
};
|
||||
|
|
|
@ -72,6 +72,7 @@ uint32_t PhysicsEngine::getNumSubsteps() {
|
|||
|
||||
// private
|
||||
void PhysicsEngine::addObjectToDynamicsWorld(ObjectMotionState* motionState) {
|
||||
qCDebug(physics) << "templog addObject" << (void*)(motionState); // TODO: remove this
|
||||
assert(motionState);
|
||||
|
||||
btVector3 inertia(0.0f, 0.0f, 0.0f);
|
||||
|
@ -193,6 +194,7 @@ void PhysicsEngine::removeObjects(const VectorOfMotionStates& objects) {
|
|||
for (auto object : objects) {
|
||||
btRigidBody* body = object->getRigidBody();
|
||||
if (body) {
|
||||
qCDebug(physics) << "removeObject" << (void*)(body->getMotionState()); // TODO: remove this
|
||||
removeDynamicsForBody(body);
|
||||
_dynamicsWorld->removeRigidBody(body);
|
||||
|
||||
|
|
|
@ -20,28 +20,21 @@ public:
|
|||
Owner() = default;
|
||||
Owner(const Owner& other) = default;
|
||||
Owner& operator=(const Owner& other) = default;
|
||||
|
||||
template <class T> Owner(const T& data) : _concept(std::make_shared<Model<T>>(data)) {}
|
||||
|
||||
~Owner() {}
|
||||
|
||||
template <class T> const T get() const { return std::static_pointer_cast<const Model<T>>(_concept)->_data; }
|
||||
|
||||
protected:
|
||||
class Concept {
|
||||
public:
|
||||
virtual ~Concept() = default;
|
||||
|
||||
};
|
||||
template <class T> class Model : public Concept {
|
||||
public:
|
||||
using Data = T;
|
||||
Data _data;
|
||||
|
||||
Model(const Data& data) : _data(data) {}
|
||||
virtual ~Model() = default;
|
||||
};
|
||||
|
||||
private:
|
||||
std::shared_ptr<Concept> _concept;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue