webruby 0.2.2 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/webruby/config.rb +4 -9
- data/lib/webruby/rake/files.rake +2 -2
- data/modules/emscripten/AUTHORS +9 -1
- data/modules/emscripten/CONTRIBUTING.markdown +5 -0
- data/modules/emscripten/ChangeLog +435 -0
- data/modules/emscripten/cmake/Modules/FindOpenAL.cmake +26 -0
- data/modules/emscripten/cmake/Platform/Emscripten.cmake +9 -2
- data/modules/emscripten/em++ +0 -2
- data/modules/emscripten/emcc +92 -32
- data/modules/emscripten/emlink.py +16 -13
- data/modules/emscripten/emmake +1 -1
- data/modules/emscripten/emrun +918 -0
- data/modules/emscripten/emrun.bat +2 -0
- data/modules/emscripten/emscripten.py +545 -20
- data/modules/emscripten/src/analyzer.js +6 -1
- data/modules/emscripten/src/compiler.js +25 -16
- data/modules/emscripten/src/emrun_postjs.js +20 -0
- data/modules/emscripten/{tests → src}/hello_world.js +0 -0
- data/modules/emscripten/src/intertyper.js +45 -16
- data/modules/emscripten/src/jsifier.js +78 -48
- data/modules/emscripten/src/library.js +381 -96
- data/modules/emscripten/src/library_browser.js +50 -53
- data/modules/emscripten/src/library_egl.js +66 -24
- data/modules/emscripten/src/library_fs.js +122 -90
- data/modules/emscripten/src/library_gl.js +739 -353
- data/modules/emscripten/src/library_glfw.js +9 -3
- data/modules/emscripten/src/library_glut.js +10 -5
- data/modules/emscripten/src/library_idbfs.js +14 -14
- data/modules/emscripten/src/library_memfs.js +65 -41
- data/modules/emscripten/src/library_nodefs.js +61 -9
- data/modules/emscripten/src/library_openal.js +4 -4
- data/modules/emscripten/src/library_path.js +9 -13
- data/modules/emscripten/src/library_sdl.js +301 -64
- data/modules/emscripten/src/library_sockfs.js +7 -5
- data/modules/emscripten/src/modules.js +62 -22
- data/modules/emscripten/src/parseTools.js +135 -102
- data/modules/emscripten/src/postamble.js +3 -4
- data/modules/emscripten/src/preamble.js +49 -29
- data/modules/emscripten/src/proxyClient.js +1 -1
- data/modules/emscripten/src/proxyWorker.js +10 -10
- data/modules/emscripten/src/relooper/Relooper.cpp +15 -4
- data/modules/emscripten/src/runtime.js +32 -8
- data/modules/emscripten/src/settings.js +25 -8
- data/modules/emscripten/src/shell.html +6 -3
- data/modules/emscripten/src/shell.js +13 -11
- data/modules/emscripten/src/simd.js +602 -432
- data/modules/emscripten/src/struct_info.json +22 -2
- data/modules/emscripten/src/utility.js +32 -17
- data/modules/emscripten/system/include/SDL/SDL_events.h +1 -0
- data/modules/emscripten/system/include/compat/ctype.h +17 -0
- data/modules/emscripten/system/include/compat/wchar.h +23 -0
- data/modules/emscripten/system/include/compat/wctype.h +23 -0
- data/modules/emscripten/system/include/emscripten/emmintrin.h +87 -0
- data/modules/emscripten/system/include/emscripten/emscripten.h +30 -4
- data/modules/emscripten/system/include/emscripten/vector.h +29 -1
- data/modules/emscripten/system/include/emscripten/xmmintrin.h +131 -0
- data/modules/emscripten/system/include/libcxx/CREDITS.TXT +9 -1
- data/modules/emscripten/system/include/libcxx/__bit_reference +8 -8
- data/modules/emscripten/system/include/libcxx/__config +95 -17
- data/modules/emscripten/system/include/libcxx/__debug +25 -4
- data/modules/emscripten/system/include/libcxx/__functional_03 +7 -7
- data/modules/emscripten/system/include/libcxx/__functional_base +169 -9
- data/modules/emscripten/system/include/libcxx/__functional_base_03 +1 -1
- data/modules/emscripten/system/include/libcxx/__hash_table +25 -25
- data/modules/emscripten/system/include/libcxx/__locale +21 -19
- data/modules/emscripten/system/include/libcxx/__mutex_base +2 -33
- data/modules/emscripten/system/include/libcxx/__split_buffer +9 -9
- data/modules/emscripten/system/include/libcxx/__std_stream +14 -0
- data/modules/emscripten/system/include/libcxx/__tree +35 -26
- data/modules/emscripten/system/include/libcxx/__tuple +15 -15
- data/modules/emscripten/system/include/libcxx/__tuple_03 +2 -2
- data/modules/emscripten/system/include/libcxx/__undef_min_max +8 -0
- data/modules/emscripten/system/include/libcxx/algorithm +121 -110
- data/modules/emscripten/system/include/libcxx/array +15 -15
- data/modules/emscripten/system/include/libcxx/bitset +4 -4
- data/modules/emscripten/system/include/libcxx/chrono +51 -17
- data/modules/emscripten/system/include/libcxx/cmath +25 -23
- data/modules/emscripten/system/include/libcxx/codecvt +21 -18
- data/modules/emscripten/system/include/libcxx/complex +48 -7
- data/modules/emscripten/system/include/libcxx/cstddef +1 -1
- data/modules/emscripten/system/include/libcxx/cstdio +8 -1
- data/modules/emscripten/system/include/libcxx/cstdlib +1 -1
- data/modules/emscripten/system/include/libcxx/cwchar +1 -1
- data/modules/emscripten/system/include/libcxx/deque +26 -12
- data/modules/emscripten/system/include/libcxx/dynarray +311 -0
- data/modules/emscripten/system/include/libcxx/exception +4 -4
- data/modules/emscripten/system/include/libcxx/ext/__hash +3 -3
- data/modules/emscripten/system/include/libcxx/ext/hash_map +19 -15
- data/modules/emscripten/system/include/libcxx/ext/hash_set +7 -3
- data/modules/emscripten/system/include/libcxx/forward_list +33 -7
- data/modules/emscripten/system/include/libcxx/fstream +4 -4
- data/modules/emscripten/system/include/libcxx/functional +200 -170
- data/modules/emscripten/system/include/libcxx/future +83 -39
- data/modules/emscripten/system/include/libcxx/initializer_list +24 -11
- data/modules/emscripten/system/include/libcxx/iomanip +147 -0
- data/modules/emscripten/system/include/libcxx/ios +24 -16
- data/modules/emscripten/system/include/libcxx/iosfwd +19 -19
- data/modules/emscripten/system/include/libcxx/istream +13 -8
- data/modules/emscripten/system/include/libcxx/iterator +108 -417
- data/modules/emscripten/system/include/libcxx/limits +8 -4
- data/modules/emscripten/system/include/libcxx/list +28 -8
- data/modules/emscripten/system/include/libcxx/locale +153 -390
- data/modules/emscripten/system/include/libcxx/map +280 -100
- data/modules/emscripten/system/include/libcxx/memory +49 -97
- data/modules/emscripten/system/include/libcxx/mutex +2 -2
- data/modules/emscripten/system/include/libcxx/new +43 -14
- data/modules/emscripten/system/include/libcxx/numeric +2 -2
- data/modules/emscripten/system/include/libcxx/optional +697 -0
- data/modules/emscripten/system/include/libcxx/ostream +17 -8
- data/modules/emscripten/system/include/libcxx/queue +5 -5
- data/modules/emscripten/system/include/libcxx/random +53 -51
- data/modules/emscripten/system/include/libcxx/ratio +11 -11
- data/modules/emscripten/system/include/libcxx/readme.txt +1 -1
- data/modules/emscripten/system/include/libcxx/regex +23 -20
- data/modules/emscripten/system/include/libcxx/scoped_allocator +1 -1
- data/modules/emscripten/system/include/libcxx/set +166 -2
- data/modules/emscripten/system/include/libcxx/shared_mutex +419 -0
- data/modules/emscripten/system/include/libcxx/sstream +4 -4
- data/modules/emscripten/system/include/libcxx/stack +3 -3
- data/modules/emscripten/system/include/libcxx/streambuf +5 -5
- data/modules/emscripten/system/include/libcxx/string +372 -324
- data/modules/emscripten/system/include/libcxx/support/ibm/limits.h +99 -0
- data/modules/emscripten/system/include/libcxx/support/ibm/support.h +54 -0
- data/modules/emscripten/system/include/libcxx/support/ibm/xlocale.h +326 -0
- data/modules/emscripten/system/include/libcxx/support/win32/limits_win32.h +6 -6
- data/modules/emscripten/system/include/libcxx/support/win32/locale_win32.h +15 -15
- data/modules/emscripten/system/include/libcxx/support/win32/math_win32.h +2 -0
- data/modules/emscripten/system/include/libcxx/support/win32/support.h +6 -1
- data/modules/emscripten/system/include/libcxx/system_error +14 -8
- data/modules/emscripten/system/include/libcxx/thread +7 -8
- data/modules/emscripten/system/include/libcxx/tuple +29 -88
- data/modules/emscripten/system/include/libcxx/type_traits +253 -209
- data/modules/emscripten/system/include/libcxx/typeindex +3 -3
- data/modules/emscripten/system/include/libcxx/unordered_map +162 -101
- data/modules/emscripten/system/include/libcxx/unordered_set +79 -2
- data/modules/emscripten/system/include/libcxx/utility +20 -20
- data/modules/emscripten/system/include/libcxx/valarray +23 -23
- data/modules/emscripten/system/include/libcxx/vector +114 -91
- data/modules/emscripten/system/lib/libc/musl/src/regex/regcomp.c +3352 -0
- data/modules/emscripten/system/lib/libc/musl/src/regex/regerror.c +35 -0
- data/modules/emscripten/system/lib/libc/musl/src/regex/regexec.c +1011 -0
- data/modules/emscripten/system/lib/libc/musl/src/regex/tre-mem.c +158 -0
- data/modules/emscripten/system/lib/libc/musl/src/regex/tre.h +231 -0
- data/modules/emscripten/system/lib/libcextra.symbols +7 -0
- data/modules/emscripten/system/lib/libcxx/CREDITS.TXT +9 -1
- data/modules/emscripten/system/lib/libcxx/algorithm.cpp +1 -0
- data/modules/emscripten/system/lib/libcxx/debug.cpp +66 -42
- data/modules/emscripten/system/lib/libcxx/exception.cpp +88 -16
- data/modules/emscripten/system/lib/libcxx/future.cpp +6 -0
- data/modules/emscripten/system/lib/libcxx/ios.cpp +7 -2
- data/modules/emscripten/system/lib/libcxx/iostream.cpp +8 -8
- data/modules/emscripten/system/lib/libcxx/locale.cpp +38 -11
- data/modules/emscripten/system/lib/libcxx/mutex.cpp +3 -0
- data/modules/emscripten/system/lib/libcxx/new.cpp +44 -10
- data/modules/emscripten/system/lib/libcxx/optional.cpp +25 -0
- data/modules/emscripten/system/lib/libcxx/random.cpp +26 -0
- data/modules/emscripten/system/lib/libcxx/readme.txt +1 -1
- data/modules/emscripten/system/lib/libcxx/shared_mutex.cpp +101 -0
- data/modules/emscripten/system/lib/libcxx/stdexcept.cpp +11 -7
- data/modules/emscripten/system/lib/libcxx/string.cpp +3 -1
- data/modules/emscripten/system/lib/libcxx/strstream.cpp +7 -7
- data/modules/emscripten/system/lib/libcxx/support/win32/locale_win32.cpp +12 -13
- data/modules/emscripten/system/lib/libcxx/support/win32/support.cpp +33 -36
- data/modules/emscripten/system/lib/libcxx/symbols +187 -168
- data/modules/emscripten/system/lib/libcxx/system_error.cpp +1 -0
- data/modules/emscripten/system/lib/libcxx/thread.cpp +7 -3
- data/modules/emscripten/system/lib/libcxx/typeinfo.cpp +9 -6
- data/modules/emscripten/system/lib/libcxx/valarray.cpp +2 -0
- data/modules/emscripten/third_party/lzma.js/doit.bat +4 -0
- data/modules/emscripten/third_party/lzma.js/doit.sh +9 -2
- data/modules/emscripten/tools/cache.py +5 -7
- data/modules/emscripten/tools/cache.pyc +0 -0
- data/modules/emscripten/tools/eliminator/asm-eliminator-test-output.js +7 -0
- data/modules/emscripten/tools/eliminator/asm-eliminator-test.js +9 -1
- data/modules/emscripten/tools/eliminator/eliminator-test-output.js +3 -0
- data/modules/emscripten/tools/eliminator/eliminator-test.js +9 -1
- data/modules/emscripten/tools/file_packager.py +93 -50
- data/modules/emscripten/tools/js-optimizer.js +98 -48
- data/modules/emscripten/tools/js_optimizer.py +4 -4
- data/modules/emscripten/tools/js_optimizer.pyc +0 -0
- data/modules/emscripten/tools/jsrun.py +1 -1
- data/modules/emscripten/tools/jsrun.pyc +0 -0
- data/modules/emscripten/tools/response_file.py +6 -0
- data/modules/emscripten/tools/response_file.pyc +0 -0
- data/modules/emscripten/tools/settings_template_readonly.py +2 -0
- data/modules/emscripten/tools/shared.py +88 -34
- data/modules/emscripten/tools/shared.pyc +0 -0
- data/modules/emscripten/tools/split.py +21 -13
- data/modules/mruby/build_config.rb +7 -1
- data/modules/mruby/doc/compile/README.md +5 -9
- data/modules/mruby/include/mrbconf.h +5 -2
- data/modules/mruby/include/mruby/array.h +1 -0
- data/modules/mruby/include/mruby/compile.h +2 -4
- data/modules/mruby/include/mruby/dump.h +7 -16
- data/modules/mruby/include/mruby/hash.h +1 -1
- data/modules/mruby/include/mruby/irep.h +14 -2
- data/modules/mruby/include/mruby/khash.h +8 -7
- data/modules/mruby/include/mruby/string.h +1 -0
- data/modules/mruby/include/mruby/value.h +5 -2
- data/modules/mruby/include/mruby.h +12 -13
- data/modules/mruby/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c +16 -6
- data/modules/mruby/mrbgems/mruby-bin-mruby/tools/mruby/mruby.c +18 -30
- data/modules/mruby/mrbgems/mruby-fiber/src/fiber.c +21 -0
- data/modules/mruby/mrbgems/mruby-math/src/math.c +1 -1
- data/modules/mruby/mrbgems/mruby-random/src/random.c +144 -47
- data/modules/mruby/mrbgems/mruby-random/test/random.rb +44 -0
- data/modules/mruby/mrbgems/mruby-struct/src/struct.c +5 -5
- data/modules/mruby/mrblib/numeric.rb +99 -33
- data/modules/mruby/src/array.c +11 -4
- data/modules/mruby/src/backtrace.c +2 -2
- data/modules/mruby/src/class.c +49 -30
- data/modules/mruby/src/codegen.c +131 -79
- data/modules/mruby/src/debug.c +1 -1
- data/modules/mruby/src/dump.c +213 -163
- data/modules/mruby/src/error.c +17 -17
- data/modules/mruby/src/error.h +1 -1
- data/modules/mruby/src/etc.c +10 -0
- data/modules/mruby/src/gc.c +35 -17
- data/modules/mruby/src/hash.c +5 -5
- data/modules/mruby/src/kernel.c +36 -14
- data/modules/mruby/src/load.c +238 -296
- data/modules/mruby/src/numeric.c +18 -98
- data/modules/mruby/src/object.c +3 -5
- data/modules/mruby/src/parse.y +63 -56
- data/modules/mruby/src/proc.c +8 -5
- data/modules/mruby/src/re.h +0 -1
- data/modules/mruby/src/state.c +65 -27
- data/modules/mruby/src/string.c +3 -31
- data/modules/mruby/src/symbol.c +3 -3
- data/modules/mruby/src/variable.c +12 -5
- data/modules/mruby/src/vm.c +90 -72
- data/modules/mruby/tasks/mruby_build.rake +10 -1
- data/modules/mruby/tasks/toolchains/gcc.rake +12 -2
- data/modules/mruby/tasks/toolchains/{vs2012.rake → visualcpp.rake} +1 -1
- data/modules/mruby/test/driver.c +3 -3
- data/modules/mruby/test/t/array.rb +5 -5
- data/modules/mruby/test/t/class.rb +14 -1
- data/modules/mruby/test/t/kernel.rb +4 -0
- data/modules/mruby/test/t/module.rb +4 -4
- data/modules/mruby/test/t/nameerror.rb +1 -1
- data/modules/mruby/tools/mrbc/mrbc.c +23 -17
- data/modules/mruby/travis_config.rb +10 -1
- metadata +28 -5
- data/modules/mruby/tasks/toolchains/vs2010.rake +0 -3
@@ -75,6 +75,7 @@ var LibrarySDL = {
|
|
75
75
|
textInput: false,
|
76
76
|
|
77
77
|
startTime: null,
|
78
|
+
initFlags: 0, // The flags passed to SDL_Init
|
78
79
|
buttonState: 0,
|
79
80
|
modState: 0,
|
80
81
|
DOMButtons: [0, 0, 0],
|
@@ -153,24 +154,30 @@ var LibrarySDL = {
|
|
153
154
|
120: 27,
|
154
155
|
121: 28,
|
155
156
|
122: 29, // Z
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
157
|
+
49: 30, // 1
|
158
|
+
50: 31,
|
159
|
+
51: 32,
|
160
|
+
52: 33,
|
161
|
+
53: 34,
|
162
|
+
54: 35,
|
163
|
+
55: 36,
|
164
|
+
56: 37,
|
165
|
+
57: 38, // 9
|
166
|
+
48: 39, // 0
|
167
|
+
13: 40, // return
|
168
|
+
27: 41, // escape
|
169
|
+
8: 42, // backspace
|
170
|
+
9: 43, // tab
|
171
|
+
32: 44, // space
|
172
|
+
61: 46, // equals
|
173
|
+
91: 47, // left bracket
|
174
|
+
93: 48, // right bracket
|
175
|
+
92: 49, // backslash
|
176
|
+
59: 51, // ;
|
177
|
+
96: 52, // apostrophe
|
178
|
+
44: 54, // comma
|
179
|
+
46: 55, // period
|
180
|
+
47: 56, // slash
|
174
181
|
305: 224, // ctrl
|
175
182
|
308: 226, // alt
|
176
183
|
},
|
@@ -254,9 +261,13 @@ var LibrarySDL = {
|
|
254
261
|
}
|
255
262
|
|
256
263
|
var webGLContextAttributes = {
|
257
|
-
antialias: ((SDL.glAttributes[13 /*SDL_GL_MULTISAMPLEBUFFERS*/] != 0) && (SDL.glAttributes[14 /*SDL_GL_MULTISAMPLESAMPLES*/] > 1))
|
264
|
+
antialias: ((SDL.glAttributes[13 /*SDL_GL_MULTISAMPLEBUFFERS*/] != 0) && (SDL.glAttributes[14 /*SDL_GL_MULTISAMPLESAMPLES*/] > 1)),
|
265
|
+
depth: (SDL.glAttributes[6 /*SDL_GL_DEPTH_SIZE*/] > 0),
|
266
|
+
stencil: (SDL.glAttributes[7 /*SDL_GL_STENCIL_SIZE*/] > 0)
|
258
267
|
};
|
268
|
+
|
259
269
|
var ctx = Browser.createContext(canvas, useWebGL, usePageCanvas, webGLContextAttributes);
|
270
|
+
|
260
271
|
SDL.surfaces[surf] = {
|
261
272
|
width: width,
|
262
273
|
height: height,
|
@@ -629,6 +640,21 @@ var LibrarySDL = {
|
|
629
640
|
{{{ makeSetValue('ptr', C_STRUCTS.SDL_ResizeEvent.h, 'event.h', 'i32') }}};
|
630
641
|
break;
|
631
642
|
}
|
643
|
+
case 'joystick_button_up': case 'joystick_button_down': {
|
644
|
+
var state = event.type === 'joystick_button_up' ? 0 : 1;
|
645
|
+
{{{ makeSetValue('ptr', C_STRUCTS.SDL_JoyButtonEvent.type, 'SDL.DOMEventToSDLEvent[event.type]', 'i32') }}};
|
646
|
+
{{{ makeSetValue('ptr', C_STRUCTS.SDL_JoyButtonEvent.which, 'event.index', 'i8') }}};
|
647
|
+
{{{ makeSetValue('ptr', C_STRUCTS.SDL_JoyButtonEvent.button, 'event.button', 'i8') }}};
|
648
|
+
{{{ makeSetValue('ptr', C_STRUCTS.SDL_JoyButtonEvent.state, 'state', 'i8') }}};
|
649
|
+
break;
|
650
|
+
}
|
651
|
+
case 'joystick_axis_motion': {
|
652
|
+
{{{ makeSetValue('ptr', C_STRUCTS.SDL_JoyAxisEvent.type, 'SDL.DOMEventToSDLEvent[event.type]', 'i32') }}};
|
653
|
+
{{{ makeSetValue('ptr', C_STRUCTS.SDL_JoyAxisEvent.which, 'event.index', 'i8') }}};
|
654
|
+
{{{ makeSetValue('ptr', C_STRUCTS.SDL_JoyAxisEvent.axis, 'event.axis', 'i8') }}};
|
655
|
+
{{{ makeSetValue('ptr', C_STRUCTS.SDL_JoyAxisEvent.value, 'SDL.joystickAxisValueConversion(event.value)', 'i32') }}};
|
656
|
+
break;
|
657
|
+
}
|
632
658
|
default: throw 'Unhandled SDL event: ' + event.type;
|
633
659
|
}
|
634
660
|
},
|
@@ -685,7 +711,109 @@ var LibrarySDL = {
|
|
685
711
|
for (var i = 0; i < num; i++) {
|
686
712
|
console.log(' diagonal ' + i + ':' + [data[i*surfData.width*4 + i*4 + 0], data[i*surfData.width*4 + i*4 + 1], data[i*surfData.width*4 + i*4 + 2], data[i*surfData.width*4 + i*4 + 3]]);
|
687
713
|
}
|
688
|
-
}
|
714
|
+
},
|
715
|
+
|
716
|
+
// Joystick helper methods and state
|
717
|
+
|
718
|
+
joystickEventState: 1, // SDL_ENABLE
|
719
|
+
lastJoystickState: {}, // Map from SDL_Joystick* to their last known state. Required to determine if a change has occurred.
|
720
|
+
// Maps Joystick names to pointers. Allows us to avoid reallocating memory for
|
721
|
+
// joystick names each time this function is called.
|
722
|
+
joystickNamePool: {},
|
723
|
+
recordJoystickState: function(joystick, state) {
|
724
|
+
// Standardize button state.
|
725
|
+
var buttons = new Array(state.buttons.length);
|
726
|
+
for (var i = 0; i < state.buttons.length; i++) {
|
727
|
+
buttons[i] = SDL.getJoystickButtonState(state.buttons[i]);
|
728
|
+
}
|
729
|
+
|
730
|
+
SDL.lastJoystickState[joystick] = {
|
731
|
+
buttons: buttons,
|
732
|
+
axes: state.axes.slice(0),
|
733
|
+
timestamp: state.timestamp,
|
734
|
+
index: state.index,
|
735
|
+
id: state.id
|
736
|
+
};
|
737
|
+
},
|
738
|
+
// Retrieves the button state of the given gamepad button.
|
739
|
+
// Abstracts away implementation differences.
|
740
|
+
// Returns 'true' if pressed, 'false' otherwise.
|
741
|
+
getJoystickButtonState: function(button) {
|
742
|
+
if (typeof button === 'object') {
|
743
|
+
// Current gamepad API editor's draft (Firefox Nightly)
|
744
|
+
// https://dvcs.w3.org/hg/gamepad/raw-file/default/gamepad.html#idl-def-GamepadButton
|
745
|
+
return button.pressed;
|
746
|
+
} else {
|
747
|
+
// Current gamepad API working draft (Firefox / Chrome Stable)
|
748
|
+
// http://www.w3.org/TR/2012/WD-gamepad-20120529/#gamepad-interface
|
749
|
+
return button > 0;
|
750
|
+
}
|
751
|
+
},
|
752
|
+
// Queries for and inserts controller events into the SDL queue.
|
753
|
+
queryJoysticks: function() {
|
754
|
+
for (var joystick in SDL.lastJoystickState) {
|
755
|
+
var state = SDL.getGamepad(joystick - 1);
|
756
|
+
var prevState = SDL.lastJoystickState[joystick];
|
757
|
+
// Check only if the timestamp has differed.
|
758
|
+
// NOTE: Timestamp is not available in Firefox.
|
759
|
+
if (typeof state.timestamp !== 'number' || state.timestamp !== prevState.timestamp) {
|
760
|
+
var i;
|
761
|
+
for (i = 0; i < state.buttons.length; i++) {
|
762
|
+
var buttonState = SDL.getJoystickButtonState(state.buttons[i]);
|
763
|
+
// NOTE: The previous state already has a boolean representation of
|
764
|
+
// its button, so no need to standardize its button state here.
|
765
|
+
if (buttonState !== prevState.buttons[i]) {
|
766
|
+
// Insert button-press event.
|
767
|
+
SDL.events.push({
|
768
|
+
type: buttonState ? 'joystick_button_down' : 'joystick_button_up',
|
769
|
+
joystick: joystick,
|
770
|
+
index: joystick - 1,
|
771
|
+
button: i
|
772
|
+
});
|
773
|
+
}
|
774
|
+
}
|
775
|
+
for (i = 0; i < state.axes.length; i++) {
|
776
|
+
if (state.axes[i] !== prevState.axes[i]) {
|
777
|
+
// Insert axes-change event.
|
778
|
+
SDL.events.push({
|
779
|
+
type: 'joystick_axis_motion',
|
780
|
+
joystick: joystick,
|
781
|
+
index: joystick - 1,
|
782
|
+
axis: i,
|
783
|
+
value: state.axes[i]
|
784
|
+
});
|
785
|
+
}
|
786
|
+
}
|
787
|
+
|
788
|
+
SDL.recordJoystickState(joystick, state);
|
789
|
+
}
|
790
|
+
}
|
791
|
+
},
|
792
|
+
// Converts the double-based browser axis value [-1, 1] into SDL's 16-bit
|
793
|
+
// value [-32768, 32767]
|
794
|
+
joystickAxisValueConversion: function(value) {
|
795
|
+
// Ensures that 0 is 0, 1 is 32767, and -1 is 32768.
|
796
|
+
return Math.ceil(((value+1) * 32767.5) - 32768);
|
797
|
+
},
|
798
|
+
|
799
|
+
getGamepads: function() {
|
800
|
+
var fcn = navigator.getGamepads || navigator.webkitGamepads || navigator.mozGamepads || navigator.gamepads || navigator.webkitGetGamepads;
|
801
|
+
if (fcn !== undefined) {
|
802
|
+
// The function must be applied on the navigator object.
|
803
|
+
return fcn.apply(navigator);
|
804
|
+
} else {
|
805
|
+
return [];
|
806
|
+
}
|
807
|
+
},
|
808
|
+
|
809
|
+
// Helper function: Returns the gamepad if available, or null if not.
|
810
|
+
getGamepad: function(deviceIndex) {
|
811
|
+
var gamepads = SDL.getGamepads();
|
812
|
+
if (gamepads.length > deviceIndex && deviceIndex >= 0) {
|
813
|
+
return gamepads[deviceIndex];
|
814
|
+
}
|
815
|
+
return null;
|
816
|
+
},
|
689
817
|
},
|
690
818
|
|
691
819
|
SDL_Linked_Version: function() {
|
@@ -698,8 +826,10 @@ var LibrarySDL = {
|
|
698
826
|
return SDL.version;
|
699
827
|
},
|
700
828
|
|
701
|
-
SDL_Init: function(
|
829
|
+
SDL_Init: function(initFlags) {
|
702
830
|
SDL.startTime = Date.now();
|
831
|
+
SDL.initFlags = initFlags;
|
832
|
+
|
703
833
|
// capture all key events. we just keep down and up, but also capture press to prevent default actions
|
704
834
|
if (!Module['doNotCaptureKeyboard']) {
|
705
835
|
document.addEventListener("keydown", SDL.receiveEvent);
|
@@ -708,6 +838,15 @@ var LibrarySDL = {
|
|
708
838
|
window.addEventListener("blur", SDL.receiveEvent);
|
709
839
|
document.addEventListener("visibilitychange", SDL.receiveEvent);
|
710
840
|
}
|
841
|
+
|
842
|
+
if (initFlags & 0x200) {
|
843
|
+
// SDL_INIT_JOYSTICK
|
844
|
+
// Firefox will not give us Joystick data unless we register this NOP
|
845
|
+
// callback.
|
846
|
+
// https://bugzilla.mozilla.org/show_bug.cgi?id=936104
|
847
|
+
addEventListener("gamepadconnected", function() {});
|
848
|
+
}
|
849
|
+
|
711
850
|
window.addEventListener("unload", SDL.receiveEvent);
|
712
851
|
SDL.keyboardState = _malloc(0x10000); // Our SDL needs 512, but 64K is safe for older SDLs
|
713
852
|
_memset(SDL.keyboardState, 0, 0x10000);
|
@@ -720,6 +859,12 @@ var LibrarySDL = {
|
|
720
859
|
SDL.DOMEventToSDLEvent['mousemove'] = 0x400 /* SDL_MOUSEMOTION */;
|
721
860
|
SDL.DOMEventToSDLEvent['unload'] = 0x100 /* SDL_QUIT */;
|
722
861
|
SDL.DOMEventToSDLEvent['resize'] = 0x7001 /* SDL_VIDEORESIZE/SDL_EVENT_COMPAT2 */;
|
862
|
+
// These are not technically DOM events; the HTML gamepad API is poll-based.
|
863
|
+
// However, we define them here, as the rest of the SDL code assumes that
|
864
|
+
// all SDL events originate as DOM events.
|
865
|
+
SDL.DOMEventToSDLEvent['joystick_axis_motion'] = 0x600 /* SDL_JOYAXISMOTION */;
|
866
|
+
SDL.DOMEventToSDLEvent['joystick_button_down'] = 0x603 /* SDL_JOYBUTTONDOWN */;
|
867
|
+
SDL.DOMEventToSDLEvent['joystick_button_up'] = 0x604 /* SDL_JOYBUTTONUP */;
|
723
868
|
return 0; // success
|
724
869
|
},
|
725
870
|
|
@@ -786,6 +931,14 @@ var LibrarySDL = {
|
|
786
931
|
['mousedown', 'mouseup', 'mousemove', 'DOMMouseScroll', 'mousewheel', 'mouseout'].forEach(function(event) {
|
787
932
|
Module['canvas'].addEventListener(event, SDL.receiveEvent, true);
|
788
933
|
});
|
934
|
+
|
935
|
+
// (0,0) means 'use fullscreen' in native; in Emscripten, use the current canvas size.
|
936
|
+
if (width == 0 && height == 0) {
|
937
|
+
var canvas = Module['canvas'];
|
938
|
+
width = canvas.width;
|
939
|
+
height = canvas.height;
|
940
|
+
}
|
941
|
+
|
789
942
|
Browser.setCanvasSize(width, height, true);
|
790
943
|
// Free the old surface first.
|
791
944
|
if (SDL.screen) {
|
@@ -1094,6 +1247,8 @@ var LibrarySDL = {
|
|
1094
1247
|
return 0;
|
1095
1248
|
},
|
1096
1249
|
|
1250
|
+
SDL_LowerBlit: 'SDL_UpperBlit',
|
1251
|
+
|
1097
1252
|
SDL_FillRect: function(surf, rect, color) {
|
1098
1253
|
var surfData = SDL.surfaces[surf];
|
1099
1254
|
assert(!surfData.locked); // but we could unlock and re-lock if we must..
|
@@ -1171,6 +1326,11 @@ var LibrarySDL = {
|
|
1171
1326
|
},
|
1172
1327
|
|
1173
1328
|
SDL_PollEvent: function(ptr) {
|
1329
|
+
if (SDL.initFlags & 0x200 && SDL.joystickEventState) {
|
1330
|
+
// If SDL_INIT_JOYSTICK was supplied AND the joystick system is configured
|
1331
|
+
// to automatically query for events, query for joystick events.
|
1332
|
+
SDL.queryJoysticks();
|
1333
|
+
}
|
1174
1334
|
if (SDL.events.length === 0) return 0;
|
1175
1335
|
if (ptr) {
|
1176
1336
|
SDL.makeCEvent(SDL.events.shift(), ptr);
|
@@ -1219,11 +1379,11 @@ var LibrarySDL = {
|
|
1219
1379
|
surfData.colors = new Uint8Array(256 * 3); //256 RGB colors
|
1220
1380
|
}
|
1221
1381
|
|
1222
|
-
for (var i =
|
1223
|
-
var index = i *3;
|
1382
|
+
for (var i = 0; i < nColors; ++i) {
|
1383
|
+
var index = (firstColor + i) * 3;
|
1224
1384
|
surfData.colors[index] = {{{ makeGetValue('colors', 'i*4', 'i8', null, true) }}};
|
1225
|
-
surfData.colors[index +1] = {{{ makeGetValue('colors', 'i*4 +1', 'i8', null, true) }}};
|
1226
|
-
surfData.colors[index +2] = {{{ makeGetValue('colors', 'i*4 +2', 'i8', null, true) }}};
|
1385
|
+
surfData.colors[index + 1] = {{{ makeGetValue('colors', 'i*4 + 1', 'i8', null, true) }}};
|
1386
|
+
surfData.colors[index + 2] = {{{ makeGetValue('colors', 'i*4 + 2', 'i8', null, true) }}};
|
1227
1387
|
}
|
1228
1388
|
|
1229
1389
|
return 1;
|
@@ -1283,12 +1443,12 @@ var LibrarySDL = {
|
|
1283
1443
|
IMG_Load_RW: function(rwopsID, freeSrc) {
|
1284
1444
|
try {
|
1285
1445
|
// stb_image integration support
|
1286
|
-
|
1446
|
+
function cleanup() {
|
1287
1447
|
if (rwops && freeSrc) _SDL_FreeRW(rwopsID);
|
1288
1448
|
};
|
1289
1449
|
function addCleanup(func) {
|
1290
1450
|
var old = cleanup;
|
1291
|
-
cleanup = function() {
|
1451
|
+
cleanup = function added_cleanup() {
|
1292
1452
|
old();
|
1293
1453
|
func();
|
1294
1454
|
}
|
@@ -1451,7 +1611,7 @@ var LibrarySDL = {
|
|
1451
1611
|
} else if (SDL.audio.channels != 1 && SDL.audio.channels != 2) { // Unsure what SDL audio spec supports. Web Audio spec supports up to 32 channels.
|
1452
1612
|
console.log('Warning: Using untested number of audio channels ' + SDL.audio.channels);
|
1453
1613
|
}
|
1454
|
-
if (SDL.audio.samples <
|
1614
|
+
if (SDL.audio.samples < 128 || SDL.audio.samples > 524288 /* arbitrary cap */) {
|
1455
1615
|
throw 'Unsupported audio callback buffer size ' + SDL.audio.samples + '!';
|
1456
1616
|
} else if ((SDL.audio.samples & (SDL.audio.samples-1)) != 0) {
|
1457
1617
|
throw 'Audio callback buffer size ' + SDL.audio.samples + ' must be a power-of-two!';
|
@@ -1462,8 +1622,12 @@ var LibrarySDL = {
|
|
1462
1622
|
SDL.audio.bufferSize = totalSamples*SDL.audio.bytesPerSample;
|
1463
1623
|
SDL.audio.buffer = _malloc(SDL.audio.bufferSize);
|
1464
1624
|
|
1625
|
+
// To account for jittering in frametimes, always have multiple audio buffers queued up for the audio output device.
|
1626
|
+
// This helps that we won't starve that easily if a frame takes long to complete.
|
1627
|
+
SDL.audio.numSimultaneouslyQueuedBuffers = Module['SDL_numSimultaneouslyQueuedBuffers'] || 3;
|
1628
|
+
|
1465
1629
|
// Create a callback function that will be routinely called to ask more audio data from the user application.
|
1466
|
-
SDL.audio.caller = function() {
|
1630
|
+
SDL.audio.caller = function SDL_audio_caller() {
|
1467
1631
|
if (!SDL.audio) {
|
1468
1632
|
return;
|
1469
1633
|
}
|
@@ -1477,7 +1641,8 @@ var LibrarySDL = {
|
|
1477
1641
|
SDL.audio.audioOutput['mozSetup'](SDL.audio.channels, SDL.audio.freq); // use string attributes on mozOutput for closure compiler
|
1478
1642
|
SDL.audio.mozBuffer = new Float32Array(totalSamples);
|
1479
1643
|
SDL.audio.nextPlayTime = 0;
|
1480
|
-
SDL.audio.pushAudio = function(ptr, size) {
|
1644
|
+
SDL.audio.pushAudio = function SDL_audio_pushAudio(ptr, size) {
|
1645
|
+
--SDL.audio.numAudioTimersPending;
|
1481
1646
|
var mozBuffer = SDL.audio.mozBuffer;
|
1482
1647
|
// The input audio data for SDL audio is either 8-bit or 16-bit interleaved across channels, output for Mozilla Audio Data API
|
1483
1648
|
// needs to be Float32 interleaved, so perform a sample conversion.
|
@@ -1496,14 +1661,22 @@ var LibrarySDL = {
|
|
1496
1661
|
|
1497
1662
|
// Compute when the next audio callback should be called.
|
1498
1663
|
var curtime = Date.now() / 1000.0 - SDL.audio.startTime;
|
1664
|
+
#if ASSERTIONS
|
1499
1665
|
if (curtime > SDL.audio.nextPlayTime && SDL.audio.nextPlayTime != 0) {
|
1500
1666
|
console.log('warning: Audio callback had starved sending audio by ' + (curtime - SDL.audio.nextPlayTime) + ' seconds.');
|
1501
1667
|
}
|
1668
|
+
#endif
|
1502
1669
|
var playtime = Math.max(curtime, SDL.audio.nextPlayTime);
|
1503
1670
|
var buffer_duration = SDL.audio.samples / SDL.audio.freq;
|
1504
1671
|
SDL.audio.nextPlayTime = playtime + buffer_duration;
|
1505
|
-
// Schedule the next audio callback call.
|
1672
|
+
// Schedule the next audio callback call to occur when the current one finishes.
|
1506
1673
|
SDL.audio.timer = Browser.safeSetTimeout(SDL.audio.caller, 1000.0 * (playtime-curtime));
|
1674
|
+
++SDL.audio.numAudioTimersPending;
|
1675
|
+
// And also schedule extra buffers _now_ if we have too few in queue.
|
1676
|
+
if (SDL.audio.numAudioTimersPending < SDL.audio.numSimultaneouslyQueuedBuffers) {
|
1677
|
+
++SDL.audio.numAudioTimersPending;
|
1678
|
+
Browser.safeSetTimeout(SDL.audio.caller, 1.0);
|
1679
|
+
}
|
1507
1680
|
}
|
1508
1681
|
} else {
|
1509
1682
|
// Initialize Web Audio API if we haven't done so yet. Note: Only initialize Web Audio context ever once on the web page,
|
@@ -1566,9 +1739,11 @@ var LibrarySDL = {
|
|
1566
1739
|
// Schedule the generated sample buffer to be played out at the correct time right after the previously scheduled
|
1567
1740
|
// sample buffer has finished.
|
1568
1741
|
var curtime = SDL.audioContext['currentTime'];
|
1569
|
-
|
1570
|
-
|
1571
|
-
|
1742
|
+
#if ASSERTIONS
|
1743
|
+
if (curtime > SDL.audio.nextPlayTime && SDL.audio.nextPlayTime != 0) {
|
1744
|
+
console.log('warning: Audio callback had starved sending audio by ' + (curtime - SDL.audio.nextPlayTime) + ' seconds.');
|
1745
|
+
}
|
1746
|
+
#endif
|
1572
1747
|
var playtime = Math.max(curtime, SDL.audio.nextPlayTime);
|
1573
1748
|
SDL.audio.soundSource[SDL.audio.nextSoundSource]['start'](playtime);
|
1574
1749
|
var buffer_duration = sizeSamplesPerChannel / SDL.audio.freq;
|
@@ -1583,8 +1758,8 @@ var LibrarySDL = {
|
|
1583
1758
|
++SDL.audio.numAudioTimersPending;
|
1584
1759
|
}
|
1585
1760
|
|
1586
|
-
// If we are risking starving, immediately queue
|
1587
|
-
if (secsUntilNextCall <= buffer_duration && SDL.audio.numAudioTimersPending
|
1761
|
+
// If we are risking starving, immediately queue extra buffers.
|
1762
|
+
if (secsUntilNextCall <= buffer_duration && SDL.audio.numAudioTimersPending < SDL.audio.numSimultaneouslyQueuedBuffers) {
|
1588
1763
|
++SDL.audio.numAudioTimersPending;
|
1589
1764
|
Browser.safeSetTimeout(SDL.audio.caller, 1.0);
|
1590
1765
|
}
|
@@ -1737,23 +1912,19 @@ var LibrarySDL = {
|
|
1737
1912
|
var filename = '';
|
1738
1913
|
var audio;
|
1739
1914
|
var bytes;
|
1740
|
-
|
1915
|
+
|
1741
1916
|
if (rwops.filename !== undefined) {
|
1742
1917
|
filename = PATH.resolve(rwops.filename);
|
1743
1918
|
var raw = Module["preloadedAudios"][filename];
|
1744
1919
|
if (!raw) {
|
1745
1920
|
if (raw === null) Module.printErr('Trying to reuse preloaded audio, but freePreloadedMediaOnUse is set!');
|
1746
1921
|
Runtime.warnOnce('Cannot find preloaded audio ' + filename);
|
1747
|
-
|
1922
|
+
|
1748
1923
|
// see if we can read the file-contents from the in-memory FS
|
1749
|
-
|
1750
|
-
|
1751
|
-
|
1752
|
-
|
1753
|
-
// We found the file. Load the contents
|
1754
|
-
if (fileObject && !fileObject.isFolder && fileObject.read) {
|
1755
|
-
bytes = fileObject.contents;
|
1756
|
-
} else {
|
1924
|
+
try {
|
1925
|
+
bytes = FS.readFile(filename);
|
1926
|
+
} catch (e) {
|
1927
|
+
Module.printErr('Couldn\'t find file for: ' + filename);
|
1757
1928
|
return 0;
|
1758
1929
|
}
|
1759
1930
|
}
|
@@ -1768,16 +1939,16 @@ var LibrarySDL = {
|
|
1768
1939
|
else {
|
1769
1940
|
return 0;
|
1770
1941
|
}
|
1771
|
-
|
1942
|
+
|
1772
1943
|
// Here, we didn't find a preloaded audio but we either were passed a filepath for
|
1773
1944
|
// which we loaded bytes, or we were passed some bytes
|
1774
1945
|
if (audio === undefined && bytes) {
|
1775
|
-
var blob = new Blob([
|
1946
|
+
var blob = new Blob([bytes], {type: rwops.mimetype});
|
1776
1947
|
var url = URL.createObjectURL(blob);
|
1777
1948
|
audio = new Audio();
|
1778
1949
|
audio.src = url;
|
1779
1950
|
}
|
1780
|
-
|
1951
|
+
|
1781
1952
|
var id = SDL.audios.length;
|
1782
1953
|
// Keep the loaded audio in the audio arrays, ready for playback
|
1783
1954
|
SDL.audios.push({
|
@@ -1844,7 +2015,7 @@ var LibrarySDL = {
|
|
1844
2015
|
audio.frequency = info.audio.frequency;
|
1845
2016
|
// TODO: handle N loops. Behavior matches Mix_PlayMusic
|
1846
2017
|
audio.loop = loops != 0;
|
1847
|
-
audio['onended'] = function() { // TODO: cache these
|
2018
|
+
audio['onended'] = function SDL_audio_onended() { // TODO: cache these
|
1848
2019
|
channelInfo.audio = null;
|
1849
2020
|
if (SDL.channelFinished) {
|
1850
2021
|
Runtime.getFuncWrapper(SDL.channelFinished, 'vi')(channel);
|
@@ -1871,7 +2042,7 @@ var LibrarySDL = {
|
|
1871
2042
|
source.loop = false;
|
1872
2043
|
source.buffer = context.createBuffer(numChannels, 1, audio.frequency);
|
1873
2044
|
var jsNode = context.createJavaScriptNode(2048, numChannels, numChannels);
|
1874
|
-
jsNode.onaudioprocess = function(event) {
|
2045
|
+
jsNode.onaudioprocess = function jsNode_onaudioprocess(event) {
|
1875
2046
|
var buffers = new Array(numChannels);
|
1876
2047
|
for (var i = 0; i < numChannels; ++i) {
|
1877
2048
|
buffers[i] = event.outputBuffer.getChannelData(i);
|
@@ -2357,37 +2528,103 @@ var LibrarySDL = {
|
|
2357
2528
|
|
2358
2529
|
// Joysticks
|
2359
2530
|
|
2360
|
-
SDL_NumJoysticks: function() {
|
2531
|
+
SDL_NumJoysticks: function() {
|
2532
|
+
var count = 0;
|
2533
|
+
var gamepads = SDL.getGamepads();
|
2534
|
+
// The length is not the number of gamepads; check which ones are defined.
|
2535
|
+
for (var i = 0; i < gamepads.length; i++) {
|
2536
|
+
if (gamepads[i] !== undefined) count++;
|
2537
|
+
}
|
2538
|
+
return count;
|
2539
|
+
},
|
2361
2540
|
|
2362
|
-
SDL_JoystickName: function(deviceIndex) {
|
2541
|
+
SDL_JoystickName: function(deviceIndex) {
|
2542
|
+
var gamepad = SDL.getGamepad(deviceIndex);
|
2543
|
+
if (gamepad) {
|
2544
|
+
var name = gamepad.id;
|
2545
|
+
if (SDL.joystickNamePool.hasOwnProperty(name)) {
|
2546
|
+
return SDL.joystickNamePool[name];
|
2547
|
+
}
|
2548
|
+
return SDL.joystickNamePool[name] = allocate(intArrayFromString(name), 'i8', ALLOC_NORMAL);
|
2549
|
+
}
|
2550
|
+
return 0;
|
2551
|
+
},
|
2363
2552
|
|
2364
|
-
SDL_JoystickOpen: function(deviceIndex) {
|
2553
|
+
SDL_JoystickOpen: function(deviceIndex) {
|
2554
|
+
var gamepad = SDL.getGamepad(deviceIndex);
|
2555
|
+
if (gamepad) {
|
2556
|
+
// Use this as a unique 'pointer' for this joystick.
|
2557
|
+
var joystick = deviceIndex+1;
|
2558
|
+
SDL.recordJoystickState(joystick, gamepad);
|
2559
|
+
return joystick;
|
2560
|
+
}
|
2561
|
+
return 0;
|
2562
|
+
},
|
2365
2563
|
|
2366
|
-
SDL_JoystickOpened: function(deviceIndex) {
|
2564
|
+
SDL_JoystickOpened: function(deviceIndex) {
|
2565
|
+
return SDL.lastJoystickState.hasOwnProperty(deviceIndex+1) ? 1 : 0;
|
2566
|
+
},
|
2367
2567
|
|
2368
|
-
SDL_JoystickIndex: function(joystick) {
|
2568
|
+
SDL_JoystickIndex: function(joystick) {
|
2569
|
+
// joystick pointers are simply the deviceIndex+1.
|
2570
|
+
return joystick - 1;
|
2571
|
+
},
|
2369
2572
|
|
2370
|
-
SDL_JoystickNumAxes: function(joystick) {
|
2573
|
+
SDL_JoystickNumAxes: function(joystick) {
|
2574
|
+
var gamepad = SDL.getGamepad(joystick - 1);
|
2575
|
+
if (gamepad) {
|
2576
|
+
return gamepad.axes.length;
|
2577
|
+
}
|
2578
|
+
return 0;
|
2579
|
+
},
|
2371
2580
|
|
2372
2581
|
SDL_JoystickNumBalls: function(joystick) { return 0; },
|
2373
2582
|
|
2374
2583
|
SDL_JoystickNumHats: function(joystick) { return 0; },
|
2375
2584
|
|
2376
|
-
SDL_JoystickNumButtons: function(joystick) {
|
2585
|
+
SDL_JoystickNumButtons: function(joystick) {
|
2586
|
+
var gamepad = SDL.getGamepad(joystick - 1);
|
2587
|
+
if (gamepad) {
|
2588
|
+
return gamepad.buttons.length;
|
2589
|
+
}
|
2590
|
+
return 0;
|
2591
|
+
},
|
2377
2592
|
|
2378
|
-
SDL_JoystickUpdate: function() {
|
2593
|
+
SDL_JoystickUpdate: function() {
|
2594
|
+
SDL.queryJoysticks();
|
2595
|
+
},
|
2379
2596
|
|
2380
|
-
SDL_JoystickEventState: function(state) {
|
2597
|
+
SDL_JoystickEventState: function(state) {
|
2598
|
+
if (state < 0) {
|
2599
|
+
// SDL_QUERY: Return current state.
|
2600
|
+
return SDL.joystickEventState;
|
2601
|
+
}
|
2602
|
+
return SDL.joystickEventState = state;
|
2603
|
+
},
|
2381
2604
|
|
2382
|
-
SDL_JoystickGetAxis: function(joystick, axis) {
|
2605
|
+
SDL_JoystickGetAxis: function(joystick, axis) {
|
2606
|
+
var gamepad = SDL.getGamepad(joystick - 1);
|
2607
|
+
if (gamepad && gamepad.axes.length > axis) {
|
2608
|
+
return SDL.joystickAxisValueConversion(gamepad.axes[axis]);
|
2609
|
+
}
|
2610
|
+
return 0;
|
2611
|
+
},
|
2383
2612
|
|
2384
2613
|
SDL_JoystickGetHat: function(joystick, hat) { return 0; },
|
2385
2614
|
|
2386
2615
|
SDL_JoystickGetBall: function(joystick, ball, dxptr, dyptr) { return -1; },
|
2387
2616
|
|
2388
|
-
SDL_JoystickGetButton: function(joystick, button) {
|
2617
|
+
SDL_JoystickGetButton: function(joystick, button) {
|
2618
|
+
var gamepad = SDL.getGamepad(joystick - 1);
|
2619
|
+
if (gamepad && gamepad.buttons.length > button) {
|
2620
|
+
return SDL.getJoystickButtonState(gamepad.buttons[button]) ? 1 : 0;
|
2621
|
+
}
|
2622
|
+
return 0;
|
2623
|
+
},
|
2389
2624
|
|
2390
|
-
SDL_JoystickClose: function(joystick) {
|
2625
|
+
SDL_JoystickClose: function(joystick) {
|
2626
|
+
delete SDL.lastJoystickState[joystick];
|
2627
|
+
},
|
2391
2628
|
|
2392
2629
|
// Misc
|
2393
2630
|
|
@@ -2436,7 +2673,7 @@ var LibrarySDL = {
|
|
2436
2673
|
|
2437
2674
|
SDL_WaitThread: function() { throw 'SDL_WaitThread' },
|
2438
2675
|
SDL_GetThreadID: function() { throw 'SDL_GetThreadID' },
|
2439
|
-
SDL_ThreadID: function() {
|
2676
|
+
SDL_ThreadID: function() { return 0; },
|
2440
2677
|
SDL_AllocRW: function() { throw 'SDL_AllocRW: TODO' },
|
2441
2678
|
SDL_CondBroadcast: function() { throw 'SDL_CondBroadcast: TODO' },
|
2442
2679
|
SDL_CondWaitTimeout: function() { throw 'SDL_CondWaitTimeout: TODO' },
|
@@ -1,6 +1,6 @@
|
|
1
1
|
mergeInto(LibraryManager.library, {
|
2
2
|
$SOCKFS__postset: '__ATINIT__.push({ func: function() { SOCKFS.root = FS.mount(SOCKFS, {}, null); } });',
|
3
|
-
$SOCKFS__deps: ['$FS'],
|
3
|
+
$SOCKFS__deps: ['$FS', 'mkport'],
|
4
4
|
$SOCKFS: {
|
5
5
|
mount: function(mount) {
|
6
6
|
return FS.createNode(null, '/', {{{ cDefine('S_IFDIR') }}} | 0777, 0);
|
@@ -138,7 +138,9 @@ mergeInto(LibraryManager.library, {
|
|
138
138
|
console.log('connect: ' + url);
|
139
139
|
#endif
|
140
140
|
// the node ws library API is slightly different than the browser's
|
141
|
-
var opts = ENVIRONMENT_IS_NODE ? {} : ['binary'];
|
141
|
+
var opts = ENVIRONMENT_IS_NODE ? {headers: {'websocket-protocol': ['binary']}} : ['binary'];
|
142
|
+
// If node we use the ws library.
|
143
|
+
var WebSocket = ENVIRONMENT_IS_NODE ? require('ws') : window['WebSocket'];
|
142
144
|
ws = new WebSocket(url, opts);
|
143
145
|
ws.binaryType = 'arraybuffer';
|
144
146
|
} catch (e) {
|
@@ -208,7 +210,7 @@ mergeInto(LibraryManager.library, {
|
|
208
210
|
}
|
209
211
|
};
|
210
212
|
|
211
|
-
|
213
|
+
function handleMessage(data) {
|
212
214
|
assert(typeof data !== 'string' && data.byteLength !== undefined); // must receive an ArrayBuffer
|
213
215
|
data = new Uint8Array(data); // make a typed array view on the array buffer
|
214
216
|
|
@@ -247,7 +249,7 @@ mergeInto(LibraryManager.library, {
|
|
247
249
|
});
|
248
250
|
} else {
|
249
251
|
peer.socket.onopen = handleOpen;
|
250
|
-
peer.socket.onmessage = function(event) {
|
252
|
+
peer.socket.onmessage = function peer_socket_onmessage(event) {
|
251
253
|
handleMessage(event.data);
|
252
254
|
};
|
253
255
|
}
|
@@ -573,4 +575,4 @@ mergeInto(LibraryManager.library, {
|
|
573
575
|
}
|
574
576
|
}
|
575
577
|
}
|
576
|
-
});
|
578
|
+
});
|