scheduling
Advanced tools
Comparing version 1.3.3 to 1.3.4
@@ -1,1 +0,1 @@ | ||
let n=window,e=60,r=performance.now(),t=0,o=0,f=r;const u=[],c=[],a=[],i=[];let s=[],l=[],g=0;function m(){!function(){let n,g=0,m=1e3/e,p=0;for(g=0;g<u.length;g++)n=u[g],null!=n&&n.func(n.args);for(;s.length>0;)n=s.pop(),n.func(n.args);let h=performance.now();for(o=(h-r)/1e3,t=h-f,g=0;g<c.length;g++)n=c[g],h-n.time>n.delay&&(n.func(n.args),c.splice(g,1));for(h=performance.now();a.length>0;){if(n=a.shift(),p=performance.now(),!(p-h<m)){a.unshift(n);break}n.func(n.args)}for(h=performance.now();i.length>0;)n=i.shift(),p=performance.now(),p-h<m&&n.func(n.args);f=h,s=s.concat(l),l=[]}(),n.requestAnimationFrame(m)}m();var p={addEF:function(n,e){const r=++g;return u[r]={func:n,args:e},r},removeEF:function(n){return void 0!==u[n]&&(u[n]=null),-1},delay:function(n,e,r){const t=performance.now();c.push({func:n,args:e,delay:r,time:t})},next:function(n,e){l.push({func:n,args:e})},defer:function(n,e){a.push({func:n,args:e})},usurp:function(n,e){i.push({func:n,args:e})},setRequestAnimationFrameSource:function(e){n=e,m()},setFrameRate:function(n){e=n},getElapsedTime:function(){return o},getDeltaTime:function(){return t}};export default p; | ||
let n=window,e=60,r=performance.now(),t=0,o=0,u=r;const c=[],f=[],a=[],i=[];let s=[],l=[],m=-1,g=0;function p(){!function(){let n,m=0,g=1e3/e,p=0;for(m=0;m<c.length;m++)n=c[m],null!=n&&n.func(n.args);for(;s.length>0;)n=s.pop(),n.func(n.args);let h=performance.now();for(o=(h-r)/1e3,t=h-u,m=0;m<f.length;m++)n=f[m],h-n.time>n.delay&&(n.func(n.args),f.splice(m,1));for(h=performance.now();a.length>0;){if(n=a.shift(),p=performance.now(),!(p-h<g)){a.unshift(n);break}n.func(n.args)}for(h=performance.now();i.length>0;)n=i.shift(),p=performance.now(),p-h<g&&n.func(n.args);u=h,s=s.concat(l),l=[]}(),m=n.requestAnimationFrame(p)}p();var h={addEF:function(n,e){const r=++g;return c[r]={func:n,args:e},r},removeEF:function(n){return void 0!==c[n]&&(c[n]=null),-1},delay:function(n,e,r){const t=performance.now();f.push({func:n,args:e,delay:r,time:t})},next:function(n,e){l.push({func:n,args:e})},defer:function(n,e){a.push({func:n,args:e})},usurp:function(n,e){i.push({func:n,args:e})},setRequestAnimationFrameSource:function e(r){console.log("setRequestAnimationFrameSource",e,m),m>-1&&window.cancelAnimationFrame(m),n=r,p()},setFrameRate:function(n){e=n},getElapsedTime:function(){return o},getDeltaTime:function(){return t}};export default h; |
{ | ||
"name": "scheduling", | ||
"version": "1.3.3", | ||
"version": "1.3.4", | ||
"description": "A enterframe tool", | ||
"main": "src/scheduler.js", | ||
"module": "src/scheduler.js", | ||
"browser": "src/scheduler.js", | ||
"main": "build/scheduler.js", | ||
"module": "build/scheduler.js", | ||
"browser": "build/scheduler.js", | ||
"scripts": { | ||
@@ -9,0 +9,0 @@ "start": "npm run dev", |
@@ -21,2 +21,5 @@ // animation frame source | ||
// animation frame id | ||
let requestAnimationFrameId = -1; | ||
// indexing | ||
@@ -122,2 +125,6 @@ let idTable = 0; | ||
function setRequestAnimationFrameSource(mSource) { | ||
console.log('setRequestAnimationFrameSource', setRequestAnimationFrameSource, requestAnimationFrameId) | ||
if(requestAnimationFrameId > -1) { | ||
window.cancelAnimationFrame(requestAnimationFrameId); | ||
} | ||
afSource = mSource; | ||
@@ -210,3 +217,3 @@ loop(); | ||
process(); | ||
afSource.requestAnimationFrame(loop); | ||
requestAnimationFrameId = afSource.requestAnimationFrame(loop); | ||
} | ||
@@ -213,0 +220,0 @@ |
17097
11
536