You are on page 1of 3

/* Start Header ****************************************************************

*/
/*!
/file StateMachine.h
/author Team42, Jiawei Gu
/e-mail Team42@digipen.edu, jiawei.gu@digipen.edu
/date 10/04/2015
/Brief Copyright (C) 2015 DigiPen Institute of Technology. Reproduction or
disclosure of this file or its contents without the prior written consent of
DigiPen Institute of Technology is prohibited.
*/
/* End Header ******************************************************************
*/
#ifndef T_STATE_MACHINE
#define T_STATE_MACHINE
#include <map>
#include <vector>
#include <string>
#include
#include
#include
#include
#include

"OGRE/Ogre.h"
"../Component.h"
"../../Serialization/ISerializable.h"
"../../Behaviors/Behavior.h"
"../../Systems/EventSystem/IEventListener.h"

namespace TrillianComponent
{
enum class StateMachineStatus
{
OnEnter,
OnUpdate,
OnExit
};
class StateMachine : public Component, public TrillianEvent::IEventListe
ner
{
public:
StateMachine();
~StateMachine() override;
/// <summary>
/// Assignment operator used to create copies of objects with Ar
chetype and clone function
/// </summary>
/// <param name="stateMachine">The state machine.</param>
/// <returns>State Machine</returns>
StateMachine & operator= (const StateMachine & stateMachine);
/// <summary>
/// Initialize the state machine
/// </summary>
void Initialize() override;
///
///
///
///

<summary>
Update the state machine
</summary>
<param name="dt">The delta time.</param>

void Update(Ogre::Real dt) override;


/// <summary>
/// Deserialize from a document.
/// </summary>
/// <param name="block">Json file block.</param>
bool Deserialize(const TrillianSerialization::JsonBlock& block)
override;
/// <summary>
/// Serialize to a document.
/// </summary>
/// <param name="document">Json document.</param>
/// <param name="allocator">Allocator.</param>
bool Serialize(TrillianSerialization::JsonBlock& document, Trill
ianSerialization::Allocator& allocator) override;
/// <summary>
/// Register state to the state machine.
/// </summary>
/// <param name="state">state.</param>
void RegisterState(TrillianBehavior::Behavior * state);
/// <summary>
/// The begin state.
/// </summary>
/// <param name="startState">Start state.</param>
void SetStartState(const std::string & startState);
/// <summary>
/// Get the event listener ID.
/// </summary>
/// <returns>Hash code of the listener.</returns>
TrillianUtility::Hashing::Hash GetListenerId() const override;
/// <summary>
/// Handle the event.
/// </summary>
/// <param name="event">The event.</param>
bool HandleEvent(const TrillianEvent::BaseEvent* event) override
;
/// <summary>
/// Get current state.
/// </summary>
/// <returns>Current state.</returns>
const std::string & GetCurrentState() const;
private:
/// <summary>
/// Register events it listens to.
/// </summary>
void RegisterEvents() override;
/// <summary>
/// Unregister events it listens to.
/// </summary>
void UnregisterEvents() override;
/// <summary>
/// Events it listens to.

/// </summary>
std::vector<std::string> events;
/// <summary>
/// States.
/// </summary>
std::map<std::string, TrillianBehavior::Behavior *> states;
/// <summary>
/// Stack used by common behaviors.
/// </summary>
std::vector<std::string> stack;
/// <summary>
/// Current state.
/// </summary>
std::string currentState;
/// <summary>
/// Next state.
/// </summary>
std::string nextState;
/// <summary>
/// Current state machine status.
/// </summary>
StateMachineStatus status;
};
}
#endif

You might also like