<commit_before>#include <babylon/animations/runtime_animation.h>

#include <cmath>

#include <babylon/animations/animatable.h>
#include <babylon/animations/animation.h>
#include <babylon/animations/easing/ieasing_function.h>
#include <babylon/animations/ianimatable.h>
#include <babylon/animations/ianimation_key.h>
#include <babylon/babylon_stl_util.h>

namespace BABYLON {

RuntimeAnimation::RuntimeAnimation(const IAnimatablePtr& target,
                                   const AnimationPtr& animation, Scene* scene,
                                   Animatable* host)
    : currentFrame{this, &RuntimeAnimation::get_currentFrame}
    , weight{this, &RuntimeAnimation::get_weight}
    , currentValue{this, &RuntimeAnimation::get_currentValue}
    , _workValue{std::nullopt}
    , targetPath{this, &RuntimeAnimation::get_targetPath}
    , target{this, &RuntimeAnimation::get_target}
    , _currentFrame{0}
    , _animation{animation}
    , _target{target}
    , _host{host}
    , _stopped{false}
    , _blendingFactor{0.f}
    , _scene{scene}
    , _currentValue{std::nullopt}
    , _targetPath{""}
    , _weight{1.f}
    , _ratioOffset{0.f}
    , _previousDelay{millisecond_t{0}}
    , _previousRatio{0.f}
{
  // Cloning events locally
  const auto& events = animation->getEvents();
  if (!events.empty()) {
    for (const auto& e : events) {
      _events.emplace_back(e);
    }
  }
}

RuntimeAnimation::~RuntimeAnimation()
{
}

void RuntimeAnimation::addToRuntimeAnimations(
  const RuntimeAnimationPtr& animation)
{
  _animation->_runtimeAnimations.emplace_back(animation);
}

float RuntimeAnimation::get_currentFrame() const
{
  return _currentFrame;
}

float RuntimeAnimation::get_weight() const
{
  return _weight;
}

std::optional<AnimationValue>& RuntimeAnimation::get_currentValue()
{
  return _currentValue;
}

std::string RuntimeAnimation::get_targetPath() const
{
  return _targetPath;
}

IAnimatable*& RuntimeAnimation::get_target()
{
  return _activeTarget;
}

AnimationPtr& RuntimeAnimation::animation()
{
  return _animation;
}

void RuntimeAnimation::reset(bool restoreOriginal)
{
  if (restoreOriginal) {
    if (!_originalValue.empty() && _originalValue[0] != std::nullopt) {
      // _setValue(_target, _originalValue[0], -1);
    }
  }

  _offsetsCache.clear();
  _highLimitsCache.clear();
  _currentFrame   = 0;
  _blendingFactor = 0;
  _originalValue.clear();

  // Events
  for (auto& event : _events) {
    event.isDone = false;
  }
}

bool RuntimeAnimation::isStopped() const
{
  return _stopped;
}

void RuntimeAnimation::dispose()
{
  auto& runtimeAnimations = _animation->runtimeAnimations();
  runtimeAnimations.erase(
    std::remove_if(runtimeAnimations.begin(), runtimeAnimations.end(),
                   [this](const RuntimeAnimationPtr& runtimeAnimation) {
                     return runtimeAnimation.get() == this;
                   }),
    runtimeAnimations.end());
}

AnimationValue RuntimeAnimation::_interpolate(
  float iCurrentFrame, int repeatCount, unsigned int loopMode,
  const AnimationValue& offsetValue, const AnimationValue& highLimitValue)
{
  _currentFrame = iCurrentFrame;

  if (_animation->dataType != -1
      && static_cast<unsigned>(_animation->dataType)
           == Animation::ANIMATIONTYPE_MATRIX()
      && !_workValue) {
    _workValue = Matrix::Zero();
  }

  return _animation->_interpolate(currentFrame, repeatCount, _workValue,
                                  loopMode, offsetValue, highLimitValue);
}

void RuntimeAnimation::setValue(const AnimationValue& iCurrentValue,
                                float iWeight)
{
  _setValue(_target, iCurrentValue, iWeight);
}

void RuntimeAnimation::_setValue(const IAnimatablePtr& iTarget,
                                 const AnimationValue& iCurrentValue,
                                 float iWeight, unsigned int targetIndex)
{
  // Set value
  std::string path = "";
  any destination  = nullptr;

  const auto& targetPropertyPath = _animation->targetPropertyPath;

  if (targetPropertyPath.size() > 1) {
    auto property = iTarget->getProperty(targetPropertyPath[0]);

    for (size_t index = 1; index < targetPropertyPath.size() - 1; ++index) {
      property = iTarget->getProperty(property, targetPropertyPath[index]);
    }

    path        = targetPropertyPath.back();
    destination = property;
  }
  else {
    path        = targetPropertyPath[0];
    destination = iTarget;
  }

  _targetPath   = path;
  _activeTarget = destination;
  _weight       = iWeight;

  if (targetIndex >= _originalValue.size()) {
    _originalValue.resize(targetIndex + 1);
    _originalValue[targetIndex] = std::nullopt;
  }
<commit_msg>Revert "Fixed compile error"<commit_after>#include <babylon/animations/runtime_animation.h>

#include <cmath>

#include <babylon/animations/animatable.h>
#include <babylon/animations/animation.h>
#include <babylon/animations/easing/ieasing_function.h>
#include <babylon/animations/ianimatable.h>
#include <babylon/animations/ianimation_key.h>
#include <babylon/babylon_stl_util.h>

namespace BABYLON {

RuntimeAnimation::RuntimeAnimation(const IAnimatablePtr& target,
                                   const AnimationPtr& animation, Scene* scene,
                                   Animatable* host)
    : currentFrame{this, &RuntimeAnimation::get_currentFrame}
    , weight{this, &RuntimeAnimation::get_weight}
    , currentValue{this, &RuntimeAnimation::get_currentValue}
    , _workValue{std::nullopt}
    , targetPath{this, &RuntimeAnimation::get_targetPath}
    , target{this, &RuntimeAnimation::get_target}
    , _currentFrame{0}
    , _animation{animation}
    , _target{target}
    , _host{host}
    , _stopped{false}
    , _blendingFactor{0.f}
    , _scene{scene}
    , _currentValue{std::nullopt}
    , _targetPath{""}
    , _weight{1.f}
    , _ratioOffset{0.f}
    , _previousDelay{millisecond_t{0}}
    , _previousRatio{0.f}
{
  // Cloning events locally
  const auto& events = animation->getEvents();
  if (!events.empty()) {
    for (const auto& e : events) {
      _events.emplace_back(e);
    }
  }
}

RuntimeAnimation::~RuntimeAnimation()
{
}

void RuntimeAnimation::addToRuntimeAnimations(
  const RuntimeAnimationPtr& animation)
{
  _animation->_runtimeAnimations.emplace_back(animation);
}

float RuntimeAnimation::get_currentFrame() const
{
  return _currentFrame;
}

float RuntimeAnimation::get_weight() const
{
  return _weight;
}

std::optional<AnimationValue>& RuntimeAnimation::get_currentValue()
{
  return _currentValue;
}

std::string RuntimeAnimation::get_targetPath() const
{
  return _targetPath;
}

IAnimatable*& RuntimeAnimation::get_target()
{
  return _activeTarget;
}

AnimationPtr& RuntimeAnimation::animation()
{
  return _animation;
}

void RuntimeAnimation::reset(bool restoreOriginal)
{
  if (restoreOriginal) {
    if (!_originalValue.empty() && _originalValue[0] != std::nullopt) {
      // _setValue(_target, _originalValue[0], -1);
    }
  }

  _offsetsCache.clear();
  _highLimitsCache.clear();
  _currentFrame   = 0;
  _blendingFactor = 0;
  _originalValue.clear();

  // Events
  for (auto& event : _events) {
    event.isDone = false;
  }
}

bool RuntimeAnimation::isStopped() const
{
  return _stopped;
}

void RuntimeAnimation::dispose()
{
  auto& runtimeAnimations = _animation->runtimeAnimations();
  runtimeAnimations.erase(
    std::remove_if(runtimeAnimations.begin(), runtimeAnimations.end(),
                   [this](const RuntimeAnimationPtr& runtimeAnimation) {
                     return runtimeAnimation.get() == this;
                   }),
    runtimeAnimations.end());
}

AnimationValue RuntimeAnimation::_interpolate(
  float iCurrentFrame, int repeatCount, unsigned int loopMode,
  const AnimationValue& offsetValue, const AnimationValue& highLimitValue)
{
  _currentFrame = iCurrentFrame;

  if (_animation->dataType != -1
      && static_cast<unsigned>(_animation->dataType)
           == Animation::ANIMATIONTYPE_MATRIX()
      && !_workValue) {
    _workValue = Matrix::Zero();
  }

  return _animation->_interpolate(currentFrame, repeatCount, _workValue,
                                  loopMode, offsetValue, highLimitValue);
}

void RuntimeAnimation::setValue(const AnimationValue& iCurrentValue,
                                float iWeight)
{
  _setValue(_target, iCurrentValue, iWeight);
}

void RuntimeAnimation::_setValue(const IAnimatablePtr& iTarget,
                                 const AnimationValue& iCurrentValue,
                                 float iWeight, unsigned int targetIndex)
{
  // Set value
  std::string path = "";
  any destination  = nullptr;

  const auto& targetPropertyPath = _animation->targetPropertyPath;

  if (targetPropertyPath.size() > 1) {
    auto property = iTarget->getProperty(targetPropertyPath[0]);

    for (size_t index = 1; index < targetPropertyPath.size() - 1; ++index) {
      property = iTarget->getProperty(property, targetPropertyPath[index]);
    }

    path        = targetPropertyPath.back();
    destination = property;
  }
  else {
    path        = targetPropertyPath[0];
    destination = target;
  }

  _targetPath   = path;
  _activeTarget = destination;
  _weight       = iWeight;

  if (targetIndex >= _originalValue.size()) {
    _originalValue.resize(targetIndex + 1);
    _originalValue[targetIndex] = std::nullopt;
  }

{'fraction_non_alphanumeric': 0.11596998928188638, 'fraction_numerical': 0.0038585209003215433, 'mean_word_length': 3.5965517241379312, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3626600', 'n_tokens_mistral': 2843, 'n_tokens_neox': 2782, 'n_words': 503}