55 lines
1.3 KiB
C++
55 lines
1.3 KiB
C++
// Copyright (c) 2023 Dominic Masters
|
|
//
|
|
// This software is released under the MIT License.
|
|
// https://opensource.org/licenses/MIT
|
|
|
|
#pragma once
|
|
#include "assert/assert.hpp"
|
|
#include "event/Event.hpp"
|
|
|
|
namespace Dawn {
|
|
class IStateEvent;
|
|
|
|
template<typename...A>
|
|
class StateEvent;
|
|
|
|
template<typename ...A>
|
|
class StateOwnerEventLegacy;
|
|
|
|
class IStateOwnerEventLegacy {
|
|
public:
|
|
virtual void removeListener() = 0;
|
|
virtual void teardown() = 0;
|
|
};
|
|
|
|
class IStateOwner {
|
|
public:
|
|
virtual void _stateEventDisposed(IStateEvent *evt) = 0;
|
|
virtual void _stateLegacyEventDisposed(IStateOwnerEventLegacy *evt) = 0;
|
|
};
|
|
|
|
template<typename...A>
|
|
struct StateEventListener {
|
|
uint32_t id;
|
|
IStateOwner *owner;
|
|
std::function<void(A...)> listener;
|
|
std::function<void(StateEventListener<A...>)> unsubWithParams;
|
|
std::function<void()> unsub;
|
|
StateEvent<A...> *event;
|
|
};
|
|
|
|
class IStateProperty {
|
|
public:
|
|
IStateOwner *owner = nullptr;
|
|
|
|
std::vector<std::function<void()>> _effectListners;
|
|
std::vector<std::function<std::function<void()>()>> _effectListnersWithTeardown;
|
|
std::vector<std::function<void()>> _effectTeardowns;
|
|
};
|
|
|
|
class IStateEvent {
|
|
protected:
|
|
virtual void _stateOwnerDestroyed(IStateOwner *owner) = 0;
|
|
friend class StateOwner;
|
|
};
|
|
} |