refactor: loop
This commit is contained in:
parent
d107d0b6aa
commit
5ffce376f6
|
@ -7,7 +7,7 @@ import {
|
|||
import {join} from 'path';
|
||||
import {promisify} from 'util';
|
||||
|
||||
import {createLoop, destroyLoop} from '@avocado/timing';
|
||||
import {createLoop, destroyLoop} from '@avocado/timing/server';
|
||||
import {D} from '@flecks/core';
|
||||
import glob from 'glob';
|
||||
|
||||
|
@ -180,34 +180,26 @@ export default class Universe {
|
|||
|
||||
start() {
|
||||
if (!this.#informLoopHandle) {
|
||||
this.#informLoopHandle = setInterval(
|
||||
async () => {
|
||||
try {
|
||||
await this.inform();
|
||||
}
|
||||
catch (error) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error('Informing error:', error);
|
||||
}
|
||||
this.#informLoopHandle = createLoop(
|
||||
() => {
|
||||
this.inform();
|
||||
},
|
||||
1000 / 60,
|
||||
1 / this.#tps,
|
||||
);
|
||||
}
|
||||
if (!this.#mainLoopHandle) {
|
||||
// eslint-disable-next-line no-eval
|
||||
const {performance} = eval('require')('perf_hooks');
|
||||
this.#mainLoopHandle = createLoop((elapsed) => {
|
||||
this.tick(elapsed);
|
||||
}, {
|
||||
sampler: performance.now,
|
||||
frequency: 1 / this.#tps,
|
||||
});
|
||||
this.#mainLoopHandle = createLoop(
|
||||
(elapsed) => {
|
||||
this.tick(elapsed);
|
||||
},
|
||||
1 / this.#tps,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
stop() {
|
||||
if (this.#informLoopHandle) {
|
||||
clearInterval(this.#informLoopHandle);
|
||||
destroyLoop(this.#informLoopHandle);
|
||||
this.#informLoopHandle = null;
|
||||
}
|
||||
if (this.#mainLoopHandle) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user