-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworkerMain.js
87 lines (61 loc) · 2.18 KB
/
workerMain.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
var worker = new Worker("./workerInstance.js");;
worker.addEventListener("message", function(message) {
// console.log("received message from worker");
if(message.data.array) {
localUint = message.data.array;
// console.log("main: sega e kaj mene")
}
else {
// console.log("main: dobiv potvrda bez uint")
}
if(localUint.length != 0)
refreshCanvas(localUint);
})
function refreshCanvas(localUint) {
console.log("refreshnuvam")
let ctx = canvas.getContext('2d')
let image = new ImageData(localUint, Application.config.windowWidth, Application.config.windowHeight);
ctx.putImageData(image,0,0)
Application.draw()
}
var localUint = new Uint8ClampedArray(4*Application.config.windowWidth*Application.config.windowHeight);
var specifichno = 12;
function workerPan() {
let width = Application.config.windowWidth
let height = Application.config.windowHeight
let amount = [mouseX-lastMouseX, mouseY-lastMouseY];
let uint = localUint;
if(localUint.length == 0) {
// console.log("main: ne e kaj mene momentalno ama prakjam poraka")
worker.postMessage({config: {
width, height, amount,
xInterval: Application.xInterval, yInterval:Application.yInterval,
scale: Application.config.scale
}})
return;
}
// if(!globalMemoryImageTestThing)
// testUint()
// translateH(uint, mouseX-lastMouseX)
// translateV(uint, mouseY-lastMouseY)
// console.log("main:kaj mene e i prakjam poraka")
worker.postMessage({config: {
width, height, amount,
xInterval: Application.xInterval, yInterval:Application.yInterval,
scale: Application.scale,
}, array: uint
}, [uint.buffer])
// if(amount < 0) {
// worker.postMessage({start: {lo: width+amount, hi: width}, end: {lo: 0, hi: height}, array: uint}, [uint.buffer])
// }
// else if(amount > 0) {
// worker.postMessage({start: {lo: 0, hi: amount}, end: {lo: 0, hi: height}, array: uint}, [uint.buffer])
// }
// amount = mouseY-lastMouseY;
// if(amount < 0) {
// worker.postMessage({start: {lo: 0, hi:width}, end: {lo: height+amount, hi: height}, array: uint}, [uint.buffer])
// }
// else if(amount > 0) {
// worker.postMessage({start: {lo: 0, hi:width}, end: {lo: 0, hi: amount}, array: uint}, [uint.buffer])
// }
}