| 190 | // Animation object holds a group of frame sequences and can mutate an AnimationState token |
| 191 | template<typename StatesEnum> |
| 192 | class Animation |
| 193 | { |
| 194 | public: |
| 195 | Animation() = default; |
| 196 | |
| 197 | // Change an animation state token to a new state |
| 198 | inline bool ChangeState(AnimationState& state, const StatesEnum& sStateName) const |
| 199 | { |
| 200 | size_t idx = m_mapStateIndices.at(sStateName); |
| 201 | if (state.nIndex != idx) |
| 202 | { |
| 203 | state.fTime = 0.0f; |
| 204 | state.nIndex = idx; |
| 205 | state.bComplete = false; |
| 206 | return true; |
| 207 | } |
| 208 | |
| 209 | return false; |
| 210 | } |
| 211 | |
| 212 | // Update an animation state token |
| 213 | inline void UpdateState(AnimationState& state, const float fElapsedTime) const |
| 214 | { |
| 215 | state.fTime += fElapsedTime; |
| 216 | state.bComplete = m_vSequences[state.nIndex].Complete(state.fTime); |
| 217 | } |
| 218 | |
| 219 | public: |
| 220 | // Retrieve the frame information for a given animation state |
| 221 | inline const Frame& GetFrame(const AnimationState& state) const |
| 222 | { |
| 223 | return m_vSequences[state.nIndex].GetFrame(state.fTime); |
| 224 | } |
| 225 | |
| 226 | public: |
| 227 | // Add a named Frame sequence as a state |
| 228 | inline void AddState(const StatesEnum& sStateName, const FrameSequence& sequence) |
| 229 | { |
| 230 | m_vSequences.emplace_back(sequence); |
| 231 | m_mapStateIndices[sStateName] = m_vSequences.size() - 1; |
| 232 | } |
| 233 | |
| 234 | private: |
| 235 | std::vector<FrameSequence> m_vSequences; |
| 236 | std::unordered_map<StatesEnum, size_t> m_mapStateIndices; |
| 237 | }; |
| 238 | } |
nothing calls this directly
no outgoing calls
no test coverage detected