diff options
Diffstat (limited to 'src/libjin/ai/je_state_machine.h')
| -rw-r--r-- | src/libjin/ai/je_state_machine.h | 118 | 
1 files changed, 117 insertions, 1 deletions
| diff --git a/src/libjin/ai/je_state_machine.h b/src/libjin/ai/je_state_machine.h index 7869925..0d19be9 100644 --- a/src/libjin/ai/je_state_machine.h +++ b/src/libjin/ai/je_state_machine.h @@ -4,17 +4,133 @@  #include "../core/je_configuration.h"  #if defined(jin_ai) +#include <map> +#include <vector> + +#include "../common/je_object.h" +  namespace JinEngine  {      namespace AI      { +        // From Unity3D game engine. + +        class State; + +        enum ConditionType +        { + +        };          /// +        /// Traslation's condition.          /// +        struct Condition +        { + +        }; + +        ///  +        /// Translate to another state.  +        ///  +        struct Transition +        { +            Condition condition; ///< Condition to active transition. +            State* state;        ///< State translate to. +        }; + +        /// +        /// Definition of state.          /// -        class StateMachine +        struct StateDef          { +        }; + +        /// +        /// A single state. +        /// +        struct State +        { +            std::string name;                     ///< Name of state.  +            std::vector<Transition> translations; ///< All transitions this state have. +            StateDef definition;                  ///< Definition of state. +            void* userdata;                       ///< A state could have a user data. +        }; + +        /// +        /// A single layer statemachine. +        /// +        class StateMachine : public Object +        { +        public:  +            /// +            /// +            /// +            typedef void(*SingleStateCallback)(State* state); + +            /// +            /// +            /// +            typedef void(*DoubleStateCallback)(State* stateFrom, State* stateTo); + +            /// +            /// State machine constructor. +            /// +            StateMachine(); + +            /// +            /// State machine destructor. +            /// +            ~StateMachine(); + +            /// +            /// Update statemachine. +            /// +            void onUpdate(); + +            ///  +            /// Add new state. +            ///  +            void addState(const std::string& name, const State& state); + +            /// +            /// Get state reference by given state name. +            /// +            const State* getState(const std::string& name); + +            void addEnterListener(); +            void addExitListener();  +            void addTranslateListener();  + +            const std::string& getCurrentStateName(); +            const State* getCurrentState(); + +        private: +            /// +            /// All state this state machine keeps. +            /// +            std::map<std::string, State> mStates; + +            /// +            /// +            /// +            std::map<std::string, SingleStateCallback> mOnEnterState; + +            /// +            /// +            /// +            std::map<std::string, SingleStateCallback> mOnExitState; + +            /// +            /// From first to second. +            /// +            std::map<std::pair<std::string, std::string>, DoubleStateCallback> mOnStateTranslate; +            /// +            /// Current state. +            /// +            State* mCurrentState; +                      };      } | 
