export abstract class SimulatorBase { public mass : any ; public damping : any ; public frameTime : number ; public offset : number ; public abstract cache : any [ ] ; constructor ( fps , mass , damping ) { this . mass = mass ; this . damping = damping ; this . frameTime = 1 / fps ; this . offset = 0 ; } public setFPS ( value ) { this . frameTime = 1 / value ; } public lastFrame ( ) { return this . cache [ this . cache . length - 1 ] ; } param { timeStep } timeStep public generateFrames ( timeStep ) { let totalTimeStep = this . offset + timeStep ; let framesToGenerate = Math . floor ( totalTimeStep / this . frameTime ) ; this . offset = totalTimeStep % this . frameTime ; if ( framesToGenerate > 0 ) { for ( let i = 0 ; i < framesToGenerate ; i ++ ) { this . cache . push ( this . getFrame ( i + 1 === framesToGenerate ) ) ; } this . cache = this . cache . slice ( - 2 ) ; } } public abstract getFrame ( isLastFrame ) ; public abstract simulate ( timeStep ) ; }