Skip to content

Instantly share code, notes, and snippets.

@coderofsalvation
Last active September 22, 2022 09:12
Show Gist options
  • Save coderofsalvation/c11903dc247452d36540f75f3cb07f68 to your computer and use it in GitHub Desktop.
Save coderofsalvation/c11903dc247452d36540f75f3cb07f68 to your computer and use it in GitHub Desktop.

Revisions

  1. coderofsalvation revised this gist Sep 22, 2022. 1 changed file with 20 additions and 20 deletions.
    40 changes: 20 additions & 20 deletions AFRAME.utils.throttleTicks.js
    Original file line number Diff line number Diff line change
    @@ -5,31 +5,31 @@
    * 'aabb-collider':{ "*": 150 },
    * 'texturescroll':{ "*": 50 },
    * 'foo': { "*": AFRAME.utils.device.isMobile() ? 150 : 50 }
    * })
    * }, true)
    *
    */

    AFRAME.utils.throttleTicks = (opts) => {
    AFRAME.utils.throttleTicks = (opts, debug) => {
    for ( let i in AFRAME.components ) {
    let com = AFRAME.components[i]
    let com = AFRAME.components[i]
    let opt = opts[i]
    let proto = com.Component.prototype
    let proto = com.Component.prototype
    if( opt && proto.tick ){
    proto.init = function(init){
    return function(){
    init.apply(this, arguments)
    this.tickOrig = this.tick
    this.throttleTicks = {}
    proto.init = function(init){
    return function(){
    init.apply(this, arguments)
    this.tickOrig = this.tick
    this.throttleTicks = {}
    for ( let i in opt )
    this.throttleTicks[i] = AFRAME.utils.throttleTick(this.tickOrig, opt[i], this )
    this.tick = function(t, dt){
    let f = this.throttleTicks[ '#'+String(this.el.id ) ] ||
    this.throttleTicks[ '.'+String(this.el.className) ] ||
    this.throttleTicks[ '*' ]
    f(t, dt)
    }
    }
    }(proto.init)
    }
    }
    this.throttleTicks[i] = AFRAME.utils.throttleTick(this.tickOrig, opt[i], this )
    this.tick = function(t, dt){
    let f = this.throttleTicks[ '#'+String(this.el.id ) ] ||
    this.throttleTicks[ '.'+String(this.el.className) ] ||
    this.throttleTicks[ '*' ]
    f(t, dt)
    }
    }
    }(proto.init)
    }else if(debug && proto.tick) console.warn(`throttleTicks: ${i} was not specified`)
    }
    }
  2. coderofsalvation revised this gist Sep 22, 2022. No changes.
  3. coderofsalvation revised this gist Sep 22, 2022. No changes.
  4. coderofsalvation renamed this gist Sep 22, 2022. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  5. coderofsalvation revised this gist Sep 22, 2022. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion throttleTicks.js
    Original file line number Diff line number Diff line change
    @@ -15,7 +15,6 @@ AFRAME.utils.throttleTicks = (opts) => {
    let opt = opts[i]
    let proto = com.Component.prototype
    if( opt && proto.tick ){
    console.log("throttleTicks: "+i)
    proto.init = function(init){
    return function(){
    init.apply(this, arguments)
  6. coderofsalvation revised this gist Sep 22, 2022. 1 changed file with 24 additions and 29 deletions.
    53 changes: 24 additions & 29 deletions throttleTicks.js
    Original file line number Diff line number Diff line change
    @@ -1,41 +1,36 @@
    /*
    * Usage:
    *
    * <script src="aframe.min.js"></script>
    * <script>
    * AFRAME.utils.throttleTicks({
    * 'aabb-collider':{ "*": 150 },
    * 'texturescroll':{ "*": 50 },
    * 'foo': { "*": AFRAME.utils.device.isMobile() ? 150 : 50 }
    * })
    * </script>
    * <!-- include components afterwards -->
    * <script src="aframe-components.js"></script>
    *
    */

    AFRAME.utils.throttleTicks = (opts) => {
    AFRAME.registerComponent = (
    (registerComponent, opts) => function(component, impl){
    let opt = opts[component]
    if( opt && impl.tick ){
    impl.init = function(init){
    return function(){
    init.apply(this, arguments)
    this.tickOrig = this.tick
    this.throttleTicks = {}
    for ( let i in opt )
    this.throttleTicks[i] = AFRAME.utils.throttleTick(this.tickOrig, opt[i], this )
    this.tick = function(t, dt){
    let f = this.throttleTicks[ '#'+String(this.el.id ) ] ||
    this.throttleTicks[ '.'+String(this.el.className) ] ||
    this.throttleTicks[ '*' ]
    f(t, dt)
    }
    }
    }(impl.init)
    }else if( impl.tick ) console.warn(`AFRAME.util.throttleTicks: component '${component}' not specified`)
    registerComponent.apply(AFRAME, arguments)
    AFRAME.utils.throttleTicks = (opts) => {
    for ( let i in AFRAME.components ) {
    let com = AFRAME.components[i]
    let opt = opts[i]
    let proto = com.Component.prototype
    if( opt && proto.tick ){
    console.log("throttleTicks: "+i)
    proto.init = function(init){
    return function(){
    init.apply(this, arguments)
    this.tickOrig = this.tick
    this.throttleTicks = {}
    for ( let i in opt )
    this.throttleTicks[i] = AFRAME.utils.throttleTick(this.tickOrig, opt[i], this )
    this.tick = function(t, dt){
    let f = this.throttleTicks[ '#'+String(this.el.id ) ] ||
    this.throttleTicks[ '.'+String(this.el.className) ] ||
    this.throttleTicks[ '*' ]
    f(t, dt)
    }
    }
    }(proto.init)
    }
    )(AFRAME.registerComponent,opts)
    }
    }
    }
  7. coderofsalvation revised this gist Sep 22, 2022. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion throttleTicks.js
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,8 @@
    * <script>
    * AFRAME.utils.throttleTicks({
    * 'aabb-collider':{ "*": 150 },
    * 'texturescroll':{ "*": 50 }
    * 'texturescroll':{ "*": 50 },
    * 'foo': { "*": AFRAME.utils.device.isMobile() ? 150 : 50 }
    * })
    * </script>
    * <!-- include components afterwards -->
  8. coderofsalvation revised this gist Sep 22, 2022. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion throttleTicks.js
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,15 @@
    /*
    * Usage:
    *
    * // run this in global scope somewhere
    * <script src="aframe.min.js"></script>
    * <script>
    * AFRAME.utils.throttleTicks({
    * 'aabb-collider':{ "*": 150 },
    * 'texturescroll':{ "*": 50 }
    * })
    * </script>
    * <!-- include components afterwards -->
    * <script src="aframe-components.js"></script>
    *
    */

  9. coderofsalvation revised this gist Sep 22, 2022. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions throttleTicks.js
    Original file line number Diff line number Diff line change
    @@ -22,8 +22,10 @@ AFRAME.utils.throttleTicks = (opts) => {
    for ( let i in opt )
    this.throttleTicks[i] = AFRAME.utils.throttleTick(this.tickOrig, opt[i], this )
    this.tick = function(t, dt){
    let f = this.throttleTicks[ '#'+this.el.id ] || this.throttleTicks[ '*' ]
    f(t, dt)
    let f = this.throttleTicks[ '#'+String(this.el.id ) ] ||
    this.throttleTicks[ '.'+String(this.el.className) ] ||
    this.throttleTicks[ '*' ]
    f(t, dt)
    }
    }
    }(impl.init)
  10. coderofsalvation revised this gist Sep 22, 2022. No changes.
  11. coderofsalvation revised this gist Sep 22, 2022. No changes.
  12. coderofsalvation created this gist Sep 22, 2022.
    34 changes: 34 additions & 0 deletions throttleTicks.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    /*
    * Usage:
    *
    * // run this in global scope somewhere
    * AFRAME.utils.throttleTicks({
    * 'aabb-collider':{ "*": 150 },
    * 'texturescroll':{ "*": 50 }
    * })
    *
    */

    AFRAME.utils.throttleTicks = (opts) => {
    AFRAME.registerComponent = (
    (registerComponent, opts) => function(component, impl){
    let opt = opts[component]
    if( opt && impl.tick ){
    impl.init = function(init){
    return function(){
    init.apply(this, arguments)
    this.tickOrig = this.tick
    this.throttleTicks = {}
    for ( let i in opt )
    this.throttleTicks[i] = AFRAME.utils.throttleTick(this.tickOrig, opt[i], this )
    this.tick = function(t, dt){
    let f = this.throttleTicks[ '#'+this.el.id ] || this.throttleTicks[ '*' ]
    f(t, dt)
    }
    }
    }(impl.init)
    }else if( impl.tick ) console.warn(`AFRAME.util.throttleTicks: component '${component}' not specified`)
    registerComponent.apply(AFRAME, arguments)
    }
    )(AFRAME.registerComponent,opts)
    }