diff --git a/src/dawn/state/State.hpp b/src/dawn/state/State.hpp index 3bc85f07..a57f8a4f 100644 --- a/src/dawn/state/State.hpp +++ b/src/dawn/state/State.hpp @@ -93,6 +93,15 @@ namespace Dawn { const std::function &fn, IStateProperty &property ) { + if(property.owner == nullptr) { + property.owner = this; + } else { + // TODO: This actually isn't needed, but because I need to teardown + // all the listeners on StateProperty<> that belong to this StateOwner + // I need to keep track of what events I've subbed to, consuming more + // memory, and I don't know if I actually need to do this or not. + assertTrue(property.owner == this); + } property._effectListners.push_back(fn); return fn; } @@ -111,7 +120,9 @@ namespace Dawn { ) { auto itProp = props.begin(); while(itProp != props.end()) { - (*itProp)->_effectListners.push_back(fn); + auto property = *itProp; + if(property->owner == nullptr) { property->owner = this; } else { assertTrue(property->owner == this); } + property->_effectListners.push_back(fn); ++itProp; } return fn; @@ -130,6 +141,7 @@ namespace Dawn { const std::function()> &fn, IStateProperty &property ) { + if(property.owner == nullptr) { property.owner = this; } else { assertTrue(property.owner == this); } property._effectListnersWithTeardown.push_back(fn); return std::bind([&]( diff --git a/src/dawn/state/StateInterfaces.hpp b/src/dawn/state/StateInterfaces.hpp index 010481ce..bc612eb3 100644 --- a/src/dawn/state/StateInterfaces.hpp +++ b/src/dawn/state/StateInterfaces.hpp @@ -37,9 +37,11 @@ namespace Dawn { std::function unsub; StateEvent *event; }; - + class IStateProperty { public: + IStateOwner *owner = nullptr; + std::vector> _effectListners; std::vector()>> _effectListnersWithTeardown; std::vector> _effectTeardowns; diff --git a/src/dawntictactoe/scenes/TicTacToeScene.hpp b/src/dawntictactoe/scenes/TicTacToeScene.hpp index a50beba7..76cd691d 100644 --- a/src/dawntictactoe/scenes/TicTacToeScene.hpp +++ b/src/dawntictactoe/scenes/TicTacToeScene.hpp @@ -43,11 +43,6 @@ namespace Dawn { tile->ticTacToe->tile = i++; } } - - evtUnsub = useEventLegacy([&]{ - std::cout << "Legacy Event Invoked " << age << std::endl; - evtUnsub(); - }, this->eventSceneUpdate); } std::vector getRequiredAssets() override {