From f6cd6434ae9037c069e1992dc2e66b3dc7952a8a Mon Sep 17 00:00:00 2001 From: Amadeus Demarzi Date: Thu, 24 Jul 2014 21:37:48 -0700 Subject: [PATCH] A few subtle draw performance fixes By rounding all floated values to whole numbers... we can help a tad with aliasing and the like --- .../source/javascripts/app/Engine.Particle.Fixed.js | 4 ++-- website/source/javascripts/app/Engine.Particle.js | 4 ++-- website/source/javascripts/app/Engine.Polygon.js | 12 ++++++------ website/source/javascripts/app/Engine.Shape.js | 12 +++++++++--- 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/website/source/javascripts/app/Engine.Particle.Fixed.js b/website/source/javascripts/app/Engine.Particle.Fixed.js index 164b43057..530edad9c 100644 --- a/website/source/javascripts/app/Engine.Particle.Fixed.js +++ b/website/source/javascripts/app/Engine.Particle.Fixed.js @@ -55,8 +55,8 @@ Engine.Particle.Fixed.prototype = { // Draw a circle - far less performant ctx.beginPath(); ctx.arc( - this.pos.x * scale, - this.pos.y * scale, + this.pos.x * scale >> 0, + this.pos.y * scale >> 0, this.radius * scale, 0, Math.PI * 2, diff --git a/website/source/javascripts/app/Engine.Particle.js b/website/source/javascripts/app/Engine.Particle.js index 5b5c0d9e0..b2ef88452 100644 --- a/website/source/javascripts/app/Engine.Particle.js +++ b/website/source/javascripts/app/Engine.Particle.js @@ -135,8 +135,8 @@ Engine.Particle.prototype = { // Draw a square - very performant ctx.fillRect( - this.pos.x * scale, - this.pos.y * scale, + this.pos.x * scale >> 0, + this.pos.y * scale >> 0, this.radius * scale, this.radius * scale ); diff --git a/website/source/javascripts/app/Engine.Polygon.js b/website/source/javascripts/app/Engine.Polygon.js index 67ebf383b..88b08a918 100644 --- a/website/source/javascripts/app/Engine.Polygon.js +++ b/website/source/javascripts/app/Engine.Polygon.js @@ -63,16 +63,16 @@ Engine.Polygon.prototype = { draw: function(ctx, scale){ ctx.beginPath(); ctx.moveTo( - this.a.pos.x * scale, - this.a.pos.y * scale + this.a.pos.x * scale >> 0, + this.a.pos.y * scale >> 0 ); ctx.lineTo( - this.b.pos.x * scale, - this.b.pos.y * scale + this.b.pos.x * scale >> 0, + this.b.pos.y * scale >> 0 ); ctx.lineTo( - this.c.pos.x * scale, - this.c.pos.y * scale + this.c.pos.x * scale >> 0, + this.c.pos.y * scale >> 0 ); ctx.closePath(); ctx.fillStyle = this.fillStyle; diff --git a/website/source/javascripts/app/Engine.Shape.js b/website/source/javascripts/app/Engine.Shape.js index f371dddff..d7c632cc2 100644 --- a/website/source/javascripts/app/Engine.Shape.js +++ b/website/source/javascripts/app/Engine.Shape.js @@ -42,20 +42,23 @@ Engine.Shape.prototype = { selfDestruct: function(time){ this.destruct = time; + this.elapsed = 0; return this; }, update: function(engine){ var p; + // if (this.destruct) { + // this.elapsed += engine.tick; + // } + for (p = 0; p < this.points.length; p++) { this.points[p].update(engine); - // this.points[p].draw(this.context, scale); } for (p = 0; p < this.polygons.length; p++) { this.polygons[p].update(engine); - // this.polygons[p].draw(this.context, scale); } return this; @@ -65,7 +68,10 @@ Engine.Shape.prototype = { var p; ctx.save(); - ctx.translate(this.pos.x * scale, this.pos.y * scale); + ctx.translate( + this.pos.x * scale >> 0, + this.pos.y * scale >> 0 + ); for (p = 0; p < this.polygons.length; p++) { this.polygons[p].draw(ctx, scale); }