views:

983

answers:

2

I am creating a game using the irrlicht c++ 3D graphics engine port to android platform. The graphics engine is written in c++. I need to be able to load meshes and textures etc from c++ code. My current plan is to place all the game asset files in either the res/raw directory or the assets directory then on startup copy these files to the sdcard so they are accessable from the irrlicht c++ code. Is this the best way to make the game media files accessable from c++?

+1  A: 

There are several ways to do this...they each have their own limitations so I can't give a good recommendation without knowing more about your situation. Here are some links to discussions with some advice that may help you out:

http://groups.google.com/group/android-ndk/browse_thread/thread/842ca9d7d82995b0

http://groups.google.com/group/android-ndk/browse_thread/thread/4e25a5dfd46f8fea/1269bcd10bdb066d?lnk=gst&q=apk+compressed#1269bcd10bdb066d

I can give you more specific suggestions if i knew a) How many resources you needed to access b) The size of the largest resource you will encounter, more specifically, are all of your resources < 1MB in size uncompressed?

cjserio
Those are good threads I didn't find before. Here is another I found usefull http://thedevelopersinfo.com/2010/01/13/working-with-sdcards-filesystem-in-android/The game is not well defined yet but here are some appoximationsof files I will need to access from c++approx 8 meshes of approx 400k size (3.2MB)approx 8 textures of approx 50k size (0.4MB)approx 20 textures of approx 20k size (0.4MB)1 texture of 193K (0.193MB)Total approx 4.2MBAlso a video 249K and some sound effects 306K but these will be in the res/raw folder and played in the android media player
slytron
Ok, the reason I ask is that there appears to be a 1MB uncompressed file size limit PER RESOURCE and there also appears to be a maximum resource count of 512. Since it seems like you're under both of those, you can put all of your resources in the "/assets" folder and then access them by using the AssetManager class. If you APK is zipaligned, the AssetManager will memorymap the files for you which will be a big speed improvement.
cjserio
thanks. I believe I have what I need to do.
slytron
A: 

In theory, you can pass the InputStream to native C++ code and have it call its methods. You can even implement an istream on top of those. However, I don't think this is what you're after.

Keep in mind that asset files in the APK are not stored as, well, files. They're compressed and archived - an APK is actually a renamed ZIP file. So I'd recommend copying the asset into a data folder from within Java, then passing the filename of that copy to C++.

This, by the way, completely rules out writing to those assets.

Seva Alekseyev