diff --git a/libraries/render/src/render/Scene.h b/libraries/render/src/render/Scene.h index 8ea0c1700c..ba4c1b54a3 100644 --- a/libraries/render/src/render/Scene.h +++ b/libraries/render/src/render/Scene.h @@ -24,7 +24,11 @@ namespace render { class Context; + + + + class Item { public: typedef std::vector Vector; @@ -59,24 +63,16 @@ public: // Payload is whatever is in this Item and implement the Payload Interface class PayloadInterface { public: - virtual const State&& getState() const = 0; - virtual const Bound&& getBound() const = 0; + virtual const State getState() const = 0; + virtual const Bound getBound() const = 0; virtual void render(Context& context) = 0; ~PayloadInterface() {} protected: }; - - template class Payload : public PayloadInterface { - public: - virtual const State&& getState() const { return getState(*this); } - virtual const Bound&& getBound() const { return getBound(*this); } - virtual void render(Context& context) { render(*this, context); } - protected: - }; - + typedef std::shared_ptr PayloadPointer; - + Item() {} Item(PayloadPointer& payload): _payload(payload) {} @@ -108,7 +104,7 @@ public: bool isPickable() const { return _state[PICKABLE]; } // Payload Interface - const Bound&& getBound() const { return _payload->getBound(); } + const Bound getBound() const { return _payload->getBound(); } void render(Context& context) { _payload->render(context); } protected: @@ -118,6 +114,21 @@ protected: friend class Scene; }; +template const Item::State payloadGetState(const T* payload) { return Item::State(); } +template const Item::Bound payloadGetBound(const T* payload) { return Item::Bound(); } +template void payloadRender(const T* payload) { } + +template class ItemPayload : public Item::PayloadInterface { +public: + virtual const Item::State getState() const { return payloadGetState(_pointee); } + virtual const Item::Bound getBound() const { return payloadGetBound(_pointee); } + virtual void render(Context& context) { payloadRender(_pointee, context); } + + ItemPayload(std::shared_ptr& pointee) : _pointee(pointee) {} +protected: + std::shared_ptr _pointee; +}; + typedef Item::PayloadInterface Payload; typedef Item::PayloadPointer PayloadPointer; typedef std::vector< PayloadPointer > Payloads; @@ -217,6 +228,8 @@ protected: friend class Engine; }; + + typedef std::shared_ptr ScenePointer; typedef std::vector Scenes;