From 9fcaf643009f0ac7099d19fe97d8381153a9c287 Mon Sep 17 00:00:00 2001 From: jmoenig Date: Thu, 3 Dec 2020 17:29:16 +0100 Subject: [PATCH] use video pixel buffer for raycasting --- src/objects.js | 9 +-------- src/threads.js | 6 +++--- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/src/objects.js b/src/objects.js index 255ebe25..8d2ef1e6 100644 --- a/src/objects.js +++ b/src/objects.js @@ -2104,19 +2104,12 @@ SpriteMorph.prototype.getImageData = function () { ).data; this.imageData = { version : this.version, - pixels : new Uint32Array(imageData.buffer.slice(0)), - full : imageData // +++ get rid of this + pixels : new Uint32Array(imageData.buffer.slice(0)) }; } return this.imageData.pixels; }; -SpriteMorph.prototype.getFullImageData = function () { - // temporary hack for raycasting. // +++ - this.getImageData(); - return this.imageData.full; -}; - SpriteMorph.prototype.projectionSnap = function() { var stage = this.parentThatIsA(StageMorph), center = this.center().subtract(stage.position()) diff --git a/src/threads.js b/src/threads.js index f8e5f9de..8f820094 100644 --- a/src/threads.js +++ b/src/threads.js @@ -4933,13 +4933,13 @@ Process.prototype.reportDistanceFacing = function (name) { */ width = Math.floor(targetBounds.width() / stage.scale); // +++ - imageData = thatObj.getFullImageData(); // +++ + imageData = thatObj.getImageData(); // +++ // scan the ray along the coordinates of a Bresenham line // for the first opaque pixel function alphaAt(imageData, width, x, y) { - var idx = (y * width * 4) + x * 4; - return imageData[idx + 3]; + var idx = y * width + x; + return imageData[idx] && 0x000000FF; // alpha } function isOpaque(x, y) {