diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 6f529a66d3..73c25f3e7a 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -3170,6 +3170,7 @@ public: typedef render::Payload Payload; typedef Payload::DataPointer Pointer; + int _val = 0; static render::ItemID _item; // unique WorldBoxRenderData }; @@ -3406,11 +3407,11 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se pendingChanges.resetItem(WorldBoxRenderData::_item, worldBoxRenderPayload); } else { - pendingChanges.updateItem(WorldBoxRenderData::_item, - render::UpdateFunctor( + pendingChanges.updateItem(WorldBoxRenderData::_item, [](WorldBoxRenderData& payload) { - qCDebug(interfaceapp, "MyFirst update message!!!!!"); - })); + payload._val++; + qCDebug(interfaceapp, "MyFirst update message!!!!! %u", payload._val); + }); } { diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.h b/libraries/entities-renderer/src/EntityTreeRenderer.h index 234e590b7d..3ad706605a 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.h +++ b/libraries/entities-renderer/src/EntityTreeRenderer.h @@ -19,7 +19,7 @@ #include // for RayToEntityIntersectionResult #include #include -#include +//#include #include #include diff --git a/libraries/entities-renderer/src/RenderableEntityItem.cpp b/libraries/entities-renderer/src/RenderableEntityItem.cpp index 0161df5c6f..926889ccac 100644 --- a/libraries/entities-renderer/src/RenderableEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableEntityItem.cpp @@ -41,3 +41,4 @@ namespace render { } + diff --git a/libraries/render/src/render/Scene.cpp b/libraries/render/src/render/Scene.cpp index f027c42f52..93b8b4d7ef 100644 --- a/libraries/render/src/render/Scene.cpp +++ b/libraries/render/src/render/Scene.cpp @@ -66,10 +66,6 @@ void Item::kill() { _key._flags.reset(); } -void Item::update(const UpdateFunctor& functor) { - _payload->update(functor); -} - void PendingChanges::resetItem(ItemID id, const PayloadPointer& payload) { _resetItems.push_back(id); _resetPayloads.push_back(payload); @@ -79,7 +75,7 @@ void PendingChanges::removeItem(ItemID id) { _removedItems.push_back(id); } -void PendingChanges::updateItem(ItemID id, const UpdateFunctor& functor) { +void PendingChanges::updateItem(ItemID id, const UpdateFunctorPointer& functor) { _updatedItems.push_back(id); _updateFunctors.push_back(functor); } diff --git a/libraries/render/src/render/Scene.h b/libraries/render/src/render/Scene.h index f9394fc44e..afacb25067 100644 --- a/libraries/render/src/render/Scene.h +++ b/libraries/render/src/render/Scene.h @@ -177,6 +177,7 @@ inline QDebug operator<<(QDebug debug, const ItemFilter& me) { return debug; } + class Item { public: typedef std::vector Vector; @@ -195,10 +196,12 @@ public: }; // Update Functor - struct UpdateFunctor { - void* _something; + class UpdateFunctorInterface { + public: + virtual ~UpdateFunctorInterface() {} }; - + typedef std::shared_ptr UpdateFunctorPointer; + // Payload is whatever is in this Item and implement the Payload Interface class PayloadInterface { public: @@ -206,21 +209,23 @@ public: virtual const Bound getBound() const = 0; virtual void render(RenderArgs* args) = 0; - virtual void update(const UpdateFunctor& functor) = 0; + virtual void update(const UpdateFunctorPointer& functor) = 0; ~PayloadInterface() {} protected: }; + + typedef std::shared_ptr PayloadPointer; + Item() {} ~Item() {} void resetPayload(const PayloadPointer& payload); void kill(); - void update(const UpdateFunctor& updateFunctor); // Check heuristic key const ItemKey& getKey() const { return _key; } @@ -228,6 +233,7 @@ public: // Payload Interface const Bound getBound() const { return _payload->getBound(); } void render(RenderArgs* args) { _payload->render(args); } + void update(const UpdateFunctorPointer& updateFunctor) { _payload->update(updateFunctor); } protected: PayloadPointer _payload; @@ -236,8 +242,19 @@ protected: friend class Scene; }; -typedef Item::UpdateFunctor UpdateFunctor; -typedef std::vector UpdateFunctors; + +typedef Item::UpdateFunctorInterface UpdateFunctorInterface; +typedef Item::UpdateFunctorPointer UpdateFunctorPointer; +typedef std::vector UpdateFunctors; + +template class UpdateFunctor : public Item::UpdateFunctorInterface { +public: + typedef std::function Func; + Func _func; + + UpdateFunctor(Func func): _func(func) {} + ~UpdateFunctor() {} +}; inline QDebug operator<<(QDebug debug, const Item& item) { @@ -245,7 +262,6 @@ inline QDebug operator<<(QDebug debug, const Item& item) { return debug; } - // THe Payload class is the real Payload to be used // THis allow anything to be turned into a Payload as long as the required interface functions are available // When creating a new kind of payload from a new "stuff" class then you need to create specialized version for "stuff" @@ -257,13 +273,13 @@ template void payloadRender(const std::shared_ptr& payloadData, Ren template class Payload : public Item::PayloadInterface { public: typedef std::shared_ptr DataPointer; - typedef std::function Updator; + typedef UpdateFunctor Updater; virtual const ItemKey getKey() const { return payloadGetKey(_data); } virtual const Item::Bound getBound() const { return payloadGetBound(_data); } virtual void render(RenderArgs* args) { payloadRender(_data, args); } - virtual void update(const UpdateFunctor& functor) { functor._f((*_data)); } + virtual void update(const UpdateFunctorPointer& functor) { static_cast(functor.get())->_func((*_data)); } Payload(const DataPointer& data) : _data(data) {} protected: @@ -339,8 +355,11 @@ public: void resetItem(ItemID id, const PayloadPointer& payload); void removeItem(ItemID id); - template void updateItem(ItemID id, std::function) { updateItem_(id, std::weak_ptr - void updateItem_(ItemID id, const UpdateFunctor& functor); + template void updateItem(ItemID id, std::function func) { + updateItem(id, UpdateFunctorPointer(new UpdateFunctor(func))); + } + + void updateItem(ItemID id, const UpdateFunctorPointer& functor); void merge(PendingChanges& changes);