From 454f79862d0aee9bf61debe0e976d61d7e0f3469 Mon Sep 17 00:00:00 2001 From: chai Date: Thu, 25 Oct 2018 22:28:17 +0800 Subject: =?UTF-8?q?*luajit=20=E9=9D=99=E6=80=81=E7=BC=96=E8=AF=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/libjin/ai/je_state_machine.h | 118 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 117 insertions(+), 1 deletion(-) (limited to 'src/libjin/ai/je_state_machine.h') 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 +#include + +#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 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 mStates; + + /// + /// + /// + std::map mOnEnterState; + + /// + /// + /// + std::map mOnExitState; + + /// + /// From first to second. + /// + std::map, DoubleStateCallback> mOnStateTranslate; + /// + /// Current state. + /// + State* mCurrentState; + }; } -- cgit v1.1-26-g67d0