]> zoso.dev Git - libnemo.git/commitdiff
Condense introductory code of calculate function. Remove logging of readPixels since...
authorChris Duncan <chris@zoso.dev>
Thu, 12 Dec 2024 21:25:18 +0000 (13:25 -0800)
committerChris Duncan <chris@zoso.dev>
Thu, 12 Dec 2024 21:25:18 +0000 (13:25 -0800)
src/lib/workers/pow.ts

index ff48dd9bae78a8ace1b09d94f84e228800e70a64..b71370ead43c379a579b0b3e746832a982d1d5b4 100644 (file)
@@ -48,13 +48,8 @@ export class Pow {
                if (typeof threshold === 'number') threshold = '0x' + threshold.toString(16)
                if (!/^[A-F-a-f0-9]{64}$/.test(hashHex)) throw new Error(`invalid_hash ${hashHex}`)
                let reverseHex = ''
-               for (let i = hashHex.length; i > 0; i -= 2) {
-                       reverseHex += hashHex.slice(i - 2, i)
-               }
-
-               if (this.gl == null)
-                       throw new Error('webgl2_required')
-
+               for (let i = hashHex.length; i > 0; i -= 2) reverseHex += hashHex.slice(i - 2, i)
+               if (this.gl == null) throw new Error('webgl2_required')
                this.gl.clearColor(0, 0, 0, 1)
 
                // Vertext Shader
@@ -306,22 +301,20 @@ export class Pow {
                        this.gl.drawArrays(this.gl.TRIANGLES, 0, 6)
                        const pixels = new Uint8Array(this.gl.drawingBufferWidth * this.gl.drawingBufferHeight * 4)
 
-                       console.log(`start readPixels: ${performance.now()}`)
                        this.gl.readPixels(0, 0, this.gl.drawingBufferWidth, this.gl.drawingBufferHeight, this.gl.RGBA, this.gl.UNSIGNED_BYTE, pixels)
-                       console.log(`end readPixels: ${performance.now()}`)
 
                        // Check the pixels for any success
                        for (let i = pixels.length - 4; i >= 0; i -= 4) {
                                if (pixels[i] !== 0) {
                                        console.log(`frame time: ${performance.now() - start}`)
+                                       const hex = this.hexify(this.work1) + this.hexify([
+                                               pixels[i + 2],
+                                               pixels[i + 3],
+                                               this.work0[2] ^ (pixels[i] - 1),
+                                               this.work0[3] ^ (pixels[i + 1] - 1)
+                                       ])
                                        // Return the work value with the custom bits
-                                       typeof callback === 'function' &&
-                                               callback(this.hexify(this.work1) + this.hexify([
-                                                       pixels[i + 2],
-                                                       pixels[i + 3],
-                                                       this.work0[2] ^ (pixels[i] - 1),
-                                                       this.work0[3] ^ (pixels[i + 1] - 1)
-                                               ]))
+                                       typeof callback === 'function' && callback(hex)
                                        return
                                }
                        }