• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

変愚蛮怒のメインリポジトリです


Commit MetaInfo

修订版14ea65770041af24848df65f8efb9cc3d9246f22 (tree)
时间2020-03-29 16:06:41
作者shimitei <shimitei@gmai...>
Commitershimitei

Log Message

receive keydown message

更改概述

差异

--- /dev/null
+++ b/src/lib.js
@@ -0,0 +1,9 @@
1+mergeInto(LibraryManager.library, {
2+ mysleep: function(interval) {
3+ Asyncify.handleSleep(function(wakeUp) {
4+ setTimeout(function() {
5+ wakeUp();
6+ }, interval);
7+ });
8+ },
9+});
\ No newline at end of file
--- a/src/main-wasm-term.c
+++ b/src/main-wasm-term.c
@@ -70,7 +70,6 @@ static void Term_nuke_wasm(term* t)
7070 */
7171 static errr Term_text_wasm(int x, int y, int n, byte a, concptr s)
7272 {
73- printf("%s", s);
7473 EM_ASM({
7574 var s = UTF8ToString($0);
7675 console.log(s);
@@ -124,6 +123,15 @@ static errr Term_xtra_wasm(int n, int v)
124123 return (1);
125124 }
126125
126+EMSCRIPTEN_KEEPALIVE void Term_wasm_keypress(int k)
127+{
128+ EM_ASM({
129+ console.log($0);
130+ }, k);
131+
132+ Term_keypress(k);
133+}
134+
127135 /*
128136 * Prepare this file for Angband usage
129137 */
--- a/src/main-wasm.c
+++ b/src/main-wasm.c
@@ -8,9 +8,9 @@
88 * are included in all such copies.
99 */
1010
11+#include <emscripten.h>
1112 #include "angband.h"
1213
13-
1414 /*
1515 * A hook for "quit()".
1616 *
--- a/src/makefile.em
+++ b/src/makefile.em
@@ -2,50 +2,51 @@
22
33 CC = emcc
44 LD = emcc
5-CFLAGS = -fPIC -s ASYNCIFY=1
6-LDFLAGS = -v -s EXIT_RUNTIME=1 -s ALLOW_MEMORY_GROWTH=1 -s ASYNCIFY=1
5+CFLAGS = -fPIC
6+LDFLAGS = -v -s VERBOSE -s EXIT_RUNTIME -s ALLOW_MEMORY_GROWTH -s SINGLE_FILE
77 DEFINES =
8+DEFASYNCIFY = -s ASYNCIFY -s 'ASYNCIFY_IMPORTS=["emscripten_sleep", "mysleep"]'
89
9-TARGET_FILE = hengband.html
10+TARGET_FILE = hengband.js
1011
1112 OBJS = \
12- main-wasm.bc main-wasm-term.bc \
13- artifact.bc autopick.bc avatar.bc \
14- birth.bc bldg.bc \
15- chest.bc chuukei.bc cmd2.bc cmd4.bc cmd-activate.bc cmd-eat.bc \
16- cmd-hissatsu.bc cmd-item.bc cmd-magiceat.bc cmd-mane.bc cmd-pet.bc \
17- cmd-quaff.bc cmd-read.bc cmd-smith.bc cmd-spell.bc cmd-usestaff.bc \
18- cmd-zaprod.bc cmd-zapwand.bc \
19- dungeon.bc \
20- effects.bc \
21- feature.bc files.bc flavor.bc floor-events.bc floor-generate.bc \
22- floor-save.bc floor-streams.bc \
23- gameoption.bc geometry.bc grid.bc \
24- history.bc \
25- inet.bc init1.bc init2.bc \
26- japanese.bc \
27- load.bc \
28- melee1.bc mind.bc monster1.bc monster2.bc monster-process.bc \
29- monsterrace-hook.bc monster-status.bc mspells1.bc mspells2.bc mspells3.bc \
30- mspells4.bc mutation.bc \
31- object1.bc object2.bc object-boost.bc object-broken.bc object-curse.bc \
32- object-hook.bc objectkind-hook.bc \
33- patron.bc player-damage.bc player-move.bc player-status.bc projection.bc \
34- quest.bc \
35- racial.bc realm-arcane.bc realm-chaos.bc realm-craft.bc realm-crusade.bc \
36- realm-daemon.bc realm-death.bc realm-hex.bc realm-hissatsu.bc \
37- realm-life.bc realm-nature.bc realm-song.bc realm-sorcery.bc \
38- realm-trump.bc report.bc rooms.bc rooms-city.bc rooms-fractal.bc \
39- rooms-normal.bc rooms-pitnest.bc rooms-special.bc rooms-trap.bc \
40- rooms-vault.bc rumor.bc \
41- save.bc scores.bc selfinfo.bc shoot.bc snipe.bc sort.bc spells1.bc \
42- spells2.bc spells3.bc spells-diceroll.bc spells-floor.bc spells-object.bc \
43- spells-status.bc spells-summon.bc spells-world.bc store.bc \
44- tables.bc term.bc trap.bc \
45- util.bc \
46- variable.bc view-mainwindow.bc \
47- warning.bc wild.bc wizard1.bc wizard2.bc world.bc xtra2.bc \
48- z-form.bc z-rand.bc z-term.bc z-util.bc z-virt.bc
13+ main-wasm.o main-wasm-term.o \
14+ artifact.o autopick.o avatar.o \
15+ birth.o bldg.o \
16+ chest.o chuukei.o cmd2.o cmd4.o cmd-activate.o cmd-eat.o \
17+ cmd-hissatsu.o cmd-item.o cmd-magiceat.o cmd-mane.o cmd-pet.o \
18+ cmd-quaff.o cmd-read.o cmd-smith.o cmd-spell.o cmd-usestaff.o \
19+ cmd-zaprod.o cmd-zapwand.o \
20+ dungeon.o \
21+ effects.o \
22+ feature.o files.o flavor.o floor-events.o floor-generate.o \
23+ floor-save.o floor-streams.o \
24+ gameoption.o geometry.o grid.o \
25+ history.o \
26+ inet.o init1.o init2.o \
27+ japanese.o \
28+ load.o \
29+ melee1.o mind.o monster1.o monster2.o monster-process.o \
30+ monsterrace-hook.o monster-status.o mspells1.o mspells2.o mspells3.o \
31+ mspells4.o mutation.o \
32+ object1.o object2.o object-boost.o object-broken.o object-curse.o \
33+ object-hook.o objectkind-hook.o \
34+ patron.o player-damage.o player-move.o player-status.o projection.o \
35+ quest.o \
36+ racial.o realm-arcane.o realm-chaos.o realm-craft.o realm-crusade.o \
37+ realm-daemon.o realm-death.o realm-hex.o realm-hissatsu.o \
38+ realm-life.o realm-nature.o realm-song.o realm-sorcery.o \
39+ realm-trump.o report.o rooms.o rooms-city.o rooms-fractal.o \
40+ rooms-normal.o rooms-pitnest.o rooms-special.o rooms-trap.o \
41+ rooms-vault.o rumor.o \
42+ save.o scores.o selfinfo.o shoot.o snipe.o sort.o spells1.o \
43+ spells2.o spells3.o spells-diceroll.o spells-floor.o spells-object.o \
44+ spells-status.o spells-summon.o spells-world.o store.o \
45+ tables.o term.o trap.o \
46+ util.o \
47+ variable.o view-mainwindow.o \
48+ warning.o wild.o wizard1.o wizard2.o world.o xtra2.o \
49+ z-form.o z-rand.o z-term.o z-util.o z-virt.o
4950
5051 .PHONY: all
5152 all : $(TARGET_FILE)
@@ -57,12 +58,12 @@ prebuild :
5758 # ln -s ../lib lib
5859
5960 $(TARGET_FILE): $(OBJS)
60- $(LD) $(LDFLAGS) $(OBJS) --js-library worker.message.js --preload-file lib -o $(TARGET_FILE)
61+ $(LD) $(LDFLAGS) $(DEFASYNCIFY) $(OBJS) --pre-js pre.js --js-library lib.js --preload-file lib -o $(TARGET_FILE)
6162
62-.SUFFIXES: .c .bc
63-.c.bc:
64- $(CC) $(CFLAGS) $(DEFINES) -c $< -o $@
63+.SUFFIXES: .c .o
64+.c.o:
65+ $(CC) $(CFLAGS) $(DEFINES) $(DEFASYNCIFY) -c $< -o $@
6566
6667 .PHONY: clean
6768 clean:
68- $(RM) hengband.* *.bc
69+ $(RM) hengband.* *.o
--- a/src/worker.message.js
+++ b/src/pre.js
@@ -1,3 +1,4 @@
11 onmessage = function(e) {
22 console.log('worker:', e);
3+ _Term_wasm_keypress(e.data.keyCode);
34 }
--- a/src/util.c
+++ b/src/util.c
@@ -12,6 +12,9 @@
1212
1313 #include "angband.h"
1414 #include "monsterrace-hook.h"
15+#ifdef __EMSCRIPTEN__
16+#include <emscripten.h>
17+#endif
1518
1619
1720 static int num_more = 0;
@@ -2114,6 +2117,8 @@ char inkey(void)
21142117 /* Get a key */
21152118 while (!ch)
21162119 {
2120+ emscripten_sleep(10);
2121+
21172122 /* Hack -- Handle "inkey_scan" */
21182123 if (!inkey_base && inkey_scan &&
21192124 (0 != Term_inkey(&kk, FALSE, FALSE)))