<commit_before>const quat = require('pex-math/quat')
const vec3 = require('pex-math/vec3')
const vec4 = require('pex-math/vec4')
const utils = require('pex-math/utils')
const Signal = require('signals')

let currentOutputVec3 = vec3.create()
let currentOutputQuat = quat.create()

// Assumptions:
// - all channels have the same time length
// - animation channels can reference other entities
// - currently all animations track time by themselves
function Animation(opts) {
  this.type = 'Animation'
  this.entity = null
  this.enabled = true
  this.playing = false
  this.loop = false
  this.time = 0 // seconds
  this.prevTime = Date.now() // ms
  this.channels = opts.channels || []
  this.changed = new Signal()
  this.set(opts)
}

Animation.prototype.init = function(entity) {
  this.entity = entity
}

Animation.prototype.set = function(opts) {
  Object.assign(this, opts)
  Object.keys(opts).forEach((prop) => this.changed.dispatch(prop))

  if (opts.autoplay || opts.playing) {
    this.playing = true
    // reset timer to avoid jumps
    this.time = 0
    this.prevTime = Date.now()
  }
}

Animation.prototype.update = function() {
  if (!this.playing || !this.enabled) return

  const animationLength = this.channels[0].input[
    this.channels[0].input.length - 1
  ]
  const now = Date.now()
  const deltaTime = (now - this.prevTime) / 1000

  this.prevTime = now
  this.time += deltaTime

  if (this.time > animationLength) {
    if (this.loop) {
      this.time %= animationLength
    } else {
      this.time = 0
      this.set({ playing: false })
    }
  }

  for (let i = 0; i < this.channels.length; i++) {
    const channel = this.channels[i]
    const inputData = channel.input

    let prevIndex
    let nextIndex<commit_msg>Update animation if time changes even if not playing<commit_after>const quat = require('pex-math/quat')
const vec3 = require('pex-math/vec3')
const vec4 = require('pex-math/vec4')
const utils = require('pex-math/utils')
const Signal = require('signals')

let currentOutputVec3 = vec3.create()
let currentOutputQuat = quat.create()

// Assumptions:
// - all channels have the same time length
// - animation channels can reference other entities
// - currently all animations track time by themselves
function Animation(opts) {
  this.type = 'Animation'
  this.entity = null
  this.enabled = true
  this.playing = false
  this.loop = false
  this.time = 0 // seconds
  this.prevTime = Date.now() // ms
  this.channels = opts.channels || []
  this.changed = new Signal()
  this.needsUpdate = true
  this.set(opts)
}

Animation.prototype.init = function(entity) {
  this.entity = entity
}

Animation.prototype.set = function(opts) {
  Object.assign(this, opts)
  Object.keys(opts).forEach((prop) => this.changed.dispatch(prop))

  if (opts.autoplay || opts.playing) {
    this.playing = true
    // reset timer to avoid jumps
    this.time = 0
    this.prevTime = Date.now()
  }

  this.needsUpdate = true
}

Animation.prototype.update = function() {
  if (!this.enabled) return


  if (this.playing) {
    const animationLength = this.channels[0].input[
      this.channels[0].input.length - 1
    ]
    const now = Date.now()
    const deltaTime = (now - this.prevTime) / 1000

    this.prevTime = now
    this.time += deltaTime

    if (this.time > animationLength) {
      if (this.loop) {
        this.time %= animationLength
      } else {
        this.time = 0
        this.set({ playing: false })
      }
    }

    this.needsUpdate = true
  }

  if (!this.needsUpdate) return

  this.needsUpdate = false

  for (let i = 0; i < this.channels.length; i++) {
    const channel = this.channels[i]
    const inputData = channel.input

    let prevIndex
    let nextIndex
{'fraction_non_alphanumeric': 0.12876344086021504, 'fraction_numerical': 0.00913978494623656, 'mean_word_length': 3.0357917570498913, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1815748', 'n_tokens_mistral': 1224, 'n_tokens_neox': 1159, 'n_words': 305}