small optimization
This commit is contained in:
parent
151187d40e
commit
30fcf97b6b
1 changed files with 13 additions and 8 deletions
|
@ -1,7 +1,7 @@
|
||||||
import Player from "./player.js";
|
import Player from "./player.js";
|
||||||
|
|
||||||
class GameBasic {
|
class GameBasic {
|
||||||
constructor() {
|
constructor(width = 7500, height = 7500) {
|
||||||
let player = new Player(false, true);
|
let player = new Player(false, true);
|
||||||
let entities = [player];
|
let entities = [player];
|
||||||
|
|
||||||
|
@ -12,21 +12,26 @@ class GameBasic {
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.entities = entities;
|
this.entities = entities;
|
||||||
|
|
||||||
this.width = this.height = 7500;
|
this.width = width;
|
||||||
|
this.height = height;
|
||||||
|
|
||||||
|
this.intCount = 8;
|
||||||
}
|
}
|
||||||
main() {
|
main(j) {
|
||||||
let { entities } = this;
|
let { entities } = this;
|
||||||
let that = this;
|
let that = this;
|
||||||
|
|
||||||
for (let ent of entities) {
|
for (let i = j; i < entities.length; i += this.intCount) {
|
||||||
(async function() {
|
let ent = entities[i];
|
||||||
ent.handleTick(that)
|
ent.handleTick(that)
|
||||||
})();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
init() {
|
init() {
|
||||||
let that = this;
|
let that = this;
|
||||||
setInterval(function () { that.main() }, 1000 / 60);
|
|
||||||
|
for (let i = 0; i < that.intCount; i++) {
|
||||||
|
setInterval(function () { that.main(i) }, 1000 / 60);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue