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

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, workload::Owner(entity.get())); transaction.reset(spaceIndex, sphere, workload::Owner(entity));
_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

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