-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainLoopX.min.js
2 lines (2 loc) · 1.85 KB
/
MainLoopX.min.js
1
2
/* MainLoopX.js v1.1.0 | (c) 2021, Emanuel Rojas Vásquez | MIT License | https://github.com/erovas/MainLoopX.js */
!function(e){if(e.MainLoopX)return console.error("MainLoopX.js has already been defined");function t(){}var n,r=1e3,a=r/60,u=a,s=a,o=r,i=.9,p=240,f=0,d=0,m=0,c=0,g=0,l=0,M=0,h=0,S=a,F=u,v=s,y=o,U=i,b=!1,w=!1,x=!1,A=t,D=t,L=t,P=t,X=t,I=t,T=e.requestAnimationFrame,j=e.cancelAnimationFrame;function k(e){return"number"==typeof e}function q(e){return"function"==typeof e}function R(e){if(n=T(R),A(f,x,e,d,m,g=e-c,l,M,h),!(g<s)){for(d+=e-m,c=(m=e)-g%s,D(f,x,e,d,m,g,l,M,h),l+o<e&&(f=i*M*r/(e-l)+(1-i)*f,l=e,M=0),M++,x=!1,h=0;a<=d;)if(L(u),d-=a,++h>=p){x=!0;break}P(d/a),X(f,x,e,d,m,g,l,M,h)}}e.MainLoopX=e.MLX={advanced:{get timeStep(){return u},set timeStep(e){k(e)&&0<=e&&(u=e)},get simulationTimeStep(){return a},set simulationTimeStep(e){k(e)&&0<e&&(a=e)},get frameDelay(){return s},set frameDelay(e){k(e)&&0<e&&(s=e)},get fpsUpdateInterval(){return o},set fpsUpdateInterval(e){k(e)&&0<=e&&(o=e)},get fpsAlpha(){return i},set fpsAlpha(e){k(e)&&0<=e&&(i=e)},get maxUpdateSteps(){return p},set maxUpdateSteps(e){k(e)&&0<e&&(p=e)},get FPS(){return f}},dev:{get speed(){return Math.round(r/a)},set speed(e){!k(e)||e<=0||600<e||(a=r/Math.round(e))},get maxFPS(){return Math.round(r/s)},set maxFPS(e){!k(e)||e===1/0||e<=0||(f=Math.round(e),s=r/f)},get steps(){return Math.round(r/u)},set steps(e){!k(e)||e<1||144<e||(u=r/Math.round(e))},get FPS(){return Math.round(f)}},get isRunning(){return b},set raw(e){A=q(e)?e:A},set begin(e){D=q(e)?e:D},set update(e){L=q(e)?e:L},set draw(e){P=q(e)?e:P},set end(e){X=q(e)?e:X},set reset(e){I=q(e)?e:I},resetDefaultValues:function(){u=F,a=S,s=v,o=y,i=U},resetFrameDelta:function(){var e=d;return d=0,e},resetUser:function(){I()},start:function(){w||(w=!0,n=T(function(e){P(1),b=!0,l=m=e,M=0,n=T(R)}))},stop:function(){w=b=!1,j(n)}}}(window);