It seems that on android SDL wants to read files from the assets directory. I would like to read from an arbitrary location (really the external storage /sdcard). Is there some way for SDL to support this directly? My current thought is to implement my own SDL_RWOps that use plain posix file IO and pass those ops to SDL_LoadBMP() and whatnot.
I want to read files from the sdcard because I expect users to add additional data to my game (extra characters, stages, music, etc).
A follow up to this: I forced SDL to use standard stdio operations.
SDL/src/file/SDL_rwops.c:448
Code:
#if defined(ANDROID) && defined(DONT_CARE)
So instead of using the android functions it will fall to the #if defined(HAVE_STDIO_H) and use that instead. Now my application can load files from regular filesystem paths.
I figured it’d be easier to extract everything to internal storage so
I could leave the rest of the code the same as on other platforms.
But now I’ve tried also just loading them straight in with RWops and
there’s definitely a problem in that part.
I’m pretty much doing the same thing. I’m copying an asset from the apk to
internal storage so that it can be modified by the user (custom game
levels).
The only difference I can see is that my code uses SDL_RWFromFile() for
file_out instead of going through a FILE pointer. What problems are you
experiencing? Does logcat tell you anything interesting? Did you do a
sanity check over your paths and the function results? Are you using the
official SDL 2.0 build or are you using the latest from hg?
Jonny DOn Thu, Sep 19, 2013 at 10:03 PM, Michael Brough wrote:
Hi, I’m struggling to get basic file IO working on android, using
SDL_RWops to decompress files from the .apk. Am I missing something
really obvious?
I figured it’d be easier to extract everything to internal storage so
I could leave the rest of the code the same as on other platforms.
But now I’ve tried also just loading them straight in with RWops and
there’s definitely a problem in that part.
SDL_RWFromFile returns something non-NULL, but then trying to
SDL_RWread on that gives nothing / 0 bytes.
I got it from hg since the 2.0 release, not sure how to tell whether
it’s the stable/dev branch.
thanks,> ------------------------------
Message: 2
Date: Thu, 19 Sep 2013 23:20:08 -0400
From: Jonathan Dearborn
To: SDL Development List
Subject: Re: [SDL] reading files on android
Message-ID:
<CA+DSiHb1DO–AgBzQ1NC1gV27dtKsYy=1Q13fm-f6Xafyu5sTw at mail.gmail.com>
Content-Type: text/plain; charset=“iso-8859-1”
I’m pretty much doing the same thing. I’m copying an asset from the apk to
internal storage so that it can be modified by the user (custom game
levels).
The only difference I can see is that my code uses SDL_RWFromFile() for
file_out instead of going through a FILE pointer. What problems are you
experiencing? Does logcat tell you anything interesting? Did you do a
sanity check over your paths and the function results? Are you using the
official SDL 2.0 build or are you using the latest from hg?
Jonny D
On Thu, Sep 19, 2013 at 10:03 PM, Michael Brough <@Michael_Brough> wrote:
Hi, I’m struggling to get basic file IO working on android, using
SDL_RWops to decompress files from the .apk. Am I missing something
really obvious?
I figured it’d be easier to extract everything to internal storage so
I could leave the rest of the code the same as on other platforms.
But now I’ve tried also just loading them straight in with RWops and
there’s definitely a problem in that part.
Any chance that SDL_GetError() tells you anything? Have you checked your
read buffer data to see which operation (read or write) is having problems?
If reading is a problem, can you successfully load assets via SDL_image,
SDL_mixer, or something else that uses SDL_RWops?
Jonny DOn Fri, Sep 20, 2013 at 1:35 PM, Michael Brough wrote:
logcat doesn’t say anything relevant.
SDL_RWFromFile returns something non-NULL, but then trying to
SDL_RWread on that gives nothing / 0 bytes.
I got it from hg since the 2.0 release, not sure how to tell whether
it’s the stable/dev branch.
thanks,
Message: 2
Date: Thu, 19 Sep 2013 23:20:08 -0400
From: Jonathan Dearborn <@Jonathan_Dearborn>
To: SDL Development List
Subject: Re: [SDL] reading files on android
Message-ID:
<CA+DSiHb1DO–AgBzQ1NC1gV27dtKsYy=
1Q13fm-f6Xafyu5sTw at mail.gmail.com>
Content-Type: text/plain; charset=“iso-8859-1”
I’m pretty much doing the same thing. I’m copying an asset from the apk
to
internal storage so that it can be modified by the user (custom game
levels).
The only difference I can see is that my code uses SDL_RWFromFile() for
file_out instead of going through a FILE pointer. What problems are you
experiencing? Does logcat tell you anything interesting? Did you do a
sanity check over your paths and the function results? Are you using the
official SDL 2.0 build or are you using the latest from hg?
Jonny D
On Thu, Sep 19, 2013 at 10:03 PM, Michael Brough wrote:
Hi, I’m struggling to get basic file IO working on android, using
SDL_RWops to decompress files from the .apk. Am I missing something
really obvious?
I figured it’d be easier to extract everything to internal storage so
I could leave the rest of the code the same as on other platforms.
But now I’ve tried also just loading them straight in with RWops and
there’s definitely a problem in that part.