UNPKG

@downpourdigital/physics

Version:

Animation physics!

2 lines (1 loc) 1.01 kB
"use strict";class t{constructor(){this.entities=[]}add(t){this.entities.push(t)}remove(t){this.entities.includes(t)&&this.entities.splice(this.entities.findIndex((e=>e===t)),1)}step(t){this.entities.forEach((e=>{e.step(t)}))}}const e=new t;exports.Stepper=class{constructor({maxTimestep:t=17,maxStepCount:s=8,autoStep:i=!0}={}){this.lastFrame=0,this.isResting=!1,this.maxTimestep=t,this.maxStepCount=s,i&&e.add(this)}step(t){if(!this.isResting){let e=this.lastFrame,s=0;for(;e<t&&s<this.maxStepCount;){const i=Math.min(t-e,this.maxTimestep);this.integrate(i),e+=i,s+=1}}this.lastFrame=t}integrate(t){}stop(){e.remove(this)}},exports.World=t,exports.__rest=function(t,e){var s={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&e.indexOf(i)<0&&(s[i]=t[i]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(t);r<i.length;r++)e.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(t,i[r])&&(s[i[r]]=t[i[r]])}return s},exports.defaultWorld=e;