Skip to content

Commit

Permalink
fixes for newer emscripten
Browse files Browse the repository at this point in the history
  • Loading branch information
ianmaclarty committed Feb 23, 2020
1 parent dd223d6 commit 95f58b0
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ C99_OPT = -std=c99

EMSCRIPTEN_LIBS = html/library_sdl.js
EMSCRIPTEN_LIBS_OPTS = $(patsubst %,--js-library %,$(EMSCRIPTEN_LIBS))
EMSCRIPTEN_EXPORTS_OPT = -s EXPORTED_FUNCTIONS="['_main', '_am_emscripten_run', '_am_emscripten_run_waiting', '_am_emscripten_pause', '_am_emscripten_resume', '_am_emscripten_resize']" -s EXTRA_EXPORTED_RUNTIME_METHODS="['Pointer_stringify', 'ccall', 'stringToUTF8', 'lengthBytesUTF8']" -s BINARYEN_TRAP_MODE=clamp
EMSCRIPTEN_EXPORTS_OPT = -s EXPORTED_FUNCTIONS="['_main', '_am_emscripten_run', '_am_emscripten_run_waiting', '_am_emscripten_pause', '_am_emscripten_resume', '_am_emscripten_resize']" -s EXTRA_EXPORTED_RUNTIME_METHODS="['UTF8ToString', 'ccall', 'stringToUTF8', 'lengthBytesUTF8']" -s BINARYEN_TRAP_MODE=clamp

TARGET_CFLAGS=-ffast-math

Expand Down
18 changes: 9 additions & 9 deletions html/library_sdl.js
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ var LibrarySDL = {
var sdlEventPtr = allocate({{{ C_STRUCTS.SDL_KeyboardEvent.__size__ }}}, "i8", ALLOC_STACK);

while (SDL.pollEvent(sdlEventPtr)) {
Runtime.dynCall('iii', SDL.eventHandler, [SDL.eventHandlerContext, sdlEventPtr]);
dynCall('iii', SDL.eventHandler, [SDL.eventHandlerContext, sdlEventPtr]);
}
},

Expand Down Expand Up @@ -1751,7 +1751,7 @@ var LibrarySDL = {
if (secsUntilNextPlayStart >= SDL.audio.bufferingDelay + SDL.audio.bufferDurationSecs*SDL.audio.numSimultaneouslyQueuedBuffers) return;

// Ask SDL audio data from the user code.
Runtime.dynCall('viii', SDL.audio.callback, [SDL.audio.userdata, SDL.audio.buffer, SDL.audio.bufferSize]);
dynCall('viii', SDL.audio.callback, [SDL.audio.userdata, SDL.audio.buffer, SDL.audio.bufferSize]);
// And queue it to be played after the currently playing audio stream.
SDL.audio.pushAudio(SDL.audio.buffer, SDL.audio.bufferSize);
}
Expand Down Expand Up @@ -2238,7 +2238,7 @@ var LibrarySDL = {
}
SDL.music.audio = null;
if (SDL.hookMusicFinished) {
Runtime.dynCall('v', SDL.hookMusicFinished);
dynCall('v', SDL.hookMusicFinished);
}
return 0;
},
Expand Down Expand Up @@ -2324,7 +2324,7 @@ var LibrarySDL = {
},

TTF_OpenFont: function(filename, size) {
filename = FS.standardizePath(Pointer_stringify(filename));
filename = FS.standardizePath(UTF8ToString(filename));
var id = SDL.fonts.length;
SDL.fonts.push({
name: filename, // but we don't actually do anything with it..
Expand All @@ -2339,7 +2339,7 @@ var LibrarySDL = {

TTF_RenderText_Solid: function(font, text, color) {
// XXX the font and color are ignored
text = Pointer_stringify(text) || ' '; // if given an empty string, still return a valid surface
text = UTF8ToString(text) || ' '; // if given an empty string, still return a valid surface
var fontData = SDL.fonts[font];
var w = SDL.estimateTextWidth(fontData, text);
var h = fontData.size;
Expand All @@ -2362,7 +2362,7 @@ var LibrarySDL = {
TTF_SizeText: function(font, text, w, h) {
var fontData = SDL.fonts[font];
if (w) {
{{{ makeSetValue('w', '0', 'SDL.estimateTextWidth(fontData, Pointer_stringify(text))', 'i32') }}};
{{{ makeSetValue('w', '0', 'SDL.estimateTextWidth(fontData, UTF8ToString(text))', 'i32') }}};
}
if (h) {
{{{ makeSetValue('h', '0', 'fontData.size', 'i32') }}};
Expand Down Expand Up @@ -2573,7 +2573,7 @@ var LibrarySDL = {
},

SDL_SetWindowTitle: function(window, title) {
if (title) document.title = Pointer_stringify(title);
if (title) document.title = UTF8ToString(title);
},

SDL_GetWindowSize: function(window, width, height){
Expand Down Expand Up @@ -2735,7 +2735,7 @@ var LibrarySDL = {

SDL_RWFromFile: function(_name, mode) {
var id = SDL.rwops.length; // TODO: recycle ids when they are null
var name = Pointer_stringify(_name)
var name = UTF8ToString(_name)
SDL.rwops.push({ filename: name, mimetype: Browser.getMimetype(name) });
return id;
},
Expand Down Expand Up @@ -2763,7 +2763,7 @@ var LibrarySDL = {

SDL_AddTimer: function(interval, callback, param) {
return window.setTimeout(function() {
Runtime.dynCall('iii', callback, [interval, param]);
dynCall('iii', callback, [interval, param]);
}, interval);
},
SDL_RemoveTimer: function(id) {
Expand Down
2 changes: 1 addition & 1 deletion src/am_backend_emscripten.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ am_native_window *am_create_native_window(
init_mouse_state();
EM_ASM_INT({
var title_el = document.getElementById("title");
if (title_el) title_el.innerHTML = Module.Pointer_stringify($0);
if (title_el) title_el.innerHTML = Module.UTF8ToString($0);
}, title);
return (am_native_window*)sdl_window;
}
Expand Down
2 changes: 1 addition & 1 deletion src/am_browser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ static int eval_js(lua_State *L) {
const char *js = lua_tostring(L, 1);
if (js == NULL) return luaL_error(L, "expecting a string at position 1");
int res_ptr = EM_ASM_INT({
var js_str = Pointer_stringify($0);
var js_str = UTF8ToString($0);
var res = eval(js_str);
var res_str;
if (res === undefined) {
Expand Down
4 changes: 2 additions & 2 deletions src/am_http.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ static int http_request(lua_State *L) {
if (!window.amulet.http_reqs) window.amulet.http_reqs = {};
var xhr = new XMLHttpRequest();
window.amulet.http_reqs[$0] = xhr;
var url = Pointer_stringify($1);
var url = UTF8ToString($1);
var data = null;
if ($2 == 0) {
xhr.open('GET', url, true);
xhr.send();
} else {
data = Pointer_stringify($2);
data = UTF8ToString($2);
xhr.open('POST', url, true);
xhr.send(data);
}
Expand Down

0 comments on commit 95f58b0

Please sign in to comment.