From 77071c2e490d07f085468687f0eb8259a9b2440e Mon Sep 17 00:00:00 2001 From: biglyderv Date: Mon, 25 Nov 2024 14:14:20 -0500 Subject: [PATCH] small optimization --- common/game_basic.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/common/game_basic.js b/common/game_basic.js index 98c49ea..9788af8 100644 --- a/common/game_basic.js +++ b/common/game_basic.js @@ -1,7 +1,7 @@ import Player from "./player.js"; class GameBasic { - constructor() { + constructor(width = 7500, height = 7500) { let player = new Player(false, true); let entities = [player]; @@ -12,21 +12,26 @@ class GameBasic { this.player = player; this.entities = entities; - this.width = this.height = 7500; + this.width = width; + this.height = height; + + this.intCount = 8; } - main() { + main(j) { let { entities } = this; let that = this; - for (let ent of entities) { - (async function() { - ent.handleTick(that) - })(); + for (let i = j; i < entities.length; i += this.intCount) { + let ent = entities[i]; + ent.handleTick(that) } } init() { let that = this; - setInterval(function () { that.main() }, 1000 / 60); + + for (let i = 0; i < that.intCount; i++) { + setInterval(function () { that.main(i) }, 1000 / 60); + } } }