Skip to content

Commit

Permalink
Use gen_struct_info for more things in library_sdl.js
Browse files Browse the repository at this point in the history
It looks like the hardcoded values here were actually wrong.
  • Loading branch information
sbc100 committed Sep 25, 2024
1 parent 4f0ffdd commit 845210c
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/library_sdl.js
Original file line number Diff line number Diff line change
Expand Up @@ -2668,19 +2668,19 @@ 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) {
rwops = { filename: stream.path };
}
}
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 };
}
Expand Down
23 changes: 23 additions & 0 deletions src/struct_info.json
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,29 @@
]
}
},
{
"file": "SDL/SDL_rwops.h",
"structs": {
"SDL_RWops": [
"type",
{
"hidden": [
{
"mem": [
"base",
"stop"
]
},
{
"stdio": [
"fp"
]
}
]
}
]
}
},
{
"file": "uuid/uuid.h",
"defines": [
Expand Down
16 changes: 16 additions & 0 deletions src/struct_info_generated.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 16 additions & 0 deletions src/struct_info_generated_wasm64.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 845210c

Please sign in to comment.