Transitions being a way to allow for automatic state change and allow for a way to allow or forbbid a transition between two states
41 lines
855 B
C++
41 lines
855 B
C++
#ifndef STATE_HPP
|
|
#define STATE_HPP
|
|
|
|
#include <functional>
|
|
#include <vector>
|
|
#include <string>
|
|
|
|
template <typename Type>
|
|
struct Transition {
|
|
const std::string from;
|
|
const std::string target_state;
|
|
const std::function<bool (const Type&)> condition;
|
|
};
|
|
|
|
template <typename OwnerType>
|
|
class State {
|
|
public:
|
|
virtual ~State() = default;
|
|
|
|
virtual void OnEnter(OwnerType &owner) = 0;
|
|
virtual void OnUpdate(OwnerType &owner) = 0;
|
|
virtual void OnExit(OwnerType &owner) = 0;
|
|
|
|
virtual std::string Id() const = 0;
|
|
};
|
|
|
|
template <typename OwnerType>
|
|
class AState : public State<OwnerType> {
|
|
public:
|
|
AState(const std::string &id) : entity_id(id) {};
|
|
|
|
std::string Id() const override {
|
|
return entity_id;
|
|
}
|
|
|
|
private:
|
|
std::string entity_id;
|
|
};
|
|
|
|
#endif // STATE_HPP
|