Atoms Crowd  7.0.0
StateMachineOperator.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 
11 #include <AtomsGraph/Ports.h>
12 #include <Atoms/Globals.h>
13 #include <Atoms/Graph/Operator.h>
14 #include <Atoms/AnimationClip.h>
15 #include <Atoms/AnimationState.h>
16 #include <Atoms/StateMachine.h>
17 #include <Atoms/Graph/AgentBehaviourNetwork.h>
18 #include <Atoms/Graph/Operators/StateMachineBaseNodeOperator.h>
19 #include <mutex>
20 
21 namespace Atoms
22 {
23 
24  class ATOMS_EXPORT StateMachineOperator : public Operator
25  {
26  public:
27 
29  {
30  public:
32  op(nullptr),
33  weightPort(nullptr),
34  timePort(nullptr),
35  activePort(nullptr),
36  weight(0),
37  frame(0),
38  forceActive(false)
39  {}
40 
42  AtomsGraph::DoublePort* weightPort;
43  AtomsGraph::DoublePort* timePort;
44  AtomsGraph::BooleanPort* activePort;
45  AtomsGraph::LongPort* frameOffsetPort;
46 
47  double weight;
48  double frame;
49  bool forceActive;
50  };
51 
53  {
54  public:
55  int blendIn;
56  int blendOut;
57  };
58 
59  NODE_STANDARD_MEMBERS
60 
62 
63  virtual ~StateMachineOperator();
64 
65  bool compute(const AtomsGraph::ComputeData* computeData);
66 
67  void reset();
68 
69  void setFps(double fps);
70 
71  void initRandom(int value);
72 
73  void advanceTime(const AtomsGraph::ComputeData* computeData, const double frameStep, const bool incrementFrame = true);
74 
75  void linearBlendStates(const std::pair<int, int>& transition,
76  int stateIndex,
77  double frameStep,
78  double timeStep,
79  unsigned int blendInTransition,
80  const AtomsGraph::ComputeData* computeData);
81 
82  bool isStateInQueue(int state);
83 
84  void buildNetwork(const AtomsPtr<Atoms::StateMachine> &stateMachine, std::map<std::string, std::string>& clipToAgentTypeNames, std::mutex& mutex, const double timeOffset, const bool forceUnsyncedClips, const int frameOffset);
85 
86  AgentBehaviourNetwork& network() { return m_network; };
87 
88  void advanceSingleState(int stateIndex, double timeStep, double frameStep);
89 
90  const std::list<unsigned int>& getStateQueue() const { return m_stateQueue; };
91 
92  const bool isInTransition() const { return m_isInTransition; }
93 
94  private:
95 
96  AgentBehaviourNetwork m_network;
97 
98  AtomsGraph::DoublePort* m_timePort;
99 
100  AtomsGraph::DoublePort* m_fpsPort;
101 
102  AtomsGraph::LongPort* m_statePort;
103 
104  AtomsGraph::BooleanPort* m_allowPathSearch;
105 
106  std::map<int, AnimationStateData> m_states;
107 
108  std::unordered_map<int, int> m_statePortIndex;
109 
110  std::map<std::pair<int, int>, int> m_transitionPortIndex;
111 
112  std::map < std::pair<int, int>, TransitionNoClipData> m_transitionNoClipsData;
113 
114  std::list<unsigned int> m_stateQueue;
115 
116  AtomsCore::Vector3 m_previousDirection;
117 
118  AtomsCore::Vector3 m_cacheUpVector;
119 
120  AtomsCore::Vector3 m_cacheDirectionVector;
121 
122  AtomsCore::Rand32 m_idRandom;
123 
124  double m_framesBlendInOffset;
125 
126  double m_previousTime;
127 
128  //double m_prevTurnAngle;
129 
130  int m_currentState;
131 
132  int m_previousState;
133 
134  int m_prevFromOneShot;
135 
136  bool m_first;
137 
138  bool m_isInTransition;
139 
140  bool m_transitionStarted;
141 
142  bool m_transitionIsEnded;
143  };
144 }
Agent behaviour network.
Definition: AgentBehaviourNetwork.h:29
Operator node.
Definition: Operator.h:26
Definition: StateMachineBaseNodeOperator.h:27
Definition: StateMachineOperator.h:29
Definition: StateMachineOperator.h:53
Definition: StateMachineOperator.h:25
bool compute(const AtomsGraph::ComputeData *computeData)
Compute function.
void reset()
Operator reset function.
Definition: Node.h:21
Generic node port class.
Definition: PortTemplate.h:24
AtomsMath::Vector3 Vector3
Vector3 class.
Definition: AtomsMath.h:57
Atoms namespace.
Definition: Agent.h:29