More work on State System

This commit is contained in:
2023-03-01 08:03:03 -08:00
parent f723c5f20a
commit 7e452eb365
6 changed files with 167 additions and 48 deletions

View File

@ -0,0 +1,53 @@
// 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:
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;
};
}