変愚蛮怒のメインリポジトリです
修订版 | 14ea65770041af24848df65f8efb9cc3d9246f22 (tree) |
---|---|
时间 | 2020-03-29 16:06:41 |
作者 | shimitei <shimitei@gmai...> |
Commiter | shimitei |
receive keydown message
@@ -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 |
@@ -70,7 +70,6 @@ static void Term_nuke_wasm(term* t) | ||
70 | 70 | */ |
71 | 71 | static errr Term_text_wasm(int x, int y, int n, byte a, concptr s) |
72 | 72 | { |
73 | - printf("%s", s); | |
74 | 73 | EM_ASM({ |
75 | 74 | var s = UTF8ToString($0); |
76 | 75 | console.log(s); |
@@ -124,6 +123,15 @@ static errr Term_xtra_wasm(int n, int v) | ||
124 | 123 | return (1); |
125 | 124 | } |
126 | 125 | |
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 | + | |
127 | 135 | /* |
128 | 136 | * Prepare this file for Angband usage |
129 | 137 | */ |
@@ -8,9 +8,9 @@ | ||
8 | 8 | * are included in all such copies. |
9 | 9 | */ |
10 | 10 | |
11 | +#include <emscripten.h> | |
11 | 12 | #include "angband.h" |
12 | 13 | |
13 | - | |
14 | 14 | /* |
15 | 15 | * A hook for "quit()". |
16 | 16 | * |
@@ -2,50 +2,51 @@ | ||
2 | 2 | |
3 | 3 | CC = emcc |
4 | 4 | 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 | |
7 | 7 | DEFINES = |
8 | +DEFASYNCIFY = -s ASYNCIFY -s 'ASYNCIFY_IMPORTS=["emscripten_sleep", "mysleep"]' | |
8 | 9 | |
9 | -TARGET_FILE = hengband.html | |
10 | +TARGET_FILE = hengband.js | |
10 | 11 | |
11 | 12 | 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 | |
49 | 50 | |
50 | 51 | .PHONY: all |
51 | 52 | all : $(TARGET_FILE) |
@@ -57,12 +58,12 @@ prebuild : | ||
57 | 58 | # ln -s ../lib lib |
58 | 59 | |
59 | 60 | $(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) | |
61 | 62 | |
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 $@ | |
65 | 66 | |
66 | 67 | .PHONY: clean |
67 | 68 | clean: |
68 | - $(RM) hengband.* *.bc | |
69 | + $(RM) hengband.* *.o |
@@ -1,3 +1,4 @@ | ||
1 | 1 | onmessage = function(e) { |
2 | 2 | console.log('worker:', e); |
3 | + _Term_wasm_keypress(e.data.keyCode); | |
3 | 4 | } |
@@ -12,6 +12,9 @@ | ||
12 | 12 | |
13 | 13 | #include "angband.h" |
14 | 14 | #include "monsterrace-hook.h" |
15 | +#ifdef __EMSCRIPTEN__ | |
16 | +#include <emscripten.h> | |
17 | +#endif | |
15 | 18 | |
16 | 19 | |
17 | 20 | static int num_more = 0; |
@@ -2114,6 +2117,8 @@ char inkey(void) | ||
2114 | 2117 | /* Get a key */ |
2115 | 2118 | while (!ch) |
2116 | 2119 | { |
2120 | + emscripten_sleep(10); | |
2121 | + | |
2117 | 2122 | /* Hack -- Handle "inkey_scan" */ |
2118 | 2123 | if (!inkey_base && inkey_scan && |
2119 | 2124 | (0 != Term_inkey(&kk, FALSE, FALSE))) |