Atoms Crowd  4.1.0
StateMachine.h
1 #pragma once
2 // ===========================================================================
3 // Copyright (c) 2015 Toolchefs Ltd. All rights reserved.
4 //
5 // Use of this software is subject to the terms of the Toolchefs license
6 // agreement provided at the time of installation or download, or which
7 // otherwise accompanies this software in either electronic or hard copy form.
8 // ===========================================================================
9 
10 #include <AtomsCore/Globals.h>
11 
12 #include <Atoms/Globals.h>
13 #include <Atoms/AnimationState.h>
14 
15 #include <vector>
16 #include <string>
17 #include <map>
18 
19 
20 namespace Atoms
21 {
23 
26  class ATOMS_EXPORT StateMachine
27  {
28  public:
29 
32 
34 
37  StateMachine(const std::string &name);
38 
40  StateMachine(const StateMachine& other);
41 
44 
47 
49 
52  inline void addAnimationState(const AnimationState &state);
53 
55 
58  AnimationState& animationState(const std::string& name);
59 
61 
65 
67 
70  inline const std::vector<AnimationState>& animationStates() const;
71 
73  void connect(const std::string& fromState, const std::string& toState, AnimationState& transition);
74 
76  void breakConnection(const std::string& fromState, const std::string& toState);
77 
79  inline const std::map<std::pair<int, int>, AnimationState>& connections() const;
80 
82  void getConnectedStates(std::vector<int> &connectedStates, const AnimationState &state) const;
83 
85 
88  inline void setName(const std::string& name);
89 
91 
94  inline const std::string& name() const;
95 
97  std::vector<int> getShortestPathBetweenStates(const int startStateId, const int endStateid);
98 
99  private:
100 
102  std::vector<AnimationState> m_animationStates;
103 
105  std::map<std::pair<int, int>, AnimationState> m_connections;
106 
108  std::string m_name;
109 
110  private:
111 
112  static AnimationState m_emptyState;
113  };
114 }
115 
116 
117 #include "StateMachine.impl.h"
Atoms::StateMachine::getShortestPathBetweenStates
std::vector< int > getShortestPathBetweenStates(const int startStateId, const int endStateid)
Get shortest path between two states.
Atoms::StateMachine::StateMachine
StateMachine(const StateMachine &other)
Copy constructor.
Atoms::StateMachine::animationState
AnimationState & animationState(const std::string &name)
Gets animation state.
Atoms::StateMachine::StateMachine
StateMachine(const std::string &name)
Constructor.
Atoms::AnimationState
Animation State.
Definition: AnimationState.h:25
Atoms::StateMachine::operator=
StateMachine & operator=(const StateMachine &other)
Assign operator.
Atoms
Atoms namespace.
Definition: Agent.h:28
Atoms::StateMachine::~StateMachine
~StateMachine()
Destructor.
Atoms::StateMachine::animationStateFromId
AnimationState & animationStateFromId(const int id)
Gets animation state from id.
Atoms::StateMachine::breakConnection
void breakConnection(const std::string &fromState, const std::string &toState)
Disconnects two states.
Atoms::StateMachine::getConnectedStates
void getConnectedStates(std::vector< int > &connectedStates, const AnimationState &state) const
Gets all states connected to this state.
Atoms::StateMachine::StateMachine
StateMachine()
Constructor.
Atoms::StateMachine
State machine.
Definition: StateMachine.h:27
Atoms::StateMachine::connect
void connect(const std::string &fromState, const std::string &toState, AnimationState &transition)
Connects two states.