diff options
-rw-r--r-- | AUTHORS | 1 | ||||
-rw-r--r-- | src/closure-externs.js | 60 | ||||
-rw-r--r-- | src/runtime.js | 5 | ||||
-rw-r--r-- | tests/sdl_wm_togglefullscreen.c | 11 | ||||
-rw-r--r-- | tools/file_packager.py | 16 | ||||
-rw-r--r-- | tools/profile_stripper.py | 24 | ||||
-rw-r--r-- | tools/profile_used.py | 11 |
7 files changed, 106 insertions, 22 deletions
@@ -130,4 +130,5 @@ a license to everyone to use it as detailed in LICENSE.) * Nicolas Peri <nicox@shivaengine.com> (copyright owned by ShiVa Technologies, SAS) * Bernhard Fey <e-male@web.de> * Dave Nicponski <dave.nicponski@gmail.com> +* Jonathan Jarri <noxalus@gmail.com> diff --git a/src/closure-externs.js b/src/closure-externs.js index a82aa669..fe6d84aa 100644 --- a/src/closure-externs.js +++ b/src/closure-externs.js @@ -108,3 +108,63 @@ var flags = {}; flags.binary; +/** + * @fileoverview Definitions for W3C's Gamepad specification. + * @see http://www.w3.org/TR/gamepad/ + * @externs + */ + +/** + * @typedef {{id: string, index: number, timestamp: number, axes: Array.<number>, buttons: Array.<number>}} + */ +var Gamepad; + +/** +* @type {Array.<number>} +*/ +Gamepad.buttons; + +/** +* @type {Array.<number>} +*/ +Gamepad.axes; + +/** +* @type {number} +*/ +Gamepad.index; + +/** +* @type {string} +*/ +Gamepad.id; + +/** +* @type {number} +*/ +Gamepad.timestamp; + +/** + * @return {Array.<Gamepad>} + */ +navigator.getGamepads = function() {}; + +/** + * @return {Array.<Gamepad>} + */ +navigator.webkitGetGamepads = function() {}; + +/** + * @return {Array.<Gamepad>} + */ +navigator.webkitGamepads = function() {}; + +/** + * @return {Array.<Gamepad>} + */ +navigator.mozGamepads = function() {}; + +/** + * @return {Array.<Gamepad>} + */ +navigator.gamepads = function() {}; diff --git a/src/runtime.js b/src/runtime.js index 97de7473..2ae68279 100644 --- a/src/runtime.js +++ b/src/runtime.js @@ -484,6 +484,11 @@ var Runtime = { return ret; } this.processJSString = function processJSString(string) { + /* TODO: use TextEncoder when present, + var encoder = new TextEncoder(); + encoder['encoding'] = "utf-8"; + var utf8Array = encoder['encode'](aMsg.data); + */ string = unescape(encodeURIComponent(string)); var ret = []; for (var i = 0; i < string.length; i++) { diff --git a/tests/sdl_wm_togglefullscreen.c b/tests/sdl_wm_togglefullscreen.c index b8052988..c76ced76 100644 --- a/tests/sdl_wm_togglefullscreen.c +++ b/tests/sdl_wm_togglefullscreen.c @@ -12,7 +12,15 @@ int inFullscreen = 0; int wasFullscreen = 0; +void render() { + int width, height, isfs; + emscripten_get_canvas_size(&width, &height, &isfs); + SDL_Rect rect = { 0, 0, width, height }; + SDL_FillRect(screen, &rect, 0xff00ffff); +} + void mainloop() { + render(); SDL_Event event; int isInFullscreen = EM_ASM_INT_V(return !!(document.fullscreenElement || document.mozFullScreenElement || document.webkitFullscreenElement || document.msFullscreenElement)); if (isInFullscreen && !wasFullscreen) { @@ -62,9 +70,6 @@ int main() { SDL_Init(SDL_INIT_VIDEO); screen = SDL_SetVideoMode(600, 450, 32, SDL_HWSURFACE); - SDL_Rect rect = { 0, 0, 600, 450 }; - SDL_FillRect(screen, &rect, 0xff00ffff); - printf("You should see a yellow canvas.\n"); printf("Click on the canvas to enter full screen, and then click on the canvas again to finish the test.\n"); printf("When in full screen, you should see the whole screen filled yellow, and after exiting, the yellow canvas should be restored in the window.\n"); diff --git a/tools/file_packager.py b/tools/file_packager.py index 12cc5475..0ab68511 100644 --- a/tools/file_packager.py +++ b/tools/file_packager.py @@ -113,7 +113,7 @@ for arg in sys.argv[2:]: try: from shared import CRUNCH except Exception, e: - print >> sys.stderr, 'count not import CRUNCH (make sure it is defined properly in ~/.emscripten)' + print >> sys.stderr, 'could not import CRUNCH (make sure it is defined properly in ~/.emscripten)' raise e crunch = arg.split('=')[1] if '=' in arg else '128' leading = '' @@ -123,12 +123,13 @@ for arg in sys.argv[2:]: leading = '' elif leading == 'preload' or leading == 'embed': mode = leading - if '@' in arg: + uses_at_notation = '@' in arg + if uses_at_notation: srcpath, dstpath = arg.split('@') # User is specifying destination filename explicitly. else: srcpath = dstpath = arg # Use source path as destination path. if os.path.isfile(srcpath) or os.path.isdir(srcpath): - data_files.append({ 'srcpath': srcpath, 'dstpath': dstpath, 'mode': mode }) + data_files.append({ 'srcpath': srcpath, 'dstpath': dstpath, 'mode': mode, 'explicit_dst_path': uses_at_notation }) else: print >> sys.stderr, 'Warning: ' + arg + ' does not exist, ignoring.' elif leading == 'exclude': @@ -206,7 +207,7 @@ def add(arg, dirname, names): new_names.append(name) if not os.path.isdir(fullname): dstpath = os.path.join(rootpathdst, os.path.relpath(fullname, rootpathsrc)) # Convert source filename relative to root directory of target FS. - new_data_files.append({ 'srcpath': fullname, 'dstpath': dstpath, 'mode': mode }) + new_data_files.append({ 'srcpath': fullname, 'dstpath': dstpath, 'mode': mode, 'explicit_dst_path': True }) del names[:] names.extend(new_names) @@ -223,13 +224,14 @@ if len(data_files) == 0: sys.exit(1) # Absolutize paths, and check that they make sense -curr_abspath = os.path.abspath(os.getcwd()) +curr_abspath = os.path.abspath(os.getcwd()) # os.getcwd() always returns the hard path with any symbolic links resolved, even if we cd'd into a symbolic link. + for file_ in data_files: - if file_['srcpath'] == file_['dstpath']: + if not file_['explicit_dst_path']: # This file was not defined with src@dst, so we inferred the destination from the source. In that case, # we require that the destination not be under the current location path = file_['dstpath'] - abspath = os.path.abspath(path) + abspath = os.path.realpath(os.path.abspath(path)) # Use os.path.realpath to resolve any symbolic links to hard paths, to match the structure in curr_abspath. if DEBUG: print >> sys.stderr, path, abspath, curr_abspath if not abspath.startswith(curr_abspath): print >> sys.stderr, 'Error: Embedding "%s" which is below the current directory "%s". This is invalid since the current directory becomes the root that the generated code will see' % (path, curr_abspath) diff --git a/tools/profile_stripper.py b/tools/profile_stripper.py index bbc23937..3e538ef3 100644 --- a/tools/profile_stripper.py +++ b/tools/profile_stripper.py @@ -7,15 +7,37 @@ import sys, json used = json.loads(open(sys.argv[1]).read()) show = True +in_table = False for orig in open(sys.argv[2]).readlines(): line = orig.strip() + if orig.startswith('function _') and line.endswith(('){', ') {')): name = line.split(' ')[1].split('(')[0] if name.startswith('_') and not used.get(name): #print >> sys.stderr, 'remove', name show = False - if show: print orig, + + if line.startswith('var FUNCTION_TABLE'): + in_table = True + + if in_table: + start = 0 + if 'var ' in line: + start = line.index('[')+1 + end = len(line) + if ']' in line: + end = line.index(']') + contents = line[start:end] + fixed = map(lambda name: '"' + name + '"' if not used.get(name) else name, contents.split(',')) + print (line[:start] + ','.join(fixed) + line[end:]).replace('""', '') + else: + if show: + print orig, + if orig.startswith('}'): show = True + if in_table and line.endswith(';'): + in_table = False + diff --git a/tools/profile_used.py b/tools/profile_used.py index b954f7d1..45420e0f 100644 --- a/tools/profile_used.py +++ b/tools/profile_used.py @@ -7,10 +7,6 @@ dump(JSON.stringify(usedFunctions)) import sys print 'var usedFunctions = {};' -#print "function getFuncName(f) { return f.toString().split(' ')[1].split('(')[0] }" -print "function getFuncName(f) { return f.name }" - -last = [] for line in open(sys.argv[1]).readlines(): line = line.strip() @@ -18,11 +14,4 @@ for line in open(sys.argv[1]).readlines(): if line.startswith('function _') and line.endswith(('){', ') {')): name = line.split(' ')[1].split('(')[0] print 'usedFunctions["%s"] = 1;' % name - if line.startswith('var FUNCTION_TABLE'): - name = line.split(' ')[1].split('=')[0] - last += ['for (var i = 0; i < %s.length; i++) if (typeof %s[i] === "function") usedFunctions[getFuncName(%s[i])] = 1;' % (name, name, name)] - if len(last) > 0 and line.endswith(';'): - for l in last: - print l - last = [] |