void loadShaders(JNIEnv *env, jobject &obj) { AAssetManager *asset_manager = AAssetManager_fromJava(env, obj); FILE *fd; fd = android_fopen("vertex.glsl", "r", asset_manager); gVertexShader = readToString(fd); fclose(fd); fd = android_fopen("fragment.glsl", "r", asset_manager); gFragmentShader = readToString(fd); fclose(fd); }
void aboutInit() { char buf[128]; list_t* txt; listItem* it; FILE* fp = android_fopen("data/about.txt", "r"); if(!fp) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't open data/about.txt"); return; } txt = listInit(NULL); while( fgets(buf, 128, fp ) ) { int l = strlen(buf); it = listAppendData(txt, malloc( l+1 ) ); strcpy( (char*)(it->data), buf ); } numLines = txt->count; lines = malloc( sizeof(char*)*numLines ); listAddToArray((void*)lines,txt); listFree(txt); }
long android_asset_get_size(const char *name) { FILE *fl = android_fopen(name, "r"); if (fl == NULL) return -1; fseek(fl, 0, SEEK_END); long len = ftell(fl); return len; }
char* android_asset_get_bytes(const char *name) { FILE *fl = android_fopen(name, "r"); if (fl == NULL) return NULL; fseek(fl, 0, SEEK_END); long len = ftell(fl); char *buf = (char *)malloc(len); fseek(fl, 0, SEEK_SET); size_t loaded = fread(buf, 1, len, fl); if (loaded != len) { fclose(fl); return NULL; } fclose(fl); return buf; }
int packAdd(const char* packDir, int isDLC) { char* buf = malloc(sizeof(char)*2048); char* buf2= malloc(sizeof(char)*1024); char* val = malloc(sizeof(char)*1024); char* set = malloc(sizeof(char)*1024); //This block is for playlists list_t* playList=0; listItem* li=0; playListItem* pli=0; int i; //Counter FILE* f=0; packInfoType* ti = malloc(sizeof(packInfoType)); ti->lives=3; //Default 3 lives, if pack do not define another number. ti->isDLC=isDLC; //Any levels? (Packs are invalid without a levels folder and atleast one level) sprintf(buf, "%s/levels/level000.wzp", packDir); //Initialize list for playlist playList = listInit(_freePlaylistItem); //Open packs/packname/info.ini sprintf(buf, "%s/info.ini", packDir); f = android_fopen(buf, "r"); if(f) { while( fgets(buf, 128, f) ) { stripNewLine(buf); if(splitVals('=',buf,set,val)) { if(strcmp("author", set)==0) { ti->author = malloc( sizeof(char)*(strlen(val)+1+3) ); sprintf(ti->author, "By %s", val); } else if(strcmp("packname", set)==0) { ti->name = malloc( sizeof(char)*(strlen(val)+1) ); strcpy(ti->name,val); } else if(strcmp("comment", set)==0) { ti->comment = malloc( sizeof(char)*(strlen(val)+1+1) ); sprintf(ti->comment, "-%s", val); } else if(strcmp("mus", set)==0) { //mus=00,song if( splitVals(',',val, buf,set ) && splitVals('-',buf,val,buf2) ) { //val= from buf2=to set=song name pli = malloc( sizeof( playListItem ) ); pli->from=atoi(val); pli->to=atoi(buf2); pli->song=malloc(sizeof(char)*strlen(set)+1); strcpy( pli->song, set ); listAppendData( playList, (void*)pli ); } else { SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, " Playlist entry format is mus=XX-XX,song name.ogg where XX-XX is a level range.\n"); } } else if(strcmp("lives", set)==0) { ti->lives = atoi(val); } } //Found = } //reading file //Close the info file. fclose(f); } else { //Fall back if no file was found. SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "Warning: '%s' not found, using defaults.\n",buf); ti->author = malloc( sizeof(char)* 20 ); strcpy(ti->author, "info.ini not found"); ti->comment=ti->author; ti->name = malloc( sizeof(char)*(strlen(packDir)+1) ); strcpy(ti->name, packDir); } //Set path ti->path = malloc( sizeof(char)*(strlen(packDir)+1) ); strcpy(ti->path,packDir); //Set pack icon sprintf(buf, "%s/icon.png", packDir); ti->icon = loadImg(buf); if(!ti->icon) { ti->icon = loadImg( "data/noicon.png" ); } //Check if pack have a "finished" icon. sprintf(buf, "%s/finished.png", packDir); //Set ps.cp before entering makeLevelist, it makes use of packGetFile ps.cp = ti; //Add levels. ti->levels=0; ti->levels=makeLevelList(packDir); //makeLevelList looks in packDir/levels/ //set number of levels in pack ti->numLevels = ti->levels->count - 1 ; //The last level does not count (because it is just a "completed" screen). //Add to list of packages listAppendData( ps.packs, (void*)ti ); //Increase number of available packages ps.numPacks++; //Put playlist songs into levelfiles. li=&playList->begin; while( LISTFWD(playList,li) ) { pli=(playListItem*)li->data; for(i=0; i<ti->numLevels;i++) { if(i >= pli->from && i <= pli->to) { levelInfo(i)->musicFile = malloc( sizeof(char)*strlen(pli->song)+1 ); strcpy(levelInfo(i)->musicFile, pli->song); } } } //Clear playlist data listFree( playList ); free(buf); free(buf2); free(val); free(set); return(ps.numPacks-1); }