From 1640a4fb4bb0c831dd3f2a28bf99a49f3f41e829 Mon Sep 17 00:00:00 2001 From: ThomasAvans Date: Mon, 22 Apr 2024 10:40:59 +0200 Subject: Processed review --- main/CMakeLists.txt | 1 - main/puzzle/fsm/FSM.cpp | 3 -- main/puzzle/fsm/FSM.h | 50 -------------------------- main/puzzle/fsm/FSM.hpp | 68 ----------------------------------- main/puzzle/fsm/IBehaviouralState.hpp | 25 ------------- 5 files changed, 147 deletions(-) delete mode 100644 main/puzzle/fsm/FSM.cpp delete mode 100644 main/puzzle/fsm/FSM.h delete mode 100644 main/puzzle/fsm/FSM.hpp delete mode 100644 main/puzzle/fsm/IBehaviouralState.hpp (limited to 'main') diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 8af9402..a50a9a6 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -13,7 +13,6 @@ pico_sdk_init() add_executable(main main.cpp - FSM.cpp ) pico_enable_stdio_usb(main 1) diff --git a/main/puzzle/fsm/FSM.cpp b/main/puzzle/fsm/FSM.cpp deleted file mode 100644 index fad7fb3..0000000 --- a/main/puzzle/fsm/FSM.cpp +++ /dev/null @@ -1,3 +0,0 @@ -#include "FSM.h" - -#include "IBehaviouralState.hpp" \ No newline at end of file diff --git a/main/puzzle/fsm/FSM.h b/main/puzzle/fsm/FSM.h deleted file mode 100644 index 792a44f..0000000 --- a/main/puzzle/fsm/FSM.h +++ /dev/null @@ -1,50 +0,0 @@ -#ifndef _FSM_H_ -#define _FSM_H_ - -#include -#include - -#include "IBehaviouralState.hpp" - -/// -/// -/// -/// IBehaviouralState is the only accepted -/// class. -template class FSM { -public: - template FSM(TPState &...args) { - int i = 0; - - ((void)_states.emplace(i++, args), ...); - } - - /// - /// Implement with FSM::act() - /// - void act(); - - /// - /// Used to check current state. - /// - /// Current state. - std::shared_ptr &get_state() { return _currentState; } - - /// - /// Used to get all states. - /// - /// Current states. - std::map> get_states(); - - /// - /// Sets current state, calls appropiate functions. - /// - /// State to transition into. - void set_state(std::shared_ptr); - -private: - std::map> _states; - std::shared_ptr _currentState; -}; - -#endif // _FSM_H_ \ No newline at end of file diff --git a/main/puzzle/fsm/FSM.hpp b/main/puzzle/fsm/FSM.hpp deleted file mode 100644 index c86ed80..0000000 --- a/main/puzzle/fsm/FSM.hpp +++ /dev/null @@ -1,68 +0,0 @@ -#ifndef _FSM_HPP_ -#define _FSM_HPP_ - -#include "FSM.h" - -#include - -/// -/// This is a generic update method, unknown classes are not supported. -/// -/// IBehaviouralState is the only accepted -/// class. -template void FSM::act() { - // No implementation for unknown class. - std::cout << "No implementation for unknown class" << std::endl; -} -// -///// -///// Calls the IBehaviouralState act method. -///// -///// IBehaviouralState is the only accepted -/// class. -template <> inline void FSM::act() { _currentState->act(); } - -/// -/// This is a generic return of the type. -/// -/// Any class type works with this return. -/// The current IBehaviouralState map. -template -std::map> FSM::get_states() { - return _states; -} - -///// -///// State transitioning from current state to newState. -///// Calls Exit on the current state and Enter on the new state. -///// -///// IBehaviouralState is the only accepted -/// class. -///// New state to transition into. -template <> -inline void -FSM::set_state(std::shared_ptr newState) { - // We can guarantee all statemachines are based on IBehaviouralState - if (_currentState != nullptr) - _currentState->exit(); - - _currentState = nullptr; - _currentState = newState; - _currentState->enter(); -} - -/// -/// State transitioning from current state to newState. -/// Calls Exit on the current state and Enter on the new state. -/// -/// IBehaviouralState is the only accepted -/// class. New state to transition -/// into. -template -void FSM::set_state(std::shared_ptr newState) { - // We can guarantee all statemachines are based on IBehaviouralState - // No implementation for an unknown state change class. - std::cout << "No implementation for unknown state change class" << std::endl; -} - -#endif // _FSM_HPP_ \ No newline at end of file diff --git a/main/puzzle/fsm/IBehaviouralState.hpp b/main/puzzle/fsm/IBehaviouralState.hpp deleted file mode 100644 index c41fef3..0000000 --- a/main/puzzle/fsm/IBehaviouralState.hpp +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef _FSM_IBEHAVIOURALSTATE_HPP_ -#define _FSM_IBEHAVIOURALSTATE_HPP_ - -/// -/// Sub class used to define methods implemented by behavioural specific states. -/// -class IBehaviouralState { -public: - /// - /// Enters the current state. Used for setup. - /// - virtual void enter() = 0; - - /// - /// Updates the current state, used for physics, etc. - /// - virtual void act() = 0; - - /// - /// Exits the state, used for cleanup. - /// - virtual void exit() = 0; -}; - -#endif // _FSM_IBEHAVIOURALSTATE_HPP_ \ No newline at end of file -- cgit v1.2.3