Skip to content

Commit

Permalink
remove render from interval name
Browse files Browse the repository at this point in the history
  • Loading branch information
lounsbrough committed Aug 22, 2024
1 parent 9136400 commit ce2e8a5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/Universe.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('Universe', () => {

const universe = new Universe({
bodies: [],
renderInterval: 0,
simulationInterval: 0,
changeCallback: () => { resolver() }
})

Expand Down Expand Up @@ -37,7 +37,7 @@ describe('Universe', () => {
velocity: new Vector(0, 0, 0)
})
],
renderInterval: 0,
simulationInterval: 0,
changeCallback: () => { resolver() }
})

Expand Down
19 changes: 9 additions & 10 deletions src/Universe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ export default class Universe {
collisions: boolean
deltaTime: number
deltaTimeSegments: number
renderInterval: number

simulationInterval: NodeJS.Timeout
simulationInterval: number
changeCallback: () => void
private internalInterval: NodeJS.Timeout

constructor({
/** orbital bodies in the simulation */
Expand All @@ -24,7 +23,7 @@ export default class Universe {
/** number of segments in which to split the simlation time delta for more precise calculations */
deltaTimeSegments,
/** computer time between iterations */
renderInterval,
simulationInterval,
/** callback fired when simulation state changes */
changeCallback
}: {
Expand All @@ -33,32 +32,32 @@ export default class Universe {
collisions?: boolean
deltaTime?: number
deltaTimeSegments?: number,
renderInterval?: number
simulationInterval?: number
changeCallback: () => void
}) {
this.bodies = bodies
this.deltaTime = deltaTime ?? 0.5
this.gravity = gravity ?? 6.674e-11
this.collisions = collisions ?? false
this.deltaTimeSegments = deltaTimeSegments ?? 1
this.renderInterval = renderInterval ?? 10
this.simulationInterval = simulationInterval ?? 10
this.changeCallback = changeCallback

this.start()
}

/** start simulation */
start() {
clearInterval(this.simulationInterval)
this.simulationInterval = setInterval(() => {
clearInterval(this.internalInterval)
this.internalInterval = setInterval(() => {
this.moveBodiesThroughTime()
this.changeCallback()
}, this.renderInterval)
}, this.simulationInterval)
}

/** stop simulation */
stop() {
clearInterval(this.simulationInterval)
clearInterval(this.internalInterval)
}

calculateGravitationalForces = () => {
Expand Down

0 comments on commit ce2e8a5

Please sign in to comment.