From 607c478e43eeb57f570249fb5cdee183cf94fcfe Mon Sep 17 00:00:00 2001 From: Date: Fri, 27 Jul 2018 01:33:07 -0400 Subject: [PATCH] Half CPU usage of game --- TODO.txt | 4 +--- src/game-components/planet-sector.js | 4 ++-- src/game-components/planet.js | 21 ++++++++++++++++++--- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/TODO.txt b/TODO.txt index 5d38927..775616c 100644 --- a/TODO.txt +++ b/TODO.txt @@ -16,9 +16,7 @@ Create a simulation (calculations only) https://stackoverflow.com/questions/29429219/how-put-a-texture-on-pixi-js-polygon -Optimize planets - split int osections or something - Only body needs to be optimized +Speed up sector rendering by computing once for both graphics and planet If rocket is inside planet teleport it out diff --git a/src/game-components/planet-sector.js b/src/game-components/planet-sector.js index 72fa52b..cf6a52f 100644 --- a/src/game-components/planet-sector.js +++ b/src/game-components/planet-sector.js @@ -61,14 +61,14 @@ class PlanetSector { Matter.Body.setStatic(this.body, true); // Debugging - let graphics = new PIXI.Graphics(); + /* let graphics = new PIXI.Graphics(); for (let i=1;i config.planet_sector_size * 5) { - Matter.Composite.remove(sim.engine.world, this.sectors[a].body); + // Matter.Composite.remove(sim.engine.world, this.sectors[a].body); + Matter.Sleeping.set(this.sectors[a].body, true); + this.sectors[a].body.collision + this.sectors_to_delete.push(this.sectors[a].body); delete this.sectors[a]; } + + if (Math.abs(angle - a) > config.planet_graphic_sector_size * 5) { + sim.stage.removeChild(this.texture_sectors[a].body); + delete this.texture_sectors[a]; + } + } + } + + /* Delete matter.js bodies in one swoop */ + if (this.sectors_to_delete.length > 30 || Math.random() < 0.05) { + for (let sector of this.sectors_to_delete) { + Matter.Composite.remove(sim.engine.world, sector); } } }