変愚蛮怒のメインリポジトリです
修订版 | adcfa63406c1d04d38a40ad5f0e5eaf259424c5c (tree) |
---|---|
时间 | 2020-03-25 23:43:22 |
作者 | shimitei <shimitei@gmai...> |
Commiter | shimitei |
post keydown-event to worker
@@ -2,8 +2,8 @@ | ||
2 | 2 | |
3 | 3 | CC = emcc |
4 | 4 | LD = emcc |
5 | -CFLAGS = -fPIC | |
6 | -LDFLAGS = -v -s EXIT_RUNTIME=1 | |
5 | +CFLAGS = -fPIC -s ASYNCIFY=1 | |
6 | +LDFLAGS = -v -s EXIT_RUNTIME=1 -s ALLOW_MEMORY_GROWTH=1 -s ASYNCIFY=1 | |
7 | 7 | DEFINES = |
8 | 8 | |
9 | 9 | TARGET_FILE = hengband.html |
@@ -57,7 +57,7 @@ prebuild : | ||
57 | 57 | # ln -s ../lib lib |
58 | 58 | |
59 | 59 | $(TARGET_FILE): $(OBJS) |
60 | - $(LD) $(LDFLAGS) $(OBJS) --preload-file lib -o $(TARGET_FILE) | |
60 | + $(LD) $(LDFLAGS) $(OBJS) --js-library worker.message.js --preload-file lib -o $(TARGET_FILE) | |
61 | 61 | |
62 | 62 | .SUFFIXES: .c .bc |
63 | 63 | .c.bc: |
@@ -0,0 +1,3 @@ | ||
1 | +onmessage = function(e) { | |
2 | + console.log('worker:', e); | |
3 | +} |
@@ -1,11 +1,14 @@ | ||
1 | 1 | <html> |
2 | +<canvas id="canvas" oncontextmenu="event.preventDefault()" width="640px" height="480px" tabindex=-1></canvas> | |
2 | 3 | <script> |
3 | 4 | var worker = new Worker("hengband.js"); |
4 | -worker.onerror = function (e) { | |
5 | - console.log(e); | |
5 | +worker.onmessage = function(e) { | |
6 | + console.log('main:', e); | |
6 | 7 | } |
7 | -worker.onmessage = function (e) { | |
8 | - console.log(e.data); | |
8 | + | |
9 | +canvas.addEventListener('keydown', onKeydown); | |
10 | +function onKeydown(e) { | |
11 | + worker.postMessage({keyCode: e.keyCode, ctrlKey: e.ctrlKey, shiftKey: e.shiftKey}); | |
9 | 12 | } |
10 | 13 | </script> |
11 | -</html>> | |
\ No newline at end of file | ||
14 | +</html> | |
\ No newline at end of file |