StateMachine.hpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-09-05
  6. * Changed: 2022-07-15
  7. *
  8. * */
  9. #ifndef LS_STD_STATE_MACHINE_HPP
  10. #define LS_STD_STATE_MACHINE_HPP
  11. #include <memory>
  12. #include <unordered_map>
  13. #include <string>
  14. #include <vector>
  15. #include <ls_std/core/Class.hpp>
  16. #include "State.hpp"
  17. #include <ls_std/core/types/StateMachineTypes.hpp>
  18. #include <ls_std/os/dynamic_goal.hpp>
  19. namespace ls::std::logic
  20. {
  21. class [[deprecated("consider using ls_game_tool_kit dependency instead!")]] LS_STD_DYNAMIC_GOAL StateMachine : public ls::std::core::Class
  22. {
  23. public:
  24. explicit StateMachine(const ::std::string &_name);
  25. ~StateMachine() override = default;
  26. bool addState(const ::std::shared_ptr<ls::std::logic::State> &_state);
  27. ::std::shared_ptr<ls::std::logic::State> getCurrentState();
  28. ::std::vector<ls::std::core::type::state_id> getMemory();
  29. ::std::string getName();
  30. ::std::unordered_map<ls::std::core::type::state_id, ::std::shared_ptr<ls::std::logic::State>> getStates();
  31. bool hasState(const ls::std::core::type::state_id &_id);
  32. bool proceed();
  33. void setMemory(const ::std::vector<ls::std::core::type::state_id> &_memory);
  34. void setName(const ::std::string &_name);
  35. bool setStartState(const ls::std::core::type::state_id &_id);
  36. private:
  37. ::std::shared_ptr<ls::std::logic::State> currentState{};
  38. ::std::vector<ls::std::core::type::state_id> memory{};
  39. ::std::string name{};
  40. ::std::unordered_map<ls::std::core::type::state_id, ::std::shared_ptr<ls::std::logic::State>> states{};
  41. void _assignMemory(const ::std::vector<ls::std::core::type::state_id> &_memory);
  42. void _assignName(const ::std::string &_name);
  43. ::std::vector<ls::std::core::type::state_id> _getNextValidStates();
  44. void _remember(const ls::std::core::type::state_id &_id);
  45. bool _hasState(const ls::std::core::type::state_id &_id);
  46. };
  47. }
  48. #endif