[SOLVED] Android resource management |
Android resource management |
gabomdq
|
On Lun 07 Nov 2011 17:17:11 wilbefast escribió:
I don't completely understand what you are asking, so apologies in advance if I'm answering a question you didn't ask, but SDL supports asset reading in Android, just place your files in "assets" in the root of your Android project, and they'll be picked up by the Android build system when you build the package. Accessing them (in read only mode at least) is trivial using IMG_Load or any other function that works through RWops. If you need to acces files somewhere else, I think you can just use fopen, fread,etc. Gabriel. _______________________________________________ SDL mailing list http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org |
|||||||||||||
|
Re: Android resource management |
wilbefast
|
Not sure I understand. I've always given IMG_Load a filename, which clearly isn't possible here as the file is compressed, inside an archive, somewhere in "/system/app" (I think). Yes, I know that since a .apk is just a .zip it should be theoretically possible to open it and read the contents with some library (zlib?). An yes, we can take this pointer and pass it to SDL (via RWops? Never heard of it up till now) or OpenGL directly. But this seems like a rather dirty, round-about way of doing things, plus really dangerous to boot. I'd think it would be safest to send resources via the JNI, ie. open them in Java (Davlik has easy access to JNI contents) and pass them to the native code. What I'm wondering is whether the SDL port has anything like this implemented or whether it needs to be written from scratch. Is this what you meant? |
|||||||||||||
|
Android resource management |
gabomdq
|
1) Put a image.png inside an "assets" directory in the Android project root (that is where AndroidManifest.xml and build.xml live). 2) Call IMG_Load("image.png") 3) ndk-build, ant build, etc 3) ???? 4) Profit. SDL and Android work their magic behind the scenes, your image.png is going to be placed inside the apk, and you don't have to worry about compression, where it is decompressed or when, it just works. If you want to know the details, I'm afraid you'll have to check for yourself in the source code. This works for SDL_ttf as well if you want to load fonts for example using the same technique (that's as far as I've tried, _image and _ttf, though I think anything that uses RWOps should work in the same way). Gabriel. _______________________________________________ SDL mailing list http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org |
|||||||||||||
|
Re: Android resource management |
wilbefast
|
That's nice and simple - I'll give it a try... Unfortunately it doesn't seem to be working: IMG_Load fails to find the file in the working directory. This despite it being in the apk under /assets. Perhaps I'm using an older version of the port which doesn't include this shortcut - is it a recent addition? edit: found a good example of decompressing files in Java and passing them via the JNI: http://www.philhassey.com/blog/2010/07/22/android-day-3-packaging-assets-jni-and-opengl/ I'd rather get SDL's implementation working though... |
|||||||||||||
|
Android resource management |
gabomdq
|
I don't remember when these patches by Tim Angus where applied but I think it was fairly recent, for more information you should check Bugzilla for the "android" keyword, check the closed tickets, you'll see this patch I'm refering to, the multitouch stuff, and some other changes (like OpenGL ES 2 support). Gabriel. _______________________________________________ SDL mailing list http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org |
|||||||||||||
|
Re: Android resource management |
wilbefast
|
Found it: http://bugzilla.libsdl.org/show_bug.cgi?id=1261 I guess it's time I got the new release of Mercurial, since I don't know whether the version I'm using is compatible with the patch. So: replaced the old SDL C code, plus the SDLActivity class with the new one. Okay, so a little error:
I replaced:
With what I had before:
Working now, except I notices touches are no longer interpreted as mouse clicks so I'll need to modify my code to support the new multi-touch stuff... Still, thanks a lot gabomdq, I can now load images from the apk |
|||||||||||||||||||
|
Re: Android resource management |
wilbefast
|
This works so well I forgot myself a moment and tried to use it for TinyXML - dang, looks like I'll still need to write something that extracts the XML files. Well, if you'll excuse me I'm off to cannibalise some code...
|
|||||||||||
|
[SOLVED] Android resource management |
Jonny D
|
Did you look at TiXmlDocument::Parse()? I don't know where the magic is happening on Android, but if something like SDL_RWFromFile() works by itself, then you might be able to pass the char data to Parse().
Jonny D On Fri, Nov 11, 2011 at 4:54 PM, wilbefast wrote:
|
|||||||||||||
|
Re: [SOLVED] Android resource management |
wilbefast
|
Good idea only one way to find out. Actually two ways: read the code or try it and see what happens. I'm too impatient to read code so I switched to loading using RWops to see what would happen. Here are my results:
Used as follows:
Works on both Linux and Android Assertions are warning are used to wrap stderr or __android_log_print depending on platform. Long story short, XML can now be loaded from the assets folder. Thanks for the pointer |
|||||||||||||||||
|
[SOLVED] Android resource management |
Jonny D
|
Sweet.
Jonny D On Sat, Nov 12, 2011 at 7:41 AM, wilbefast wrote:
|
|||||||||||||
|
Re: [SOLVED] Android resource management |
wilbefast
|
Blog post explaining all this in detail
http://wilbefast.com/2011/11/16/tinyxmlsdl-glue-code/ |
|||||||||||
|