Did a bit of provider cleanup
This commit is contained in:
@ -46,6 +46,8 @@ namespace Dawn {
|
|||||||
std::vector<IStateOwnerEventLegacy*> eventLegacyBridge;
|
std::vector<IStateOwnerEventLegacy*> eventLegacyBridge;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
std::vector<std::function<void()>> _stateProviderListeners;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called by the state event when it is disposing (before the StateOwner
|
* Called by the state event when it is disposing (before the StateOwner
|
||||||
* itself is).
|
* itself is).
|
||||||
@ -228,6 +230,13 @@ namespace Dawn {
|
|||||||
* useEffects or useEvents.
|
* useEffects or useEvents.
|
||||||
*/
|
*/
|
||||||
virtual ~StateOwner() {
|
virtual ~StateOwner() {
|
||||||
|
auto providers = this->_stateProviderListeners;
|
||||||
|
auto itProvider = providers.begin();
|
||||||
|
while(itProvider != providers.end()) {
|
||||||
|
(*itProvider)();
|
||||||
|
++itProvider;
|
||||||
|
}
|
||||||
|
|
||||||
auto it = this->eventsSubscribed.begin();
|
auto it = this->eventsSubscribed.begin();
|
||||||
while(it != this->eventsSubscribed.end()) {
|
while(it != this->eventsSubscribed.end()) {
|
||||||
(*it)->_stateOwnerDestroyed(this);
|
(*it)->_stateOwnerDestroyed(this);
|
||||||
|
@ -38,12 +38,13 @@ namespace Dawn {
|
|||||||
l.data = data;
|
l.data = data;
|
||||||
this->listeners.push_back(l);
|
this->listeners.push_back(l);
|
||||||
|
|
||||||
return std::bind([&](struct StateListener<D, A...> listener) {
|
auto unsub = std::bind([&](struct StateListener<D, A...> listener) {
|
||||||
|
// Not yet implemented
|
||||||
assertUnreachable();
|
assertUnreachable();
|
||||||
// auto it = std::find(listeners.begin(), listeners.end(), listener);
|
|
||||||
// assertFalse(it == listeners.end());
|
|
||||||
// listeners.erase(it);
|
|
||||||
}, l);
|
}, l);
|
||||||
|
|
||||||
|
context->_stateProviderListeners.push_back(unsub);
|
||||||
|
return unsub;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
@ -77,6 +77,16 @@ namespace Dawn {
|
|||||||
return context->getGame()->timeManager.timeoutProvider.addEffect(someCallback, timeout, context);
|
return context->getGame()->timeManager.timeoutProvider.addEffect(someCallback, timeout, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use interval provider method. Invokes your callback at a consistant and
|
||||||
|
* common time based on the interval you provide.
|
||||||
|
*
|
||||||
|
* @tparam T Your context type (usually SceneItemComponent).
|
||||||
|
* @param someCallback Callback to be invoked.
|
||||||
|
* @param timeout Interval to invoke your callback.
|
||||||
|
* @param context Context of the component, just use (this).
|
||||||
|
* @return Method that when invoked will unsubscribe from the interval.
|
||||||
|
*/
|
||||||
template<class T>
|
template<class T>
|
||||||
std::function<void()> useInterval(
|
std::function<void()> useInterval(
|
||||||
std::function<void()> callback,
|
std::function<void()> callback,
|
||||||
|
Reference in New Issue
Block a user