Changeset 227 for cpp/common


Ignore:
Timestamp:
04/20/14 01:48:23 (10 years ago)
Author:
Maciej Komosinski
Message:

Android compilation and access to RESOURCES and HOME files

Location:
cpp/common
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • cpp/common/nonstd.h

    r220 r227  
    8181#ifdef __ANDROID__
    8282 #define GET_APP_HOME getAppHome()
    83  #define GET_APP_RESOURCES "./" //w APK trzymamy w katalogu w "assets", bo w "res" nie ma podkatalogow ani odwolywania sie po nazwach
     83 #define GET_APP_RESOURCES "/resrc/" //inside APK, resources are kept in the "assets" subdirectory (in the "res" subdirectory there is no support for subdirectories nor accessing files by name). The prefix /resrc/ is just an indication that lets mfile easily discriminate between HOME (r/w) and RESOURCES (r) locations
    8484#endif
    8585
  • cpp/common/nonstd_math.cpp

    r226 r227  
    2424
    2525
    26 #if defined LINUX || defined TIZEN || defined __ANDROID__
     26#if defined LINUX || defined TIZEN || defined __ANDROID__ || defined IPHONE
    2727
    2828#include <fenv.h>
     
    4444#endif
    4545
    46 
    47 #ifdef IPHONE
    48 
    49 #include <fenv.h>
    50 
    51 void fpExceptInit()
    52 {}
    53 
    54 void fpExceptEnable()
    55 {
    56 feclearexcept(FE_DIVBYZERO | FE_OVERFLOW);
    57 //feenableexcept(FE_DIVBYZERO | FE_OVERFLOW);
    58 }
    59 
    60 void fpExceptDisable()
    61 {
    62 //fedisableexcept(FE_DIVBYZERO | FE_OVERFLOW);
    63 }
    64 #endif
    6546
    6647
  • cpp/common/nonstd_stdio.cpp

    r215 r227  
    139139
    140140#ifdef __ANDROID__
    141 //#include "framsg.h"
     141#include "framsg.h"
    142142#include "nonstd.h"
     143#include "nonstd_stl.h"
    143144MFILE *mfopen(const char *path, const char *mode)
    144145{
    145         NvFile *rfile=NULL; //umie tylko czytac
     146        string respath=GET_APP_RESOURCES; //the macro can be char* or std::string, we don't know (nonstd.h, INITIAL_DIR_IS_RES, cwd.cpp) so we convert it to std::string
     147        //printFM("Opening '%s', mode='%s'",path,mode);
     148        //printFM("GET_APP_RESOURCES='%s'",respath.c_str());
     149        NvFile *rfile=NULL; //can only read
    146150        FILE *rwfile=NULL;
    147         if (strstr(path,GET_APP_RESOURCES)==path) //otwieramy resource! wiec uzywamy czytania z assets
    148         {
    149                 if (path[0]=='.' && path[1]=='/') path+=2; //nie rozpoznaje sciezek "./costam", a w sailorze zrobiles tak ze nie moze byc pusty path bo to jest znacznik ze jest niezainicjowany, dlatego uzywasz "./" i musimy je tu obcinac
    150                 rfile=NvFOpen(path); //"mode" not supported! umie tylko czytac
     151        if (strstr(path,respath.c_str())==path) //opening resource! so we use a dedicated way to read from assets
     152        {
     153                path+=respath.length(); //strip the prefix, we need a relative path in assets
     154                if (strstr(mode,"w"))
     155                        printFM("Warning: attempt to open a read-only resource '%s' in writable mode '%s'",path,mode);
     156                rfile=NvFOpen(path); //"mode" not supported! can only read
     157                //printFM("Opened RES file as %p",rfile);
    151158                if (rfile==NULL) return NULL;
    152         } else //"normalny" dostep (do HOME)
     159        } else //a "normal" access (HOME)
    153160        {
    154161                rwfile=fopen(path,mode);
     162                //printFM("Opened HOME file as %p",rwfile);
    155163                if (rwfile==NULL) return NULL;
    156164        }
     
    174182{
    175183        if (f->rfile)
    176                 return size==0?0:NvFRead(ptr, size, count, f->rfile)/size; //blad nvidii w interpretacji zwracanej wartosci - zwraca liczbe bajtow zamiast liczbe porcji
     184                return NvFRead(ptr, size, count, f->rfile); //nvidia introduced my corrections in SDK v10.14, so a fix is no longer needed here
    177185        else
    178186                return fread(ptr, size, count, f->rwfile);
     
    182190{
    183191        if (f->rfile)
    184                 return 0; //write not supported funkcjami nvidii
     192                return 0; //write not supported in assets using nvidia functions
    185193        else
    186194                return fwrite(ptr, size, count, f->rwfile);
     
    197205{
    198206        if (f->rfile)
    199                 return NvFGets(str, num, f->rfile);
     207        {
     208                char *ret=NvFGets(str, num, f->rfile);
     209                //fixing nvidia inconsistency... their function never returns NULL (fix submitted)
     210                if (ret!=NULL && *ret==0 && num>0) //nothing has been read, must have been eof
     211                        return NULL;
     212                return ret;
     213        }
    200214        else
    201215                return fgets(str,num,f->rwfile);
     
    213227{
    214228        if (f->rfile)
    215                 return NvFSeek(f->rfile, position, type)==-1; // off_t AAsset_seek(AAsset* asset, off_t offset, int whence): Returns the new position on success, or (off_t) -1 on error.
     229                return NvFSeek(f->rfile, position, type); //nvidia introduced my corrections in SDK v10.14, so a fix is no longer needed here
    216230        else
    217231                return fseek(f->rwfile, position, type);
  • cpp/common/nonstd_stdio.h

    r201 r227  
    4545#include <nv_file/nv_file.h>
    4646 struct rwFILE //jedno z dwoch pol jest zainicjowane w zaleznosci od tego gdzie jest plik
    47  {
    48         NvFile *rfile; //umie tylko czytac
     47 { //nvidia uses a similar trick in nv_file.h (STD_FILE and APK_FILE), maybe doing a similar thing here is redundant? but their trick uses some trial-and-error code (see NvFOpen())
     48        NvFile *rfile; //can only read
    4949        FILE *rwfile;
    5050        rwFILE() {rfile=rwfile=NULL;}
Note: See TracChangeset for help on using the changeset viewer.