//
// Created by martin on 12.11.21.
//

#ifndef ANIMTESTBED_ANIMATIONCONTROLLER_H
#define ANIMTESTBED_ANIMATIONCONTROLLER_H

#include <ozz/animation/runtime/animation.h>
#include <ozz/animation/runtime/sampling_job.h>
#include <ozz/base/containers/vector.h>
#include <ozz/base/maths/soa_transform.h>
#include <ozz/base/maths/transform.h>
#include <ozz/base/maths/vec_float.h>

struct SkinnedMesh;
struct AnimNode;

struct AnimationController {
  explicit AnimationController(SkinnedMesh* skinned_mesh);
  virtual ~AnimationController();

  void ResetAnims();

  // Creates a list of nodes where for node at index i for all inputs holds index > i.
  void UpdateOrderedNodes();

  // Updates all nodes.
  void UpdateTime(float dt);

  // Recursively evaluates all nodes.
  void Evaluate();

  void DrawDebugUi();

  float m_current_time;
  bool m_paused;
  bool m_calc_root_transform;
  ozz::math::Transform m_root_transform;

  SkinnedMesh* m_skinned_mesh = nullptr;

  AnimNode* m_output_node;

  std::vector<AnimNode*> m_anim_nodes;
  std::vector<AnimNode*> m_ordered_nodes;
};

#endif  //ANIMTESTBED_ANIMATIONCONTROLLER_H
