Dirty attempt to capture the owner typefor a payload

This commit is contained in:
samcake 2018-04-05 18:04:35 -07:00
parent c5b88d55ab
commit a5ee211dbf
3 changed files with 29 additions and 10 deletions

View file

@ -61,12 +61,12 @@ public:
uint32_t numExits = (uint32_t)regionChanges[exitIndex].size();
for (uint32_t i = 0; i < numExits; ++i) {
int32_t proxyID = regionChanges[exitIndex][i];
void* owner = space->getOwner(proxyID).get();
auto owner = space->getOwner(proxyID).get<EntityItemPointer>();
if (owner) {
EntityItem* entity = static_cast<EntityItem*>(owner);
//EntityItem* entity = static_cast<EntityItem*>(owner);
std::cout << "adebug - "
//<< owner
<< " '" << entity->getName().toStdString() << "'"
<< " '" << owner->getName().toStdString() << "'"
<< std::endl; // adebug
}
}
@ -75,12 +75,12 @@ public:
uint32_t numEntries = (uint32_t)regionChanges[enterIndex].size();
for (uint32_t i = 0; i < numEntries; ++i) {
int32_t proxyID = regionChanges[enterIndex][i];
void* owner = space->getOwner(proxyID).get();
auto owner = space->getOwner(proxyID).get<EntityItemPointer>();
if (owner) {
EntityItem* entity = static_cast<EntityItem*>(owner);
// EntityItem* entity = static_cast<EntityItem*>(owner);
std::cout << "adebug + "
//<< owner
<< " '" << entity->getName().toStdString() << "'"
<< " '" << owner->getName().toStdString() << "'"
<< std::endl; // adebug
}
}

View file

@ -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, workload::Owner(entity.get()));
transaction.reset(spaceIndex, sphere, workload::Owner(entity));
_space->enqueueTransaction(transaction);
entity->setSpaceIndex(spaceIndex);
connect(entity.get(), &EntityItem::spaceUpdate, this, &EntityTreeRenderer::handleSpaceUpdate, Qt::QueuedConnection);

View file

@ -18,13 +18,32 @@ namespace workload {
class Owner {
public:
Owner() = default;
Owner(void* data) : _data(data) {}
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() {}
void* get() const { return _data; }
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:
void* _data { nullptr };
std::shared_ptr<Concept> _concept;
};
class Proxy {