int c_loadDirectory(lua_State *L) { int dir; const char *dirPath; nebu_List *files, *p; int nFiles = 0; // load directory enum from stack int top = lua_gettop(L); // number of arguments if(top != 1) { // wrong number of arguments // lua_error(L, "wrong number of arguments for function " // "c_loadDirectory: should be 1\n"); } if(!lua_isnumber(L, -1)) { // lua_error(L, "number expected for arg1 to function " // "c_loadDirecotry"); } dir = (int) lua_tonumber(L, -1); dirPath = getDirectory(dir); // PATH_ART or PATH_LEVEL or PATH_MUSIC files = readDirectoryContents(dirPath, NULL); lua_newtable(L); for(p = files; p->next; p = p->next) { lua_pushstring(L, p->data); lua_rawseti(L, -2, nFiles + 1); nFiles++; } /* FIXME: when does the list get freed */ return 1; }
void Sound_initTracks(void) { const char *music_path; List *soundList; List *p; int i; music_path = getDirectory( PATH_MUSIC ); soundList = readDirectoryContents(music_path, NULL); if(soundList->next == NULL) { fprintf(stderr, "[sound] no music files found...exiting\n"); exit(1); // FIXME: handle missing songs somewhere else } //soundList->data="revenge_of_cats.it"; i = 1; for(p = soundList; p->next != NULL; p = p->next) { // bugfix: filter track list to readable files (and without directories) char *path = getPossiblePath( PATH_MUSIC, (char*)p->data ); if( path != NULL && fileExists( path ) ) { scripting_RunFormat("tracks[%d] = \"%s\"", i, (char*) p->data); i++; free( path ); } } scripting_Run("setupSoundTrack()"); }
void Sound_initTracks(void) { const char *music_path; nebu_List *soundList; nebu_List *p; int i; music_path = getDirectory( PATH_MUSIC ); soundList = readDirectoryContents(music_path, NULL); if(soundList->next == NULL) { fprintf(stderr, "[sound] no music files found...exiting\n"); nebu_assert(0); exit(1); // TODO: handle missing songs somewhere else } i = 1; for(p = soundList; p->next != NULL; p = p->next) { // bugfix: filter track list to readable files (and without directories) char *path = getPossiblePath( PATH_MUSIC, (char*)p->data ); if( path != NULL && nebu_FS_Test( path ) ) { scripting_RunFormat("tracks[%d] = \"%s\"", i, (char*) p->data); i++; free( path ); } free(p->data); } nebu_List_Free(soundList); scripting_Run("setupSoundTrack()"); }
void initArtpacks() { list *l, *p; int i = 0, n = 0; l = readDirectoryContents(PATH_ART, NULL); for(p = l; p->next != NULL; p = p->next) n++; artpack_list = (char**) malloc((n + 1) * sizeof(char*)); for(p = l; p->next != NULL; p = p->next) { artpack_list[i] = (char*) malloc(strlen( (char*) p->data ) + 1); memcpy(artpack_list[i], p->data, strlen( (char*) p->data ) + 1); printf("loading artpack %s\n", artpack_list[i]); if(strstr(artpack_list[i], "default") == artpack_list[i]) artpack_index = i; i++; } printf("loaded %d artpacks\n", i); artpack_list[i] = NULL; }
int main( int argc, char *argv[] ) { char *path; list *l; #ifdef SOUND int c; #endif #ifdef __FreeBSD__ fpsetmask(0); #endif #ifdef macintosh setupHomeEnvironment (); #endif SystemInit(&argc, argv); #ifndef CURRENT_EQ_DATA_DIR goto_installpath(argv[0]); #endif /* initialize artpack list before loading settigns! */ initArtpacks(); path = getFullPath("settings.txt"); if(path != NULL) initMainGameSettings(path); /* reads defaults from ~/.gltronrc */ else { printf("fatal: could not settings.txt, exiting...\n"); exit(1); } parse_args(argc, argv); consoleInit(); initGameStructures(); resetScores(); /* sound */ path = getMusicPath(MUSIC_DIR); game->settings->soundList = readDirectoryContents(path, SONG_PREFIX); game->settings->soundIndex = -1; l = game->settings->soundList; #ifdef SOUND printf("initializing sound\n"); initSound(); setFxVolume(game->settings->fxVolume); if(l->next != NULL) { char *tmp; tmp = malloc(strlen(path) + 1 + /* seperator */ strlen((char*) l->data) + 1); sprintf(tmp, "%s%c%s", path, SEPERATOR, (char*) l->data); fprintf(stderr, "loading song %s\n", tmp); loadSound(tmp); free(tmp); game->settings->soundIndex = 0; } c = 0; while(l->next != NULL) { l = l->next; c++; } game->settings->soundSongCount = c; if(game->settings->playMusic) playSound(); fprintf(stderr, "setting music volume to %.3f\n", game->settings->musicVolume); setMusicVolume(game->settings->musicVolume); free(path); #endif printf("loading menu\n"); path = getFullPath("menu.txt"); if(path != NULL) pMenuList = loadMenuFile(path); else { printf("fatal: could not load menu.txt, exiting...\n"); exit(1); } printf("menu loaded\n"); free(path); setupDisplay(game->screen); switchCallbacks(&guiCallbacks); switchCallbacks(&guiCallbacks); SystemMainLoop(); return 0; }