From 845210cf6ae14da7d87ef2aa4ee59b6fa19ef903 Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Wed, 25 Sep 2024 08:57:05 -0700 Subject: [PATCH] Use gen_struct_info for more things in library_sdl.js It looks like the hardcoded values here were actually wrong. --- src/library_sdl.js | 8 ++++---- src/struct_info.json | 23 +++++++++++++++++++++++ src/struct_info_generated.json | 16 ++++++++++++++++ src/struct_info_generated_wasm64.json | 16 ++++++++++++++++ 4 files changed, 59 insertions(+), 4 deletions(-) diff --git a/src/library_sdl.js b/src/library_sdl.js index 5ef41f6acd4c..9cf53f86a285 100644 --- a/src/library_sdl.js +++ b/src/library_sdl.js @@ -2668,10 +2668,10 @@ var LibrarySDL = { #if USE_SDL == 2 if (rwops === undefined) { - var type = {{{ makeGetValue('rwopsID', 20 /*type*/, 'i32') }}}; + var type = {{{ makeGetValue('rwopsID', C_STRUCTS.SDL_RWops.type, 'i32') }}}; if (type === 2/*SDL_RWOPS_STDFILE*/) { - var fp = {{{ makeGetValue('rwopsID', 28 /*hidden.stdio.fp*/, 'i32') }}}; + var fp = {{{ makeGetValue('rwopsID', C_STRUCTS.SDL_RWops.hidden.stdio.fp, 'i32') }}}; var fd = _fileno(fp); var stream = FS.getStream(fd); if (stream) { @@ -2679,8 +2679,8 @@ var LibrarySDL = { } } else if (type === 4/*SDL_RWOPS_MEMORY*/ || type === 5/*SDL_RWOPS_MEMORY_RO*/) { - var base = {{{ makeGetValue('rwopsID', 24 /*hidden.mem.base*/, 'i32') }}}; - var stop = {{{ makeGetValue('rwopsID', 32 /*hidden.mem.stop*/, 'i32') }}}; + var base = {{{ makeGetValue('rwopsID', C_STRUCTS.SDL_RWops.hidden.mem.base, 'i32') }}}; + var stop = {{{ makeGetValue('rwopsID', C_STRUCTS.SDL_RWops.hidden.mem.stop, 'i32') }}}; rwops = { bytes: base, count: stop - base }; } diff --git a/src/struct_info.json b/src/struct_info.json index c8541c3e2454..dd55b17cf29f 100644 --- a/src/struct_info.json +++ b/src/struct_info.json @@ -705,6 +705,29 @@ ] } }, + { + "file": "SDL/SDL_rwops.h", + "structs": { + "SDL_RWops": [ + "type", + { + "hidden": [ + { + "mem": [ + "base", + "stop" + ] + }, + { + "stdio": [ + "fp" + ] + } + ] + } + ] + } + }, { "file": "uuid/uuid.h", "defines": [ diff --git a/src/struct_info_generated.json b/src/struct_info_generated.json index 6fc3cdb87ee6..be07598c2e9a 100644 --- a/src/struct_info_generated.json +++ b/src/struct_info_generated.json @@ -744,6 +744,22 @@ "format": 0, "palette": 4 }, + "SDL_RWops": { + "__size__": 32, + "hidden": { + "__size__": 12, + "mem": { + "__size__": 12, + "base": 20, + "stop": 28 + }, + "stdio": { + "__size__": 8, + "fp": 24 + } + }, + "type": 16 + }, "SDL_Rect": { "__size__": 16, "h": 12, diff --git a/src/struct_info_generated_wasm64.json b/src/struct_info_generated_wasm64.json index 9a424fb07f11..781ed17113fa 100644 --- a/src/struct_info_generated_wasm64.json +++ b/src/struct_info_generated_wasm64.json @@ -744,6 +744,22 @@ "format": 0, "palette": 8 }, + "SDL_RWops": { + "__size__": 64, + "hidden": { + "__size__": 24, + "mem": { + "__size__": 24, + "base": 40, + "stop": 56 + }, + "stdio": { + "__size__": 16, + "fp": 48 + } + }, + "type": 32 + }, "SDL_Rect": { "__size__": 16, "h": 12,