@trusktr trusktr released this Apr 24, 2016 · 696 commits to master since this release

Assets 2

It is now possible to add render tasks to a Node (the Node gives it to the Motor to run in the animation loop). When no tasks exist, there is no animation loop -- i.e. no tasks means zero CPU usage, silence, crickets.

Working example:

import Scene from 'infamous/motor/Scene'
import Node from 'infamous/motor/Node'

let scene = new Scene(document.body)
scene.absoluteSize = [500,500,0]

let node = new Node()
node.absoluteSize = [100,100,0]
node._el.element.innerHTML = '<span>Hello 3D!</span>'


// make the node rotate for 5 seconds, then remove the task:
let rotation = 0
let elapsedTime = 0
let lastTime = performance.now()

node.addRenderTask(function task(timestamp) {
    // `this` is the node the task was added to.
    this.rotation = [0, rotation++, 0]

    let delta = timestamp - lastTime
    elapsedTime += delta
    lastTime = timestamp

    if (elapsedTime >= 5000)

Aaaaaaaand, the result: the following screenshot of Chrome timeline shows the app becomes completely idle (nothing, zero, silence, crickets) when the render task is removed after 5 seconds.

screen shot 2016-04-23 at 7 09 01 pm

Starting an animation happens by simply adding a new render task, in which case the Motor restarts the animation loop automatically to handle the new render task.