Atoms Crowd  7.0.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"
Animation State.
Definition: AnimationState.h:25
State machine.
Definition: StateMachine.h:27
StateMachine()
Constructor.
StateMachine(const std::string &name)
Constructor.
AnimationState & animationStateFromId(const int id)
Gets animation state from id.
void breakConnection(const std::string &fromState, const std::string &toState)
Disconnects two states.
StateMachine(const StateMachine &other)
Copy constructor.
StateMachine & operator=(const StateMachine &other)
Assign operator.
std::vector< int > getShortestPathBetweenStates(const int startStateId, const int endStateid)
Get shortest path between two states.
void connect(const std::string &fromState, const std::string &toState, AnimationState &transition)
Connects two states.
AnimationState & animationState(const std::string &name)
Gets animation state.
void getConnectedStates(std::vector< int > &connectedStates, const AnimationState &state) const
Gets all states connected to this state.
~StateMachine()
Destructor.
Atoms namespace.
Definition: Agent.h:29