Changeset 2584


Ignore:
Timestamp:
Mar 12, 2013, 4:54:36 PM (10 years ago)
Author:
sam
Message:

android: open files through the asset manager, meaning Lua works.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/build/android/LolActivity.java

    r2579 r2584  
    1111package net.lolengine;
    1212
    13 import android.app.NativeActivity;
     13import android.app.NativeActivity; /* NativeActivity */
     14import android.os.Bundle; /* Bundle */
    1415
    1516import android.content.res.AssetManager; /* getAssets() */
     
    2728    }
    2829
    29     public LolActivity()
     30    @Override
     31    protected void onCreate(Bundle saved_instance)
    3032    {
    31         nativeInit();
     33        super.onCreate(saved_instance);
     34
     35        m_assets = getAssets();
     36
     37        nativeInit(m_assets);
    3238    }
    3339
    34     private native void nativeInit();
     40    private native void nativeInit(AssetManager assets);
     41
     42    private AssetManager m_assets;
    3543
    3644    /*
     
    4250        try
    4351        {
    44             return BitmapFactory.decodeStream(getAssets().open(name));
     52            return BitmapFactory.decodeStream(m_assets.open(name));
    4553        }
    4654        catch (Exception e) { }
  • trunk/src/platform/android/androidapp.cpp

    r2583 r2584  
    1616
    1717#include <jni.h>
     18#include <android/asset_manager_jni.h>
    1819
    1920#include <EGL/egl.h>
     
    3435JavaVM *g_vm;
    3536jobject g_activity;
     37AAssetManager *g_assets;
    3638}; /* namespace lol */
    3739
     
    4547
    4648extern "C" void
    47 Java_net_lolengine_LolActivity_nativeInit(JNIEnv* env, jobject thiz)
     49Java_net_lolengine_LolActivity_nativeInit(JNIEnv* env, jobject thiz,
     50                                          jobject assets)
    4851{
    4952    Log::Info("Java layer initialising activity 0x%08lx", (long)thiz);
    5053    env->NewGlobalRef(thiz); /* FIXME: never released! */
    5154    g_activity = thiz;
     55    env->NewGlobalRef(assets); /* FIXME: never released! */
     56    g_assets = AAssetManager_fromJava(env, assets);
    5257}
    5358
  • trunk/src/sys/file.cpp

    r2573 r2584  
    1616#   include <sys/paths.h>
    1717#   include <cell/cell_fs.h>
     18#elif __ANDROID__
     19#   include <android/asset_manager_jni.h>
    1820#endif
    1921
     
    2224namespace lol
    2325{
     26
     27#if __ANDROID__
     28extern AAssetManager *g_assets;
     29#endif
    2430
    2531class FileData
     
    3541        if (err != CELL_FS_SUCCEEDED)
    3642            m_fd = -1;
     43#elif __ANDROID__
     44        m_asset = AAssetManager_open(g_assets, file.C(), AASSET_MODE_UNKNOWN);
    3745#elif HAVE_STDIO_H
    3846        /* FIXME: no modes, no error checking, no nothing */
     
    4553#if __CELLOS_LV2__
    4654        return m_fd > -1;
     55#elif __ANDROID__
     56        return !!m_asset;
    4757#elif HAVE_STDIO_H
    4858        return !!m_fd;
     
    6272
    6373        return (int)done;
     74#elif __ANDROID__
     75        return AAsset_read(m_asset, buf, count);
    6476#elif HAVE_STDIO_H
    6577        size_t done = fread(buf, 1, count, m_fd);
     
    99111        if (m_fd >= 0)
    100112            cellFsClose(m_fd);
     113        m_fd = -1;
     114#elif __ANDROID__
     115        if (m_asset)
     116            AAsset_close(m_asset);
     117        m_asset = nullptr;
    101118#elif HAVE_STDIO_H
    102119        if (m_fd)
     
    108125#if __CELLOS_LV2__
    109126    int m_fd;
     127#elif __ANDROID__
     128    AAsset *m_asset;
    110129#elif HAVE_STDIO_H
    111130    FILE *m_fd;
  • trunk/src/sys/init.cpp

    r2506 r2584  
    4949     */
    5050
    51 #if defined HAVE_GETCWD
     51#if __ANDROID__
     52    /* Android assets are accessed using no prefix at all. */
     53    String binarydir = "";
     54#elif defined HAVE_GETCWD
    5255    char *cwd = getcwd(nullptr, 0);
     56    String binarydir = String(cwd ? cwd : ".") + SEPARATOR;
     57    free(cwd);
    5358#elif defined HAVE__GETCWD || (defined _WIN32 && !defined _XBOX)
    5459    char *cwd = _getcwd(nullptr, 0);
    55 #else
    56     char *cwd = nullptr;
    57 #endif
    5860    String binarydir = String(cwd ? cwd : ".") + SEPARATOR;
    5961    free(cwd);
     62#else
     63    String binarydir = "./";
     64#endif
     65
    6066    if (argc > 0)
    6167    {
     
    100106    {
    101107        String rootdir = binarydir;
    102         if (rootdir.Last() != SEPARATOR)
     108        if (rootdir.Count() && rootdir.Last() != SEPARATOR)
    103109            rootdir += SEPARATOR;
    104110        for (int i = 1; i < sourcesubdir.Count(); ++i)
     
    118124    }
    119125
    120     Log::Debug("binary dir: %s\n", binarydir.C());
     126    Log::Debug("binary dir: “%s”\n", binarydir.C());
    121127    for (int i = 0; i < data_dir.Count(); ++i)
    122         Log::Debug("data dir %d/%d: %s\n", i + 1, data_dir.Count(),
     128        Log::Debug("data dir %d/%d: “%s”\n", i + 1, data_dir.Count(),
    123129                   data_dir[i].C());
    124130}
Note: See TracChangeset for help on using the changeset viewer.