Skip to content

Commit 55499e0

Browse files
author
HarshKhandeparkar
committed
feat: ultra mega giga fast undo
1 parent 640542c commit 55499e0

File tree

7 files changed

+17
-39
lines changed

7 files changed

+17
-39
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ e.g.: `RealRenderer.draw().reset().startRender()`
102102
103103
- `toggleRender()`: Toggles the rendering.
104104
105+
- `getData()`: Returns a 3D array of the pixel values.
106+
107+
- `loadData()`: Returns a 3D array of the pixels.
108+
105109
- `resetTime()`: Resets the internal time value to `0`.
106110
107111
- `reset()`: Resets the pixels on the graph to a blank graph with the coordinate axes.

dist/gpujs-real-renderer-browser.js

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,11 @@
113113
function getLoadDataKernel(gpu, dimensions) {
114114
return gpu.createKernel(function (graphPixels) {
115115
return [
116-
graphPixels[this.thread.y * this.output.x * 3 + this.thread.x * 3 + 0],
117-
graphPixels[this.thread.y * this.output.x * 3 + this.thread.x * 3 + 1],
118-
graphPixels[this.thread.y * this.output.x * 3 + this.thread.x * 3 + 2]
116+
graphPixels[this.thread.y][this.thread.x][0],
117+
graphPixels[this.thread.y][this.thread.x][1],
118+
graphPixels[this.thread.y][this.thread.x][2]
119119
];
120120
}, {
121-
argumentTypes: {
122-
graphPixels: 'Array'
123-
},
124121
output: dimensions,
125122
pipeline: true
126123
});
@@ -263,16 +260,7 @@
263260
return this;
264261
};
265262
RealRenderer.prototype.getData = function () {
266-
var returnedArray = this.graphPixels.toArray();
267-
var outArr = [];
268-
for (var i = 0; i < returnedArray.length; i++) {
269-
for (var j = 0; j < returnedArray[0].length; j++) {
270-
for (var k = 0; k < returnedArray[0][0].length; k++) {
271-
outArr[i * returnedArray[0].length * returnedArray[0][0].length + j * returnedArray[0][0].length + k] = returnedArray[i][j][k];
272-
}
273-
}
274-
}
275-
return outArr;
263+
return this.graphPixels.toArray();
276264
};
277265
RealRenderer.prototype.loadData = function (pixels) {
278266
this.graphPixels = this._loadData(pixels);

dist/gpujs-real-renderer-browser.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/examples/drawboard.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Draw Board
22
const drawBoardOptions = {
33
canvas: document.getElementById('drawboard-canvas'),
4-
dimensions: [420, 360],
4+
dimensions: [1000, 1000],
55

66
xScaleFactor: 1,
77
yScaleFactor: 1,

src/kernels/loadData.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,12 @@ export function getLoadDataKernel(
1212
return gpu.createKernel(
1313
function(graphPixels) {
1414
return [
15-
graphPixels[this.thread.y * this.output.x * 3 + this.thread.x * 3 + 0],
16-
graphPixels[this.thread.y * this.output.x * 3 + this.thread.x * 3 + 1],
17-
graphPixels[this.thread.y * this.output.x * 3 + this.thread.x * 3 + 2]
15+
graphPixels[this.thread.y][this.thread.x][0],
16+
graphPixels[this.thread.y][this.thread.x][1],
17+
graphPixels[this.thread.y][this.thread.x][2]
1818
]
1919
},
2020
{
21-
argumentTypes: {
22-
graphPixels: 'Array'
23-
},
2421
output: dimensions,
2522
pipeline: true
2623
}

src/renderers/RealDrawBoard/RealDrawBoard.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ export class RealDrawBoard extends RealRenderer {
3939
eraserSize: number;
4040
tool: Tool = RealDrawBoardDefaults.tool;
4141
_isDrawing: boolean = false;
42-
_isStroking: boolean = false; // If a tool is drawing a stroke
43-
_snapshots: number[][] = []; // Undo snapshots
42+
_isStroking: boolean = false; // If a tool is drawing a strwoke
43+
_snapshots: (number[][][])[] = []; // Undo snapshots
4444
_currentSnapshotIndex = 0; // Current snapshot
4545
_maxSnapshots: number;
4646
_plotKernel: IKernelRunShortcut;

src/renderers/RealRenderer.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -146,21 +146,10 @@ export class RealRenderer {
146146
}
147147

148148
getData() {
149-
let returnedArray: number[][][] = <number[][][]>this.graphPixels.toArray();
150-
let outArr: number[] = [];
151-
152-
for (let i = 0; i < returnedArray.length; i++) {
153-
for (let j = 0; j < returnedArray[0].length; j++) {
154-
for (let k = 0; k < returnedArray[0][0].length; k++) {
155-
outArr[i * returnedArray[0].length * returnedArray[0][0].length + j * returnedArray[0][0].length + k] = returnedArray[i][j][k];
156-
}
157-
}
158-
}
159-
160-
return outArr;
149+
return <number[][][]>this.graphPixels.toArray();
161150
}
162151

163-
loadData(pixels: number[]) {
152+
loadData(pixels: number[][][]) {
164153
this.graphPixels = <Texture>this._loadData(pixels);
165154
this._display(this.graphPixels);
166155
}

0 commit comments

Comments
 (0)